web user and password
This commit is contained in:
parent
60aa2b05ac
commit
ee95931f00
|
|
@ -75,6 +75,10 @@
|
|||
"username": "",
|
||||
"password": ""
|
||||
},
|
||||
"webadmin": {
|
||||
"username": "admin",
|
||||
"password": ""
|
||||
},
|
||||
"other": {
|
||||
"rememberStationTime": 30,
|
||||
"lowPowerMode": false,
|
||||
|
|
|
|||
|
|
@ -1541,6 +1541,75 @@
|
|||
</div>
|
||||
<hr />
|
||||
|
||||
<div class="row my-5 d-flex align-items-top">
|
||||
<div class="col-lg-3 col-sm-12">
|
||||
<h5>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="20"
|
||||
height="20"
|
||||
fill="currentColor"
|
||||
class="bi bi-cloud-upload-fill"
|
||||
viewBox="0 0 16 16"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M8 0a5.53 5.53 0 0 0-3.594 1.342c-.766.66-1.321 1.52-1.464 2.383C1.266 4.095 0 5.555 0 7.318 0 9.366 1.708 11 3.781 11H7.5V5.707L5.354 7.854a.5.5 0 1 1-.708-.708l3-3a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 5.707V11h4.188C14.502 11 16 9.57 16 7.773c0-1.636-1.242-2.969-2.834-3.194C12.923 1.999 10.69 0 8 0m-.5 14.5V11h1v3.5a.5.5 0 0 1-1 0"
|
||||
/>
|
||||
</svg>
|
||||
Admin
|
||||
</h5>
|
||||
<small
|
||||
>Set your username and password to allow
|
||||
access to the web interface.</small
|
||||
>
|
||||
</div>
|
||||
<div class="col-lg-9 col-sm-12">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="form-check form-switch">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="webadmin.active"
|
||||
id="webadmin.active"
|
||||
class="form-check-input"
|
||||
/>
|
||||
<label
|
||||
for="webadmin.active"
|
||||
class="form-label"
|
||||
>Web interface authentication</label
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<label for="webadmin.username" class="form-label"
|
||||
>Username</label
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
name="webadmin.username"
|
||||
id="webadmin.username"
|
||||
class="form-control"
|
||||
value="admin"
|
||||
required=""
|
||||
/>
|
||||
</div>
|
||||
<div class="col-12 mt-3">
|
||||
<label for="webadmin.password" class="form-label"
|
||||
>Password</label
|
||||
>
|
||||
<input
|
||||
type="password"
|
||||
name="webadmin.password"
|
||||
id="webadmin.password"
|
||||
class="form-control"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
|
||||
<div class="row my-5 d-flex align-items-top">
|
||||
<div class="col-lg-3 col-sm-12">
|
||||
<h5>
|
||||
|
|
|
|||
|
|
@ -201,6 +201,11 @@ function loadSettings(settings) {
|
|||
document.getElementById("ota.username").value = settings.ota.username;
|
||||
document.getElementById("ota.password").value = settings.ota.password;
|
||||
|
||||
// Webadmin
|
||||
document.getElementById("webadmin.active").checked = settings.webadmin.active;
|
||||
document.getElementById("webadmin.username").value = settings.webadmin.username;
|
||||
document.getElementById("webadmin.password").value = settings.webadmin.password;
|
||||
|
||||
// Experimental
|
||||
document.getElementById("other.backupDigiMode").checked = settings.other.backupDigiMode;
|
||||
|
||||
|
|
@ -276,6 +281,20 @@ function toggleFields() {
|
|||
externalVoltagePinInput.disabled = !sendExternalVoltageCheckbox.checked;
|
||||
voltageDividerR1.disabled = !sendExternalVoltageCheckbox.checked;
|
||||
voltageDividerR2.disabled = !sendExternalVoltageCheckbox.checked;
|
||||
|
||||
const WebadminCheckbox = document.querySelector(
|
||||
'input[name="webadmin.active"]'
|
||||
);
|
||||
|
||||
const WebadminUsername = document.querySelector(
|
||||
'input[name="webadmin.username"]'
|
||||
);
|
||||
|
||||
const WebadminPassword = document.querySelector(
|
||||
'input[name="webadmin.password"]'
|
||||
);
|
||||
WebadminUsername.disabled = !WebadminCheckbox.checked;
|
||||
WebadminPassword.disabled = !WebadminCheckbox.checked;
|
||||
}
|
||||
|
||||
const sendExternalVoltageCheckbox = document.querySelector(
|
||||
|
|
@ -299,6 +318,22 @@ sendExternalVoltageCheckbox.addEventListener("change", function () {
|
|||
voltageDividerR2.disabled = !this.checked;
|
||||
});
|
||||
|
||||
const WebadminCheckbox = document.querySelector(
|
||||
'input[name="webadmin.active"]'
|
||||
);
|
||||
|
||||
const WebadminUsername = document.querySelector(
|
||||
'input[name="webadmin.username"]'
|
||||
);
|
||||
|
||||
const WebadminPassword = document.querySelector(
|
||||
'input[name="webadmin.password"]'
|
||||
);
|
||||
WebadminCheckbox.addEventListener("change", function () {
|
||||
WebadminUsername.disabled = !this.checked;
|
||||
WebadminPassword.disabled = !this.checked;
|
||||
});
|
||||
|
||||
document.querySelector(".new button").addEventListener("click", function () {
|
||||
const networksContainer = document.querySelector(".list-networks");
|
||||
|
||||
|
|
|
|||
|
|
@ -97,12 +97,16 @@ void Configuration::writeFile() {
|
|||
|
||||
data["other"]["rememberStationTime"] = rememberStationTime;
|
||||
|
||||
data["other"]["backupDigiMode"] = backupDigiMode;
|
||||
data["other"]["backupDigiMode"] = backupDigiMode;
|
||||
|
||||
data["other"]["lowPowerMode"] = lowPowerMode;
|
||||
data["other"]["lowVoltageCutOff"] = lowVoltageCutOff;
|
||||
|
||||
data["personalNote"] = personalNote;
|
||||
data["personalNote"] = personalNote;
|
||||
|
||||
data["webadmin"]["active"] = webadmin.active;
|
||||
data["webadmin"]["username"] = webadmin.username;
|
||||
data["webadmin"]["password"] = webadmin.password;
|
||||
|
||||
serializeJson(data, configFile);
|
||||
|
||||
|
|
@ -188,6 +192,10 @@ bool Configuration::readFile() {
|
|||
|
||||
personalNote = data["personalNote"].as<String>();
|
||||
|
||||
webadmin.active = data["webadmin"]["active"].as<bool>();
|
||||
webadmin.username = data["webadmin"]["username"].as<String>();
|
||||
webadmin.password = data["webadmin"]["password"].as<String>();
|
||||
|
||||
int stationMode = data["stationMode"].as<int>(); // deprecated but need to specify config version
|
||||
|
||||
if (stationMode == 0) {
|
||||
|
|
@ -362,6 +370,10 @@ void Configuration::init() {
|
|||
|
||||
personalNote = "";
|
||||
|
||||
webadmin.active = false;
|
||||
webadmin.username = "admin";
|
||||
webadmin.password = "";
|
||||
|
||||
Serial.println("All is Written!");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -106,6 +106,13 @@ public:
|
|||
String password;
|
||||
};
|
||||
|
||||
class WEBADMIN {
|
||||
public:
|
||||
bool active;
|
||||
String username;
|
||||
String password;
|
||||
};
|
||||
|
||||
class Configuration {
|
||||
public:
|
||||
bool reload; // ?
|
||||
|
|
@ -129,6 +136,7 @@ public:
|
|||
SYSLOG syslog;
|
||||
TNC tnc;
|
||||
OTA ota;
|
||||
WEBADMIN webadmin;
|
||||
|
||||
void init();
|
||||
void writeFile();
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ namespace WEB_Utils {
|
|||
}
|
||||
|
||||
void handleHome(AsyncWebServerRequest *request) {
|
||||
if(Config.webadmin.active && !request->authenticate(Config.webadmin.username.c_str(), Config.webadmin.password.c_str()))
|
||||
return request->requestAuthentication();
|
||||
|
||||
AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", (const uint8_t*)web_index_html, web_index_html_len);
|
||||
response->addHeader("Content-Encoding", "gzip");
|
||||
request->send(response);
|
||||
|
|
@ -61,6 +64,9 @@ namespace WEB_Utils {
|
|||
}
|
||||
|
||||
void handleReadConfiguration(AsyncWebServerRequest *request) {
|
||||
if(Config.webadmin.active && !request->authenticate(Config.webadmin.username.c_str(), Config.webadmin.password.c_str()))
|
||||
return request->requestAuthentication();
|
||||
|
||||
File file = SPIFFS.open("/igate_conf.json");
|
||||
|
||||
String fileContent;
|
||||
|
|
@ -193,6 +199,12 @@ namespace WEB_Utils {
|
|||
|
||||
Config.personalNote = request->getParam("personalNote", true)->value();
|
||||
|
||||
Config.webadmin.active = request->hasParam("webadmin.active", true);
|
||||
if (Config.webadmin.active) {
|
||||
Config.webadmin.username = request->getParam("webadmin.username", true)->value();
|
||||
Config.webadmin.password = request->getParam("webadmin.password", true)->value();
|
||||
}
|
||||
|
||||
Config.writeFile();
|
||||
|
||||
AsyncWebServerResponse *response = request->beginResponse(302, "text/html", "");
|
||||
|
|
|
|||
|
|
@ -110,7 +110,9 @@ namespace WIFI_Utils {
|
|||
#endif
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
Serial.print("Connected as ");
|
||||
Serial.println(WiFi.localIP());
|
||||
Serial.print(WiFi.localIP());
|
||||
Serial.print(" / MAC Address: ");
|
||||
Serial.println(WiFi.macAddress());
|
||||
show_display("", " Connected!!", "" , " loading ...", 1000);
|
||||
} else if (WiFi.status() != WL_CONNECTED) {
|
||||
startAP = true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue