diff --git a/cmd/cmd.h b/cmd/cmd.h index 03549cc..3b4e8ab 100644 --- a/cmd/cmd.h +++ b/cmd/cmd.h @@ -58,8 +58,6 @@ typedef enum { CMD_SOCKET_SETUP = 40, // set-up callbacks CMD_SOCKET_SEND, // send data over UDP socket - CMD_GET_WIFI_INFO = 50,// Query IP address info - } CmdName; typedef void (*cmdfunc_t)(CmdPacket *cmd); diff --git a/cmd/handlers.c b/cmd/handlers.c index ee43982..c191091 100644 --- a/cmd/handlers.c +++ b/cmd/handlers.c @@ -17,7 +17,6 @@ #ifdef SOCKET #include #endif -#include #ifdef CMD_DBG #define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) @@ -30,7 +29,6 @@ static void cmdSync(CmdPacket *cmd); static void cmdWifiStatus(CmdPacket *cmd); static void cmdGetTime(CmdPacket *cmd); static void cmdAddCallback(CmdPacket *cmd); -static void cmdGetWifiInfo(CmdPacket *cmd); // keep track of last status sent to uC so we can notify it when it changes static uint8_t lastWifiStatus = wifiIsDisconnected; @@ -46,7 +44,6 @@ const CmdList commands[] = { {CMD_WIFI_STATUS, "WIFI_STATUS", cmdWifiStatus}, {CMD_CB_ADD, "ADD_CB", cmdAddCallback}, {CMD_GET_TIME, "GET_TIME", cmdGetTime}, - {CMD_GET_WIFI_INFO, "GET_WIFI_INFO", cmdGetWifiInfo}, #ifdef MQTT {CMD_MQTT_SETUP, "MQTT_SETUP", MQTTCMD_Setup}, {CMD_MQTT_PUBLISH, "MQTT_PUB", MQTTCMD_Publish}, @@ -181,32 +178,6 @@ cmdGetTime(CmdPacket *cmd) { return; } -// Command handler for IP information -static void ICACHE_FLASH_ATTR -cmdGetWifiInfo(CmdPacket *cmd) { - CmdRequest req; - - cmdRequest(&req, cmd); - if(cmd->argc != 0 || cmd->value == 0) { - cmdResponseStart(CMD_RESP_V, 0, 0); - cmdResponseEnd(); - return; - } - - uint32_t callback = req.cmd->value; - - struct ip_info info; - wifi_get_ip_info(0, &info); - - cmdResponseStart(CMD_RESP_CB, callback, 3); - cmdResponseBody(&info.ip.addr, sizeof(info.ip.addr)); - cmdResponseBody(&info.netmask.addr, sizeof(info.netmask.addr)); - cmdResponseBody(&info.gw.addr, sizeof(info.gw.addr)); - cmdResponseEnd(); - - return; -} - // Command handler to add a callback to the named-callbacks list, this is for a callback to the uC static void ICACHE_FLASH_ATTR cmdAddCallback(CmdPacket *cmd) { diff --git a/esp-link/cgiwifi.c b/esp-link/cgiwifi.c index 284704e..70d40dc 100644 --- a/esp-link/cgiwifi.c +++ b/esp-link/cgiwifi.c @@ -34,7 +34,7 @@ bool mdns_started = false; // ===== wifi status change callbacks static WifiStateChangeCb wifi_state_change_cb[4]; -// Temp store for new station config +// Temp store for new staion config struct station_config stconf; // Temp store for new ap config @@ -54,8 +54,6 @@ static char *wifiReasons[] = { static char *wifiMode[] = { 0, "STA", "AP", "AP+STA" }; static char *wifiPhy[] = { 0, "11b", "11g", "11n" }; -static char *portMode[] = { "unsecure", "disabled", "secure" }; - void (*wifiStatusCb)(uint8_t); // callback when wifi status changes static char* ICACHE_FLASH_ATTR wifiGetReason(void) { @@ -826,99 +824,6 @@ int ICACHE_FLASH_ATTR cgiWifiInfo(HttpdConnData *connData) { return HTTPD_CGI_DONE; } -static char *portMode2string(int8_t m) { - if (m < 0 || m > 2) return "?"; - return portMode[m]; -} - -// print various Wifi information into json buffer -int ICACHE_FLASH_ATTR printWiFiSecurity(char *buff) { - int len; - - len = os_sprintf(buff, - "\"port1mode\" : \"%s\", \"port1portnumber\" : \"%d\", \"port1pwd\" : \"%s\", " - "\"port2mode\" : \"%s\", \"port2portnumber\" : \"%d\", \"port2pwd\" : \"%s\" ", - portMode2string(flashConfig.port1_mode), flashConfig.port1_portnumber, "", - portMode2string(flashConfig.port2_mode), flashConfig.port2_portnumber, "" - ); - - return len; -} - -// Cgi to return various Wifi information -int ICACHE_FLASH_ATTR jsonWiFiSecurity(HttpdConnData *connData) { - char buff[1024]; - - if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. - - os_strcpy(buff, "{"); - printWiFiSecurity(buff+1); - os_strcat(buff, "}"); - - jsonHeader(connData, 200); - httpdSend(connData, buff, -1); - return HTTPD_CGI_DONE; -} - -// Change security settings -int ICACHE_FLASH_ATTR cgiWiFiSecurity(HttpdConnData *connData) { - char dhcp[8]; - char staticip[20]; - char netmask[20]; - char gateway[20]; - - if (connData->conn==NULL) return HTTPD_CGI_DONE; - - // get args and their string lengths - int dl = httpdFindArg(connData->getArgs, "dhcp", dhcp, sizeof(dhcp)); - int sl = httpdFindArg(connData->getArgs, "staticip", staticip, sizeof(staticip)); - int nl = httpdFindArg(connData->getArgs, "netmask", netmask, sizeof(netmask)); - int gl = httpdFindArg(connData->getArgs, "gateway", gateway, sizeof(gateway)); - - if (!(dl > 0 && sl >= 0 && nl >= 0 && gl >= 0)) { - jsonHeader(connData, 400); - httpdSend(connData, "Request is missing fields", -1); - return HTTPD_CGI_DONE; - } - - char url[64]; // redirect URL - if (os_strcmp(dhcp, "off") == 0) { - // parse static IP params - struct ip_info ipi; - bool ok = parse_ip(staticip, &ipi.ip); - if (nl > 0) ok = ok && parse_ip(netmask, &ipi.netmask); - else IP4_ADDR(&ipi.netmask, 255, 255, 255, 0); - if (gl > 0) ok = ok && parse_ip(gateway, &ipi.gw); - else ipi.gw.addr = 0; - if (!ok) { - jsonHeader(connData, 400); - httpdSend(connData, "Cannot parse static IP config", -1); - return HTTPD_CGI_DONE; - } - // save the params in flash - flashConfig.staticip = ipi.ip.addr; - flashConfig.netmask = ipi.netmask.addr; - flashConfig.gateway = ipi.gw.addr; - // construct redirect URL - os_sprintf(url, "{\"url\": \"http://%d.%d.%d.%d\"}", IP2STR(&ipi.ip)); - - } else { - // dynamic IP - flashConfig.staticip = 0; - os_sprintf(url, "{\"url\": \"http://%s\"}", flashConfig.hostname); - } - - configSave(); // ignore error... - // schedule change-over - os_timer_disarm(&reassTimer); - os_timer_setfn(&reassTimer, configWifiIP, NULL); - os_timer_arm(&reassTimer, 1000, 0); // 1 second for the response of this request to make it - // return redirect info - jsonHeader(connData, 200); - httpdSend(connData, url, -1); - return HTTPD_CGI_DONE; -} - // Check string againt invalid characters int ICACHE_FLASH_ATTR checkString(char *str){ for(int i=0; iChange! - -
-

Security Settings

-
- Disable or protect station access -
- Port 1 - - - -
-
-
- - -
-
- - -
- -
- Port 2 - - - -
-
-
- - -
-
- - -
- - -
-
- @@ -131,17 +78,6 @@ onLoad(function() { getWifiInfo(); bnd($("#wifiform"), "submit", changeWifiAp); bnd($("#specform"), "submit", changeSpecial); - - getSecurityInfo(); - bnd($("#securform"), "submit", changeSecurity); - bnd($("#secure-port1-roff"), "click", doPort1Off); - bnd($("#secure-port1-ron"), "click", doPort1Unsecure); - bnd($("#secure-port1-rpwd"), "click", doPort1Secure); - - bnd($("#secure-port2-roff"), "click", doPort2Off); - bnd($("#secure-port2-ron"), "click", doPort2Unsecure); - bnd($("#secure-port2-rpwd"), "click", doPort2Secure); - bnd($("#dhcp-ron"), "click", doDhcp); bnd($("#dhcp-roff"), "click", doStatic); scanTimeout = window.setTimeout(scanAPs, 500); diff --git a/html/wifi/wifiSta.js b/html/wifi/wifiSta.js index f46e822..0ab167a 100644 --- a/html/wifi/wifiSta.js +++ b/html/wifi/wifiSta.js @@ -192,68 +192,6 @@ function changeSpecial(e) { }); } -function changeSecurity(e) { - e.preventDefault(); - var url = "security"; - - url += "?port1=" + document.querySelector('input[name="port1"]:checked').value; - url += "&portnumber=" + encodeURIComponent($("#port1-portnumber").value); - url += "&password=" + encodeURIComponent($("#port1-password").value); - - url += "?port2=" + document.querySelector('input[name="port2"]:checked').value; - url += "&portnumber=" + encodeURIComponent($("#port2-portnumber").value); - url += "&password=" + encodeURIComponent($("#port2-password").value); - - hideWarning(); - var cb = $("#secure-button"); - addClass(cb, 'pure-button-disabled'); - ajaxSpin("POST", url, function(resp) { - removeClass(cb, 'pure-button-disabled'); - getSecurityInfo(); - //getWifiInfo(); // it takes 1 second for new settings to be applied - }, function(s, st) { - showWarning("Error: "+st); - removeClass(cb, 'pure-button-disabled'); - getSecurityInfo(); - }); -} - -function doPort1Secure() { - $('#port1-off').setAttribute('hidden', ''); - $('#port1-pn').removeAttribute('hidden'); - $('#port1-pwd').removeAttribute('hidden'); -} - -function doPort1Off() { - $('#port1-off').removeAttribute('hidden'); - $('#port1-pn').setAttribute('hidden', ''); - $('#port1-pwd').setAttribute('hidden', ''); -} - -function doPort1Unsecure() { - $('#port1-off').setAttribute('hidden', ''); - $('#port1-pn').removeAttribute('hidden'); - $('#port1-pwd').setAttribute('hidden', ''); -} - -function doPort2Secure() { - $('#port2-off').setAttribute('hidden', ''); - $('#port2-pn').removeAttribute('hidden'); - $('#port2-pwd').removeAttribute('hidden'); -} - -function doPort2Off() { - $('#port2-off').removeAttribute('hidden'); - $('#port2-pn').setAttribute('hidden', ''); - $('#port2-pwd').setAttribute('hidden', ''); -} - -function doPort2Unsecure() { - $('#port2-off').setAttribute('hidden', ''); - $('#port2-pn').removeAttribute('hidden'); - $('#port2-pwd').setAttribute('hidden', ''); -} - function doDhcp() { $('#dhcp-on').removeAttribute('hidden'); $('#dhcp-off').setAttribute('hidden', '');