fix #126: allow short SSIDs

pull/140/merge
Thorsten von Eicken 9 years ago
parent 0df5264c8b
commit df2f36b8ef
  1. 39
      esp-link/cgiwifi.c
  2. 17
      html/wifi/wifiAp.js
  3. 3
      mqtt/mqtt.c

@ -533,7 +533,7 @@ int ICACHE_FLASH_ATTR cgiApSettingsChange(HttpdConnData *connData) {
} }
// Set new SSID // Set new SSID
len=httpdFindArg(connData->getArgs, "ap_ssid", buff, sizeof(buff)); len=httpdFindArg(connData->getArgs, "ap_ssid", buff, sizeof(buff));
if(checkString(buff) && len>7 && len<32){ if(checkString(buff) && len>0 && len<=32){
// STRING PREPROCESSING DONE IN CLIENT SIDE // STRING PREPROCESSING DONE IN CLIENT SIDE
os_memset(apconf.ssid, 0, 32); os_memset(apconf.ssid, 0, 32);
os_memcpy(apconf.ssid, buff, len); os_memcpy(apconf.ssid, buff, len);
@ -545,13 +545,11 @@ int ICACHE_FLASH_ATTR cgiApSettingsChange(HttpdConnData *connData) {
} }
// Set new PASSWORD // Set new PASSWORD
len=httpdFindArg(connData->getArgs, "ap_password", buff, sizeof(buff)); len=httpdFindArg(connData->getArgs, "ap_password", buff, sizeof(buff));
if(checkString(buff) && len>7 && len<64){ os_memset(apconf.password, 0, 64);
if (checkString(buff) && len>7 && len<=64) {
// String preprocessing done in client side, wifiap.js line 31 // String preprocessing done in client side, wifiap.js line 31
os_memset(apconf.password, 0, 64);
os_memcpy(apconf.password, buff, len); os_memcpy(apconf.password, buff, len);
}else if (len == 0){ } else if (len != 0) {
os_memset(apconf.password, 0, 64);
}else{
jsonHeader(connData, 400); jsonHeader(connData, 400);
httpdSend(connData, "PASSWORD not valid or out of range", -1); httpdSend(connData, "PASSWORD not valid or out of range", -1);
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;
@ -733,11 +731,17 @@ int ICACHE_FLASH_ATTR printWifiInfo(char *buff) {
uint8_t chan = wifi_get_channel(); uint8_t chan = wifi_get_channel();
len = os_sprintf(buff, len = os_sprintf(buff,
"\"mode\": \"%s\", \"modechange\": \"%s\", \"ssid\": \"%s\", \"status\": \"%s\", \"phy\": \"%s\", " "\"mode\": \"%s\", \"modechange\": \"%s\", \"ssid\": \"%s\", \"status\": \"%s\", "
"\"rssi\": \"%ddB\", \"warn\": \"%s\", \"apwarn\": \"%s\",\"mac\":\"%02x:%02x:%02x:%02x:%02x:%02x\", \"chan\":\"%d\", \"apssid\": \"%s\", " "\"phy\": \"%s\", \"rssi\": \"%ddB\", \"warn\": \"%s\", \"apwarn\": \"%s\", "
"\"appass\": \"%s\", \"apchan\": \"%d\", \"apmaxc\": \"%d\", \"aphidd\": \"%s\", \"apbeac\": \"%d\", \"apauth\": \"%s\",\"apmac\":\"%02x:%02x:%02x:%02x:%02x:%02x\"", "\"mac\":\"%02x:%02x:%02x:%02x:%02x:%02x\", \"chan\":\"%d\", \"apssid\": \"%s\", "
mode, MODECHANGE, (char*)stconf.ssid, status, phy, rssi, warn, apwarn, "\"appass\": \"%s\", \"apchan\": \"%d\", \"apmaxc\": \"%d\", \"aphidd\": \"%s\", "
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5], chan, (char*)apconf.ssid,(char*)apconf.password,apconf.channel,apconf.max_connection,apconf.ssid_hidden?"enabled":"disabled",apconf.beacon_interval, apauth,apmac_addr[0], apmac_addr[1], apmac_addr[2], apmac_addr[3], apmac_addr[4], apmac_addr[5]); "\"apbeac\": \"%d\", \"apauth\": \"%s\",\"apmac\":\"%02x:%02x:%02x:%02x:%02x:%02x\"",
mode, MODECHANGE, (char*)stconf.ssid, status, phy, rssi, warn, apwarn,
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5],
chan, (char*)apconf.ssid, (char*)apconf.password, apconf.channel, apconf.max_connection,
apconf.ssid_hidden?"enabled":"disabled", apconf.beacon_interval,
apauth,apmac_addr[0], apmac_addr[1], apmac_addr[2], apmac_addr[3], apmac_addr[4],
apmac_addr[5]);
struct ip_info info; struct ip_info info;
if (wifi_get_ip_info(0, &info)) { if (wifi_get_ip_info(0, &info)) {
@ -806,12 +810,9 @@ int ICACHE_FLASH_ATTR cgiWifiInfo(HttpdConnData *connData) {
// Check string againt invalid characters // Check string againt invalid characters
int ICACHE_FLASH_ATTR checkString(char *str){ int ICACHE_FLASH_ATTR checkString(char *str){
int i = 0; for(int i=0; i<os_strlen(str); i++) {
for(; i < os_strlen(str); i++) // We allow any printable character
{ if (str[i] < '!' || str[i] > '~') {
// Alphanumeric and underscore allowed
if (!(isalnum((unsigned char)str[i]) || str[i] == '_'))
{
DBG("Error: String has non alphanumeric chars\n"); DBG("Error: String has non alphanumeric chars\n");
return 0; return 0;
} }
@ -855,7 +856,7 @@ void ICACHE_FLASH_ATTR wifiInit() {
} }
#endif #endif
// Change SOFT_AP settings if defined // Change SOFT_AP settings if defined in Makefile
#if defined(AP_SSID) #if defined(AP_SSID)
// Check if ssid and pass are alphanumeric values // Check if ssid and pass are alphanumeric values
int ssidlen = os_strlen(VERS_STR(AP_SSID)); int ssidlen = os_strlen(VERS_STR(AP_SSID));
@ -909,7 +910,7 @@ void ICACHE_FLASH_ATTR wifiInit() {
// Debug info // Debug info
DBG("Wifi Soft-AP parameters change: %s\n",softap_set_conf? "success":"fail"); DBG("Wifi Soft-AP parameters change: %s\n",softap_set_conf? "success":"fail");
#endif // AP_SSID && AP_PASS #endif // if defined(AP_SSID)
configWifiIP(); configWifiIP();

@ -26,15 +26,14 @@ function changeApSettings(e) {
if (inputs[i].type == "checkbox") { if (inputs[i].type == "checkbox") {
var val = (inputs[i].checked) ? 1 : 0; var val = (inputs[i].checked) ? 1 : 0;
url += "&" + inputs[i].name + "=" + val; url += "&" + inputs[i].name + "=" + val;
} } else {
else{ var clean = inputs[i].value.replace(/[^!-~]/g, "");
var clean = inputs[i].value.replace(/[^\w]/gi, ""); var comp = clean.localeCompare(inputs[i].value);
var comp = clean.localeCompare(inputs[i].value); if ( comp != 0 ){
if ( comp != 0 ){ showWarning("Invalid characters in " + specials[inputs[i].name]);
showWarning("Invalid characters in " + specials[inputs[i].name]); return;
return; }
} url += "&" + inputs[i].name + "=" + clean;
url += "&" + inputs[i].name + "=" + clean;
} }
}; };

@ -707,7 +707,8 @@ MQTT_Connect(MQTT_Client* client) {
os_timer_arm(&client->mqttTimer, 1000, 1); os_timer_arm(&client->mqttTimer, 1000, 1);
// initiate the TCP connection or DNS lookup // initiate the TCP connection or DNS lookup
os_printf("MQTT: Connect to %s:%d %p\n", client->host, client->port, client->pCon); os_printf("MQTT: Connect to %s:%d %p (client=%p)\n",
client->host, client->port, client->pCon, client);
if (UTILS_StrToIP((const char *)client->host, if (UTILS_StrToIP((const char *)client->host,
(void*)&client->pCon->proto.tcp->remote_ip)) { (void*)&client->pCon->proto.tcp->remote_ip)) {
uint8_t err; uint8_t err;

Loading…
Cancel
Save