Change web authentication

Change web authentication (#4865)
This commit is contained in:
Theo Arends 2019-01-10 12:57:42 +01:00
parent 5776faf857
commit 2e101839a4
7 changed files with 49 additions and 45 deletions

View File

@ -5,7 +5,8 @@
* Fix Home Assistant Sensor Discovery Software Watchdog restart (#4831)
* Add support for OBI Power Socket 2 (#4829)
* Add support for YTF IR Bridge (#4855)
*
* Change web authentication (#4865)
*
* 6.4.1.7 20190106
* Fix HLW8012, HJL01 and BL0937 based energy sensors low Power (below 10W) measurement regression from 6.4.1.6
* Add Power status functionality to LED2 when configured leaving LED1 for Link status indication

View File

@ -755,11 +755,17 @@ void HandleAjaxStatusRefresh(void)
WebServer->send(200, FPSTR(HDR_CTYPE_HTML), mqtt_data);
}
boolean HttpUser(void)
boolean HttpCheckPriviledgedAccess(boolean autorequestauth = true)
{
boolean status = (HTTP_USER == webserver_state);
if (status) { HandleRoot(); }
return status;
if (HTTP_USER == webserver_state) {
HandleRoot();
return false;
}
if (autorequestauth && !WebAuthenticate()) {
WebServer->requestAuthentication();
return false;
}
return true;
}
/*-------------------------------------------------------------------------------------------*/
@ -768,8 +774,8 @@ boolean HttpUser(void)
void HandleConfiguration(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONFIGURATION);
String page = FPSTR(HTTP_HEAD);
@ -791,8 +797,7 @@ void HandleConfiguration(void)
void HandleModuleConfiguration(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
if (WebServer->hasArg("save")) {
ModuleSaveSettings();
@ -910,8 +915,7 @@ String htmlEscape(String s)
void HandleWifiConfiguration(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONFIGURE_WIFI);
@ -1038,8 +1042,8 @@ void WifiSaveSettings(void)
void HandleLoggingConfiguration(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONFIGURE_LOGGING);
if (WebServer->hasArg("save")) {
@ -1121,8 +1125,8 @@ void LoggingSaveSettings(void)
void HandleOtherConfiguration(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONFIGURE_OTHER);
if (WebServer->hasArg("save")) {
@ -1193,8 +1197,8 @@ void OtherSaveSettings(void)
void HandleBackupConfiguration(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_BACKUP_CONFIGURATION));
if (!SettingsBufferAlloc()) { return; }
@ -1237,8 +1241,7 @@ void HandleBackupConfiguration(void)
void HandleResetConfiguration(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
char svalue[33];
@ -1258,8 +1261,8 @@ void HandleResetConfiguration(void)
void HandleRestoreConfiguration(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_RESTORE_CONFIGURATION);
String page = FPSTR(HTTP_HEAD);
@ -1279,8 +1282,8 @@ void HandleRestoreConfiguration(void)
void HandleInformation(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_INFORMATION);
char stopic[TOPSZ];
@ -1402,8 +1405,8 @@ void HandleInformation(void)
void HandleUpgradeFirmware(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_FIRMWARE_UPGRADE);
String page = FPSTR(HTTP_HEAD);
@ -1422,8 +1425,8 @@ void HandleUpgradeFirmware(void)
void HandleUpgradeFirmwareStart(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
char svalue[100];
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_UPGRADE_STARTED));
@ -1451,8 +1454,8 @@ void HandleUpgradeFirmwareStart(void)
void HandleUploadDone(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_UPLOAD_DONE));
char error[100];
@ -1709,8 +1712,8 @@ void HandlePreflightRequest(void)
void HandleHttpCommand(void)
{
if (HttpUser()) { return; }
// if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess(false)) { return; }
char svalue[INPUT_BUFFER_SIZE]; // Large to serve Backlog
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_COMMAND));
@ -1769,8 +1772,8 @@ void HandleHttpCommand(void)
void HandleConsole(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONSOLE);
String page = FPSTR(HTTP_HEAD);
@ -1785,8 +1788,8 @@ void HandleConsole(void)
void HandleAjaxConsoleRefresh(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
char svalue[INPUT_BUFFER_SIZE]; // Large to serve Backlog
byte cflg = 1;
byte counter = 0; // Initial start, should never be 0 again

View File

@ -863,8 +863,8 @@ const char HTTP_FORM_MQTT[] PROGMEM =
void HandleMqttConfiguration(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONFIGURE_MQTT);
if (WebServer->hasArg("save")) {

View File

@ -448,8 +448,8 @@ const char HTTP_FORM_DOMOTICZ_TIMER[] PROGMEM =
void HandleDomoticzConfiguration(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONFIGURE_DOMOTICZ);
if (WebServer->hasArg("save")) {

View File

@ -682,8 +682,8 @@ const char HTTP_FORM_TIMER1[] PROGMEM =
void HandleTimerConfiguration(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONFIGURE_TIMER);
if (WebServer->hasArg("save")) {

View File

@ -805,8 +805,8 @@ const char HTTP_FORM_KNX_ADD_TABLE_ROW2[] PROGMEM =
void HandleKNXConfiguration(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONFIGURE_KNX);
char tmp[100];

View File

@ -393,8 +393,8 @@ const char HTTP_FORM_HX711[] PROGMEM =
void HandleHxAction(void)
{
if (HttpUser()) { return; }
if (!WebAuthenticate()) { return WebServer->requestAuthentication(); }
if (!HttpCheckPriviledgedAccess()) { return; }
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONFIGURE_HX711);
if (WebServer->hasArg("save")) {