allow dynamic variables in html and json files only, added some varables

in HTTPPrintSystem
This commit is contained in:
Bogdan Pilyugin 2022-08-27 18:21:36 +02:00
parent 4b4b4cda42
commit 876f7dada9
2 changed files with 26 additions and 11 deletions

View File

@ -212,6 +212,11 @@ static void HTTPPrint_wlev(char *VarData, void *arg)
snprintf(VarData, MAX_DYNVAR_LENGTH, "--"); snprintf(VarData, MAX_DYNVAR_LENGTH, "--");
} }
static void HTTPPrint_defadp(char *VarData, void *arg)
{
GetDefaultNetIFName(VarData);
}
#if CONFIG_WEBGUIAPP_WIFI_ENABLE #if CONFIG_WEBGUIAPP_WIFI_ENABLE
@ -394,16 +399,20 @@ static void HTTPPrint_emacadr(char *VarData, void *arg)
#endif #endif
void HTTPPrint_gsmstat(char *VarData, void *arg)
{
PrintInterfaceState(VarData, arg, GetPPPNetifAdapter());
}
#if CONFIG_WEBGUIAPP_GPRS_ENABLE #if CONFIG_WEBGUIAPP_GPRS_ENABLE
/*GSM MODEM*/ /*GSM MODEM*/
void HTTPPrint_gsmen(char *VarData, void *arg) void HTTPPrint_gsmen(char *VarData, void *arg)
{ {
PrintCheckbox(VarData, arg, GetSysConf()->gsmSettings.Flags1.bIsGSMEnabled); 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) void HTTPPrint_gsmmod(char *VarData, void *arg)
{ {
snprintf(VarData, MAX_DYNVAR_LENGTH, GetPPPModemInfo()->model); snprintf(VarData, MAX_DYNVAR_LENGTH, GetPPPModemInfo()->model);
@ -576,6 +585,8 @@ dyn_var_handler_t HANDLERS_ARRAY[] = {
{ "uptime", sizeof("uptime") - 1, &HTTPPrint_uptime }, { "uptime", sizeof("uptime") - 1, &HTTPPrint_uptime },
{ "tshift", sizeof("tshift") - 1, &HTTPPrint_tshift }, { "tshift", sizeof("tshift") - 1, &HTTPPrint_tshift },
{ "tz", sizeof("tz") - 1, &HTTPPrint_tz }, { "tz", sizeof("tz") - 1, &HTTPPrint_tz },
{ "defadp", sizeof("defadp") - 1, &HTTPPrint_defadp },
{ "wlev", sizeof("wlev") - 1, &HTTPPrint_wlev }, { "wlev", sizeof("wlev") - 1, &HTTPPrint_wlev },
#if CONFIG_WEBGUIAPP_WIFI_ENABLE #if CONFIG_WEBGUIAPP_WIFI_ENABLE
@ -614,10 +625,12 @@ dyn_var_handler_t HANDLERS_ARRAY[] = {
{ "emacadr", sizeof("emacadr") - 1, &HTTPPrint_emacadr }, { "emacadr", sizeof("emacadr") - 1, &HTTPPrint_emacadr },
#endif #endif
{ "gsmstat", sizeof("gsmstat") - 1, &HTTPPrint_gsmstat },
#if CONFIG_WEBGUIAPP_GPRS_ENABLE #if CONFIG_WEBGUIAPP_GPRS_ENABLE
/*GSM modem*/ /*GSM modem*/
{ "gsmen", sizeof("gsmen") - 1, &HTTPPrint_gsmen }, { "gsmen", sizeof("gsmen") - 1, &HTTPPrint_gsmen },
{ "gsmstat", sizeof("gsmstat") - 1, &HTTPPrint_gsmstat },
{ "gsmmod", sizeof("gsmmod") - 1, &HTTPPrint_gsmmod }, { "gsmmod", sizeof("gsmmod") - 1, &HTTPPrint_gsmmod },
{ "gsmopr", sizeof("gsmopr") - 1, &HTTPPrint_gsmopr }, { "gsmopr", sizeof("gsmopr") - 1, &HTTPPrint_gsmopr },
{ "gimei", sizeof("gimei") - 1, &HTTPPrint_gimei }, { "gimei", sizeof("gimei") - 1, &HTTPPrint_gimei },

View File

@ -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"); 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")) else if (IS_FILE_EXT(filename, ".ico"))
{ {
return httpd_resp_set_type(req, "image/x-icon"); 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]; char filepath[FILE_PATH_MAX];
espfs_file_t *file; espfs_file_t *file;
struct espfs_stat_t stat; struct espfs_stat_t stat;
bool isCompressed = false; bool isDynamicVars = false;
const char *filename = get_path_from_uri(filepath, const char *filename = get_path_from_uri(filepath,
((struct file_server_data*) req->user_ctx)->base_path, ((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, "Content-Encoding", "gzip");
httpd_resp_set_hdr(req, "Cache-Control", "max-age=600"); httpd_resp_set_hdr(req, "Cache-Control", "max-age=600");
isCompressed = true;
} }
//prevent mangle compressed font files if (IS_FILE_EXT(filename, ".html") || IS_FILE_EXT(filename, ".json"))
if (IS_FILE_EXT(filename, ".woff2")) isDynamicVars = true;
isCompressed = true;
int pt = 0; int pt = 0;
do do
@ -327,7 +329,7 @@ static esp_err_t GETHandler(httpd_req_t *req)
readBytes = 0; readBytes = 0;
while (pt < fileSize && readBytes < (SCRATCH_BUFSIZE - 64)) while (pt < fileSize && readBytes < (SCRATCH_BUFSIZE - 64))
{ {
if (buf[pt] == '~' && !isCompressed) if (buf[pt] == '~' && isDynamicVars)
{ {
int k = 0; int k = 0;
char DynVarName[16]; char DynVarName[16];