From bdda14f528b32edd899dc3dd37e977e9a0e612cf Mon Sep 17 00:00:00 2001 From: Seamus Tuohy Date: Tue, 6 Aug 2013 18:45:06 -0400 Subject: [PATCH 1/3] added base code to allow for a mesh password (backhaul) module --- .../lua/luci/view/QS/module/meshPassword.htm | 18 ++++++++++++++++++ usr/lib/lua/luci/view/QS/module/name.htm | 9 +++++++++ 2 files changed, 27 insertions(+) create mode 100644 usr/lib/lua/luci/view/QS/module/meshPassword.htm 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..419c8dc --- /dev/null +++ b/usr/lib/lua/luci/view/QS/module/meshPassword.htm @@ -0,0 +1,18 @@ +<%- + if pv.errorMsg and pv.errorMsg.meshPassword then + if pv.errorMsg.meshPassword.pw then pwErr = pv.errorMsg.meshPassword.pw end + end +-%> +
+
+ +
+ +

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

+

<%=pwErr%>

+ +

Retype your password here

+ +
+
+
diff --git a/usr/lib/lua/luci/view/QS/module/name.htm b/usr/lib/lua/luci/view/QS/module/name.htm index 2aa9dc9..5b81884 100644 --- a/usr/lib/lua/luci/view/QS/module/name.htm +++ b/usr/lib/lua/luci/view/QS/module/name.htm @@ -54,5 +54,14 @@

<%=nameErr%>

+ From 1f44dbd471f2dac8579588863b2623cf1a8c8dbf Mon Sep 17 00:00:00 2001 From: Seamus Tuohy Date: Tue, 6 Aug 2013 20:06:38 -0400 Subject: [PATCH 2/3] finished adding feature set for mesh backhaul password on QuickStart - note this officially removes plug and play Quickstart without coordination between node owners --- etc/config/quickstart | 1 + usr/lib/lua/luci/controller/QS/QS.lua | 11 +++- usr/lib/lua/luci/controller/QS/modules.lua | 52 ++++++++++++++++--- .../lua/luci/view/QS/module/adminPassword.htm | 6 ++- .../lua/luci/view/QS/module/meshPassword.htm | 11 ++-- usr/lib/lua/luci/view/QS/module/name.htm | 9 ---- 6 files changed, 68 insertions(+), 22 deletions(-) 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..8b1ea94 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 @@ -265,8 +305,6 @@ function replaceLine(fn, find, replacement) return errorCode end - - function adminPasswordParser(val) --[=[ --]=] errors = {} @@ -391,12 +429,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 index 419c8dc..b10bdc5 100644 --- a/usr/lib/lua/luci/view/QS/module/meshPassword.htm +++ b/usr/lib/lua/luci/view/QS/module/meshPassword.htm @@ -1,15 +1,18 @@ <%- - if pv.errorMsg and pv.errorMsg.meshPassword then - if pv.errorMsg.meshPassword.pw then pwErr = pv.errorMsg.meshPassword.pw end + 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.

-

<%=pwErr%>

+

<%=MeshPWErr%>

Retype your password here

diff --git a/usr/lib/lua/luci/view/QS/module/name.htm b/usr/lib/lua/luci/view/QS/module/name.htm index 5b81884..2aa9dc9 100644 --- a/usr/lib/lua/luci/view/QS/module/name.htm +++ b/usr/lib/lua/luci/view/QS/module/name.htm @@ -54,14 +54,5 @@

<%=nameErr%>

-
From 3ab17cf31ed2d84f1a579514271ee7c0ee9a3b8f Mon Sep 17 00:00:00 2001 From: Seamus Tuohy Date: Wed, 7 Aug 2013 07:55:26 -0400 Subject: [PATCH 3/3] removed quickstart settings file after completion of QS --- usr/lib/lua/luci/controller/QS/modules.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/usr/lib/lua/luci/controller/QS/modules.lua b/usr/lib/lua/luci/controller/QS/modules.lua index 8b1ea94..96ccfc1 100644 --- a/usr/lib/lua/luci/controller/QS/modules.lua +++ b/usr/lib/lua/luci/controller/QS/modules.lua @@ -268,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