diff options
Diffstat (limited to 'HouseControl.ino')
-rw-r--r-- | HouseControl.ino | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/HouseControl.ino b/HouseControl.ino index 2dbf282..ce3a669 100644 --- a/HouseControl.ino +++ b/HouseControl.ino @@ -169,6 +169,17 @@ bool str_to_mac(byte *buf, byte *mac) { return str_to_bytearray(buf,mac,16,6,':'); } +bool verify_utcoffset(byte *buf, int *dest) { + int v, min; + char *next; + v = strtoul((char*)buf, &next, 10); + min = v % 100; + if ((v < -1200) || (v > 1400) || (min <= -60) || (min >= 60) || (next == (char*)buf)) + return false; + + *dest = v; + return true; +} /*********************************************************************************/ /* NTP/Time functions */ @@ -337,7 +348,7 @@ void configGetHandler(WebServer &server, WebServer::ConnectionType type, char *u server.print("\",\"ntpserver\":\""); server.print(ip_to_str(buf2, config.ntpServer)); - sprintf((char*)buf1, "\",\"utcoffset\":%d,\"stathost\":\"", config.UTC_offset); + sprintf((char*)buf1, "\",\"utcoffset\":\"%+05d\",\"stathost\":\"", config.UTC_offset); server.print((char*)buf1); server.print(ip_to_str(buf2, config.notifyHost)); @@ -370,6 +381,9 @@ void configSetHandler(WebServer &server, WebServer::ConnectionType type, char *u if ((strcmp((const char*)buf2, "ntpserver") == 0)) if (!str_to_ip(buf1, config.ntpServer)) { server.print("Invalid NTP Server"); return; } + if ((strcmp((const char*)buf2, "utcoffset") == 0)) + if (!verify_utcoffset(buf1, &config.UTC_offset)) { server.print("Invalid UTC offset"); return; } + if ((strcmp((const char*)buf2, "stathost") == 0)) if (!str_to_ip(buf1, config.notifyHost)) { server.print("Invalid Status target"); return; } |