commit b8ebdc34988282ad4b4f2016ed1990ce64aef759
Author: Nils Schneider
Date: Tue May 22 19:28:02 2012 +0200
initial configmode
diff --git a/luci/config-mode/Makefile b/luci/config-mode/Makefile
new file mode 100644
index 0000000..15281f9
--- /dev/null
+++ b/luci/config-mode/Makefile
@@ -0,0 +1,39 @@
+# Copyright (C) 2012 Nils Schneider
+# This is free software, licensed under the Apache 2.0 license.
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=configmode
+PKG_RELEASE:=0.0.1
+
+PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/configmode
+ SECTION:=luci
+ CATEGORY:=LuCI
+ SUBMENU:=9. Freifunk
+ TITLE:=Luci based configmode for userfriendly setup of new meshnodes
+ DEPENDS:=+firewall
+endef
+
+define Package/configmode/description
+ Luci based configmode
+endef
+
+define Build/Prepare
+ mkdir -p $(PKG_BUILD_DIR)
+endef
+
+define Build/Configure
+endef
+
+define Build/Compile
+endef
+
+define Package/configmode/install
+ $(CP) ./files/* $(1)/
+endef
+
+$(eval $(call BuildPackage,configmode))
diff --git a/luci/config-mode/files/etc/config/ffhl b/luci/config-mode/files/etc/config/ffhl
new file mode 100644
index 0000000..5993307
--- /dev/null
+++ b/luci/config-mode/files/etc/config/ffhl
@@ -0,0 +1,4 @@
+
+config wizard
+ option enabled '1'
+
diff --git a/luci/config-mode/files/usr/lib/lua/luci/controller/ffhl/index.lua b/luci/config-mode/files/usr/lib/lua/luci/controller/ffhl/index.lua
new file mode 100644
index 0000000..c042f9c
--- /dev/null
+++ b/luci/config-mode/files/usr/lib/lua/luci/controller/ffhl/index.lua
@@ -0,0 +1,12 @@
+module("luci.controller.ffhl.index", package.seeall)
+
+function index()
+ entry({}, call("maybe_wizard"), "luebeck.freifunk.net", 20).dependent=false
+end
+
+function maybe_wizard()
+ -- This function should figure out whether the wizard already ran succesfully
+ -- and redirect to the wizard or the status page.
+
+ luci.http.redirect(luci.dispatcher.build_url("wizard", "welcome"))
+end
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
new file mode 100644
index 0000000..2a55383
--- /dev/null
+++ b/luci/config-mode/files/usr/lib/lua/luci/controller/ffhl/wizard.lua
@@ -0,0 +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
+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()
+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
new file mode 100644
index 0000000..47e77b1
--- /dev/null
+++ b/luci/config-mode/files/usr/lib/lua/luci/model/cbi/ffhl-wizard/hostname.lua
@@ -0,0 +1,38 @@
+local uci = luci.model.uci.cursor()
+
+local nav = require "luci.tools.ffhl-wizard.nav"
+
+local f = SimpleForm("hostname", "Name deines Freifunkknotens", "Als nächstes solltest du einem Freifunkknoten einen individuellen Namen geben. Dieser hilft dir und auch uns den Überblick zu behalten.")
+f.template = "ffhl-wizard/wizardform"
+
+hostname = f:field(Value, "hostname", "Hostname")
+hostname.value = uci:get_first("system", "system", "hostname")
+hostname.rmempty = false
+
+function hostname.validate(self, value, section)
+ 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
+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
new file mode 100644
index 0000000..73c4fa9
--- /dev/null
+++ b/luci/config-mode/files/usr/lib/lua/luci/model/cbi/ffhl-wizard/meshvpn.lua
@@ -0,0 +1,39 @@
+local uci = luci.model.uci.cursor()
+
+local nav = require "luci.tools.ffhl-wizard.nav"
+
+local f = SimpleForm("meshvpn", "Mesh-VPN", "Um deinen Freifunkknoten auch über das Internet mit anderen Knoten zu verbinden, muss das Mesh-VPN aktiviert werden.
Dadurch ist es möglich das Freifunknetz auch ohne WLAN Verbindung zu anderen Knoten zu nutzen.")
+f.template = "ffhl-wizard/wizardform"
+
+meshvpn = f:field(Flag, "meshvpn", "Mesh-VPN aktivieren?")
+meshvpn.default = string.format("%d", uci:get("fastd", "ffhl_mesh_vpn", "enabled"))
+meshvpn.rmempty = false
+
+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")
+
+ if data.meshvpn == "1" 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")
+
+ 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
new file mode 100644
index 0000000..5f5e15b
--- /dev/null
+++ b/luci/config-mode/files/usr/lib/lua/luci/model/cbi/ffhl-wizard/password.lua
@@ -0,0 +1,36 @@
+local nav = require "luci.tools.ffhl-wizard.nav"
+
+f = SimpleForm("password", "Administrator Passwort setzen", "Damit nur du Zugriff auf deinen Freifunkknoten hast, solltest du jetzt ein Passwort vergeben.
Bitte wähle ein sicheres Passwort. Sonst könnten Leute wilden Scheiß machen, den du nicht willst!")
+f.template = "ffhl-wizard/wizardform"
+
+pw1 = f:field(Value, "pw1", "Passwort")
+pw1.password = true
+pw1.rmempty = false
+
+pw2 = f:field(Value, "pw2", "Wiederholung")
+pw2.password = true
+pw2.rmempty = false
+
+function pw2.validate(self, value, section)
+ 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
+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
new file mode 100644
index 0000000..8ef509a
--- /dev/null
+++ b/luci/config-mode/files/usr/lib/lua/luci/tools/ffhl-wizard/nav.lua
@@ -0,0 +1,43 @@
+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))
+ end
+end
+
+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
+
+ if r == request[2] then
+ found_pre = true
+ elseif found_pre and successor == nil then
+ successor = nnode
+ end
+
+ if not found_pre then
+ predecessor = nnode
+ 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
new file mode 100644
index 0000000..cbec028
--- /dev/null
+++ b/luci/config-mode/files/usr/lib/lua/luci/view/ffhl-wizard/completed.htm
@@ -0,0 +1,14 @@
+<%
+ local disp = require "luci.dispatcher"
+%>
+<%+header%>
+
Konfiguration abgeschlossen
+
+ 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
new file mode 100644
index 0000000..888ee5f
--- /dev/null
+++ b/luci/config-mode/files/usr/lib/lua/luci/view/ffhl-wizard/footer.htm
@@ -0,0 +1,19 @@
+<% local xtime
+if exectime then
+ xtime = (string.format("%.2fs", os.clock() - exectime))
+end %>
+
+
+
+
+
+