From b98956e47e35f8dcaaa4556b4be1a35f81ea02d2 Mon Sep 17 00:00:00 2001 From: kb-light Date: Fri, 2 Feb 2018 21:33:17 +0100 Subject: [PATCH] gluon-config-mode-domain-select: new package [Matthias Schiffer: slightly clean up code] --- docs/index.rst | 1 + .../gluon-config-mode-domain-select.rst | 19 +++++++ docs/site-example/i18n/de.po | 9 ++++ docs/site-example/i18n/en.po | 9 ++++ docs/site-example/i18n/fr.po | 6 +++ docs/site-example/i18n/gluon-site.pot | 6 +++ .../gluon-config-mode-domain-select/Makefile | 42 +++++++++++++++ .../check_site.lua | 1 + .../config-mode/wizard/0200-domain-select.lua | 54 +++++++++++++++++++ 9 files changed, 147 insertions(+) create mode 100644 docs/package/gluon-config-mode-domain-select.rst create mode 100644 package/gluon-config-mode-domain-select/Makefile create mode 100644 package/gluon-config-mode-domain-select/check_site.lua create mode 100644 package/gluon-config-mode-domain-select/luasrc/lib/gluon/config-mode/wizard/0200-domain-select.lua diff --git a/docs/index.rst b/docs/index.rst index b019b45c..ae3f4491 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -55,6 +55,7 @@ Several Freifunk communities in Germany use Gluon as the foundation of their Fre package/gluon-client-bridge package/gluon-config-mode-contact-info + package/gluon-config-mode-domain-select package/gluon-config-mode-geo-location package/gluon-ebtables-filter-multicast package/gluon-ebtables-filter-ra-dhcp diff --git a/docs/package/gluon-config-mode-domain-select.rst b/docs/package/gluon-config-mode-domain-select.rst new file mode 100644 index 00000000..3af15fda --- /dev/null +++ b/docs/package/gluon-config-mode-domain-select.rst @@ -0,0 +1,19 @@ +gluon-config-mode-domain-select +=============================== +This package provides a drop-down list for the config mode to select the domain +the node will be placed in. If the selection has changed the upgrade scripts in +``/lib/gluon/upgrade/`` are triggered to update the nodes configuration. + +Hiding domains could be useful for default or testing domains, which should not +be accidentally selected by a node operater. + +domains/*.conf +--------------------- + +hide_domain \: optional (defaults to false) + - ``false`` shows this domain in drop-down list + - ``true`` hides this domain + +Example:: + + hide_domain = true diff --git a/docs/site-example/i18n/de.po b/docs/site-example/i18n/de.po index 70f00a71..c5738333 100644 --- a/docs/site-example/i18n/de.po +++ b/docs/site-example/i18n/de.po @@ -16,6 +16,15 @@ msgstr "" "Freifunk-Knoten. Fülle das folgende Formular deinen Vorstellungen " "entsprechend aus und sende es ab." +msgid "gluon-config-mode:domain" +msgstr "Domäne" + +msgid "gluon-config-mode:domain-select" +msgstr "" +"Hier hast du die Möglichkeit, die Mesh-Domäne, in der sich dein Knoten " +"befindet, auszuwählen. Bitte denke daran, dass sich dein Knoten nur mit den " +"Knoten der ausgewählten Domäne verbinden kann." + msgid "gluon-config-mode:pubkey" msgstr "" "

Dies ist der öffentliche Schlüssel deines Freifunk-Knotens. Erst nachdem " diff --git a/docs/site-example/i18n/en.po b/docs/site-example/i18n/en.po index 181ebce1..0a014a3b 100644 --- a/docs/site-example/i18n/en.po +++ b/docs/site-example/i18n/en.po @@ -15,6 +15,15 @@ msgstr "" "Welcome to the setup wizard of your new Freifunk Alpha Centauri node. " "Please fill out the following form and submit it." +msgid "gluon-config-mode:domain" +msgstr "Domain" + +msgid "gluon-config-mode:domain-select" +msgstr "" +"Here you have the possibility of selecting the mesh domain in which your node " +"is placed. Please keep in mind that your router only connects with the nodes " +"of the selected domain" + msgid "gluon-config-mode:pubkey" msgstr "" "

This is your Freifunk node's public key. The node won't be able to " diff --git a/docs/site-example/i18n/fr.po b/docs/site-example/i18n/fr.po index bd4aef44..69522c4c 100644 --- a/docs/site-example/i18n/fr.po +++ b/docs/site-example/i18n/fr.po @@ -16,6 +16,12 @@ msgstr "" "Freifunk. Remplissez le formulaire suivant en fonction de vos besoins " "et enregistrez le" +msgid "gluon-config-mode:domain" +msgstr "Domaine" + +msgid "gluon-config-mode:domain-select" +msgstr "" + msgid "gluon-config-mode:pubkey" msgstr "" "

Ceci est la clé publique de votre nœud Freifunk. Seulment après que la clé soit " diff --git a/docs/site-example/i18n/gluon-site.pot b/docs/site-example/i18n/gluon-site.pot index 7fe3293c..b3138d28 100644 --- a/docs/site-example/i18n/gluon-site.pot +++ b/docs/site-example/i18n/gluon-site.pot @@ -4,6 +4,12 @@ msgstr "Content-Type: text/plain; charset=UTF-8" msgid "gluon-config-mode:welcome" msgstr "" +msgid "gluon-config-mode:domain" +msgstr "" + +msgid "gluon-config-mode:domain-select" +msgstr "" + msgid "gluon-config-mode:pubkey" msgstr "" diff --git a/package/gluon-config-mode-domain-select/Makefile b/package/gluon-config-mode-domain-select/Makefile new file mode 100644 index 00000000..72fe80e2 --- /dev/null +++ b/package/gluon-config-mode-domain-select/Makefile @@ -0,0 +1,42 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=gluon-config-mode-domain-select +PKG_VERSION:=1 + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) + +include ../gluon.mk + +PKG_CONFIG_DEPENDS += $(GLUON_I18N_CONFIG) + + +define Package/gluon-config-mode-domain-select + SECTION:=gluon + CATEGORY:=Gluon + TITLE:=UI for changing the node-config + DEPENDS:=+gluon-config-mode-core @GLUON_MULTIDOMAIN +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) +endef + +define Build/Configure +endef + +define Build/Compile + $(call GluonBuildI18N,gluon-config-mode-domain-select,i18n) + $(call GluonSrcDiet,./luasrc,$(PKG_BUILD_DIR)/luadest/) +endef + +define Package/gluon-config-mode-domain-select/install + $(CP) $(PKG_BUILD_DIR)/luadest/* $(1)/ + $(call GluonInstallI18N,gluon-config-mode-domain-select,$(1)) +endef + +define Package/gluon-config-domain-select/postinst +#!/bin/sh +$(call GluonCheckSite,check_site.lua) +endef + +$(eval $(call BuildPackage,gluon-config-mode-domain-select)) diff --git a/package/gluon-config-mode-domain-select/check_site.lua b/package/gluon-config-mode-domain-select/check_site.lua new file mode 100644 index 00000000..18994ecd --- /dev/null +++ b/package/gluon-config-mode-domain-select/check_site.lua @@ -0,0 +1 @@ +need_boolean(in_domain({'hide_domain'}), false) diff --git a/package/gluon-config-mode-domain-select/luasrc/lib/gluon/config-mode/wizard/0200-domain-select.lua b/package/gluon-config-mode-domain-select/luasrc/lib/gluon/config-mode/wizard/0200-domain-select.lua new file mode 100644 index 00000000..f82f1fb6 --- /dev/null +++ b/package/gluon-config-mode-domain-select/luasrc/lib/gluon/config-mode/wizard/0200-domain-select.lua @@ -0,0 +1,54 @@ +return function(form, uci) + local fs = require 'nixio.fs' + local json = require 'jsonc' + local site = require 'gluon.site' + + local selected_domain = uci:get('gluon', 'core', 'domain') + local configured = uci:get_first('gluon-setup-mode','setup_mode', 'configured') == '1' or (selected_domain ~= site.default_domain()) + + local function get_domain_list() + local list = {} + for domain_path in fs.glob('/lib/gluon/domains/*.json') do + local domain_code = domain_path:match('([^/]+)%.json$') + local domain = assert(json.load(domain_path)) + + if not domain.hide_domain or (configured and domain.domain_code == selected_domain) then + table.insert(list, { + domain_code = domain_code, + domain_name = domain.domain_names[domain_code], + }) + end + end + + table.sort(list, function(a, b) return a.domain_name < b.domain_name end) + return list + end + + local s = form:section(Section, nil, translate('gluon-config-mode:domain-select')) + local o = s:option(ListValue, 'domain', translate('gluon-config-mode:domain')) + + if configured then + o.default = selected_domain + end + + for _, domain in ipairs(get_domain_list()) do + o:value(domain.domain_code, domain.domain_name) + end + + local domain_changed = false + + function o:write(data) + if data ~= selected_domain then + domain_changed = true + uci:set('gluon', 'core', 'domain', data) + end + end + + local function reconfigure() + if domain_changed then + os.execute('gluon-reconfigure') + end + end + + return {'gluon', reconfigure} +end