Restore Default Configuration button for wifi ap page

pull/49/head
Farkas Szilárd 2022-07-07 11:23:59 +02:00
rodzic 7d4b309534
commit 22ed8c76f9
1 zmienionych plików z 15 dodań i 1 usunięć

Wyświetl plik

@ -420,7 +420,14 @@ static void ParmForm_AP(httpd_req_t *Req) // Wi-Fi access point parameters { cha
httpd_resp_sendstr_chunk(Req, "</form>\n"); }
#endif
static void ParmForm_Defaults(httpd_req_t *Req)
{
httpd_resp_sendstr_chunk(Req, "\
<form action=\"/parm.html\" method=\"POST\" onsubmit=\"return confirm('Are you sure to restore default configuration?')\">\n\
<input type=\"submit\" value=\"Restore Default Configuration\">\n\
<input type=\"hidden\" name=\"Defaults\" value=\"1\">\n\
</form>\n");
}
static void ParmForm_Restart(httpd_req_t *Req)
{
@ -794,6 +801,7 @@ static void Html_End(httpd_req_t *Req)
static esp_err_t parm_post_handler(httpd_req_t *Req)
{
bool Restart=0;
bool Defaults=0;
/* Destination buffer for content of HTTP POST request.
* httpd_req_recv() accepts char* only, but content could
* as well be any binary data (needs type casting).
@ -829,6 +837,7 @@ static esp_err_t parm_post_handler(httpd_req_t *Req)
#endif
char *Line=URL;
Restart = strstr(Line,"Restart=1");
Defaults = strstr(Line,"Defaults=1");
for( ; ; )
{ Parameters.ReadLine(Line);
Line = strchr(Line, '&'); if(Line==0) break;
@ -836,6 +845,9 @@ static esp_err_t parm_post_handler(httpd_req_t *Req)
free(URL);
Parameters.WriteToNVS();
if(Defaults)
{ Parameters.setDefault(); }
if(Restart)
{
#ifdef WITH_SPIFFS
@ -869,6 +881,8 @@ static esp_err_t parm_get_handler(httpd_req_t *Req)
ParmForm_Other(Req);
ParmForm_Defaults(Req);
ParmForm_Restart(Req);
Html_End(Req);