diff --git a/luasrc/controller/commotion/meshprofile.lua b/luasrc/controller/commotion/meshprofile.lua index f22134b..361a9e5 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,32 @@ 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") + --In order to ensure that everything works cleanly a restart is required + p = luci.sys.reboot() return({'complete'}) end @@ -97,3 +107,61 @@ 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) + if s['.name'] == old_profile then + 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.