Skip to content
Snippets Groups Projects
Commit 3aecc920 authored by Nils Schneider's avatar Nils Schneider
Browse files

gluon-config-mode: modularize wizard

This commit splits gluon-config-mode into several, mostly independent
packages.

* gluon-config-mode-core: basic functionality (required)
* gluon-config-mode-hostname: hostname field
* gluon-config-mode-autoupdater: show when autoupdater is enabled
* gluon-config-mode-mesh-vpn: fastd vpn configuration, bw limit
* gluon-config-mode-geo-location: geo coordinates
* gluon-config-mode-contact-info: contact info field

The package gluon-config-mode has been removed. You need to replace
it with these packages (or any subset of them) in site.mk:

* gluon-config-mode-hostname
* gluon-config-mode-autoupdater
* gluon-config-mode-mesh-vpn
* gluon-config-mode-geo-location
* gluon-config-mode-contact-info

Note: It is not possible to deactivate the autoupdater in config mode
anymore (expert mode will still allow it). Instead, a message is shown
in case the autoupdater is enabled.
parent 07ce0151
No related branches found
No related tags found
No related merge requests found
Showing
with 461 additions and 165 deletions
include $(TOPDIR)/rules.mk
PKG_NAME:=gluon-config-mode-autoupdater
PKG_VERSION:=1
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(GLUONDIR)/include/package.mk
define Package/gluon-config-mode-autoupdater
SECTION:=gluon
CATEGORY:=Gluon
TITLE:=Let the user know whether the autoupdater is enabled or not.
DEPENDS:=+gluon-config-mode-core +gluon-autoupdater
endef
define Package/gluon-config-mode-autoupdater/description
Luci based config mode
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/gluon-config-mode-autoupdater/install
$(CP) ./files/* $(1)/
endef
$(eval $(call BuildPackage,gluon-config-mode-autoupdater))
local cbi = require "luci.cbi"
local uci = luci.model.uci.cursor()
local M = {}
function M.section(form)
local enabled = uci:get_bool("autoupdater", "settings", "enabled")
if enabled then
local s = form:section(cbi.SimpleSection, nil,
[[Dieser Knoten aktualisiert seine Firmware automatisch, sobald
eine neue Version vorliegt.]])
end
end
function M.handle(data)
return
end
return M
include $(TOPDIR)/rules.mk
PKG_NAME:=gluon-config-mode-contact-info
PKG_VERSION:=1
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(GLUONDIR)/include/package.mk
define Package/gluon-config-mode-contact-info
SECTION:=gluon
CATEGORY:=Gluon
TITLE:=Set a custom string that will be distributed in the mesh.
DEPENDS:=+gluon-config-mode-core +gluon-node-info
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/gluon-config-mode-contact-info/install
$(CP) ./files/* $(1)/
endef
$(eval $(call BuildPackage,gluon-config-mode-contact-info))
local cbi = require "luci.cbi"
local uci = luci.model.uci.cursor()
local M = {}
function M.section(form)
local s = form:section(cbi.SimpleSection, nil,
[[Hier kannst du einen <em>öffentlichen</em> Hinweis hinterlegen um
anderen Freifunkern zu ermöglichen Kontakt mit dir aufzunehmen. Bitte
beachte, dass dieser Hinweis auch öffentlich im Internet, zusammen mit
den Koordinaten deines Knotens, einsehbar sein wird.]])
local o = s:option(cbi.Value, "_contact", "Kontakt")
o.default = uci:get_first("gluon-node-info", "owner", "contact", "")
o.rmempty = true
o.datatype = "string"
o.description = "z.B. E-Mail oder Telefonnummer"
o.maxlen = 140
end
function M.handle(data)
if data._contact ~= nil then
uci:set("gluon-node-info", uci:get_first("gluon-node-info", "owner"), "contact", data._contact)
else
uci:delete("gluon-node-info", uci:get_first("gluon-node-info", "owner"), "contact")
end
uci:save("gluon-node-info")
uci:commit("gluon-node-info")
end
return M
......@@ -3,22 +3,18 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=gluon-config-mode
PKG_VERSION:=4
PKG_NAME:=gluon-config-mode-core
PKG_VERSION:=2
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(GLUONDIR)/include/package.mk
define Package/gluon-config-mode
define Package/gluon-config-mode-core
SECTION:=gluon
CATEGORY:=Gluon
TITLE:=Luci based config mode for user friendly setup of new mesh nodes
DEPENDS:=+gluon-luci-core +gluon-setup-mode +gluon-lock-password +gluon-node-info +gluon-simple-tc
endef
define Package/gluon-config-mode/description
Luci based config mode
DEPENDS:=+gluon-luci-core +gluon-setup-mode +gluon-lock-password
endef
define Build/Prepare
......@@ -31,13 +27,13 @@ endef
define Build/Compile
endef
define Package/gluon-config-mode/install
define Package/gluon-config-mode-core/install
$(CP) ./files/* $(1)/
endef
define Package/gluon-config-mode/postinst
define Package/gluon-config-mode-core/postinst
#!/bin/sh
$(call GluonCheckSite,check_site.lua)
endef
$(eval $(call BuildPackage,gluon-config-mode))
$(eval $(call BuildPackage,gluon-config-mode-core))
need_string 'config_mode.msg_welcome'
need_string 'config_mode.msg_pubkey'
need_string 'config_mode.msg_reboot'
local site = require 'gluon.site_config'
return function () luci.template.render_string(site.config_mode.msg_reboot) end
......@@ -12,12 +12,6 @@ $Id$
module("luci.controller.gluon-config-mode.index", package.seeall)
local site = require 'gluon.site_config'
local meshvpn_name = "mesh_vpn"
function index()
local uci_state = luci.model.uci.cursor_state()
......@@ -48,24 +42,36 @@ function index()
end
function action_reboot()
local util = require "luci.util"
local pubkey
local uci = luci.model.uci.cursor()
local meshvpn_enabled = uci:get("fastd", meshvpn_name, "enabled", "0")
local sysconfig = require 'gluon.sysconfig'
if meshvpn_enabled == "1" then
pubkey = util.exec("/etc/init.d/fastd show_key " .. meshvpn_name)
end
uci:set("gluon-setup-mode", uci:get_first("gluon-setup-mode", "setup_mode"), "configured", "1")
uci:save("gluon-setup-mode")
uci:commit("gluon-setup-mode")
if nixio.fork() ~= 0 then
local fs = require "luci.fs"
local parts_dir = "/lib/gluon/config-mode/reboot/"
local files = fs.dir(parts_dir)
table.sort(files)
local parts = {}
for _, entry in ipairs(files) do
if entry:sub(1, 1) ~= '.' then
local f = dofile(parts_dir .. '/' .. entry)
if f ~= nil then
table.insert(parts, f)
end
end
end
local hostname = uci:get_first("system", "system", "hostname")
if nixio.fork() ~= 0 then
luci.template.render("gluon-config-mode/reboot",
{luci=luci, pubkey=pubkey, hostname=hostname, site=site, sysconfig=sysconfig})
luci.template.render("gluon-config-mode/reboot", { parts=parts
, hostname=hostname
})
else
debug.setfenv(io.stdout, debug.getfenv(io.open '/dev/null'))
io.stdout:close()
......
local wizard_dir = "/lib/gluon/config-mode/wizard/"
local uci = luci.model.uci.cursor()
local fs = require "luci.fs"
local f, s
local wizard = {}
local files = fs.dir(wizard_dir)
table.sort(files)
for _, entry in ipairs(files) do
if entry:sub(1, 1) ~= '.' then
table.insert(wizard, dofile(wizard_dir .. '/' .. entry))
end
end
f = SimpleForm("wizard")
f.reset = false
f.template = "gluon-config-mode/cbi/wizard"
f.submit = "Speichern &amp; Neustarten"
for _, s in ipairs(wizard) do
s.section(f)
end
function f.handle(self, state, data)
if state == FORM_VALID then
for _, s in ipairs(wizard) do
s.handle(data)
end
luci.http.redirect(luci.dispatcher.build_url("gluon-config-mode", "reboot"))
end
return true
end
return f
......@@ -3,28 +3,14 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%=luci.i18n.context.lang%>" lang="<%=luci.i18n.context.lang%>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><%=hostname%> - <% if title then %><%=title%><% else %><%:Rebooting...%><% end %></title>
<title><%=hostname%> is rebooting</title>
<link rel="stylesheet" type="text/css" media="screen" href="<%=media%>/cascade.css" />
</head>
<body>
<div id="maincontainer">
<div id="maincontent">
<h2>Geschafft! Dein Freifunkknoten ist nun fertig eingerichtet.</h2>
<% if pubkey then %>
<fieldset class="cbi-section">
<p>
<%= luci.template.render_string(site.config_mode.msg_pubkey) %>
</p>
<div class="the-key">
# <%= hostname %>
<br/>
<%= pubkey %>
</div>
</fieldset>
<% end %>
<fieldset class="cbi-section">
<%= luci.template.render_string(site.config_mode.msg_reboot) %>
</fieldset>
<h2>Dein Freifunkknoten ist nun fertig eingerichtet.</h2>
<% for k, v in ipairs(parts) do v() end %>
</div>
</div>
</body>
......
include $(TOPDIR)/rules.mk
PKG_NAME:=gluon-config-mode-geo-location
PKG_VERSION:=1
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(GLUONDIR)/include/package.mk
define Package/gluon-config-mode-geo-location
SECTION:=gluon
CATEGORY:=Gluon
TITLE:=Set geographic location of a node
DEPENDS:=+gluon-config-mode-core +gluon-node-info
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/gluon-config-mode-geo-location/install
$(CP) ./files/* $(1)/
endef
$(eval $(call BuildPackage,gluon-config-mode-geo-location))
local cbi = require "luci.cbi"
local uci = luci.model.uci.cursor()
local M = {}
function M.section(form)
local s = form:section(cbi.SimpleSection, nil,
[[Um deinen Knoten auf der Karte anzeigen zu können, benötigen
wir seine Koordinaten. Hier hast du die Möglichkeit, diese zu
hinterlegen.]])
local o
o = s:option(cbi.Flag, "_location", "Knoten auf der Karte anzeigen")
o.default = uci:get_first("gluon-node-info", "location", "share_location", o.disabled)
o.rmempty = false
o = s:option(cbi.Value, "_latitude", "Breitengrad")
o.default = uci:get_first("gluon-node-info", "location", "latitude")
o:depends("_location", "1")
o.rmempty = false
o.datatype = "float"
o.description = "z.B. 53.873621"
o = s:option(cbi.Value, "_longitude", "Längengrad")
o.default = uci:get_first("gluon-node-info", "location", "longitude")
o:depends("_location", "1")
o.rmempty = false
o.datatype = "float"
o.description = "z.B. 10.689901"
end
function M.handle(data)
local sname = uci:get_first("gluon-node-info", "location")
uci:set("gluon-node-info", sname, "share_location", data._location)
if data._location and data._latitude ~= nil and data._longitude ~= nil then
uci:set("gluon-node-info", sname, "latitude", data._latitude)
uci:set("gluon-node-info", sname, "longitude", data._longitude)
end
uci:save("gluon-node-info")
uci:commit("gluon-node-info")
end
return M
include $(TOPDIR)/rules.mk
PKG_NAME:=gluon-config-mode-hostname
PKG_VERSION:=1
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(GLUONDIR)/include/package.mk
define Package/gluon-config-mode-hostname
SECTION:=gluon
CATEGORY:=Gluon
TITLE:=Set the hostname
DEPENDS:=+gluon-config-mode-core
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/gluon-config-mode-hostname/install
$(CP) ./files/* $(1)/
endef
$(eval $(call BuildPackage,gluon-config-mode-hostname))
local cbi = require "luci.cbi"
local uci = luci.model.uci.cursor()
local M = {}
function M.section(form)
local s = form:section(cbi.SimpleSection, nil, nil)
local o = s:option(cbi.Value, "_hostname", "Name dieses Knotens")
o.value = uci:get_first("system", "system", "hostname")
o.rmempty = false
o.datatype = "hostname"
end
function M.handle(data)
uci:set("system", uci:get_first("system", "system"), "hostname", data._hostname)
uci:save("system")
uci:commit("system")
end
return M
include $(TOPDIR)/rules.mk
PKG_NAME:=gluon-config-mode-mesh-vpn
PKG_VERSION:=2
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(GLUONDIR)/include/package.mk
define Package/gluon-config-mode-mesh-vpn
SECTION:=gluon
CATEGORY:=Gluon
TITLE:=Toggle mesh-vpn and bandwidth limit
DEPENDS:=+gluon-config-mode-core +gluon-mesh-vpn-fastd +gluon-simple-tc
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/gluon-config-mode-mesh-vpn/install
$(CP) ./files/* $(1)/
endef
define Package/gluon-config-mode-mesh-vpn/postinst
#!/bin/sh
$(call GluonCheckSite,check_site.lua)
endef
$(eval $(call BuildPackage,gluon-config-mode-mesh-vpn))
need_string 'config_mode.msg_pubkey'
local msg = [[<p>
<%= luci.template.render_string(site.config_mode.msg_pubkey) %>
</p>
<div class="the-key">
# <%= hostname %>
<br/>
<%= pubkey %>
</div>]]
local uci = luci.model.uci.cursor()
local meshvpn_enabled = uci:get("fastd", "mesh_vpn", "enabled", "0")
if meshvpn_enabled ~= "1" then
return nil
else
local util = require "luci.util"
local site = require 'gluon.site_config'
local sysconfig = require 'gluon.sysconfig'
local pubkey = util.exec("/etc/init.d/fastd show_key " .. "mesh_vpn")
local hostname = uci:get_first("system", "system", "hostname")
return function ()
luci.template.render_string(msg, { pubkey=pubkey
, hostname=hostname
, site=site
, sysconfig=sysconfig
})
end
end
local cbi = require "luci.cbi"
local uci = luci.model.uci.cursor()
local M = {}
function M.section(form)
local s = form:section(cbi.SimpleSection, nil,
[[Falls du deinen Knoten über das Internet mit Freifunk verbinden
möchtest, kannst du hier das Mesh-VPN aktivieren. Solltest du dich
dafür entscheiden, hast du die Möglichkeit die dafür genutzte
Bandbreite zu beschränken. Lässt du das Mesh-VPN deaktiviert,
verbindet sich dein Knoten nur per WLAN mit anderen Knoten in der
Nähe.]])
local o
o = s:option(cbi.Flag, "_meshvpn", "Mesh-VPN aktivieren")
o.default = uci:get_bool("fastd", "mesh_vpn", "enabled") and o.enabled or o.disabled
o.rmempty = false
o = s:option(cbi.Flag, "_limit_enabled", "Mesh-VPN Bandbreite begrenzen")
o:depends("_meshvpn", "1")
o.default = uci:get_bool("gluon-simple-tc", "mesh_vpn", "enabled") and o.enabled or o.disabled
o.rmempty = false
o = s:option(cbi.Value, "_limit_ingress", "Downstream (kbit/s)")
o:depends("_limit_enabled", "1")
o.value = uci:get("gluon-simple-tc", "mesh_vpn", "limit_ingress")
o.rmempty = false
o.datatype = "integer"
o = s:option(cbi.Value, "_limit_egress", "Upstream (kbit/s)")
o:depends("_limit_enabled", "1")
o.value = uci:get("gluon-simple-tc", "mesh_vpn", "limit_egress")
o.rmempty = false
o.datatype = "integer"
end
function M.handle(data)
uci:set("fastd", "mesh_vpn", "enabled", data._meshvpn)
uci:save("fastd")
uci:commit("fastd")
-- checks for nil needed due to o:depends(...)
if data._limit_enabled ~= nil then
uci:set("gluon-simple-tc", "mesh_vpn", "interface")
uci:set("gluon-simple-tc", "mesh_vpn", "enabled", data._limit_enabled)
uci:set("gluon-simple-tc", "mesh_vpn", "ifname", "mesh-vpn")
if data._limit_ingress ~= nil then
uci:set("gluon-simple-tc", "mesh_vpn", "limit_ingress", data._limit_ingress)
end
if data._limit_egress ~= nil then
uci:set("gluon-simple-tc", "mesh_vpn", "limit_egress", data._limit_egress)
end
uci:commit("gluon-simple-tc")
uci:commit("gluon-simple-tc")
end
end
return M
local meshvpn_name = "mesh_vpn"
local uci = luci.model.uci.cursor()
local f, s, o
f = SimpleForm("wizard")
f.reset = false
f.template = "gluon-config-mode/cbi/wizard"
f.submit = "Speichern &amp; Neustarten"
s = f:section(SimpleSection, nil, nil)
o = s:option(Value, "_hostname", "Name dieses Knotens")
o.value = uci:get_first("system", "system", "hostname")
o.rmempty = false
o.datatype = "hostname"
o = s:option(Flag, "_autoupdate", "Firmware automatisch aktualisieren")
o.default = uci:get_bool("autoupdater", "settings", "enabled") and o.enabled or o.disabled
o.rmempty = false
s = f:section(SimpleSection, nil, [[Falls du deinen Knoten über das Internet
mit Freifunk verbinden möchtest, kannst du hier das Mesh-VPN aktivieren.
Solltest du dich dafür entscheiden, hast du die Möglichkeit die dafür
genutzte Bandbreite zu beschränken. Lässt du das Mesh-VPN deaktiviert,
verbindet sich dein Knoten nur per WLAN mit anderen Knoten in der Nähe.]])
o = s:option(Flag, "_meshvpn", "Mesh-VPN aktivieren")
o.default = uci:get_bool("fastd", meshvpn_name, "enabled") and o.enabled or o.disabled
o.rmempty = false
o = s:option(Flag, "_limit_enabled", "Mesh-VPN Bandbreite begrenzen")
o:depends("_meshvpn", "1")
o.default = uci:get_bool("gluon-simple-tc", meshvpn_name, "enabled") and o.enabled or o.disabled
o.rmempty = false
o = s:option(Value, "_limit_ingress", "Downstream (kbit/s)")
o:depends("_limit_enabled", "1")
o.value = uci:get("gluon-simple-tc", meshvpn_name, "limit_ingress")
o.rmempty = false
o.datatype = "integer"
o = s:option(Value, "_limit_egress", "Upstream (kbit/s)")
o:depends("_limit_enabled", "1")
o.value = uci:get("gluon-simple-tc", meshvpn_name, "limit_egress")
o.rmempty = false
o.datatype = "integer"
s = f:section(SimpleSection, nil, [[Um deinen Knoten auf der Karte anzeigen
zu können, benötigen wir seine Koordinaten. Hier hast du die Möglichkeit,
diese zu hinterlegen.]])
o = s:option(Flag, "_location", "Knoten auf der Karte anzeigen")
o.default = uci:get_first("gluon-node-info", "location", "share_location", o.disabled)
o.rmempty = false
o = s:option(Value, "_latitude", "Breitengrad")
o.default = uci:get_first("gluon-node-info", "location", "latitude")
o:depends("_location", "1")
o.rmempty = false
o.datatype = "float"
o.description = "z.B. 53.873621"
o = s:option(Value, "_longitude", "Längengrad")
o.default = uci:get_first("gluon-node-info", "location", "longitude")
o:depends("_location", "1")
o.rmempty = false
o.datatype = "float"
o.description = "z.B. 10.689901"
s = f:section(SimpleSection, nil, [[Hier kannst du einen
<em>öffentlichen</em> Hinweis hinterlegen um anderen Freifunkern zu
ermöglichen Kontakt mit dir aufzunehmen. Bitte beachte, dass dieser Hinweis
auch öffentlich im Internet, zusammen mit den Koordinaten deines Knotens,
einsehbar sein wird.]])
o = s:option(Value, "_contact", "Kontakt")
o.default = uci:get_first("gluon-node-info", "owner", "contact", "")
o.rmempty = true
o.datatype = "string"
o.description = "z.B. E-Mail oder Telefonnummer"
o.maxlen = 140
function f.handle(self, state, data)
if state == FORM_VALID then
local stat = false
uci:set("autoupdater", "settings", "enabled", data._autoupdate)
uci:save("autoupdater")
uci:commit("autoupdater")
-- checks for nil needed due to o:depends(...)
if data._limit_enabled ~= nil then
uci:set("gluon-simple-tc", meshvpn_name, "interface")
uci:set("gluon-simple-tc", meshvpn_name, "enabled", data._limit_enabled)
uci:set("gluon-simple-tc", meshvpn_name, "ifname", "mesh-vpn")
if data._limit_ingress ~= nil then
uci:set("gluon-simple-tc", meshvpn_name, "limit_ingress", data._limit_ingress)
end
if data._limit_egress ~= nil then
uci:set("gluon-simple-tc", meshvpn_name, "limit_egress", data._limit_egress)
end
uci:commit("gluon-simple-tc")
end
uci:set("fastd", meshvpn_name, "enabled", data._meshvpn)
uci:save("fastd")
uci:commit("fastd")
uci:set("system", uci:get_first("system", "system"), "hostname", data._hostname)
uci:save("system")
uci:commit("system")
local sname = uci:get_first("gluon-node-info", "location")
uci:set("gluon-node-info", sname, "share_location", data._location)
if data._location and data._latitude ~= nil and data._longitude ~= nil then
uci:set("gluon-node-info", sname, "latitude", data._latitude)
uci:set("gluon-node-info", sname, "longitude", data._longitude)
end
if data._contact ~= nil then
uci:set("gluon-node-info", uci:get_first("gluon-node-info", "owner"), "contact", data._contact)
else
uci:delete("gluon-node-info", uci:get_first("gluon-node-info", "owner"), "contact")
end
uci:save("gluon-node-info")
uci:commit("gluon-node-info")
luci.http.redirect(luci.dispatcher.build_url("gluon-config-mode", "reboot"))
end
return true
end
return f
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment