mirror of https://github.com/arendst/Tasmota.git
Fix HTTP authorization response code
Fix HTTP authorization response code (#8170)
This commit is contained in:
parent
57f836cc9e
commit
97abf68612
|
@ -2562,54 +2562,54 @@ 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));
|
||||||
|
|
||||||
bool valid = true;
|
|
||||||
if (strlen(SettingsText(SET_WEBPWD))) {
|
if (strlen(SettingsText(SET_WEBPWD))) {
|
||||||
char tmp1[33];
|
char tmp1[33];
|
||||||
WebGetArg("user", tmp1, sizeof(tmp1));
|
WebGetArg("user", tmp1, sizeof(tmp1));
|
||||||
char tmp2[strlen(SettingsText(SET_WEBPWD)) +1];
|
char tmp2[strlen(SettingsText(SET_WEBPWD)) +1];
|
||||||
WebGetArg("password", tmp2, sizeof(tmp2));
|
WebGetArg("password", tmp2, sizeof(tmp2));
|
||||||
if (!(!strcmp(tmp1, WEB_USERNAME) && !strcmp(tmp2, SettingsText(SET_WEBPWD)))) { valid = false; }
|
if (!(!strcmp(tmp1, WEB_USERNAME) && !strcmp(tmp2, SettingsText(SET_WEBPWD)))) {
|
||||||
|
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);
|
||||||
if (valid) {
|
uint32_t curridx = web_log_index;
|
||||||
uint32_t curridx = web_log_index;
|
String svalue = Webserver->arg("cmnd");
|
||||||
String svalue = Webserver->arg("cmnd");
|
if (svalue.length() && (svalue.length() < MQTT_MAX_PACKET_SIZE)) {
|
||||||
if (svalue.length() && (svalue.length() < MQTT_MAX_PACKET_SIZE)) {
|
ExecuteWebCommand((char*)svalue.c_str(), SRC_WEBCOMMAND);
|
||||||
ExecuteWebCommand((char*)svalue.c_str(), SRC_WEBCOMMAND);
|
if (web_log_index != curridx) {
|
||||||
if (web_log_index != curridx) {
|
uint32_t counter = curridx;
|
||||||
uint32_t counter = curridx;
|
WSContentSend_P(PSTR("{"));
|
||||||
WSContentSend_P(PSTR("{"));
|
bool cflg = false;
|
||||||
bool cflg = false;
|
do {
|
||||||
do {
|
char* tmp;
|
||||||
char* tmp;
|
size_t len;
|
||||||
size_t len;
|
GetLog(counter, &tmp, &len);
|
||||||
GetLog(counter, &tmp, &len);
|
if (len) {
|
||||||
if (len) {
|
// [14:49:36 MQTT: stat/wemos5/RESULT = {"POWER":"OFF"}] > [{"POWER":"OFF"}]
|
||||||
// [14:49:36 MQTT: stat/wemos5/RESULT = {"POWER":"OFF"}] > [{"POWER":"OFF"}]
|
char* JSON = (char*)memchr(tmp, '{', len);
|
||||||
char* JSON = (char*)memchr(tmp, '{', len);
|
if (JSON) { // Is it a JSON message (and not only [15:26:08 MQT: stat/wemos5/POWER = O])
|
||||||
if (JSON) { // Is it a JSON message (and not only [15:26:08 MQT: stat/wemos5/POWER = O])
|
size_t JSONlen = len - (JSON - tmp);
|
||||||
size_t JSONlen = len - (JSON - tmp);
|
if (JSONlen > sizeof(mqtt_data)) { JSONlen = sizeof(mqtt_data); }
|
||||||
if (JSONlen > sizeof(mqtt_data)) { JSONlen = sizeof(mqtt_data); }
|
char stemp[JSONlen];
|
||||||
char stemp[JSONlen];
|
strlcpy(stemp, JSON +1, JSONlen -2);
|
||||||
strlcpy(stemp, JSON +1, JSONlen -2);
|
WSContentSend_P(PSTR("%s%s"), (cflg) ? "," : "", stemp);
|
||||||
WSContentSend_P(PSTR("%s%s"), (cflg) ? "," : "", stemp);
|
cflg = true;
|
||||||
cflg = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
counter++;
|
}
|
||||||
counter &= 0xFF;
|
counter++;
|
||||||
if (!counter) counter++; // Skip 0 as it is not allowed
|
counter &= 0xFF;
|
||||||
} while (counter != web_log_index);
|
if (!counter) counter++; // Skip 0 as it is not allowed
|
||||||
WSContentSend_P(PSTR("}"));
|
} while (counter != web_log_index);
|
||||||
} else {
|
WSContentSend_P(PSTR("}"));
|
||||||
WSContentSend_P(PSTR("{\"" D_RSLT_WARNING "\":\"" D_ENABLE_WEBLOG_FOR_RESPONSE "\"}"));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
WSContentSend_P(PSTR("{\"" D_RSLT_WARNING "\":\"" D_ENTER_COMMAND " cmnd=\"}"));
|
WSContentSend_P(PSTR("{\"" D_RSLT_WARNING "\":\"" D_ENABLE_WEBLOG_FOR_RESPONSE "\"}"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
WSContentSend_P(PSTR("{\"" D_RSLT_WARNING "\":\"" D_NEED_USER_AND_PASSWORD "\"}"));
|
WSContentSend_P(PSTR("{\"" D_RSLT_WARNING "\":\"" D_ENTER_COMMAND " cmnd=\"}"));
|
||||||
}
|
}
|
||||||
WSContentEnd();
|
WSContentEnd();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue