Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate wifi password when save conf options #583

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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