Add Web Interface and REST auth (#3436)

* Ported https://github.com/jomjol/AI-on-the-edge-device/pull/2241 to latest main and extended it for all REST APIs

* .

* fix compile errors

* .

* .

* Update Changelog.md

* Update Changelog.md

---------

Co-authored-by: CaCO3 <caco@ruinelli.ch>
Co-authored-by: michael <Heinrich-Tuning@web.de>
This commit is contained in:
CaCO3
2024-12-25 20:49:47 +01:00
committed by GitHub
parent a348a51f14
commit 2986c6122d
16 changed files with 231 additions and 47 deletions

View File

@@ -33,6 +33,8 @@
#include "configFile.h"
#include "server_main.h"
#include "server_camera.h"
#include "basic_auth.h"
#ifdef ENABLE_MQTT
#include "server_mqtt.h"
#endif //ENABLE_MQTT
@@ -429,6 +431,8 @@ extern "C" void app_main(void)
StatusLED(WLAN_INIT, 3, true);
return;
}
init_basic_auth();
}
else if (iWLANStatus == -1) { // wlan.ini not available, potentially empty or content not readable
StatusLED(WLAN_INIT, 1, true);

View File

@@ -17,6 +17,7 @@
#include "MainFlowControl.h"
#include "esp_log.h"
#include "basic_auth.h"
#include "esp_chip_info.h"
#include <stdio.h>
@@ -408,7 +409,7 @@ void register_server_main_uri(httpd_handle_t server, const char *base_path)
httpd_uri_t info_get_handle = {
.uri = "/info", // Match all URIs of type /path/to/file
.method = HTTP_GET,
.handler = info_get_handler,
.handler = APPLY_BASIC_AUTH_FILTER(info_get_handler),
.user_ctx = (void*) base_path // Pass server data as context
};
httpd_register_uri_handler(server, &info_get_handle);
@@ -416,7 +417,7 @@ void register_server_main_uri(httpd_handle_t server, const char *base_path)
httpd_uri_t sysinfo_handle = {
.uri = "/sysinfo", // Match all URIs of type /path/to/file
.method = HTTP_GET,
.handler = sysinfo_handler,
.handler = APPLY_BASIC_AUTH_FILTER(sysinfo_handler),
.user_ctx = (void*) base_path // Pass server data as context
};
httpd_register_uri_handler(server, &sysinfo_handle);
@@ -424,7 +425,7 @@ void register_server_main_uri(httpd_handle_t server, const char *base_path)
httpd_uri_t starttime_tmp_handle = {
.uri = "/starttime", // Match all URIs of type /path/to/file
.method = HTTP_GET,
.handler = starttime_get_handler,
.handler = APPLY_BASIC_AUTH_FILTER(starttime_get_handler),
.user_ctx = NULL // Pass server data as context
};
httpd_register_uri_handler(server, &starttime_tmp_handle);
@@ -432,7 +433,7 @@ void register_server_main_uri(httpd_handle_t server, const char *base_path)
httpd_uri_t img_tmp_handle = {
.uri = "/img_tmp/*", // Match all URIs of type /path/to/file
.method = HTTP_GET,
.handler = img_tmp_virtual_handler,
.handler = APPLY_BASIC_AUTH_FILTER(img_tmp_virtual_handler),
.user_ctx = (void*) base_path // Pass server data as context
};
httpd_register_uri_handler(server, &img_tmp_handle);
@@ -440,7 +441,7 @@ void register_server_main_uri(httpd_handle_t server, const char *base_path)
httpd_uri_t main_rest_handle = {
.uri = "/*", // Match all URIs of type /path/to/file
.method = HTTP_GET,
.handler = hello_main_handler,
.handler = APPLY_BASIC_AUTH_FILTER(hello_main_handler),
.user_ctx = (void*) base_path // Pass server data as context
};
httpd_register_uri_handler(server, &main_rest_handle);

View File

@@ -29,6 +29,7 @@
#include "Helper.h"
#include "statusled.h"
#include "server_ota.h"
#include "basic_auth.h"
#include "lwip/err.h"
#include "lwip/sys.h"
@@ -468,7 +469,7 @@ httpd_handle_t start_webserverAP(void)
httpd_uri_t reboot_handle = {
.uri = "/reboot", // Match all URIs of type /path/to/file
.method = HTTP_GET,
.handler = reboot_handlerAP,
.handler = APPLY_BASIC_AUTH_FILTER(reboot_handlerAP),
.user_ctx = NULL // Pass server data as context
};
httpd_register_uri_handler(server, &reboot_handle);
@@ -476,7 +477,7 @@ httpd_handle_t start_webserverAP(void)
httpd_uri_t config_ini_handle = {
.uri = "/config", // Match all URIs of type /path/to/file
.method = HTTP_GET,
.handler = config_ini_handler,
.handler = APPLY_BASIC_AUTH_FILTER(config_ini_handler),
.user_ctx = NULL // Pass server data as context
};
httpd_register_uri_handler(server, &config_ini_handle);
@@ -485,7 +486,7 @@ httpd_handle_t start_webserverAP(void)
httpd_uri_t file_uploadAP = {
.uri = "/upload/*", // Match all URIs of type /upload/path/to/file
.method = HTTP_POST,
.handler = upload_post_handlerAP,
.handler = APPLY_BASIC_AUTH_FILTER(upload_post_handlerAP),
.user_ctx = NULL // Pass server data as context
};
httpd_register_uri_handler(server, &file_uploadAP);
@@ -493,7 +494,7 @@ httpd_handle_t start_webserverAP(void)
httpd_uri_t test_uri = {
.uri = "*",
.method = HTTP_GET,
.handler = test_handler,
.handler = APPLY_BASIC_AUTH_FILTER(test_handler),
.user_ctx = NULL
};
httpd_register_uri_handler(server, &test_uri);