diff --git a/resources/xrp.js b/resources/xrp.js index f0d5a89..f157d8d 100644 --- a/resources/xrp.js +++ b/resources/xrp.js @@ -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: { @@ -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); } }