From c19b4efd05eb1ce1e39dc75001de12c55af0cfe2 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Sat, 28 Sep 2013 23:18:36 +0200 Subject: [PATCH] new basic configmode --- package/gluon-config-mode/Makefile | 2 +- .../files/etc/config/config_mode | 3 - .../files/etc/config/configmode | 4 + .../files/etc/hotplug.d/button/50-config-mode | 29 ------- .../files/etc/hotplug.d/button/50-configmode | 29 +++++++ .../files/etc/init.d/config_mode | 53 ------------- .../files/etc/init.d/configmode | 54 +++++++++++++ .../luci/controller/configmode/configmode.lua | 65 +++++++++++++++ .../lua/luci/controller/freifunk/index.lua | 13 --- .../lua/luci/controller/freifunk/wizard.lua | 30 ------- .../lua/luci/model/cbi/configmode/wizard.lua | 79 +++++++++++++++++++ .../model/cbi/freifunk-wizard/hostname.lua | 38 --------- .../model/cbi/freifunk-wizard/meshvpn.lua | 67 ---------------- .../model/cbi/freifunk-wizard/password.lua | 43 ---------- .../usr/lib/lua/luci/tools/configmode.lua | 29 +++++++ .../lua/luci/tools/freifunk-wizard/nav.lua | 43 ---------- .../lib/lua/luci/view/configmode/reboot.htm | 43 ++++++++++ .../luci/view/freifunk-wizard/completed.htm | 16 ---- .../lua/luci/view/freifunk-wizard/footer.htm | 19 ----- .../lua/luci/view/freifunk-wizard/header.htm | 24 ------ .../luci/view/freifunk-wizard/meshvpn-key.htm | 18 ----- .../lib/lua/luci/view/freifunk-wizard/nav.htm | 15 ---- .../lua/luci/view/freifunk-wizard/welcome.htm | 19 ----- .../luci/view/freifunk-wizard/wizardform.htm | 68 ---------------- 24 files changed, 304 insertions(+), 499 deletions(-) delete mode 100644 package/gluon-config-mode/files/etc/config/config_mode create mode 100644 package/gluon-config-mode/files/etc/config/configmode delete mode 100755 package/gluon-config-mode/files/etc/hotplug.d/button/50-config-mode create mode 100755 package/gluon-config-mode/files/etc/hotplug.d/button/50-configmode delete mode 100755 package/gluon-config-mode/files/etc/init.d/config_mode create mode 100755 package/gluon-config-mode/files/etc/init.d/configmode create mode 100644 package/gluon-config-mode/files/usr/lib/lua/luci/controller/configmode/configmode.lua delete mode 100644 package/gluon-config-mode/files/usr/lib/lua/luci/controller/freifunk/index.lua delete mode 100644 package/gluon-config-mode/files/usr/lib/lua/luci/controller/freifunk/wizard.lua create mode 100644 package/gluon-config-mode/files/usr/lib/lua/luci/model/cbi/configmode/wizard.lua delete mode 100644 package/gluon-config-mode/files/usr/lib/lua/luci/model/cbi/freifunk-wizard/hostname.lua delete mode 100644 package/gluon-config-mode/files/usr/lib/lua/luci/model/cbi/freifunk-wizard/meshvpn.lua delete mode 100644 package/gluon-config-mode/files/usr/lib/lua/luci/model/cbi/freifunk-wizard/password.lua create mode 100644 package/gluon-config-mode/files/usr/lib/lua/luci/tools/configmode.lua delete mode 100644 package/gluon-config-mode/files/usr/lib/lua/luci/tools/freifunk-wizard/nav.lua create mode 100644 package/gluon-config-mode/files/usr/lib/lua/luci/view/configmode/reboot.htm delete mode 100644 package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/completed.htm delete mode 100644 package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/footer.htm delete mode 100644 package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/header.htm delete mode 100644 package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/meshvpn-key.htm delete mode 100644 package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/nav.htm delete mode 100644 package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/welcome.htm delete mode 100644 package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/wizardform.htm diff --git a/package/gluon-config-mode/Makefile b/package/gluon-config-mode/Makefile index 001d41d5..37035086 100644 --- a/package/gluon-config-mode/Makefile +++ b/package/gluon-config-mode/Makefile @@ -15,7 +15,7 @@ define Package/gluon-config-mode SECTION:=gluon CATEGORY:=Gluon TITLE:=Luci based config mode for user friendly setup of new meshnodes - DEPENDS:=+gluon-core +uhttpd +dnsmasq +luci-mod-admin-core + DEPENDS:=+gluon-core +uhttpd +dnsmasq +luci-mod-admin-core +luci-mod-failsafe +ip +luci-theme-openwrt +haveged endef define Package/gluon-config-mode/description diff --git a/package/gluon-config-mode/files/etc/config/config_mode b/package/gluon-config-mode/files/etc/config/config_mode deleted file mode 100644 index 179b22bf..00000000 --- a/package/gluon-config-mode/files/etc/config/config_mode +++ /dev/null @@ -1,3 +0,0 @@ -config wizard - option enabled '1' - option configured '0' diff --git a/package/gluon-config-mode/files/etc/config/configmode b/package/gluon-config-mode/files/etc/config/configmode new file mode 100644 index 00000000..d5e91003 --- /dev/null +++ b/package/gluon-config-mode/files/etc/config/configmode @@ -0,0 +1,4 @@ +config wizard + option enabled '1' + option configured '0' + option keyaddress 'keys@luebeck.freifunk.net' diff --git a/package/gluon-config-mode/files/etc/hotplug.d/button/50-config-mode b/package/gluon-config-mode/files/etc/hotplug.d/button/50-config-mode deleted file mode 100755 index 0e4e8a89..00000000 --- a/package/gluon-config-mode/files/etc/hotplug.d/button/50-config-mode +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - - -wait=3 - - -wait_config_mode() { - sleep $wait - uci set 'config_mode.@wizard[0].enabled=1' - uci commit config_mode - reboot -} - - -if [ "$BUTTON" = wps -o "$BUTTON" = reset ]; then - case "$ACTION" in - pressed) - wait_config_mode & - PID=$! - echo $PID > /tmp/.wait_config_mode - ;; - released) - if [ -r /tmp/.wait_config_mode ]; then - kill $(cat /tmp/.wait_config_mode) - rm /tmp/.wait_config_mode - fi - ;; - esac -fi diff --git a/package/gluon-config-mode/files/etc/hotplug.d/button/50-configmode b/package/gluon-config-mode/files/etc/hotplug.d/button/50-configmode new file mode 100755 index 00000000..d5032d21 --- /dev/null +++ b/package/gluon-config-mode/files/etc/hotplug.d/button/50-configmode @@ -0,0 +1,29 @@ +#!/bin/sh + + +wait=3 + + +wait_configmode() { + sleep $wait + uci set 'configmode.@wizard[0].enabled=1' + uci commit configmode + reboot +} + + +if [ "$BUTTON" = wps -o "$BUTTON" = reset ]; then + case "$ACTION" in + pressed) + wait_configmode & + PID=$! + echo $PID > /tmp/.wait_configmode + ;; + released) + if [ -r /tmp/.wait_configmode ]; then + kill $(cat /tmp/.wait_configmode) + rm /tmp/.wait_configmode + fi + ;; + esac +fi diff --git a/package/gluon-config-mode/files/etc/init.d/config_mode b/package/gluon-config-mode/files/etc/init.d/config_mode deleted file mode 100755 index e4b5efb2..00000000 --- a/package/gluon-config-mode/files/etc/init.d/config_mode +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh /etc/rc.common - -START=12 - - -config_mode_iface=eth0 -config_mode_addr=192.168.1.1 -config_mode_plen=24 - -config_mode_dnsname=freifunk -config_mode_dhcp_range=192.168.1.2,192.168.1.254 - -check_enable() { - config_get enabled "$1" enabled - config_get configured "$1" configured - - if [ "$enabled" = 1 -o "$configured" != 1 ]; then - export enable=1 - fi -} - -start() { - enable=0 - config_load config_mode - config_foreach check_enable wizard - - if [ "$enable" = '1' ]; then - lua -luci -e 'require "luci.model.uci"; uci_state=luci.model.uci.cursor_state(); uci_state:section("config_mode", "wizard", nil, { running = "1" }); uci_state:save("config_mode")' - uci set 'config_mode.@wizard[0].enabled=0' - uci commit config_mode - - ip addr add $config_mode_addr/$config_mode_plen dev $config_mode_iface - ip link set up dev $config_mode_iface - - /etc/init.d/telnet start - /etc/init.d/dropbear start - /etc/init.d/uhttpd start - /etc/init.d/led start - - # correctly finish firstboot - /etc/init.d/done boot - - echo "$config_mode_addr $config_mode_dnsname" > /tmp/hosts.config_mode - dnsmasq -h -H /tmp/hosts.config_mode -R -F interface:$config_mode_iface,$config_mode_dhcp_range -l /tmp/dhcp.leases -O option:router - - . /etc/diag.sh - get_status_led - status_led_set_timer 1000 300 - - # block further boot - while true; do sleep 1; done - fi -} diff --git a/package/gluon-config-mode/files/etc/init.d/configmode b/package/gluon-config-mode/files/etc/init.d/configmode new file mode 100755 index 00000000..7055d130 --- /dev/null +++ b/package/gluon-config-mode/files/etc/init.d/configmode @@ -0,0 +1,54 @@ +#!/bin/sh /etc/rc.common + +START=12 + + +configmode_iface=eth0 +configmode_addr=192.168.1.1 +configmode_plen=24 + +configmode_dnsname=freifunk +configmode_dhcp_range=192.168.1.2,192.168.1.254 + +check_enable() { + config_get enabled "$1" enabled + config_get configured "$1" configured + + if [ "$enabled" = 1 -o "$configured" != 1 ]; then + export enable=1 + fi +} + +start() { + enable=0 + config_load configmode + config_foreach check_enable wizard + + if [ "$enable" = '1' ]; then + lua -luci -e 'require "luci.model.uci"; uci_state=luci.model.uci.cursor_state(); uci_state:section("configmode", "wizard", nil, { running = "1" }); uci_state:save("configmode")' + uci set 'configmode.@wizard[0].enabled=0' + uci commit configmode + + ip addr add $configmode_addr/$configmode_plen dev $configmode_iface + ip link set up dev $configmode_iface + + /etc/init.d/haveged start + /etc/init.d/telnet start + /etc/init.d/dropbear start + /etc/init.d/uhttpd start + /etc/init.d/led start + + # correctly finish firstboot + /etc/init.d/done boot + + echo "$configmode_addr $configmode_dnsname" > /tmp/hosts.configmode + dnsmasq -h -H /tmp/hosts.configmode -R -F interface:$configmode_iface,$configmode_dhcp_range -l /tmp/dhcp.leases -O option:router + + . /etc/diag.sh + get_status_led + status_led_set_timer 1000 300 + + # block further boot + while true; do sleep 1; done + fi +} diff --git a/package/gluon-config-mode/files/usr/lib/lua/luci/controller/configmode/configmode.lua b/package/gluon-config-mode/files/usr/lib/lua/luci/controller/configmode/configmode.lua new file mode 100644 index 00000000..d9f850fc --- /dev/null +++ b/package/gluon-config-mode/files/usr/lib/lua/luci/controller/configmode/configmode.lua @@ -0,0 +1,65 @@ +--[[ +Copyright 2013 Nils Schneider + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ +]]-- + +module("luci.controller.configmode.configmode", package.seeall) + +local meshvpn_name = "mesh_vpn" + +function index() + local uci_state = luci.model.uci.cursor_state() + + if uci_state:get_first("configmode", "wizard", "running", "0") == "1" then + local root = node() + if not root.target then + root.target = alias("configmode") + root.index = true + end + + page = node() + page.lock = true + page.target = alias("configmode") + page.subindex = true + page.index = false + + page = node("configmode") + page.title = _("Configmode") + page.target = alias("configmode", "wizard") + page.order = 5 + page.setuser = "root" + page.setgroup = "root" + page.index = true + + entry({"configmode", "wizard"}, form("configmode/wizard"), _("Wizard"), 10).index = true + entry({"configmode", "reboot"}, call("action_reboot")) + end +end + +function action_reboot() + local configmode = require "luci.tools.configmode" + local pubkey + local uci = luci.model.uci.cursor() + local address = uci:get_first("configmode", "wizard", "keyaddress") + local meshvpn_enabled = uci:get("fastd", meshvpn_name, "enabled", "0") + if meshvpn_enabled == "1" then + pubkey = configmode.get_fastd_pubkey(meshvpn_name) + end + luci.template.render("configmode/reboot", {pubkey=pubkey, address=address}) + + uci:foreach("configmode", "wizard", function(s) + uci:set("configmode", s[".name"], "configured", "1") + uci:set("configmode", s[".name"], "enabled", "0") + end) + uci:save("configmode") + uci:commit("configmode") + + luci.sys.reboot() +end diff --git a/package/gluon-config-mode/files/usr/lib/lua/luci/controller/freifunk/index.lua b/package/gluon-config-mode/files/usr/lib/lua/luci/controller/freifunk/index.lua deleted file mode 100644 index cc2bcadb..00000000 --- a/package/gluon-config-mode/files/usr/lib/lua/luci/controller/freifunk/index.lua +++ /dev/null @@ -1,13 +0,0 @@ -module("luci.controller.freifunk.index", package.seeall) - - -function index() - local uci_state = luci.model.uci.cursor_state() - - if uci_state:get_first("config_mode", "wizard", "running", "0") == "1" then - local root = node() - root.target = alias("wizard", "welcome") - root.index = true - end -end - diff --git a/package/gluon-config-mode/files/usr/lib/lua/luci/controller/freifunk/wizard.lua b/package/gluon-config-mode/files/usr/lib/lua/luci/controller/freifunk/wizard.lua deleted file mode 100644 index ab64f4f8..00000000 --- a/package/gluon-config-mode/files/usr/lib/lua/luci/controller/freifunk/wizard.lua +++ /dev/null @@ -1,30 +0,0 @@ -module("luci.controller.freifunk.wizard", package.seeall) - -function index() - local uci_state = luci.model.uci.cursor_state() - if uci_state:get_first("config_mode", "wizard", "running", "0") == "1" then - entry({"wizard", "welcome"}, template("freifunk-wizard/welcome"), "Willkommen", 10).dependent=false - entry({"wizard", "password"}, form("freifunk-wizard/password"), "Passwort", 20).dependent=false - entry({"wizard", "hostname"}, form("freifunk-wizard/hostname"), "Hostname", 30).dependent=false - entry({"wizard", "meshvpn"}, form("freifunk-wizard/meshvpn"), "Mesh-VPN", 40).dependent=false - entry({"wizard", "meshvpn", "pubkey"}, template("freifunk-wizard/meshvpn-key"), "Mesh-VPN Key", 1).dependent=false - entry({"wizard", "completed"}, template("freifunk-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("config_mode", "wizard", - function(s) - uci:set("config_mode", s[".name"], "configured", "1") - end - ) - - uci:save("config_mode") - uci:commit("config_mode") - - luci.sys.reboot() -end - diff --git a/package/gluon-config-mode/files/usr/lib/lua/luci/model/cbi/configmode/wizard.lua b/package/gluon-config-mode/files/usr/lib/lua/luci/model/cbi/configmode/wizard.lua new file mode 100644 index 00000000..59d56aaa --- /dev/null +++ b/package/gluon-config-mode/files/usr/lib/lua/luci/model/cbi/configmode/wizard.lua @@ -0,0 +1,79 @@ +local configmode = require "luci.tools.configmode" +local meshvpn_name = "mesh_vpn" +local uci = luci.model.uci.cursor() +local f, s, o + +-- prepare fastd key as early as possible +configmode.setup_fastd_secret(meshvpn_name) + +f = SimpleForm("wizard", "Wizard", "Lorem ipsum...") + +s = f:section(SimpleSection, "Grundeinstellungen", nil) + +o = s:option(Value, "_hostname", "Knotenname") +o.value = uci:get_first("system", "system", "hostname") +o.rmempty = false +o.datatype = "hostname" + +o = s:option(Flag, "_meshvpn", "Mesh-VPN aktivieren?") +o.default = string.format("%d", uci:get("fastd", meshvpn_name, "enabled", "0")) +o.rmempty = false + +o = s:option(Flag, "_bwlimit", "Bandbreitenbegrenzung aktivieren?") +o.default = string.format("%d", uci:get_first("freifunk", "bandwidth", "enabled", "0")) +o.rmempty = false + +o = s:option(Flag, "_autoupdate", "Automatische Updates aktivieren?") +o.default = string.format("%d", uci:get_first("autoupdater", "autoupdater", "enabled", "0")) +o.rmempty = false + +s = f:section(SimpleSection, "GPS Koordinaten", "Hier kannst du die GPS Koordinaten deines Knotens festlegen damit er in der Karte angezeigt werden kann.") + +o = s:option(Value, "_latitude", "Breitengrad") +o.default = string.format("%f", uci:get_first("system", "location", "latitude", "0")) +o.rmempty = false +o.datatype = "float" + +o = s:option(Value, "_longitude", "Längengrad") +o.default = string.format("%f", uci:get_first("system", "location", "longitude", "0")) +o.rmempty = false +o.datatype = "float" + +function f.handle(self, state, data) + if state == FORM_VALID then + local stat = false + + uci:foreach("autoupdater", "autoupdater", function(s) + uci:set("autoupdater", s[".name"], "enabled", data._autoupdate) + end) + uci:save("autoupdater") + uci:commit("autoupdater") + + uci:foreach("freifunk", "bandwidth", function(s) + uci:set("freifunk", s[".name"], "enabled", data._bwlimit) + end) + uci:save("freifunk") + uci:commit("freifunk") + + uci:set("fastd", meshvpn_name, "enabled", data._meshvpn) + uci:save("fastd") + uci:commit("fastd") + + uci:foreach("system", "system", function(s) + uci:set("system", s[".name"], "hostname", data._hostname) + end) + + uci:foreach("system", "location", function(s) + uci:set("system", s[".name"], "latitude", data._latitude) + uci:set("system", s[".name"], "longitude", data._longitude) + end) + uci:save("system") + uci:commit("system") + + luci.http.redirect(luci.dispatcher.build_url("configmode", "reboot")) + end + + return true +end + +return f diff --git a/package/gluon-config-mode/files/usr/lib/lua/luci/model/cbi/freifunk-wizard/hostname.lua b/package/gluon-config-mode/files/usr/lib/lua/luci/model/cbi/freifunk-wizard/hostname.lua deleted file mode 100644 index ed387f9f..00000000 --- a/package/gluon-config-mode/files/usr/lib/lua/luci/model/cbi/freifunk-wizard/hostname.lua +++ /dev/null @@ -1,38 +0,0 @@ -local uci = luci.model.uci.cursor() - -local nav = require "luci.tools.freifunk-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 = "freifunk-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/package/gluon-config-mode/files/usr/lib/lua/luci/model/cbi/freifunk-wizard/meshvpn.lua b/package/gluon-config-mode/files/usr/lib/lua/luci/model/cbi/freifunk-wizard/meshvpn.lua deleted file mode 100644 index 6ca35c8a..00000000 --- a/package/gluon-config-mode/files/usr/lib/lua/luci/model/cbi/freifunk-wizard/meshvpn.lua +++ /dev/null @@ -1,67 +0,0 @@ -local meshvpn_name = "mesh_vpn" - -local uci = luci.model.uci.cursor() -local nav = require "luci.tools.freifunk-wizard.nav" - -local f = SimpleForm("meshvpn", "Mesh-VPN", "

