Fix RemoveSpace and tune Websend

Fix RemoveSpace and tune Websend
This commit is contained in:
Theo Arends 2019-02-23 12:48:39 +01:00
parent 06bec0d95e
commit 5d8ae266d0
2 changed files with 13 additions and 28 deletions

View File

@ -275,7 +275,7 @@ char* RemoveSpace(char* p)
*write++ = ch; *write++ = ch;
} }
} }
*write = '\0'; // *write = '\0'; // Removed 20190223 as it buffer overflows on no isspace found - no need either
return p; return p;
} }

View File

@ -1972,8 +1972,7 @@ void HandleHttpCommand(void)
uint8_t curridx = web_log_index; uint8_t curridx = web_log_index;
String svalue = WebServer->arg("cmnd"); String svalue = WebServer->arg("cmnd");
if (svalue.length() && (svalue.length() < INPUT_BUFFER_SIZE)) { if (svalue.length() && (svalue.length() < INPUT_BUFFER_SIZE)) {
ExecuteWebCommand((char*)svalue.c_str(), SRC_WEBCONSOLE); ExecuteWebCommand((char*)svalue.c_str(), SRC_WEBCOMMAND);
if (web_log_index != curridx) { if (web_log_index != curridx) {
uint8_t counter = curridx; uint8_t counter = curridx;
message = F("{"); message = F("{");
@ -2173,7 +2172,6 @@ int WebSend(char *buffer)
// [sonoff,admin:joker] /any/link/starting/with/a/slash.php?log=123 --> Sends http://sonoff/any/link/starting/with/a/slash.php?log=123 // [sonoff,admin:joker] /any/link/starting/with/a/slash.php?log=123 --> Sends http://sonoff/any/link/starting/with/a/slash.php?log=123
char *host; char *host;
char *port;
char *user; char *user;
char *password; char *password;
char *command; char *command;
@ -2182,35 +2180,22 @@ int WebSend(char *buffer)
// buffer = | [ 192.168.178.86 : 80 , admin : joker ] POWER1 ON | // buffer = | [ 192.168.178.86 : 80 , admin : joker ] POWER1 ON |
host = strtok_r(buffer, "]", &command); // host = | [ 192.168.178.86 : 80 , admin : joker |, command = | POWER1 ON | host = strtok_r(buffer, "]", &command); // host = | [ 192.168.178.86 : 80 , admin : joker |, command = | POWER1 ON |
if (host && command) { if (host && command) {
RemoveSpace(host); // host = |[192.168.178.86:80,admin:joker|
host++; // host = |192.168.178.86:80,admin:joker| - Skip [
host = strtok_r(host, ",", &user); // host = |192.168.178.86:80|, user = |admin:joker|
String url = F("http://"); // url = |http://| String url = F("http://"); // url = |http://|
host = Trim(host); // host = |[ 192.168.178.86 : 80 , admin : joker| url += host; // url = |http://192.168.178.86:80|
host++; // host = | 192.168.178.86 : 80 , admin : joker| - Skip [
host = strtok_r(host, ",", &user); // host = | 192.168.178.86 : 80 |, user = | admin : joker|
host = strtok_r(host, ":", &port); // host = | 192.168.178.86 |, port = | 80 |
host = Trim(host); // host = |192.168.178.86|
url += host; // url = |http://192.168.178.86|
if (port) {
port = Trim(port); // port = |80|
url += F(":"); // url = |http://192.168.178.86:|
url += port; // url = |http://192.168.178.86:80|
}
if (user) {
user = strtok_r(user, ":", &password); // user = | admin |, password = | joker|
user = Trim(user); // user = |admin|
if (password) { password = Trim(password); } // password = |joker|
}
command = Trim(command); // command = |POWER1 ON| or |/any/link/starting/with/a/slash.php?log=123| command = Trim(command); // command = |POWER1 ON| or |/any/link/starting/with/a/slash.php?log=123|
if (command[0] != '/') { if (command[0] != '/') {
url += F("/cm?"); // url = |http://192.168.178.86/cm?| url += F("/cm?"); // url = |http://192.168.178.86/cm?|
if (user && password) { if (user) {
url += F("user="); // url = |http://192.168.178.86/cm?user=| user = strtok_r(user, ":", &password); // user = |admin|, password = |joker|
url += user; // url = |http://192.168.178.86/cm?user=admin| if (user && password) {
url += F("&password="); // url = |http://192.168.178.86/cm?user=admin&password=| char userpass[128];
url += password; // url = |http://192.168.178.86/cm?user=admin&password=joker| snprintf_P(userpass, sizeof(userpass), PSTR("user=%s&password=%s&"), user, password);
url += F("&"); // url = |http://192.168.178.86/cm?user=admin&password=joker&| url += userpass; // url = |http://192.168.178.86/cm?user=admin&password=joker&|
}
} }
url += F("cmnd="); // url = |http://192.168.178.86/cm?cmnd=| or |http://192.168.178.86/cm?user=admin&password=joker&cmnd=| url += F("cmnd="); // url = |http://192.168.178.86/cm?cmnd=| or |http://192.168.178.86/cm?user=admin&password=joker&cmnd=|
} }