Skip to content

Commit

Permalink
Merge pull request #583 from tim-moody/0.8.5-wifi
Browse files Browse the repository at this point in the history
validate wifi password when save conf options
  • Loading branch information
tim-moody authored Aug 19, 2024
2 parents 6fad108 + 1ae8e7e commit 61d9359
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions roles/console/files/js/admin_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -994,17 +994,9 @@ function controlWifiHotspot(){
var cmd_args = {};
if (serverInfo.hostapd_status == 'ON') {
var hotspotPassword = gEBI('hotspot_wifi_password_UD').value;
if (hotspotPassword.length < 8 || hotspotPassword.length > 63) {
alert("WiFi password must be between 8 and 63 printable characters.");
return
}
for (let i = 0; i < hotspotPassword.length; i++) {
let charCode = hotspotPassword.charCodeAt(i);
if (charCode < 32 || charCode > 126){
alert("Password cannot contain the character '" + hotspotPassword[i] + "'")
return
}
}
if (validateHostapdPassword(hotspotPassword) == false)
return false;

cmd_args['hotspot_passord'] = hotspotPassword;
var command = "CTL-HOTSPOT " + JSON.stringify(cmd_args);
return sendCmdSrvCmd(command, genericCmdHandler, "HOSTSPOT-CTL");
Expand All @@ -1013,6 +1005,21 @@ function controlWifiHotspot(){
alert("Can't change password as Internal Hotspot is not ON.");
}

function validateHostapdPassword(password){
if (password.length < 8 || password.length > 63) {
alert("WiFi password must be between 8 and 63 printable characters.");
return false;
}
for (let i = 0; i < password.length; i++) {
let charCode = password.charCodeAt(i);
if (charCode < 32 || charCode > 126){
alert("Password cannot contain the character '" + password[i] + "'")
return false;
}
}
return true;
}

function setWifiConnectionParams(){
var cmd_args = {};

Expand Down Expand Up @@ -1260,13 +1267,25 @@ function setConfigVarsCmd () {
// we will do this on the backend
}
});
if (validateChangedVars(changed_vars) == false)
return false;

cmd_args['config_vars'] = changed_vars;
var cmd = "SET-CONF " + JSON.stringify(cmd_args);
sendCmdSrvCmd(cmd, genericCmdHandler);
alert ("Saving Configuration.");
return true;
}

function validateChangedVars(changedVars){
// field validation functions raise alerts
if (changedVars.hasOwnProperty('hostapd_password'))
if (validateHostapdPassword(changedVars['hostapd_password']) == false)
return false;

return true;
}

function getServerPublicKey(){
$.get( iiabAuthService + '/get_pubkey', function( data ) {
authData['serverPKey'] = nacl.util.decodeBase64(data);
Expand Down

0 comments on commit 61d9359

Please sign in to comment.