Files
led-controller/sim-controller/components/sim/sim_stubs.c
T
jimmyandClaude Haiku 5.5 f0615dc1b7 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>
2026-11-17 00:29:04 +13:00

66 lines
1.5 KiB
C

// Host build: what the board's hardware files (mic.c, ota.c, littlefs) provide, without hardware
#include "auth.h"
#include <string.h>
#include <sys/stat.h>
#include "esp_littlefs.h"
#include "esp_log.h"
#include "beat.h"
#include "mic.h"
#include "ota.h"
esp_err_t esp_vfs_littlefs_register(const esp_vfs_littlefs_conf_t *conf)
{
mkdir(conf->base_path, 0755);
return ESP_OK;
}
#ifndef LED_DESKTOP_ALSA
// No microphone: audio stays stopped, so the simulated-BPM clock times sequences
esp_err_t mic_start(void)
{
return beat_start(MIC_SAMPLE_RATE); // never fed: no beats detected, the BPM clock stands in
}
void mic_get_level(mic_level_t *out)
{
out->rms_dbfs = -120;
out->peak_dbfs = -120;
out->spl_db = 0;
}
esp_err_t mic_stream_open(void)
{
return ESP_ERR_NOT_SUPPORTED;
}
size_t mic_stream_read(void *buf, size_t len, TickType_t timeout)
{
(void)buf;
(void)len;
vTaskDelay(timeout ? timeout : 1);
return 0;
}
void mic_stream_close(void)
{
}
#endif // LED_DESKTOP_ALSA
void ota_confirm_later(void)
{
}
static esp_err_t ota_unsupported(httpd_req_t *req)
{
httpd_resp_set_status(req, "501 Not Implemented");
httpd_resp_set_type(req, "application/json");
return httpd_resp_sendstr(req, "{\"error\":\"firmware OTA is not available in the simulator\"}");
}
esp_err_t ota_register(httpd_handle_t server)
{
const httpd_uri_t u = { .uri = "/ota", .method = HTTP_POST, .handler = ota_unsupported };
return auth_register_uri(server, &u);
}