From 41cb5fab98d444a495d54ed7c4d975330afa02b6 Mon Sep 17 00:00:00 2001 From: Seamus Tuohy Date: Mon, 26 Aug 2013 10:18:05 -0400 Subject: [PATCH 1/2] continued development --- luasrc/controller/commotion/meshprofile.lua | 78 +++++++++++++++++++-- luasrc/view/commotion/meshprofile.htm | 2 +- 2 files changed, 75 insertions(+), 5 deletions(-) diff --git a/luasrc/controller/commotion/meshprofile.lua b/luasrc/controller/commotion/meshprofile.lua index f22134b..734b66a 100644 --- a/luasrc/controller/commotion/meshprofile.lua +++ b/luasrc/controller/commotion/meshprofile.lua @@ -27,7 +27,7 @@ function index() entry({"admin", "commotion", "meshprofile"}, call("main"), "Mesh Profile", 20).dependent=false end -function main() +function main(error) local uci = luci.model.uci.cursor() local rawProfiles = luci.fs.dir(profileDir) local available = {} @@ -51,22 +51,31 @@ end function ifprocess() log("Processing profile application...") + local error = nil local values = luci.http.formvalue() local tif = values["interfaces"] local p = values["profiles"] local uci = luci.model.uci.cursor() log("Applying " .. p .. " to " .. tif) + old_prof = uci:get('network', tif, "profile") + error = flush_wireless_profile(old_prof, p, tif) uci:set('network', tif, "profile", p) uci:commit('network') uci:save('network') - finish() + if error ~= nil then + main(error) + else + finish() + end end + function finish() luci.template.render("QS/module/applyreboot", {redirect_location=("http://"..luci.http.getenv("SERVER_NAME").."/cgi-bin/luci/admin/commotion/meshprofile")}) luci.http.close() - luci.sys.call("/etc/init.d/commotiond restart") - luci.sys.call("sleep 2; /etc/init.d/network restart") +-- luci.sys.call("/etc/init.d/commotiond restart") +-- luci.sys.call("sleep 2; /etc/init.d/network restart") + luci.sys.reboot() return({'complete'}) end @@ -97,3 +106,64 @@ function log(msg) luci.sys.exec("logger -t luci " .. msg) end end + + +function flush_wireless_profile(old_profile, new_profile, interface) + --TODO need a userspace warning that channel settings will not take effect and need to be done in the settings page. + local uci = luci.model.uci.cursor() + local found = nil + local old_dev = nil + local name = nil + local error = nil + settings = get_commotion_settings(new_profile) + uci:foreach("wireless", "wifi-iface", + function(s) + log(s['.name'] ) + if s['.name'] == old_profile then + --check that they are + log("OLD") + found = true + old_dev = s.device + name = s['.name'] + elseif s['.name'] == new_profile then + error = luci.i18n.translate("Each profile must have a seperate name. Please try with a unique profile.") + elseif s['.name'] ~= old_profile and s.network == interface then + error = luci.i18n.translate("You have multiple wireless interfaces on a single network interface. This is not allowed.") + end + end) + log(tostring(conflict).." is the conflict level") + if error ~= nil then + return error + else + uci:delete("wireless", name) + uci:section('wireless', 'wifi-iface', new_profile, + {device=old_dev, + network=interface, + ssid=settings[ssid], + mode=settings[mode]}) + uci:save("wireless") + uci:commit("wireless") + end +end + +function get_commotion_settings(file) + --[=[ Checks the quickstart settings file and returns a table with setting, value pairs.--]=] + local QS = luci.controller.QS.QS + settings = {} + for line in io.lines("/etc/commotion/profiles.d/"..file) do + setting = line:split("=") + if setting[1] ~= nil and setting[2] ~= nil then + settings[setting[1]] = setting[2] + end + end + if next(settings) then + return settings + end +end + +function string:split(sep) + local sep, fields = sep or ":", {} + local pattern = string.format("([^%s]+)", sep) + self:gsub(pattern, function(c) fields[#fields+1] = c end) + return fields +end diff --git a/luasrc/view/commotion/meshprofile.htm b/luasrc/view/commotion/meshprofile.htm index d314b50..5327d0c 100644 --- a/luasrc/view/commotion/meshprofile.htm +++ b/luasrc/view/commotion/meshprofile.htm @@ -14,7 +14,7 @@

Node Profiles

If your node includes configuration profiles for multiple Commotion -networks, this form allows you to set your defaults. +networks, this form allows you to set your defaults. NOTE: Channel settings must be manually changed. We recommend that you reboot your node after changing these settings.

From e305c4dad1f33416d7e7a91f63aec41582c85930 Mon Sep 17 00:00:00 2001 From: Seamus Tuohy Date: Mon, 26 Aug 2013 11:35:36 -0400 Subject: [PATCH 2/2] fixed a problem with the ssid and mode settings table reader --- luasrc/controller/commotion/meshprofile.lua | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/luasrc/controller/commotion/meshprofile.lua b/luasrc/controller/commotion/meshprofile.lua index 734b66a..361a9e5 100644 --- a/luasrc/controller/commotion/meshprofile.lua +++ b/luasrc/controller/commotion/meshprofile.lua @@ -73,9 +73,10 @@ end function finish() luci.template.render("QS/module/applyreboot", {redirect_location=("http://"..luci.http.getenv("SERVER_NAME").."/cgi-bin/luci/admin/commotion/meshprofile")}) luci.http.close() --- luci.sys.call("/etc/init.d/commotiond restart") --- luci.sys.call("sleep 2; /etc/init.d/network restart") - luci.sys.reboot() + --luci.sys.call("/etc/init.d/commotiond restart") + --luci.sys.call("sleep 2; /etc/init.d/network restart") + --In order to ensure that everything works cleanly a restart is required + p = luci.sys.reboot() return({'complete'}) end @@ -118,10 +119,7 @@ function flush_wireless_profile(old_profile, new_profile, interface) settings = get_commotion_settings(new_profile) uci:foreach("wireless", "wifi-iface", function(s) - log(s['.name'] ) if s['.name'] == old_profile then - --check that they are - log("OLD") found = true old_dev = s.device name = s['.name'] @@ -131,7 +129,7 @@ function flush_wireless_profile(old_profile, new_profile, interface) error = luci.i18n.translate("You have multiple wireless interfaces on a single network interface. This is not allowed.") end end) - log(tostring(conflict).." is the conflict level") + --log(tostring(conflict).." is the conflict level") if error ~= nil then return error else @@ -139,8 +137,8 @@ function flush_wireless_profile(old_profile, new_profile, interface) uci:section('wireless', 'wifi-iface', new_profile, {device=old_dev, network=interface, - ssid=settings[ssid], - mode=settings[mode]}) + ssid=settings['ssid'], + mode=settings['mode']}) uci:save("wireless") uci:commit("wireless") end