From 876f7dada9ab0f77090a47a76f43db0d1883b522 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sat, 27 Aug 2022 18:21:36 +0200 Subject: [PATCH] allow dynamic variables in html and json files only, added some varables in HTTPPrintSystem --- src/HTTPPrintSystem.c | 23 ++++++++++++++++++----- src/HTTPServer.c | 14 ++++++++------ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/HTTPPrintSystem.c b/src/HTTPPrintSystem.c index fa69a78..c008abc 100644 --- a/src/HTTPPrintSystem.c +++ b/src/HTTPPrintSystem.c @@ -212,6 +212,11 @@ static void HTTPPrint_wlev(char *VarData, void *arg) snprintf(VarData, MAX_DYNVAR_LENGTH, "--"); } +static void HTTPPrint_defadp(char *VarData, void *arg) +{ + GetDefaultNetIFName(VarData); +} + #if CONFIG_WEBGUIAPP_WIFI_ENABLE @@ -394,16 +399,20 @@ static void HTTPPrint_emacadr(char *VarData, void *arg) #endif + +void HTTPPrint_gsmstat(char *VarData, void *arg) +{ + PrintInterfaceState(VarData, arg, GetPPPNetifAdapter()); +} + + #if CONFIG_WEBGUIAPP_GPRS_ENABLE /*GSM MODEM*/ void HTTPPrint_gsmen(char *VarData, void *arg) { PrintCheckbox(VarData, arg, GetSysConf()->gsmSettings.Flags1.bIsGSMEnabled); } -void HTTPPrint_gsmstat(char *VarData, void *arg) -{ - PrintInterfaceState(VarData, arg, GetPPPNetifAdapter()); -} + void HTTPPrint_gsmmod(char *VarData, void *arg) { snprintf(VarData, MAX_DYNVAR_LENGTH, GetPPPModemInfo()->model); @@ -576,6 +585,8 @@ dyn_var_handler_t HANDLERS_ARRAY[] = { { "uptime", sizeof("uptime") - 1, &HTTPPrint_uptime }, { "tshift", sizeof("tshift") - 1, &HTTPPrint_tshift }, { "tz", sizeof("tz") - 1, &HTTPPrint_tz }, + + { "defadp", sizeof("defadp") - 1, &HTTPPrint_defadp }, { "wlev", sizeof("wlev") - 1, &HTTPPrint_wlev }, #if CONFIG_WEBGUIAPP_WIFI_ENABLE @@ -614,10 +625,12 @@ dyn_var_handler_t HANDLERS_ARRAY[] = { { "emacadr", sizeof("emacadr") - 1, &HTTPPrint_emacadr }, #endif + { "gsmstat", sizeof("gsmstat") - 1, &HTTPPrint_gsmstat }, + #if CONFIG_WEBGUIAPP_GPRS_ENABLE /*GSM modem*/ { "gsmen", sizeof("gsmen") - 1, &HTTPPrint_gsmen }, - { "gsmstat", sizeof("gsmstat") - 1, &HTTPPrint_gsmstat }, + { "gsmmod", sizeof("gsmmod") - 1, &HTTPPrint_gsmmod }, { "gsmopr", sizeof("gsmopr") - 1, &HTTPPrint_gsmopr }, { "gimei", sizeof("gimei") - 1, &HTTPPrint_gimei }, diff --git a/src/HTTPServer.c b/src/HTTPServer.c index 8e5fd64..e38296e 100644 --- a/src/HTTPServer.c +++ b/src/HTTPServer.c @@ -116,6 +116,10 @@ static esp_err_t set_content_type_from_file(httpd_req_t *req, { return httpd_resp_set_type(req, "image/jpeg"); } + else if (IS_FILE_EXT(filename, ".png")) + { + return httpd_resp_set_type(req, "image/png"); + } else if (IS_FILE_EXT(filename, ".ico")) { return httpd_resp_set_type(req, "image/x-icon"); @@ -236,7 +240,7 @@ static esp_err_t GETHandler(httpd_req_t *req) char filepath[FILE_PATH_MAX]; espfs_file_t *file; struct espfs_stat_t stat; - bool isCompressed = false; + bool isDynamicVars = false; const char *filename = get_path_from_uri(filepath, ((struct file_server_data*) req->user_ctx)->base_path, @@ -314,12 +318,10 @@ static esp_err_t GETHandler(httpd_req_t *req) { httpd_resp_set_hdr(req, "Content-Encoding", "gzip"); httpd_resp_set_hdr(req, "Cache-Control", "max-age=600"); - isCompressed = true; } - //prevent mangle compressed font files - if (IS_FILE_EXT(filename, ".woff2")) - isCompressed = true; + if (IS_FILE_EXT(filename, ".html") || IS_FILE_EXT(filename, ".json")) + isDynamicVars = true; int pt = 0; do @@ -327,7 +329,7 @@ static esp_err_t GETHandler(httpd_req_t *req) readBytes = 0; while (pt < fileSize && readBytes < (SCRATCH_BUFSIZE - 64)) { - if (buf[pt] == '~' && !isCompressed) + if (buf[pt] == '~' && isDynamicVars) { int k = 0; char DynVarName[16];