From e95a7b3aa2caead21f86f13290a76d3e2e12041c Mon Sep 17 00:00:00 2001 From: Rene Zeldenthuis Date: Fri, 4 Nov 2022 14:02:35 +0100 Subject: [PATCH] - Added basic auth to restart and LED - GUI: show IP address instead of hostname.local --- README.md | 20 +++++++++++++------- html/index.html | 11 ++++++----- include/html_data.h | 2 +- src/main.cpp | 13 +++++++++++++ 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index cae5460..d40be19 100644 --- a/README.md +++ b/README.md @@ -172,26 +172,32 @@ This link can be opened with for example [VLC](https://www.videolan.org/vlc/). ## API -There is a minimum API present to perform some tasks using HTTP requests. +There is a minimum API present to perform some tasks using HTTP requests. For some requests authentication is required. +The authentication used is basic authentication. The user is always admin and the password the access point key.\ +If using a browser, remember that the authentication is stored in the browser session so needs to be entered only once. + The URLs are below: ### GET: /restart -Calling this URL will restart the device. +Calling this URL will restart the device. Authentication is required. ### GET: /config -Calling this URL will start the form for configuring the device in the browser. +Calling this URL will start the form for configuring the device in the browser. Authentication is required. ### GET: /snapshot Calling this URL will return a JPEG snapshot of the camera in the browser. -### GET: /flash?v={value} +This request can also be used (for example using cURL) to save the snapshot to a file. -Calling this URL will set the intensity of the flash LED. -The values must for {value} must be between 0 and 255. -If no v parameter is present, it will be set to the value of the configuration. +### GET: /flash?v={intensity} + +Calling this URL will set the intensity of the flash LED. Authentication is required. + +The parameter v for the intensity must be between 0 (off) and 255 (max). +If no v parameter is present, it will be set to the value of the flash LED intensity from configuration. ## Issues / Nice to know diff --git a/html/index.html b/html/index.html index f91491e..f845706 100644 --- a/html/index.html +++ b/html/index.html @@ -182,26 +182,27 @@ The camera RTSP stream can be found at: rtsp://{{HostName}}:{{RtspPort}}/mjpeg/1 + href="rtsp://{{IpV4}}:{{RtspPort}}/mjpeg/1">rtsp://{{IpV4}}:{{RtspPort}}/mjpeg/1
A snapshot of the camera can be found at: - http://{{HostName}}/snapshot + http://{{IpV4}}/snapshot
The intensity of the flash led (0-255) can be controlled using: - http://{{HostName}}/flash?v=value. - If no value is present, the configuration value is used. + http://{{IpV4}}/flash?v=value. + Authentication is required and if no value is present, the configuration value is used.
Restarting the camera can be done using: - http://{{HostName}}/restart + http://{{IpV4}}/restart. + Authentication is required.
diff --git a/include/html_data.h b/include/html_data.h index 94be165..0bb3322 100644 --- a/include/html_data.h +++ b/include/html_data.h @@ -4,5 +4,5 @@ // ****************************************************************************** -constexpr char file_data_index_html[] = "{{AppTitle}} v{{AppVersion}}

{{ThingName}}


{{#ConfigChanged}} {{/ConfigChanged}}
ESP32
CPU model:
{{ChipModel}} rev. {{ChipRevision}}
CPU speed:
{{CpuFreqMHz}} Mhz
CPU cores:
{{CpuCores}}
RAM size:
{{HeapSize}}
PSRAM size:
{{PsRamSize}}
Flash size:
{{FlashSize}}
Diagnostics
Uptime:
{{Uptime}}
RTSP sessions:
{{NumRTSPSessions}}
Free heap:
{{FreeHeap}}
Max free block:
{{MaxAllocHeap}}
Network
Host name:
{{HostName}}
Mac address:
{{MacAddress}}
Wifi mode:
{{WifiMode}}
Access point:
{{AccessPoint}}
Signal strength:
{{SignalStrength}} dbm
IPv4 address:
{{IpV4}}
IPv6 address:
{{IpV6}}
{{#NetworkState.ApMode}} {{/NetworkState.ApMode}} {{#NetworkState.OnLine}} {{/NetworkState.OnLine}}
Settings
Camera type:
{{CameraType}}
Frame rate:
{{FrameDuration}} ms ({{FrameFrequency}} f/s)
Frame size:
{{FrameSize}}
Frame buffer location:
{{FrameBufferLocation}}
Frame buffers:
{{FrameBuffers}}
JPEG quality:
{{JpegQuality}} (1-100)
Flash LED intensity:
{{FlashLedIntensity}} (0-100)
{{#CameraInitialized}} {{/CameraInitialized}} {{^CameraInitialized}} {{/CameraInitialized}}
Special URLs / API
The camera RTSP stream can be found at: rtsp://{{HostName}}:{{RtspPort}}/mjpeg/1
A snapshot of the camera can be found at: http://{{HostName}}/snapshot
The intensity of the flash led (0-255) can be controlled using: http://{{HostName}}/flash?v=value. If no value is present, the configuration value is used.
Restarting the camera can be done using: http://{{HostName}}/restart
"; +constexpr char file_data_index_html[] = "{{AppTitle}} v{{AppVersion}}

{{ThingName}}


{{#ConfigChanged}} {{/ConfigChanged}}
ESP32
CPU model:
{{ChipModel}} rev. {{ChipRevision}}
CPU speed:
{{CpuFreqMHz}} Mhz
CPU cores:
{{CpuCores}}
RAM size:
{{HeapSize}}
PSRAM size:
{{PsRamSize}}
Flash size:
{{FlashSize}}
Diagnostics
Uptime:
{{Uptime}}
RTSP sessions:
{{NumRTSPSessions}}
Free heap:
{{FreeHeap}}
Max free block:
{{MaxAllocHeap}}
Network
Host name:
{{HostName}}
Mac address:
{{MacAddress}}
Wifi mode:
{{WifiMode}}
Access point:
{{AccessPoint}}
Signal strength:
{{SignalStrength}} dbm
IPv4 address:
{{IpV4}}
IPv6 address:
{{IpV6}}
{{#NetworkState.ApMode}} {{/NetworkState.ApMode}} {{#NetworkState.OnLine}} {{/NetworkState.OnLine}}
Settings
Camera type:
{{CameraType}}
Frame rate:
{{FrameDuration}} ms ({{FrameFrequency}} f/s)
Frame size:
{{FrameSize}}
Frame buffer location:
{{FrameBufferLocation}}
Frame buffers:
{{FrameBuffers}}
JPEG quality:
{{JpegQuality}} (1-100)
Flash LED intensity:
{{FlashLedIntensity}} (0-100)
{{#CameraInitialized}} {{/CameraInitialized}} {{^CameraInitialized}} {{/CameraInitialized}}
Special URLs / API
The camera RTSP stream can be found at: rtsp://{{HostName}}:{{RtspPort}}/mjpeg/1
A snapshot of the camera can be found at: http://{{HostName}}/snapshot
The intensity of the flash led (0-255) can be controlled using: http://{{HostName}}/flash?v=value. Authentication is required and if no value is present, the configuration value is used.
Restarting the camera can be done using: http://{{HostName}}/restart. Authentication is required.
"; constexpr char file_data_restart_html[] = "{{AppTitle}} v{{AppVersion}}

{{ThingName}}


Restart

The device is restarting.


In some cases, the device requires a hard reset (power cycle).

If this page takes longer than a minute, consider performing a power cycle.

Restarting...
"; diff --git a/src/main.cpp b/src/main.cpp index bf9a9fc..5a40f5c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -122,6 +122,12 @@ void handle_restart() { log_v("Handle restart"); + if (!web_server.authenticate("admin", iotWebConf.getApPasswordParameter()->valueBuffer)) + { + web_server.requestAuthentication(); + return; + } + const moustache_variable_t substitutions[] = { {"AppTitle", APP_TITLE}, {"AppVersion", APP_VERSION}, @@ -161,6 +167,13 @@ void handle_snapshot() void handle_flash() { log_v("handle_flash"); + + if (!web_server.authenticate("admin", iotWebConf.getApPasswordParameter()->valueBuffer)) + { + web_server.requestAuthentication(); + return; + } + // If no value present, use value from config auto value = web_server.hasArg("v") ? web_server.arg("v") : flash_led_intensity_val; // If conversion fails, v = 0