add more device fields
This commit is contained in:
@@ -105,24 +105,32 @@ and `Tunnel-Private-Group-Id=<vlanid>`.
|
||||
|
||||
A device is a client identified by its MAC address (used as the RADIUS `username`).
|
||||
One device spans three tables: `radcheck` (MAC = password), `radusergroup` (group
|
||||
membership), and `customers` (status). MAC input is normalized to uppercase,
|
||||
hyphen-separated (`AA-BB-CC-DD-EE-FF`); colons and lowercase are accepted.
|
||||
membership), and `customers` (status + human metadata). MAC input is normalized to
|
||||
uppercase, hyphen-separated (`AA-BB-CC-DD-EE-FF`); colons and lowercase are accepted.
|
||||
|
||||
The `customers` table also carries **human-only metadata that RADIUS never reads**:
|
||||
`name`, `phone`, and `device_alias`. These are collected at device creation.
|
||||
|
||||
| Action | Request |
|
||||
|------------------|-----------------------------------------------------|
|
||||
| List devices | `GET /device/` → `{total,limit,offset,items:[{mac_address,group,status}]}` |
|
||||
| List devices | `GET /device/` → `{total,limit,offset,items:[{mac_address,group,status,name,phone,alias}]}` |
|
||||
| Get one device | `GET /device/{mac_address}` |
|
||||
| Add a device | `POST /device/add` body `{"mac_address":"14-99-3E-74-CB-7F","group":"staff"}` |
|
||||
| Edit a device | `POST /device/edit` body `{"mac_address":"...","group":"...","status":"..."}` |
|
||||
| Add a device | `POST /device/add` body `{"mac_address":"14-99-3E-74-CB-7F","group":"staff","name":"Ali Hassan","phone":"7712345","alias":"Living Room TV"}` |
|
||||
| Edit a device | `POST /device/edit` body `{"mac_address":"...", group?, status?, name?, phone?, alias?}` |
|
||||
| Delete a device | `DELETE /device/{mac_address}` (removes all 3 rows) |
|
||||
|
||||
On **add**, `name` and `phone` are **required**; `alias` is **optional**. They are
|
||||
stored in `customers.name`, `customers.phone`, `customers.device_alias` and returned
|
||||
on every device response (`alias` mirrors the `device_alias` column).
|
||||
|
||||
- **Add** inserts a `radcheck` password (`Cleartext-Password := MAC`), a
|
||||
`radusergroup` row (`priority 1`), and a `customers` row (`status = paid`). The
|
||||
`group` must already exist in `radgroupreply` or you get `400`.
|
||||
- **Edit** accepts `group` and/or `status` — supply either or both (at least one
|
||||
required). A new `group` must exist in `radgroupreply` (`400` otherwise).
|
||||
`status` must be one of `new` / `paid` / `unpaid`. In the DB the group is stored
|
||||
in the `radusergroup.groupname` column.
|
||||
- **Edit** accepts any subset of `group`, `status`, `name`, `phone`, `alias` (at
|
||||
least one required); omitted fields are left unchanged. A new `group` must exist
|
||||
in `radgroupreply` (`400` otherwise). `status` must be one of `new` / `paid` /
|
||||
`unpaid`. In the DB the group is stored in the `radusergroup.groupname` column and
|
||||
`alias` in `customers.device_alias`.
|
||||
- Adding a device whose MAC already exists → `409`.
|
||||
|
||||
## Examples
|
||||
@@ -159,11 +167,11 @@ curl http://10.0.1.235:8000/vlan/55 \
|
||||
curl http://10.0.1.235:8000/device/ \
|
||||
-H "X-API-Key: staging-dev-key-change-me-7f3a9c1e5b" -s | jq
|
||||
|
||||
# Add a device (MAC + existing group)
|
||||
# Add a device (MAC + existing group + name/phone required, alias optional)
|
||||
curl http://10.0.1.235:8000/device/add \
|
||||
-H "X-API-Key: staging-dev-key-change-me-7f3a9c1e5b" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"mac_address":"14-99-3E-74-CB-7F","group":"staff"}' -s | jq
|
||||
-d '{"mac_address":"14-99-3E-74-CB-7F","group":"staff","name":"Ali Hassan","phone":"7712345","alias":"Living Room TV"}' -s | jq
|
||||
|
||||
# Edit a device (any one field: groupname and/or status)
|
||||
curl http://10.0.1.235:8000/device/edit \
|
||||
|
||||
Reference in New Issue
Block a user