diff --git a/luci/config-mode/files/usr/lib/lua/luci/controller/ffhl/wizard.lua b/luci/config-mode/files/usr/lib/lua/luci/controller/ffhl/wizard.lua index fab695f..c0cfe30 100644 --- a/luci/config-mode/files/usr/lib/lua/luci/controller/ffhl/wizard.lua +++ b/luci/config-mode/files/usr/lib/lua/luci/controller/ffhl/wizard.lua @@ -1,29 +1,29 @@ module("luci.controller.ffhl.wizard", package.seeall) function index() - local uci = luci.model.uci.cursor() - if uci:get_first("ffhl", "wizard", "enabled") == "1" then - entry({"wizard", "welcome"}, template("ffhl-wizard/welcome"), "Willkommen", 10).dependent=false - entry({"wizard", "password"}, form("ffhl-wizard/password"), "Passwort", 20).dependent=false - entry({"wizard", "hostname"}, form("ffhl-wizard/hostname"), "Hostname", 30).dependent=false - entry({"wizard", "meshvpn"}, form("ffhl-wizard/meshvpn"), "Mesh-VPN", 40).dependent=false - entry({"wizard", "meshvpn", "pubkey"}, template("ffhl-wizard/meshvpn-key"), "Mesh-VPN Key", 1).dependent=false - entry({"wizard", "completed"}, template("ffhl-wizard/completed"), "Fertig", 50).dependent=false - entry({"wizard", "completed", "reboot"}, call("reboot"), "reboot", 1).dependent=false - end + local uci = luci.model.uci.cursor() + if uci:get_first("ffhl", "wizard", "enabled") == "1" then + entry({"wizard", "welcome"}, template("ffhl-wizard/welcome"), "Willkommen", 10).dependent=false + entry({"wizard", "password"}, form("ffhl-wizard/password"), "Passwort", 20).dependent=false + entry({"wizard", "hostname"}, form("ffhl-wizard/hostname"), "Hostname", 30).dependent=false + entry({"wizard", "meshvpn"}, form("ffhl-wizard/meshvpn"), "Mesh-VPN", 40).dependent=false + entry({"wizard", "meshvpn", "pubkey"}, template("ffhl-wizard/meshvpn-key"), "Mesh-VPN Key", 1).dependent=false + entry({"wizard", "completed"}, template("ffhl-wizard/completed"), "Fertig", 50).dependent=false + entry({"wizard", "completed", "reboot"}, call("reboot"), "reboot", 1).dependent=false + end end function reboot() - local uci = luci.model.uci.cursor() - - uci:foreach("ffhl", "wizard", function(s) - uci:set("ffhl", s[".name"], "enabled", "0") - end - ) - - uci:save("ffhl") - uci:commit("ffhl") - - luci.sys.reboot() + local uci = luci.model.uci.cursor() + + uci:foreach("ffhl", "wizard", function(s) + uci:set("ffhl", s[".name"], "enabled", "0") + end + ) + + uci:save("ffhl") + uci:commit("ffhl") + + luci.sys.reboot() end diff --git a/luci/config-mode/files/usr/lib/lua/luci/model/cbi/ffhl-wizard/hostname.lua b/luci/config-mode/files/usr/lib/lua/luci/model/cbi/ffhl-wizard/hostname.lua index 47e77b1..640ab91 100644 --- a/luci/config-mode/files/usr/lib/lua/luci/model/cbi/ffhl-wizard/hostname.lua +++ b/luci/config-mode/files/usr/lib/lua/luci/model/cbi/ffhl-wizard/hostname.lua @@ -10,29 +10,29 @@ hostname.value = uci:get_first("system", "system", "hostname") hostname.rmempty = false function hostname.validate(self, value, section) - return value + return value end function f.handle(self, state, data) - if state == FORM_VALID then - local stat = true - uci:foreach("system", "system", function(s) - stat = stat and uci:set("system", s[".name"], "hostname", data.hostname) - end - ) - - stat = stat and uci:save("system") - stat = stat and uci:commit("system") - - if stat then - nav.maybe_redirect_to_successor() - f.message = "Hostname geändert!" - else - f.errmessage = "Fehler!" - end - end - - return true + if state == FORM_VALID then + local stat = true + uci:foreach("system", "system", function(s) + stat = stat and uci:set("system", s[".name"], "hostname", data.hostname) + end + ) + + stat = stat and uci:save("system") + stat = stat and uci:commit("system") + + if stat then + nav.maybe_redirect_to_successor() + f.message = "Hostname geändert!" + else + f.errmessage = "Fehler!" + end + end + + return true end return f diff --git a/luci/config-mode/files/usr/lib/lua/luci/model/cbi/ffhl-wizard/meshvpn.lua b/luci/config-mode/files/usr/lib/lua/luci/model/cbi/ffhl-wizard/meshvpn.lua index 9fe98cb..3594094 100644 --- a/luci/config-mode/files/usr/lib/lua/luci/model/cbi/ffhl-wizard/meshvpn.lua +++ b/luci/config-mode/files/usr/lib/lua/luci/model/cbi/ffhl-wizard/meshvpn.lua @@ -15,42 +15,42 @@ downstream = f:field(Value, "downstream", "Downstream bandwidth (kbit/s)") downstream.value = uci:get_first("ffhl", "bandwidth", "downstream") function f.handle(self, state, data) - if state == FORM_VALID then - local stat = false - uci:set("fastd", "ffhl_mesh_vpn", "enabled", data.meshvpn) - uci:save("fastd") - uci:commit("fastd") - - uci:foreach("ffhl", "bandwidth", function(s) - uci:set("ffhl", s[".name"], "upstream", data.upstream) - uci:set("ffhl", s[".name"], "downstream", data.downstream) - end - ) + if state == FORM_VALID then + local stat = false + uci:set("fastd", "ffhl_mesh_vpn", "enabled", data.meshvpn) + uci:save("fastd") + uci:commit("fastd") - uci:save("ffhl") - uci:commit("ffhl") + uci:foreach("ffhl", "bandwidth", function(s) + uci:set("ffhl", s[".name"], "upstream", data.upstream) + uci:set("ffhl", s[".name"], "downstream", data.downstream) + end + ) - if data.meshvpn == "1" then + uci:save("ffhl") + uci:commit("ffhl") + + if data.meshvpn == "1" then local secret = uci:get("fastd", "ffhl_mesh_vpn", "secret") - if not secret or not secret:match("%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x") then - luci.sys.call("/etc/init.d/haveged start") - local f = io.popen("fastd --generate-key --machine-readable", "r") - local secret = f:read("*a") - f:close() - luci.sys.call("/etc/init.d/haveged stop") + if not secret or not secret:match("%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x") then + luci.sys.call("/etc/init.d/haveged start") + local f = io.popen("fastd --generate-key --machine-readable", "r") + local secret = f:read("*a") + f:close() + luci.sys.call("/etc/init.d/haveged stop") + + uci:set("fastd", "ffhl_mesh_vpn", "secret", secret) + uci:save("fastd") + uci:commit("fastd") - uci:set("fastd", "ffhl_mesh_vpn", "secret", secret) - uci:save("fastd") - uci:commit("fastd") - end - luci.http.redirect(luci.dispatcher.build_url("wizard", "meshvpn", "pubkey")) - else - nav.maybe_redirect_to_successor() - end - end - - return true + luci.http.redirect(luci.dispatcher.build_url("wizard", "meshvpn", "pubkey")) + else + nav.maybe_redirect_to_successor() + end + end + + return true end return f diff --git a/luci/config-mode/files/usr/lib/lua/luci/model/cbi/ffhl-wizard/password.lua b/luci/config-mode/files/usr/lib/lua/luci/model/cbi/ffhl-wizard/password.lua index 5f5e15b..fc89cff 100644 --- a/luci/config-mode/files/usr/lib/lua/luci/model/cbi/ffhl-wizard/password.lua +++ b/luci/config-mode/files/usr/lib/lua/luci/model/cbi/ffhl-wizard/password.lua @@ -12,25 +12,25 @@ pw2.password = true pw2.rmempty = false function pw2.validate(self, value, section) - return pw1:formvalue(section) == value and value + return pw1:formvalue(section) == value and value end function f.handle(self, state, data) - if state == FORM_VALID then - local stat = luci.sys.user.setpasswd("root", data.pw1) == 0 - - if stat then - nav.maybe_redirect_to_successor() - f.message = "Passwort geändert!" - else - f.errmessage = "Fehler!" - end - - data.pw1 = nil - data.pw2 = nil - end - - return true + if state == FORM_VALID then + local stat = luci.sys.user.setpasswd("root", data.pw1) == 0 + + if stat then + nav.maybe_redirect_to_successor() + f.message = "Passwort geändert!" + else + f.errmessage = "Fehler!" + end + + data.pw1 = nil + data.pw2 = nil + end + + return true end return f diff --git a/luci/config-mode/files/usr/lib/lua/luci/tools/ffhl-wizard/nav.lua b/luci/config-mode/files/usr/lib/lua/luci/tools/ffhl-wizard/nav.lua index 8ef509a..3597c83 100644 --- a/luci/config-mode/files/usr/lib/lua/luci/tools/ffhl-wizard/nav.lua +++ b/luci/config-mode/files/usr/lib/lua/luci/tools/ffhl-wizard/nav.lua @@ -1,43 +1,43 @@ -module("luci.tools.ffhl-wizard.nav", package.seeall) +module("luci.tools.ffhl-wizard.nav", package.seeall) function maybe_redirect_to_successor() - local pre, suc = get() - - if suc then - luci.http.redirect(luci.dispatcher.build_url("wizard", suc.href)) + local pre, suc = get() + + if suc then + luci.http.redirect(luci.dispatcher.build_url("wizard", suc.href)) end end -function get() +function get() local disp = require "luci.dispatcher" local request = disp.context.path local category = request[1] local cattree = category and disp.node(category) - - local childs = disp.node_childs(cattree) - - local predecessor = nil - local successor = nil - - if #childs > 0 then - local found_pre = false - for i, r in ipairs(childs) do - local nnode = cattree.nodes[r] - nnode.href = r - + + local childs = disp.node_childs(cattree) + + local predecessor = nil + local successor = nil + + if #childs > 0 then + local found_pre = false + for i, r in ipairs(childs) do + local nnode = cattree.nodes[r] + nnode.href = r + if r == request[2] then - found_pre = true + found_pre = true elseif found_pre and successor == nil then - successor = nnode + successor = nnode end - + if not found_pre then - predecessor = nnode + predecessor = nnode end - end - end - + end + end + return predecessor, successor end diff --git a/luci/config-mode/files/usr/lib/lua/luci/view/ffhl-wizard/completed.htm b/luci/config-mode/files/usr/lib/lua/luci/view/ffhl-wizard/completed.htm index 48aa0e4..377fca2 100644 --- a/luci/config-mode/files/usr/lib/lua/luci/view/ffhl-wizard/completed.htm +++ b/luci/config-mode/files/usr/lib/lua/luci/view/ffhl-wizard/completed.htm @@ -1,14 +1,14 @@ <% - local disp = require "luci.dispatcher" + local disp = require "luci.dispatcher" %> <%+header%> -

Konfiguration abgeschlossen

- -

Die Konfiguration deines Freifunkknotens ist nun abgeschlossen.

+

Konfiguration abgeschlossen

-

Damit sie aktiv wird, muss der Knoten neugestartet werden.

- -

- ">Jetzt neustarten! -

+

Die Konfiguration deines Freifunkknotens ist nun abgeschlossen.

+ +

Damit sie aktiv wird, muss der Knoten neugestartet werden.

+ +

+ ">Jetzt neustarten! +

<%+footer%> diff --git a/luci/config-mode/files/usr/lib/lua/luci/view/ffhl-wizard/footer.htm b/luci/config-mode/files/usr/lib/lua/luci/view/ffhl-wizard/footer.htm index 888ee5f..57e20f3 100644 --- a/luci/config-mode/files/usr/lib/lua/luci/view/ffhl-wizard/footer.htm +++ b/luci/config-mode/files/usr/lib/lua/luci/view/ffhl-wizard/footer.htm @@ -1,6 +1,6 @@ <% local xtime if exectime then - xtime = (string.format("%.2fs", os.clock() - exectime)) + xtime = (string.format("%.2fs", os.clock() - exectime)) end %>