Adding web authorisation

This commit is contained in:
Ray Jones 2020-04-22 16:42:24 +10:00
parent b58ed90432
commit 28bfb28ff6
4 changed files with 19 additions and 1 deletions

View File

@ -1623,7 +1623,7 @@ void feedWatchdog()
#if USE_SW_WATCHDOG == 1 && USE_JTAG == 0
// BEST NOT USE WATCHDOG WITH JTAG DEBUG :-)
// DebugPort.printf("\r %ld Watchdog fed", millis());
DebugPort.print("~");
// DebugPort.print("~");
WatchdogTick = 1500;
#else
WatchdogTick = -1;

View File

@ -600,6 +600,8 @@ sCredentials::load()
validatedLoad("APpassword", APpassword, 31, "thereisnospoon");
validatedLoad("webUpdateUser", webUpdateUsername, 31, "Afterburner");
validatedLoad("webUpdatePass", webUpdatePassword, 31, "BurnBabyBurn");
validatedLoad("webUser", webUsername, 31, "Afterburner");
validatedLoad("webPass", webPassword, 31, "WebAccess");
preferences.end();
}
@ -612,6 +614,8 @@ sCredentials::save()
preferences.putString("APpassword", APpassword);
preferences.putString("webUpdateUser", webUpdateUsername);
preferences.putString("webUpdatePass", webUpdatePassword);
preferences.putString("webUser", webUsername);
preferences.putString("webPass", webPassword);
preferences.end();
}

View File

@ -235,11 +235,15 @@ struct sCredentials : public CESP32_NVStorage {
char APpassword[32];
char webUpdateUsername[32];
char webUpdatePassword[32];
char webUsername[32];
char webPassword[32];
void init() {
strcpy(APSSID, "Afterburner");
strcpy(APpassword, "thereisnospoon");
strcpy(webUpdateUsername, "Afterburner");
strcpy(webUpdatePassword, "BurnBabyBurn");
strcpy(webUsername, "Afterburner");
strcpy(webPassword, "WebAccess");
};
void load();
void save();
@ -249,6 +253,8 @@ struct sCredentials : public CESP32_NVStorage {
strcpy(APpassword, rhs.APpassword);
strcpy(webUpdateUsername, rhs.webUpdateUsername);
strcpy(webUpdatePassword, rhs.webUpdatePassword);
strcpy(webUsername, rhs.webUsername);
strcpy(webPassword, rhs.webPassword);
return *this;
}
};

View File

@ -177,6 +177,14 @@ String getContentType(String filename) { // convert the file extension to the MI
bool handleFileRead(String path) { // send the right file to the client (if it exists)
DebugPort.println("handleFileRead: " + path);
if (path.endsWith("/")) path += "index.html"; // If a folder is requested, send the index file
if(path.indexOf("index.html") >= 0) {
sCredentials creds = NVstore.getCredentials();
if (!server.authenticate(creds.webUsername, creds.webPassword)) {
server.requestAuthentication();
return true; // not entirely correct, but avoids 404 response
}
}
path.replace("%20", " "); // convert HTML spaces to normal spaces
String contentType = getContentType(path); // Get the MIME type
String pathWithGz = path + ".gz";