diff --git a/etc/config/quickstart b/etc/config/quickstart index dfaf952..694292a 100644 --- a/etc/config/quickstart +++ b/etc/config/quickstart @@ -9,6 +9,7 @@ config page 'welcome' option topheader 'Welcome to the Commotion Quick Start' list modules 'adminPassword' list modules 'name' + list modules 'meshPassword' list buttons 'noBack' list buttons '2:finish,|Finish >,| ,| ' list buttons '3:settingsFile,|Use a pre-built network file >,| ,| ' diff --git a/usr/lib/lua/luci/controller/QS/QS.lua b/usr/lib/lua/luci/controller/QS/QS.lua index 8d71f12..7ca43c2 100644 --- a/usr/lib/lua/luci/controller/QS/QS.lua +++ b/usr/lib/lua/luci/controller/QS/QS.lua @@ -123,6 +123,9 @@ function wirelessController(profiles) function(s) table.insert(dev, s['.name']) end) + if not luci.fs.isfile("/etc/commotion/profiles.d/quickstartMesh") then + luci.sys.call('cp /etc/commotion/profiles.d/defaultMesh /etc/commotion/profiles.d/quickstartMesh') + end --Create interfaces channel = getCommotionSetting("channel", "quickstartMesh") for devNum,device in ipairs(dev) do @@ -184,6 +187,7 @@ function checkPage() end function parseSubmit(returns) + log("Running module parser functions") --check for submission value local uci = luci.model.uci.cursor() local submit = nil @@ -241,8 +245,13 @@ function runParser(modules) for _,value in ipairs(modules) do for i,x in pairs(luci.controller.QS.modules) do if i == (value .. "Parser") then - --log(value) + log(value) errors[value] = luci.controller.QS.modules[value .. "Parser"](returns) + --logging errors again + if errors then + log(errors) + end + --if there is a set of errors then remove the "complete" module from the parsed modules so it does not run. if next(errors) then for i,x in ipairs(modules) do if x == 'complete' then diff --git a/usr/lib/lua/luci/controller/QS/modules.lua b/usr/lib/lua/luci/controller/QS/modules.lua index ac2f677..96ccfc1 100644 --- a/usr/lib/lua/luci/controller/QS/modules.lua +++ b/usr/lib/lua/luci/controller/QS/modules.lua @@ -42,8 +42,9 @@ function nameParser() local find = '^hostname=.*' local replacement = "hostname="..hostName replaceLine(file, find, replacement) - + --QS.log("wrote hostname") + --Add Secure AP files and password if val.secure == 'true' then --QS.log("passwords:"..val.pwd1.." & "..val.pwd2) pass = checkPass(val.pwd1, val.pwd2) @@ -60,7 +61,7 @@ function nameParser() local find = '^SSIDSec=.*' local replacement = "SSIDSec="..val.nodeName replaceLine(file, find, replacement) - + else return pass end @@ -84,6 +85,45 @@ function nameParser() end end +function meshPasswordRenderer() + local QS = luci.controller.QS.QS + QS.log("meshPassword rendered") + return true +end + +function meshPasswordParser() + local QS = luci.controller.QS.QS + QS.log("meshPasswordParser running") + errors = nil + local val = luci.http.formvalue() + --QS.log(val) + --QS.log("wrote hostname") + --Add Secure AP files and password + errors = checkPass(val.meshPassword_pwd1, val.meshPassword_pwd2) + if errors == nil then + if not luci.fs.isfile("/etc/commotion/profiles.d/quickstartMesh") then + luci.sys.call('cp /etc/commotion/profiles.d/defaultMesh /etc/commotion/profiles.d/quickstartMesh') + end + local file = "/etc/commotion/profiles.d/quickstartSettings" + local find = '^MeshPwd=.*' + local replacement = "MeshPwd="..val.meshPassword_pwd1 + replaceLine(file, find, replacement) + else + return errors + end +end + +function setMeshPassword(pass) + local QS = luci.controller.QS.QS + QS.log("setMeshPassword started") + + local file = "/etc/commotion/profiles.d/quickstartMesh" + local find = '^wpakey=.*' + local replacement = "wpakey="..pass + replaceLine(file, find, replacement) +end + + function setAPPassword(pass) local QS = luci.controller.QS.QS QS.log("setAPPassword started") @@ -109,7 +149,6 @@ function setSecAccessPoint(SSID) replaceLine(file, find, replacement) end - function string.split(str, pat) local t = {} if pat == nil then pat=' ' end @@ -180,6 +219,7 @@ function setValues(setting, value) hostname = setHostName, pwd = setAPPassword, SSIDSec = setSecAccessPoint, + MeshPwd = setMeshPassword, } settings[setting](value) return @@ -228,6 +268,7 @@ function completeParser() uci:set('quickstart', 'options', 'complete', 'true') uci:save('quickstart') uci:commit('quickstart') + luci.sys.call('rm /etc/commotion/profiles.d/quickstartSettings') p = luci.sys.reboot() end @@ -265,8 +306,6 @@ function replaceLine(fn, find, replacement) return errorCode end - - function adminPasswordParser(val) --[=[ --]=] errors = {} @@ -391,12 +430,14 @@ function checkPass(p1, p2) if p1 and p2 then if p1 == p2 then if p1 == '' then + QS.log("Please enter a password") return "Please enter a password" elseif string.len(p1) < 8 then + QS.log("Please enter a password that is more than 8 chars long") return "Please enter a password that is more than 8 chars long" elseif not tostring(p1):match("^[%p%w]+$") then + QS.log("Your password has spaces in it. You can't have spaces.") return "Your password has spaces in it. You can't have spaces." - end else return "Given password confirmation did not match, password not changed!" diff --git a/usr/lib/lua/luci/view/QS/module/adminPassword.htm b/usr/lib/lua/luci/view/QS/module/adminPassword.htm index d5bc099..74f62e0 100644 --- a/usr/lib/lua/luci/view/QS/module/adminPassword.htm +++ b/usr/lib/lua/luci/view/QS/module/adminPassword.htm @@ -1,6 +1,8 @@ <%- - if pv.errorMsg and pv.errorMsg.adminPassword then - if pv.errorMsg.adminPassword.pw then pwErr = pv.errorMsg.adminPassword.pw end + if pv.errorMsg then + if pv.errorMsg.adminPassword then + pwErr = pv.errorMsg.adminPassword + end end -%> <%- if luci.sys.user.getuser("root") and not luci.sys.user.getpasswd("root") then -%> diff --git a/usr/lib/lua/luci/view/QS/module/meshPassword.htm b/usr/lib/lua/luci/view/QS/module/meshPassword.htm new file mode 100644 index 0000000..b10bdc5 --- /dev/null +++ b/usr/lib/lua/luci/view/QS/module/meshPassword.htm @@ -0,0 +1,21 @@ +<%- + if pv.errorMsg then + if pv.errorMsg.meshPassword then + MeshPWErr = pv.errorMsg.meshPassword + end + end +-%> + +
+
+ +
+ +

This is the common password for devices on the mesh you wish your device to connect to.

+

<%=MeshPWErr%>

+ +

Retype your password here

+ +
+
+