diff --git a/Readme.md b/Readme.md index 4b12d93..3fab105 100644 --- a/Readme.md +++ b/Readme.md @@ -55,6 +55,8 @@ Afterwards use a Bonjour Browser, the address ESP32NMEA2k.local or the ip addres You will get a small UI to watch the status and make settings. If you want to connect to another wifi network, just enter the credentials in the wifi client tab and enable the wifi client. For all the potential inputs and outputs (NMEA2000, USB, TCP, RS485) you can set the configuration including NMEA0183 filtering. +To store your changes you will be asked for an admin password. The initial one is esp32admin. You can change this password at the config/system tab (and even completely disable it). +Be careful to notice the password - you can only recover from a lost password with a factory reset of the device (long press the led button until it goes blue->red->green). On the data page you will have a small dashboard for the currently received data. On the status page you can check the number of messages flowing in and out. diff --git a/src/main.cpp b/src/main.cpp index 6731cbc..2fa0ec9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -407,28 +407,36 @@ bool delayedRestart(){ return xTaskCreate([](void *p){ GwLog *logRef=(GwLog *)p; logRef->logDebug(GwLog::LOG,"delayed reset started"); - delay(500); + delay(800); ESP.restart(); vTaskDelete(NULL); - },"reset",1000,&logger,0,NULL) == pdPASS; + },"reset",2000,&logger,0,NULL) == pdPASS; } ApiImpl *apiImpl=new ApiImpl(MIN_USER_TASK); GwUserCode userCodeHandler(apiImpl,&mainLock); #define JSON_OK "{\"status\":\"OK\"}" +#define JSON_INVALID_PASS F("{\"status\":\"invalid password\"}") //WebServer requests that should //be processed inside the main loop //this prevents us from the need to sync all the accesses class ResetRequest : public GwRequestMessage { + String hash; public: - ResetRequest() : GwRequestMessage(F("application/json"),F("reset")){}; + ResetRequest(String hash) : GwRequestMessage(F("application/json"),F("reset")){ + this->hash=hash; + }; protected: virtual void processRequest() { logger.logDebug(GwLog::LOG, "Reset Button"); + if (! checkPass(hash)){ + result=JSON_INVALID_PASS; + return; + } result = JSON_OK; if (!delayedRestart()){ logger.logDebug(GwLog::ERROR,"cannot initiate restart"); @@ -552,8 +560,18 @@ protected: { bool ok = true; String error; + String hash; + auto it=args.find("_hash"); + if (it != args.end()){ + hash=it->second; + } + if (! checkPass(hash)){ + result=JSON_INVALID_PASS; + return; + } for (StringMap::iterator it = args.begin(); it != args.end(); it++) { + if (it->first.indexOf("_")>= 0) continue; bool rt = config.updateValue(it->first, it->second); if (!rt) { @@ -582,12 +600,19 @@ protected: }; class ResetConfigRequest : public GwRequestMessage { + String hash; public: - ResetConfigRequest() : GwRequestMessage(F("application/json"),F("resetConfig")){}; + ResetConfigRequest(String hash) : GwRequestMessage(F("application/json"),F("resetConfig")){ + this->hash=hash; + }; protected: virtual void processRequest() { + if (! checkPass(hash)){ + result=JSON_INVALID_PASS; + return; + } config.reset(true); logger.logString("reset config, restart"); result = JSON_OK; @@ -732,7 +757,7 @@ void setup() { logger.flush(); webserver.registerMainHandler("/api/reset", [](AsyncWebServerRequest *request)->GwRequestMessage *{ - return new ResetRequest(); + return new ResetRequest(request->arg("_hash")); }); webserver.registerMainHandler("/api/capabilities", [](AsyncWebServerRequest *request)->GwRequestMessage *{ return new CapabilitiesRequest(); @@ -757,7 +782,7 @@ void setup() { return msg; }); webserver.registerMainHandler("/api/resetConfig", [](AsyncWebServerRequest *request)->GwRequestMessage * - { return new ResetConfigRequest(); }); + { return new ResetConfigRequest(request->arg("_hash")); }); webserver.registerMainHandler("/api/boatData", [](AsyncWebServerRequest *request)->GwRequestMessage * { return new BoatDataRequest(); }); webserver.registerMainHandler("/api/boatDataString", [](AsyncWebServerRequest *request)->GwRequestMessage * diff --git a/web/index.css b/web/index.css index 232097a..b338b27 100644 --- a/web/index.css +++ b/web/index.css @@ -195,14 +195,14 @@ body { overflow-y: auto; } - div#overlay { + .overlay { margin: auto; background-color: white; padding: 0.5em; max-width: 100%; box-sizing: border-box; } - div#overlayContent { + .overlayContent { padding: 0.5em; } div#overlayContent.text{ @@ -237,6 +237,10 @@ body { .buttons button{ padding: 0.5em; } + .overlayButtons button{ + padding: 0.5em; + margin-left: 0.3em; + } button#reset{ padding: 0.5em; } @@ -309,4 +313,7 @@ body { .footer .source{ flex: 1; } + #adminPassInput { + margin-bottom: 1em; + } \ No newline at end of file diff --git a/web/index.html b/web/index.html index 25f0065..48f2544 100644 --- a/web/index.html +++ b/web/index.html @@ -76,8 +76,8 @@