Um deinen Freifunkknoten auch über das Internet mit dem Freifunk-Netzwerk zu verbinden, kann das Mesh-VPN aktiviert werden.\ -Dies erlaubt es, den Freifunk-Knoten zu betreiben, auch wenn es keine anderen Knoten in deiner Umgebung gibt, mit denen eine WLAN-Verbindung möglich ist.

\ -

Dabei wird zur Kommunikation ein verschlüsselter Tunnel verwendet, sodass für den Anschluss-Inhaber keinerlei Risiken entstehen.

\ -

Damit das Mesh-VPN deine Internet-Verbindung nicht unverhältnismäßig auslastet, kann die Bandbreite begrenzt werden. Wenn du zum Beispiel eine DSL-16000-Leitung hast\ -und maximal ein Viertel der Leitung zur Verfügung stellen willst, muss als Downstream-Bandbreite 4000 kbit/s eingetragen werden.

\ -

Um das Freifunk-Netz nicht zu sehr auszubremsen, bitten wir darum, mindestens 1000 kbit/s im Downstream und 100 kbit/s im Upstream bereitzustellen.

") -f.template = "freifunk-wizard/wizardform" - -meshvpn = f:field(Flag, "meshvpn", "Mesh-VPN aktivieren?") -meshvpn.default = string.format("%d", uci:get("fastd", meshvpn_name, "enabled", "0")) -meshvpn.rmempty = false - -tc = f:field(Flag, "tc", "Bandbreitenbegrenzung aktivieren?") -tc.default = string.format("%d", uci:get_first("freifunk", "bandwidth", "enabled", "0")) -tc.rmempty = false - -downstream = f:field(Value, "downstream", "Downstream-Bandbreite (kbit/s)") -downstream.value = uci:get_first("freifunk", "bandwidth", "downstream", "0") -upstream = f:field(Value, "upstream", "Upstream-Bandbreite (kbit/s)") -upstream.value = uci:get_first("freifunk", "bandwidth", "upstream", "0") - -function f.handle(self, state, data) - if state == FORM_VALID then - local stat = false - uci:set("fastd", meshvpn_name, "enabled", data.meshvpn) - uci:save("fastd") - uci:commit("fastd") - - uci:foreach("freifunk", "bandwidth", function(s) - uci:set("freifunk", s[".name"], "upstream", data.upstream) - uci:set("freifunk", s[".name"], "downstream", data.downstream) - uci:set("freifunk", s[".name"], "enabled", data.tc) - end - ) - - uci:save("freifunk") - uci:commit("freifunk") - - if data.meshvpn == "1" then - local secret = uci:get("fastd", meshvpn_name, "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") - - uci:set("fastd", meshvpn_name, "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 -end - -return f diff --git a/package/gluon-config-mode/files/usr/lib/lua/luci/model/cbi/freifunk-wizard/password.lua b/package/gluon-config-mode/files/usr/lib/lua/luci/model/cbi/freifunk-wizard/password.lua deleted file mode 100644 index b752b848..00000000 --- a/package/gluon-config-mode/files/usr/lib/lua/luci/model/cbi/freifunk-wizard/password.lua +++ /dev/null @@ -1,43 +0,0 @@ -local nav = require "luci.tools.freifunk-wizard.nav" - -f = SimpleForm("password", "Administrator-Passwort setzen", "

Damit nur du Zugriff auf deinen Freifunkknoten hast, solltest du jetzt ein Passwort vergeben. \ -Da man mit Hilfe von diesem beliebige Einstellungen geändert werden können, sollte es möglichst sicher sein.

\ -

Bitte beachte dazu folgende Hinweise:

\ -") -f.template = "freifunk-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/package/gluon-config-mode/files/usr/lib/lua/luci/tools/configmode.lua b/package/gluon-config-mode/files/usr/lib/lua/luci/tools/configmode.lua new file mode 100644 index 00000000..3b4c8b6b --- /dev/null +++ b/package/gluon-config-mode/files/usr/lib/lua/luci/tools/configmode.lua @@ -0,0 +1,29 @@ +local luci = require "luci" +local io = require "io" + +module "luci.tools.configmode" + +function setup_fastd_secret(name) + local uci = luci.model.uci.cursor() + local secret = uci:get("fastd", name, "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 + local f = io.popen("fastd --generate-key --machine-readable", "r") + local secret = f:read("*a") + f:close() + + uci:set("fastd", name, "secret", secret) + uci:save("fastd") + uci:commit("fastd") + end +end + +function get_fastd_pubkey(name) + local f = io.popen("/etc/init.d/fastd show_key " .. name, "r") + local key = f:read("*a") + f:close() + + return key +end + + diff --git a/package/gluon-config-mode/files/usr/lib/lua/luci/tools/freifunk-wizard/nav.lua b/package/gluon-config-mode/files/usr/lib/lua/luci/tools/freifunk-wizard/nav.lua deleted file mode 100644 index ec6c0a12..00000000 --- a/package/gluon-config-mode/files/usr/lib/lua/luci/tools/freifunk-wizard/nav.lua +++ /dev/null @@ -1,43 +0,0 @@ -module("luci.tools.freifunk-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/package/gluon-config-mode/files/usr/lib/lua/luci/view/configmode/reboot.htm b/package/gluon-config-mode/files/usr/lib/lua/luci/view/configmode/reboot.htm new file mode 100644 index 00000000..4ef5a1d0 --- /dev/null +++ b/package/gluon-config-mode/files/usr/lib/lua/luci/view/configmode/reboot.htm @@ -0,0 +1,43 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2008 Steven Barth +Copyright 2008 Jo-Philipp Wich + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ + +-%> + + + + <%=luci.sys.hostname()%> - <% if title then %><%=title%><% else %><%:Rebooting...%><% end %> + + + +
+
+

Geschafft! Dein Freifunkknoten ist nun fertig eingerichtet.

+ <% if pubkey then %> +
+

+ Dies ist der öffentliche Schlüssel deines Freifunkknotens. Bitte schicke ihn an <%=address%>, um ihn auf den Freifunkservern eintragen zu lassen. Sobald der Schlüssel eingetragen wurde, kann dein Knoten das Mesh-VPN nutzen. +

+
+ <%=pubkey%> +
+
+ <% end %> +
+

+ Dein Knoten startet jetzt neu. Anschließend wird er versuchen sich mit anderen Knoten in der Nähe zu verbinden. Wir wünschen dir viel Spaß dabei Freifunk zu erkunden! +

+
+
+
+ + diff --git a/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/completed.htm b/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/completed.htm deleted file mode 100644 index 3c096b7d..00000000 --- a/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/completed.htm +++ /dev/null @@ -1,16 +0,0 @@ -<% - local disp = require "luci.dispatcher" -%> -<%+header%> -

Konfiguration abgeschlossen

- -

Die Konfiguration deines Freifunkknotens ist nun abgeschlossen. Damit sie aktiv wird, muss der Knoten neugestartet werden.

- -

Um später wieder in den Konfiguration-Modus zurückzukehren, zum Beispiel um die Konfiguration zu verändern oder ein Firmware-Upgrade durchzuführen, - muss der QSS-Button am Gehäuse für einige Sekunden gedrückt gehalten werden, während der Knoten läuft. Der Knoten wird dann neu starten und in - den Konfigurationsmodus zurückkehren.

- -

- ">Jetzt neustarten! -

-<%+footer%> diff --git a/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/footer.htm b/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/footer.htm deleted file mode 100644 index 57e20f31..00000000 --- a/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/footer.htm +++ /dev/null @@ -1,19 +0,0 @@ -<% local xtime -if exectime then - xtime = (string.format("%.2fs", os.clock() - exectime)) -end %> - - - - - - - - diff --git a/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/header.htm b/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/header.htm deleted file mode 100644 index 7c28bc43..00000000 --- a/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/header.htm +++ /dev/null @@ -1,24 +0,0 @@ -<% - local fs = require "luci.fs" - local sys = require "luci.sys" - local http = require "luci.http" - local disp = require "luci.dispatcher" - - local hostname = sys.hostname() -%> - - - - - - -<%=striptags( hostname )%> - Wizard - - - - -
- - diff --git a/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/meshvpn-key.htm b/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/meshvpn-key.htm deleted file mode 100644 index 781dd11b..00000000 --- a/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/meshvpn-key.htm +++ /dev/null @@ -1,18 +0,0 @@ -<% - local meshvpn_name = "mesh_vpn" - local address = "freifunk.luebeck@asta.uni-luebeck.de" - - local disp = require "luci.dispatcher" - local f = io.popen("/etc/init.d/fastd show_key " .. meshvpn_name, "r") - local key = f:read("*a") - f:close() - -%> -<%+header%> -

Schlüsselaustausch

-

Dies ist der öffentliche Schlüssel deines Freifunkknotens. Bitte schicke ihn an <%=address%>, um ihn auf den Freifunkservern eintragen zu lassen. Sobald der Schlüssel eingetragen wurde, kann dein Knoten das Mesh-VPN nutzen.

-
- <%=key%> -
-<%+freifunk-wizard/nav%> -<%+footer%> diff --git a/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/nav.htm b/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/nav.htm deleted file mode 100644 index ca46eaee..00000000 --- a/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/nav.htm +++ /dev/null @@ -1,15 +0,0 @@ -<% - local nav = require "luci.tools.freifunk-wizard.nav" - local predecessor, successor = nav.get() -%> - -
- -<% if successor then %> - ">Weiter -<% end %> - -<% if predecessor then %> - ">Zurück -<% end %> -
diff --git a/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/welcome.htm b/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/welcome.htm deleted file mode 100644 index 259f4d85..00000000 --- a/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/welcome.htm +++ /dev/null @@ -1,19 +0,0 @@ -<% - local disp = require "luci.dispatcher" - local nav = require "luci.tools.freifunk-wizard.nav" - local predecessor, successor = nav.get() -%> -<%+header%> -

Willkommen auf deinem Freifunkknoten!

-

Danke, dass du Freifunk unterstützt.

-

Dieser Wizard hilft dir nun deinen Knoten einzurichten. Dabei führt er dich schrittweise durch die wichtigsten Punkte.

- -
-<% if successor then %> - ">Knoten neu einrichten -<% end %> - - ">Firmwareupgrade einspielen -
-<%+footer%> - diff --git a/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/wizardform.htm b/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/wizardform.htm deleted file mode 100644 index 875f448b..00000000 --- a/package/gluon-config-mode/files/usr/lib/lua/luci/view/freifunk-wizard/wizardform.htm +++ /dev/null @@ -1,68 +0,0 @@ -<% if not self.embedded then %> -
-
- - -
-<% end %> -
- <% if self.title and #self.title > 0 then %>

<%=self.title%>

<% end %> - <% if self.description and #self.description > 0 then %>
<%=self.description%>
<% end %> - <% self:render_children() %> -
-
-<%- if self.message then %> -
<%=self.message%>
-<%- end %> -<%- if self.errmessage then %> -
<%=self.errmessage%>
-<%- end %> -<% if not self.embedded then %> -
-<%- - if type(self.hidden) == "table" then - for k, v in pairs(self.hidden) do --%> - -<%- - end - end -%> -
-<% if redirect then %> -
- -
-<% end %> -<%- if self.flow and self.flow.skip then %> - -<% end %> -<%- if self.submit ~= false then %> - -<% end %> -<%- if self.reset ~= false then %> - -<% end %> -<%- if self.cancel ~= false and self.on_cancel then %> - -<% end %> -<% - local nav = require "luci.tools.freifunk-wizard.nav" - local predecessor, successor = nav.get() -%> - <% if predecessor then %> - "> - Zurück - - <% end %> - -
-
-
-<% end %>