Browse Source

improved GUI password handling

fix serial console uptime
fix #384 round total values
pull/421/head
lumapu 2 years ago
parent
commit
74f4a114cd
  1. 2
      tools/esp8266/defines.h
  2. 2
      tools/esp8266/html/login.html
  3. 3
      tools/esp8266/html/setup.html
  4. 2
      tools/esp8266/html/system.html
  5. 2
      tools/esp8266/html/visualization.html
  6. 2
      tools/esp8266/web.cpp
  7. 14
      tools/esp8266/webApi.cpp
  8. 6
      tools/esp8266/webApi.h

2
tools/esp8266/defines.h

@ -13,7 +13,7 @@
//------------------------------------- //-------------------------------------
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 5 #define VERSION_MINOR 5
#define VERSION_PATCH 30 #define VERSION_PATCH 31
//------------------------------------- //-------------------------------------
typedef struct { typedef struct {

2
tools/esp8266/html/login.html

@ -12,7 +12,7 @@
<div class="pad"> <div class="pad">
<form action="/login" method="post"> <form action="/login" method="post">
<h2>AhoyDTU</h2> <h2>AhoyDTU</h2>
<input type="password" name="pwd" value=""> <input type="password" name="pwd" value="" autofocus>
<input type="submit" name="login" value="login" class="btn"> <input type="submit" name="login" value="login" class="btn">
</form> </form>
</div> </div>

3
tools/esp8266/html/setup.html

@ -307,6 +307,9 @@
function parseSys(obj) { function parseSys(obj) {
for(var i of [["device", "device_name"], ["ssid", "ssid"]]) for(var i of [["device", "device_name"], ["ssid", "ssid"]])
document.getElementsByName(i[0])[0].value = obj[i[1]]; document.getElementsByName(i[0])[0].value = obj[i[1]];
var e = document.getElementsByName("adminpwd")[0];
if(!obj["pwd_set"])
e.value = "";
parseVersion(obj); parseVersion(obj);
} }

2
tools/esp8266/html/system.html

@ -53,7 +53,7 @@
} }
} }
getAjax("/api" + window.location.pathname, parse); getAjax("/api/html" + window.location.pathname, parse);
</script> </script>
</body> </body>
</html> </html>

2
tools/esp8266/html/visualization.html

