194671d387
Hold BOOT (GPIO0) for 10s while running to reboot into the captive portal without needing the current media login (physical access is the proof). This also covers the "forgotten login" case. button.c (new) - button_task polls GPIO0 (pull-up, 50 ms), ignores a press held since boot so download-mode entry is unaffected, and calls wifi_request_portal_physical() after 10s. - Started from app_main() right after wifi_start_provisioning_if_needed(), only when not provisioning, so it also works while the station is retrying an unreachable network. wifi.c - wifi_request_portal_physical(): stores a one-shot "portal requested by button" flag in NVS (namespace "portal") and restarts. NVS is used instead of RTC_DATA_ATTR because the flag was lost across the reset on this board. - wifi_start_provisioning_if_needed(): reads and erases the flag at boot (portal_flag_take) and sets s_physical for that portal session only. Logs the reset reason. - Portal without the button (30 failed reconnects, wifi_request_portal()) stays non-physical and asks for the current login. - /save (Wi-Fi card) now requires cam_auth_verify() unless s_physical. - /auth uses cam_auth_set() when s_physical, else cam_auth_change(). - Shared lockout: 5 wrong logins block /save and /auth until restart (not applied when s_physical). Failed attempts are delayed by 1 s. - Physical portal times out after 180 s (normal portal: 300 s). - Root page gets "var PHYS=0/1" injected before its script via chunked send; with PHYS=1 the "current login" fields are hidden and a banner is shown. - html: added current-login fields (wu/wp) to the Wi-Fi form, wrapped current-login fields in .cur, /save errors are shown to the user. - read_body()/send_text() moved above the handlers. cam_auth.c - New cam_auth_set(): validates and stores a new login with no check of the current one. cam_auth_change() now = cam_auth_verify() + cam_auth_set(). Requirements - cam_auth_load() must run before wifi_start_provisioning_if_needed(), otherwise cam_auth_verify() treats auth as disabled and accepts any login. - cam_auth.h: declare cam_auth_set(); declare wifi_request_portal_physical() where button.c can see it. Tested on board: long press reboots into the AP "ESP32_Setup" instead of reconnecting to the stored network. Not yet tested: Wi-Fi card login gating, lockout, 180 s timeout, portal page rendering on a phone.
44 lines
1.9 KiB
C
44 lines
1.9 KiB
C
#pragma once
|
|
|
|
#include <stdbool.h>
|
|
#include "esp_http_server.h"
|
|
|
|
#define CAM_AUTH_REALM "ESP32-Cam"
|
|
|
|
typedef enum {
|
|
CAM_AUTH_OK = 0,
|
|
CAM_AUTH_BAD_CURRENT, /* current user name / password is wrong */
|
|
CAM_AUTH_BAD_NEW, /* new user name / password breaks the rules */
|
|
CAM_AUTH_STORE_FAILED /* could not write to flash */
|
|
} cam_auth_result_t;
|
|
|
|
cam_auth_result_t cam_auth_set(const char *new_user, const char *new_pass);
|
|
|
|
/* Call once at boot, before Wi-Fi/portal and servers: loads the login stored in flash,
|
|
* or uses the given defaults when nothing was stored yet. */
|
|
void cam_auth_load(const char *default_user, const char *default_pass);
|
|
|
|
/* True when user + password match the current login. */
|
|
bool cam_auth_verify(const char *user, const char *pass);
|
|
|
|
/* Changes the login after checking the current one, and stores it in flash.
|
|
* New user: 3-31 chars (letters, digits . _ -). New password: 8-32 letters/digits. */
|
|
cam_auth_result_t cam_auth_change(const char *old_user, const char *old_pass,
|
|
const char *new_user, const char *new_pass);
|
|
|
|
/* Set the single account used by every service (RTSP, /pic, /stream, /mic, /spk, /vol).
|
|
* user NULL or "" disables authentication completely.
|
|
* Use letters and digits only in the password, it also travels inside URLs. */
|
|
void cam_auth_init(const char *user, const char *pass);
|
|
bool cam_auth_enabled(void);
|
|
|
|
/* ---------- HTTP ----------
|
|
* Accepts either "Authorization: Basic ..." or "?key=<password>" in the URL.
|
|
* On failure it sends 401 itself and returns false, so a handler does:
|
|
* if (!cam_http_check(req)) return ESP_OK; */
|
|
bool cam_http_check(httpd_req_t *req);
|
|
|
|
/* ---------- RTSP (Digest, MD5, no qop) ---------- */
|
|
void cam_rtsp_make_nonce(char out[33]);
|
|
bool cam_rtsp_digest_ok(const char *method, const char *authz_header_value, const char *nonce);
|