Skip to content

Commit

Permalink
Adding WPA complliant checks in Web UI (#35)
Browse files Browse the repository at this point in the history
* Adding WPA complliant checks in Web UI

* Updateding per code review comments
  • Loading branch information
jpokornyiii authored Jan 4, 2024
1 parent 950b83f commit fc5e757
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions resources/xrp.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,27 @@ window.onload = () => {
saveButton.onclick = (e) => {
e.preventDefault();
console.log("Save Button Clicked");

try {
JSON.parse(configJsonEntry.value);
// Check if can parse
let jsonObj = JSON.parse(configJsonEntry.value);

// Check if Defaul AP exists and has password 8 characters or more
if(jsonObj["network"] && jsonObj["network"]["defaultAP"] && jsonObj["network"]["defaultAP"]["password"]) {
let password = jsonObj["network"]["defaultAP"]["password"];
if(password.length < 8 || password.length > 63) {
throw new Error("Default AP password must be at least 8 characters and less than 64 per WPA standards");
}
} else {
throw new Error("In \"network\", must have field \"defaultAP\": {\"ssid\":\"APname\", \"password\":\"mypassword\"}");
}

// Don't allow for escape characters
if(configJsonEntry.value.toString().includes("\\")) {
throw new Error("Cannot use escape character '\\'.");
}

// Save config back to XRP disk
fetch("/saveconfig", {
body: configJsonEntry.value,
headers: {
Expand All @@ -35,10 +53,10 @@ window.onload = () => {
})
.then(() => {
alert("Configuration Updated. Please reset the XRP");
})
});
}
catch (e) {
alert("Invalid JSON. Please check and try again");
alert("Invalid JSON. Please check and try again.\n" + e.message);
}
}

Expand Down

0 comments on commit fc5e757

Please sign in to comment.