@ -113,7 +113,7 @@
// total // total
if(obj.length > 1) { if(obj.length > 1) {
for(var j = 0; j < root.ch0_fld_names.length; j++) { for(var j = 0; j < root.ch0_fld_names.length; j++) {
var val = total[j]; var val = Math.round(total[j] * 100) / 100;
if(val > 0) { if(val > 0) {
var sub = div(["subgrp"]); var sub = div(["subgrp"]);
sub.appendChild(span(val + " " + span(root["ch0_fld_units"][j], ["unit"]).innerHTML, ["value"])); sub.appendChild(span(val + " " + span(root["ch0_fld_units"][j], ["unit"]).innerHTML, ["value"]));

2
tools/esp8266/web.cpp

@ -327,7 +327,7 @@ void web::showSave(AsyncWebServerRequest *request) {
request->arg("device").toCharArray(mSysCfg->deviceName, DEVNAME_LEN); request->arg("device").toCharArray(mSysCfg->deviceName, DEVNAME_LEN);
if(request->arg("adminpwd") != "{PWD}") { if(request->arg("adminpwd") != "{PWD}") {
request->arg("adminpwd").toCharArray(mConfig->password, PWD_LEN); request->arg("adminpwd").toCharArray(mConfig->password, PWD_LEN);
mProtected = true; mProtected = (strlen(mConfig->password) > 0);
} }
// inverter // inverter

14
tools/esp8266/webApi.cpp

@ -43,9 +43,10 @@ void webApi::onApi(AsyncWebServerRequest *request) {
Inverter<> *iv = mApp->mSys->getInverterByPos(0, false); Inverter<> *iv = mApp->mSys->getInverterByPos(0, false);
String path = request->url().substring(5); String path = request->url().substring(5);
if(path == "system") getSystem(root); if(path == "html/system") getHtmlSystem(root);
else if(path == "logout") getLogout(root); else if(path == "html/logout") getHtmlLogout(root);
else if(path == "save") getSave(root); else if(path == "html/save") getHtmlSave(root);
else if(path == "system") getSysInfo(root);
else if(path == "reboot") getReboot(root); else if(path == "reboot") getReboot(root);
else if(path == "statistics") getStatistics(root); else if(path == "statistics") getStatistics(root);
else if(path == "inverter/list") getInverterList(root); else if(path == "inverter/list") getInverterList(root);
@ -153,6 +154,7 @@ void webApi::getSysInfo(JsonObject obj) {
obj[F("ts_sun_upd")] = mApp->getLatestSunTimestamp(); obj[F("ts_sun_upd")] = mApp->getLatestSunTimestamp();
obj[F("wifi_rssi")] = WiFi.RSSI(); obj[F("wifi_rssi")] = WiFi.RSSI();
obj[F("disclaimer")] = mConfig->disclaimer; obj[F("disclaimer")] = mConfig->disclaimer;
obj[F("pwd_set")] = (strlen(mConfig->password) > 0);
#if defined(ESP32) #if defined(ESP32)
obj[F("esp_type")] = F("ESP32"); obj[F("esp_type")] = F("ESP32");
#else #else
@ -162,7 +164,7 @@ void webApi::getSysInfo(JsonObject obj) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void webApi::getSystem(JsonObject obj) { void webApi::getHtmlSystem(JsonObject obj) {
getMenu(obj.createNestedObject(F("menu"))); getMenu(obj.createNestedObject(F("menu")));
getSysInfo(obj.createNestedObject(F("system"))); getSysInfo(obj.createNestedObject(F("system")));
obj[F("html")] = F("<a href=\"/factory\" class=\"btn\">Factory Reset</a><br/><br/><a href=\"/reboot\" class=\"btn\">Reboot</a>"); obj[F("html")] = F("<a href=\"/factory\" class=\"btn\">Factory Reset</a><br/><br/><a href=\"/reboot\" class=\"btn\">Reboot</a>");
@ -170,7 +172,7 @@ void webApi::getSystem(JsonObject obj) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void webApi::getLogout(JsonObject obj) { void webApi::getHtmlLogout(JsonObject obj) {
getMenu(obj.createNestedObject(F("menu"))); getMenu(obj.createNestedObject(F("menu")));
getSysInfo(obj.createNestedObject(F("system"))); getSysInfo(obj.createNestedObject(F("system")));
obj[F("refresh")] = 3; obj[F("refresh")] = 3;
@ -180,7 +182,7 @@ void webApi::getLogout(JsonObject obj) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void webApi::getSave(JsonObject obj) { void webApi::getHtmlSave(JsonObject obj) {
getMenu(obj.createNestedObject(F("menu"))); getMenu(obj.createNestedObject(F("menu")));
getSysInfo(obj.createNestedObject(F("system"))); getSysInfo(obj.createNestedObject(F("system")));
obj[F("refresh")] = 2; obj[F("refresh")] = 2;

6
tools/esp8266/webApi.h

@ -33,9 +33,9 @@ class webApi {
void onDwnldSetup(AsyncWebServerRequest *request); void onDwnldSetup(AsyncWebServerRequest *request);
void getSysInfo(JsonObject obj); void getSysInfo(JsonObject obj);
void getSystem(JsonObject obj); void getHtmlSystem(JsonObject obj);
void getLogout(JsonObject obj); void getHtmlLogout(JsonObject obj);
void getSave(JsonObject obj); void getHtmlSave(JsonObject obj);
void getReboot(JsonObject obj); void getReboot(JsonObject obj);
void getStatistics(JsonObject obj); void getStatistics(JsonObject obj);
void getInverterList(JsonObject obj); void getInverterList(JsonObject obj);

Loading…
Cancel
Save