Skip to content

Commit 5de2467

Browse files
committed
cleaned user rights, api tokens editor, common ui for all tabs
1 parent 6ebfdca commit 5de2467

File tree

8 files changed

+481
-117
lines changed

8 files changed

+481
-117
lines changed

README.md

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ pip uninstall ser2tcp
5454
--hash-password PASSWORD
5555
Hash password for config file and exit
5656
-c CONFIG, --config CONFIG
57-
configuration in JSON format
57+
configuration in JSON format (default: ~/.config/ser2tcp/config.json)
5858
```
5959

60+
If no config file is specified and default config doesn't exist, creates one with HTTP server on first free port from 20080.
61+
6062
### Verbose
6163

6264
- By default print only ERROR and WARNING messages
@@ -299,31 +301,37 @@ Optional HTTP server for monitoring and management:
299301
```json
300302
{
301303
"http": [
302-
{"address": "0.0.0.0", "port": 8080}
304+
{"name": "main", "address": "0.0.0.0", "port": 8080}
303305
]
304306
}
305307
```
306308

307-
With authentication:
309+
- `name`: optional label for the server (displayed in web UI Settings tab)
310+
- HTTP servers can be added/removed/modified via web UI without restart
311+
312+
With authentication (configured at root level, shared across all HTTP servers):
308313

309314
```json
310315
{
311-
"http": [{
312-
"address": "0.0.0.0",
313-
"port": 8080,
314-
"auth": {
315-
"session_timeout": 3600,
316-
"users": [
317-
{"login": "admin", "password": "sha256:...", "admin": true}
318-
],
319-
"tokens": [
320-
{"token": "my-api-key", "name": "monitoring"}
321-
]
322-
}
323-
}]
316+
"http": [
317+
{"address": "0.0.0.0", "port": 8080}
318+
],
319+
"users": [
320+
{"login": "admin", "password": "sha256:...", "admin": true}
321+
],
322+
"tokens": [
323+
{"token": "my-api-key", "name": "monitoring", "admin": false}
324+
],
325+
"session_timeout": 3600
324326
}
325327
```
326328

329+
- `users`: login credentials with optional `admin` flag and per-user `session_timeout`
330+
- `tokens`: permanent API tokens for automation (no expiration)
331+
- `session_timeout`: global default session timeout in seconds
332+
- First user added (via CLI or web UI) is automatically admin
333+
- Cannot delete last admin (user or token) — at least one admin must exist
334+
327335
Generate password hash:
328336

329337
```bash
@@ -364,20 +372,31 @@ With IP filtering:
364372
| POST | `/api/logout` | no | Invalidate session |
365373
| GET | `/api/status` | yes | Runtime status (serial ports, servers, connections) |
366374
| GET | `/api/detect` | yes | Available serial ports with USB/device attributes |
375+
| GET | `/api/signals` | yes | Signal states for all ports |
376+
| GET | `/api/settings` | yes | Get settings (http servers, session_timeout) |
377+
| DELETE | `/api/ports/<p>/connections/<s>/<c>` | yes | Disconnect client |
367378
| POST | `/api/ports` | admin | Add new port configuration |
368379
| PUT | `/api/ports/<index>` | admin | Update port configuration |
369380
| DELETE | `/api/ports/<index>` | admin | Delete port configuration |
370-
| DELETE | `/api/ports/<p>/connections/<s>/<c>` | admin | Disconnect client |
371381
| PUT | `/api/ports/<index>/signals` | admin | Set RTS/DTR signals |
372-
| GET | `/api/signals` | yes | Signal states for all ports |
373-
| GET | `/api/users` | yes | List users |
382+
| GET | `/api/users` | admin | List users |
374383
| POST | `/api/users` | admin | Add user |
375384
| PUT | `/api/users/<login>` | admin | Update user |
376385
| DELETE | `/api/users/<login>` | admin | Delete user |
386+
| GET | `/api/tokens` | admin | List API tokens |
387+
| POST | `/api/tokens` | admin | Add API token |
388+
| PUT | `/api/tokens/<token>` | admin | Update API token |
389+
| DELETE | `/api/tokens/<token>` | admin | Delete API token |
390+
| PUT | `/api/settings` | admin | Update session_timeout |
391+
| POST | `/api/settings/http` | admin | Add HTTP server |
392+
| PUT | `/api/settings/http/<index>` | admin | Update HTTP server |
393+
| DELETE | `/api/settings/http/<index>` | admin | Delete HTTP server |
377394
| GET | `/xterm/<endpoint>` | no | WebSocket VT100 terminal |
378395
| GET | `/raw/<endpoint>` | no | WebSocket raw terminal |
379396

380-
Authentication: `Authorization: Bearer <token>` header or `?token=<token>` query parameter. Without `auth` configuration, all endpoints are accessible without authentication.
397+
Auth levels: `no` = public, `yes` = any authenticated user, `admin` = admin user/token only.
398+
399+
Authentication: `Authorization: Bearer <token>` header or `?token=<token>` query parameter. Without users/tokens configured, all endpoints are accessible without authentication.
381400

382401
## Usage examples
383402

@@ -407,7 +426,7 @@ telnet localhost 10002
407426
```
408427
cp ser2tcp.service ~/.config/systemd/user/
409428
```
410-
2. Create configuration file `~/.config/ser2tcp.conf`
429+
2. Configuration file will be created automatically at `~/.config/ser2tcp/config.json` on first run
411430
3. Reload user systemd services:
412431
```
413432
systemctl --user daemon-reload

0 commit comments

Comments
 (0)