Merge branch 'main_sdcard' into 'main'

Main sdcard

See merge request userbogd/webguiapp!6
This commit is contained in:
Bogdan Pilyugin 2024-05-08 14:43:23 +00:00
commit cda4bc7722
2 changed files with 17 additions and 4 deletions

View File

@ -57,19 +57,24 @@ void regHTTPUserAppHandlers(char *url,
}
#define BASIC_LOGIN_LENGTH 31
#define BASIC_PASS_LENGTH 31
#define BASIC_DECODED_LENGTH (BASIC_LOGIN_LENGTH + BASIC_PASS_LENGTH + 1 + 1)
#define BASIC_ENCODED_LENGTH (BASIC_DECODED_LENGTH * 4 / 3)
static esp_err_t CheckAuth(httpd_req_t *req)
{
unsigned char pass[18] = { 0 }; //max length of login:password decoded string
unsigned char inp[31]; //max length of login:password coded string plus Basic
unsigned char pass[BASIC_DECODED_LENGTH] = { 0 }; //max length of login:password decoded string
unsigned char inp[BASIC_ENCODED_LENGTH]; //max length of login:password coded string plus Basic
const char keyword1[] = "Basic ";
const int keyword1len = sizeof(keyword1) - 1;
if (httpd_req_get_hdr_value_len(req, "Authorization") > 31)
if (httpd_req_get_hdr_value_len(req, "Authorization") > BASIC_ENCODED_LENGTH)
{
httpd_resp_set_hdr(req, "Connection", "close");
httpd_resp_send_err(req, HTTPD_431_REQ_HDR_FIELDS_TOO_LARGE, "Authorization field value is too large");
return ESP_FAIL;
}
httpd_req_get_hdr_value_str(req, "Authorization", (char*) inp, 31);
httpd_req_get_hdr_value_str(req, "Authorization", (char*) inp, BASIC_ENCODED_LENGTH);
unsigned char *pt = memmem(inp, sizeof(inp), keyword1, keyword1len);
if (pt)
{

View File

@ -369,12 +369,20 @@ static void funct_exec(char *argres, int rw)
static void funct_file_list(char *argres, int rw)
{
#if CONFIG_SDCARD_ENABLE
FileListHandler(argres, rw, "/sdcard/");
#else
FileListHandler(argres, rw, "/data/");
#endif
}
static void funct_file_block(char *argres, int rw)
{
#if CONFIG_SDCARD_ENABLE
FileBlockHandler(argres, rw, "/sdcard/");
#else
FileBlockHandler(argres, rw, "/data/");
#endif
}
#if CONFIG_SDCARD_ENABLE