mirror of
https://github.com/arendst/Tasmota.git
synced 2025-04-25 07:17:16 +00:00
Merge pull request #10451 from gorootde/feature/basic-auth-support
Added support for basic auth
This commit is contained in:
commit
ff631ac322
@ -2607,16 +2607,21 @@ void HandleHttpCommand(void)
|
|||||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_COMMAND));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_HTTP D_COMMAND));
|
||||||
|
|
||||||
if (strlen(SettingsText(SET_WEBPWD))) {
|
if (strlen(SettingsText(SET_WEBPWD))) {
|
||||||
char tmp1[33];
|
//Prefer authorization via HTTP header (Basic auth), if it fails, use legacy method via GET parameters
|
||||||
WebGetArg("user", tmp1, sizeof(tmp1));
|
if (!Webserver->authenticate(WEB_USERNAME, SettingsText(SET_WEBPWD))) {
|
||||||
char tmp2[strlen(SettingsText(SET_WEBPWD)) +1];
|
char tmp1[33];
|
||||||
WebGetArg("password", tmp2, sizeof(tmp2));
|
WebGetArg("user", tmp1, sizeof(tmp1));
|
||||||
if (!(!strcmp(tmp1, WEB_USERNAME) && !strcmp(tmp2, SettingsText(SET_WEBPWD)))) {
|
char tmp2[strlen(SettingsText(SET_WEBPWD)) + 1];
|
||||||
WSContentBegin(401, CT_JSON);
|
WebGetArg("password", tmp2, sizeof(tmp2));
|
||||||
WSContentSend_P(PSTR("{\"" D_RSLT_WARNING "\":\"" D_NEED_USER_AND_PASSWORD "\"}"));
|
|
||||||
WSContentEnd();
|
if (!(!strcmp(tmp1, WEB_USERNAME) && !strcmp(tmp2, SettingsText(SET_WEBPWD))))
|
||||||
return;
|
{
|
||||||
}
|
WSContentBegin(401, CT_JSON);
|
||||||
|
WSContentSend_P(PSTR("{\"" D_RSLT_WARNING "\":\"" D_NEED_USER_AND_PASSWORD "\"}"));
|
||||||
|
WSContentEnd();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WSContentBegin(200, CT_JSON);
|
WSContentBegin(200, CT_JSON);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user