feat: users, roles and per-area permissions, production demo image
The controller checks every route against the signed-in user's role, with levels none, view, control and edit per area. Guests get the permissions of a built-in guest role. Auth stays off until the first user exists; LED_ADMIN_USER and LED_ADMIN_PASSWORD create the first admin. Sessions are cookies, passwords are PBKDF2-SHA256, and logins lock per username after five failures. The simulator's WebSocket checks the view permission at handshake and per frame; /ws needs devices control. The web UI gets a sign-in button, a sign-in prompt on refused changes, and a users and roles screen. Also: the device build gets the bridge include path and forward type it was missing, Dockerfile.sim runs non-root, and Dockerfile.prod with docker-compose.prod.yml runs the controller on an internal network behind Caddy for HTTPS. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
02440be55d
commit
f0615dc1b7
26 files changed
+2116
-23
No files matched your search
@@ -22,6 +22,7 @@
|
||||
* "direction" the way it runs (degrees clockwise from +y), "mac" the driver. Each bar's flash is
|
||||
* <db>/sim/flash/<mac>.json, so a bar keeps its presets in every room it appears in.
|
||||
*/
|
||||
#include "auth.h"
|
||||
#include "sim_rig.h"
|
||||
|
||||
#include <ctype.h>
|
||||
@@ -630,6 +631,9 @@ bool sim_rig_tx(const uint8_t *frame, size_t len)
|
||||
|
||||
static esp_err_t ws_open(httpd_req_t *req)
|
||||
{
|
||||
if (auth_ws_admit(req, "sim", AUTH_VIEW) != ESP_OK) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
int fd = httpd_req_to_sockfd(req);
|
||||
xSemaphoreTake(s_tx_mu, portMAX_DELAY);
|
||||
int old = page_open_locked() ? s_page_fd : -1;
|
||||
@@ -686,6 +690,9 @@ static esp_err_t ws_handler(httpd_req_t *req)
|
||||
}
|
||||
f.payload = buf;
|
||||
err = httpd_ws_recv_frame(req, &f, f.len);
|
||||
if (err == ESP_OK && !auth_ws_allowed(httpd_req_to_sockfd(req), "sim", AUTH_VIEW)) {
|
||||
err = ESP_FAIL; // closes the socket: the socket was not admitted at its handshake
|
||||
}
|
||||
if (err == ESP_OK) {
|
||||
buf[f.len] = 0;
|
||||
if (f.type == HTTPD_WS_TYPE_BINARY) {
|
||||
@@ -981,15 +988,15 @@ esp_err_t sim_rig_register(httpd_handle_t server)
|
||||
static const httpd_method_t METHODS[] = { HTTP_GET, HTTP_POST, HTTP_PUT, HTTP_DELETE };
|
||||
for (size_t i = 0; i < 4 && err == ESP_OK; i++) {
|
||||
const httpd_uri_t u = { .uri = "/sim/api/*", .method = METHODS[i], .handler = api_handler };
|
||||
err = httpd_register_uri_handler(server, &u);
|
||||
err = auth_register_uri(server, &u);
|
||||
}
|
||||
const httpd_uri_t root = { .uri = "/sim", .method = HTTP_GET, .handler = page_handler };
|
||||
const httpd_uri_t files = { .uri = "/sim/*", .method = HTTP_GET, .handler = page_handler };
|
||||
if (err == ESP_OK) {
|
||||
err = httpd_register_uri_handler(server, &root);
|
||||
err = auth_register_uri(server, &root);
|
||||
}
|
||||
if (err == ESP_OK) {
|
||||
err = httpd_register_uri_handler(server, &files);
|
||||
err = auth_register_uri(server, &files);
|
||||
}
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "register: %s", esp_err_to_name(err));
|
||||
|
||||
Reference in new issue
Block a user