mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 09:49:32 +02:00
Add configuration options for auth
This commit is contained in:
parent
48d416b5c4
commit
b4014a0279
6 changed files with 38 additions and 3 deletions
|
@ -172,6 +172,7 @@ void init_stored_settings() {
|
|||
ha_autodiscovery_enabled = settings.getBool("HADISC", false);
|
||||
mqtt_transmit_all_cellvoltages = settings.getBool("MQTTCELLV", false);
|
||||
custom_hostname = settings.getString("HOSTNAME").c_str();
|
||||
webserver_auth = settings.getBool("AUTHREQUIRED", false);
|
||||
|
||||
static_IP_enabled = settings.getBool("STATICIP", false);
|
||||
static_local_IP1 = settings.getUInt("LOCALIP1", 192);
|
||||
|
|
|
@ -291,6 +291,18 @@ String settings_processor(const String& var, BatteryEmulatorSettingsStore& setti
|
|||
return settings.getBool("CANFDASCAN") ? "checked" : "";
|
||||
}
|
||||
|
||||
if (var == "AUTHREQUIRED") {
|
||||
return settings.getBool("AUTHREQUIRED", webserver_auth) ? "checked" : "";
|
||||
}
|
||||
|
||||
if (var == "AUTHNAME") {
|
||||
return settings.getString("AUTHNAME", "Admin");
|
||||
}
|
||||
|
||||
if (var == "AUTHPASSWORD") {
|
||||
return settings.getString("AUTHPASSWORD", "Password");
|
||||
}
|
||||
|
||||
if (var == "WIFIAPENABLED") {
|
||||
return settings.getBool("WIFIAPENABLED", wifiap_enabled) ? "checked" : "";
|
||||
}
|
||||
|
@ -965,6 +977,11 @@ const char* getCANInterfaceName(CAN_Interface interface) {
|
|||
display: contents;
|
||||
}
|
||||
|
||||
form .if-authrequired { display: none; }
|
||||
form[data-authrequired="true"] .if-authrequired {
|
||||
display: contents;
|
||||
}
|
||||
|
||||
form .if-mqtt { display: none; }
|
||||
form[data-mqttenabled="true"] .if-mqtt {
|
||||
display: contents;
|
||||
|
@ -1222,6 +1239,17 @@ const char* getCANInterfaceName(CAN_Interface interface) {
|
|||
<h3>Connectivity settings</h3>
|
||||
<div style='display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px; align-items: center;'>
|
||||
|
||||
<label>Require auth to change settings: </label>
|
||||
<input type='checkbox' name='AUTHREQUIRED' value='on' %AUTHREQUIRED% />
|
||||
|
||||
<div class='if-authrequired'>
|
||||
<label>Auth username: </label>
|
||||
<input type='text' name='AUTHNAME' value="%AUTHNAME%" />
|
||||
|
||||
<label>Auth password: </label>
|
||||
<input type='text' name='AUTHPASSWORD' value="%AUTHPASSWORD%" />
|
||||
</div>
|
||||
|
||||
<label>Broadcast Wifi access point: </label>
|
||||
<input type='checkbox' name='WIFIAPENABLED' value='on' %WIFIAPENABLED% />
|
||||
|
||||
|
@ -1264,6 +1292,7 @@ const char* getCANInterfaceName(CAN_Interface interface) {
|
|||
<input type="number" name="SUBNET3" min="0" max="255" size="3" value="%SUBNET3%">.
|
||||
<input type="number" name="SUBNET4" min="0" max="255" size="3" value="%SUBNET4%">
|
||||
</div>
|
||||
|
||||
<div></div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
extern std::string ssid;
|
||||
extern std::string password;
|
||||
extern bool webserver_auth;
|
||||
|
||||
#include "../../communication/nvm/comm_nvm.h"
|
||||
|
||||
|
|
|
@ -23,8 +23,6 @@
|
|||
extern std::string http_username;
|
||||
extern std::string http_password;
|
||||
|
||||
bool webserver_auth = false;
|
||||
|
||||
// Create AsyncWebServer object on port 80
|
||||
AsyncWebServer server(80);
|
||||
|
||||
|
@ -397,7 +395,7 @@ void init_webserver() {
|
|||
"DBLBTR", "CNTCTRL", "CNTCTRLDBL", "PWMCNTCTRL", "PERBMSRESET", "SDLOGENABLED", "STATICIP",
|
||||
"REMBMSRESET", "EXTPRECHARGE", "USBENABLED", "CANLOGUSB", "WEBENABLED", "CANFDASCAN", "CANLOGSD",
|
||||
"WIFIAPENABLED", "MQTTENABLED", "NOINVDISC", "HADISC", "MQTTTOPICS", "MQTTCELLV", "INVICNT",
|
||||
"GTWRHD", "DIGITALHVIL", "PERFPROFILE", "INTERLOCKREQ", "SOCESTIMATED",
|
||||
"GTWRHD", "DIGITALHVIL", "PERFPROFILE", "INTERLOCKREQ", "SOCESTIMATED", "AUTHREQUIRED",
|
||||
};
|
||||
|
||||
// Handles the form POST from UI to save settings of the common image
|
||||
|
@ -506,6 +504,10 @@ void init_webserver() {
|
|||
} else if (p->name() == "SUBNET4") {
|
||||
auto type = atoi(p->value().c_str());
|
||||
settings.saveUInt("SUBNET4", type);
|
||||
} else if (p->name() == "AUTHNAME") {
|
||||
settings.saveString("AUTHNAME", p->value().c_str());
|
||||
} else if (p->name() == "AUTHPASSWORD") {
|
||||
settings.saveString("AUTHPASSWORD", p->value().c_str());
|
||||
} else if (p->name() == "APNAME") {
|
||||
settings.saveString("APNAME", p->value().c_str());
|
||||
} else if (p->name() == "APPASSWORD") {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
bool wifi_enabled = true;
|
||||
bool wifiap_enabled = true;
|
||||
bool mdns_enabled = true; //If true, allows battery monitor te be found by .local address
|
||||
bool webserver_auth = false;
|
||||
uint16_t wifi_channel = 0;
|
||||
|
||||
std::string custom_hostname; //If not set, the default naming format 'esp32-XXXXXX' will be used
|
||||
|
|
|
@ -10,6 +10,7 @@ extern uint16_t wifi_channel;
|
|||
extern std::string ssidAP;
|
||||
extern std::string passwordAP;
|
||||
extern std::string custom_hostname;
|
||||
extern bool webserver_auth;
|
||||
|
||||
void init_WiFi();
|
||||
void wifi_monitor();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue