# 5dkey Credential Server 2.0

Backend server for 5dkey Smart Lock System - manages users, devices, sites, and eKey generation.

## Requirements

- PHP 7.4+ with SQLite extension
- Web server (Apache/Nginx)

## Setup

1. Clone repository to web root
2. Ensure `config/database.php` has correct paths
3. Database (`5dkey.db`) will be created automatically on first run
4. Access via browser: `http://your-server/5dkey-credential-server/`

## Structure

```
├── index.php           # Main UI (tabbed interface)
├── config/
│   └── database.php    # Database configuration
├── includes/
│   ├── Database.php    # SQLite wrapper
│   └── EKeyGenerator.php # JWT eKey generation
├── api/
│   ├── users.php       # User CRUD
│   ├── sites.php       # Site management
│   ├── devices.php     # Device/lock management
│   ├── ekeys.php       # eKey generation
│   ├── master-ekeys.php # Master eKey management
│   ├── push-sync.php   # FCM push sync
│   ├── push-alert.php  # FCM battery alerts
│   └── session.php     # Session management
├── css/style.css
└── js/app.js
```

## API Endpoints

| Endpoint | Method | Description |
|----------|--------|-------------|
| `/api/users.php` | GET/POST/DELETE | User management |
| `/api/sites.php` | GET/POST/DELETE | Site management |
| `/api/devices.php` | GET/POST/DELETE | Device management |
| `/api/ekeys.php` | POST | Generate eKey |
| `/api/master-ekeys.php` | GET/POST/DELETE | Master eKey slots |

## License

(c) Sitepics.app Pty Ltd (5dkey) - All rights reserved
