From ffd86668fecf26728b41217156b0c1167b2e69e1 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 5 Jul 2014 02:48:56 +0200 Subject: [PATCH] Validate site.conf --- package/gluon-autoupdater/Makefile | 9 +++++++-- package/gluon-autoupdater/check_site.lua | 13 +++++++++++++ package/gluon-config-mode/Makefile | 9 +++++++-- package/gluon-config-mode/check_site.lua | 3 +++ package/gluon-core/Makefile | 9 +++++++-- package/gluon-core/check_site.lua | 10 ++++++++++ package/gluon-legacy/Makefile | 9 +++++++-- package/gluon-legacy/check_site.lua | 8 ++++++++ package/gluon-mesh-batman-adv/Makefile | 10 ++++++++-- package/gluon-mesh-batman-adv/check_site.lua | 10 ++++++++++ package/gluon-mesh-vpn-fastd/Makefile | 9 +++++++-- package/gluon-mesh-vpn-fastd/check_site.lua | 13 +++++++++++++ package/gluon-next-node/Makefile | 9 +++++++-- package/gluon-next-node/check_site.lua | 4 ++++ 14 files changed, 111 insertions(+), 14 deletions(-) create mode 100644 package/gluon-autoupdater/check_site.lua create mode 100644 package/gluon-config-mode/check_site.lua create mode 100644 package/gluon-core/check_site.lua create mode 100644 package/gluon-legacy/check_site.lua create mode 100644 package/gluon-mesh-batman-adv/check_site.lua create mode 100644 package/gluon-mesh-vpn-fastd/check_site.lua create mode 100644 package/gluon-next-node/check_site.lua diff --git a/package/gluon-autoupdater/Makefile b/package/gluon-autoupdater/Makefile index a93f83f5..a885a0d0 100644 --- a/package/gluon-autoupdater/Makefile +++ b/package/gluon-autoupdater/Makefile @@ -1,12 +1,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=gluon-autoupdater -PKG_VERSION:=2 +PKG_VERSION:=3 PKG_RELEASE:=$(GLUON_BRANCH) PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) -include $(INCLUDE_DIR)/package.mk +include $(GLUONDIR)/include/package.mk define Package/gluon-autoupdater SECTION:=gluon @@ -34,4 +34,9 @@ define Package/gluon-autoupdater/install fi endef +define Package/gluon-autoupdater/postinst +#!/bin/sh +$(call GluonCheckSite,check_site.lua) +endef + $(eval $(call BuildPackage,gluon-autoupdater)) diff --git a/package/gluon-autoupdater/check_site.lua b/package/gluon-autoupdater/check_site.lua new file mode 100644 index 00000000..4d6302cd --- /dev/null +++ b/package/gluon-autoupdater/check_site.lua @@ -0,0 +1,13 @@ +need_string 'autoupdater.branch' + +local function check_branch(k, _) + local prefix = string.format('autoupdater.branches[%q].', k) + + need_string(prefix .. 'name') + need_string_array(prefix .. 'mirrors') + need_number(prefix .. 'probability') + need_number(prefix .. 'good_signatures') + need_string_array(prefix .. 'pubkeys') +end + +need_table('autoupdater.branches', check_branch) diff --git a/package/gluon-config-mode/Makefile b/package/gluon-config-mode/Makefile index 9a28d027..2d045b17 100644 --- a/package/gluon-config-mode/Makefile +++ b/package/gluon-config-mode/Makefile @@ -4,11 +4,11 @@ include $(TOPDIR)/rules.mk PKG_NAME:=gluon-config-mode -PKG_VERSION:=2 +PKG_VERSION:=3 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) -include $(INCLUDE_DIR)/package.mk +include $(GLUONDIR)/include/package.mk define Package/gluon-config-mode SECTION:=gluon @@ -35,4 +35,9 @@ define Package/gluon-config-mode/install $(CP) ./files/* $(1)/ endef +define Package/gluon-config-mode/postinst +#!/bin/sh +$(call GluonCheckSite,check_site.lua) +endef + $(eval $(call BuildPackage,gluon-config-mode)) diff --git a/package/gluon-config-mode/check_site.lua b/package/gluon-config-mode/check_site.lua new file mode 100644 index 00000000..4892ceb3 --- /dev/null +++ b/package/gluon-config-mode/check_site.lua @@ -0,0 +1,3 @@ +need_string 'config_mode.msg_welcome' +need_string 'config_mode.msg_pubkey' +need_string 'config_mode.msg_reboot' diff --git a/package/gluon-core/Makefile b/package/gluon-core/Makefile index 1282de36..5dbaee00 100644 --- a/package/gluon-core/Makefile +++ b/package/gluon-core/Makefile @@ -1,12 +1,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=gluon-core -PKG_VERSION:=2 +PKG_VERSION:=3 PKG_RELEASE:=$(GLUON_VERSION) PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) -include $(INCLUDE_DIR)/package.mk +include $(GLUONDIR)/include/package.mk define Package/gluon-core SECTION:=gluon @@ -36,4 +36,9 @@ define Package/gluon-core/install echo "$(GLUON_VERSION)" > $(1)/lib/gluon/gluon-version endef +define Package/gluon-core/postinst +#!/bin/sh +$(call GluonCheckSite,check_site.lua) +endef + $(eval $(call BuildPackage,gluon-core)) diff --git a/package/gluon-core/check_site.lua b/package/gluon-core/check_site.lua new file mode 100644 index 00000000..67035c0e --- /dev/null +++ b/package/gluon-core/check_site.lua @@ -0,0 +1,10 @@ +need_string 'site_code' +need_string 'site_name' + +need_string 'hostname_prefix' +need_string 'timezone' + +need_string_array('ntp_servers', false) + +need_string_match('prefix4', '^%d+.%d+.%d+.%d+/%d+$') +need_string_match('prefix6', '^[%x:]+/%d+$') diff --git a/package/gluon-legacy/Makefile b/package/gluon-legacy/Makefile index d074f699..7320fba6 100644 --- a/package/gluon-legacy/Makefile +++ b/package/gluon-legacy/Makefile @@ -1,11 +1,11 @@ include $(TOPDIR)/rules.mk PKG_NAME:=gluon-legacy -PKG_VERSION:=1 +PKG_VERSION:=2 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) -include $(INCLUDE_DIR)/package.mk +include $(GLUONDIR)/include/package.mk define Package/gluon-legacy SECTION:=gluon @@ -32,4 +32,9 @@ define Package/gluon-legacy/install $(CP) ./files/* $(1)/ endef +define Package/gluon-legacy/postinst +#!/bin/sh +$(call GluonCheckSite,check_site.lua) +endef + $(eval $(call BuildPackage,gluon-legacy)) diff --git a/package/gluon-legacy/check_site.lua b/package/gluon-legacy/check_site.lua new file mode 100644 index 00000000..1ec26de0 --- /dev/null +++ b/package/gluon-legacy/check_site.lua @@ -0,0 +1,8 @@ +need_string_array 'legacy.version_files' +need_string_array 'legacy.old_files' + +need_string_array 'legacy.config_mode_configs' +need_string_array 'legacy.fastd_configs' +need_string 'legacy.mesh_ifname' +need_string_array 'legacy.tc_configs' +need_string_array 'legacy.wifi_names' diff --git a/package/gluon-mesh-batman-adv/Makefile b/package/gluon-mesh-batman-adv/Makefile index bc545baf..5daf5e52 100644 --- a/package/gluon-mesh-batman-adv/Makefile +++ b/package/gluon-mesh-batman-adv/Makefile @@ -1,11 +1,11 @@ include $(TOPDIR)/rules.mk PKG_NAME:=gluon-mesh-batman-adv -PKG_VERSION:=2 +PKG_VERSION:=3 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) -include $(INCLUDE_DIR)/package.mk +include $(GLUONDIR)/include/package.mk define Package/gluon-mesh-batman-adv SECTION:=gluon @@ -32,4 +32,10 @@ define Package/gluon-mesh-batman-adv/install $(CP) ./files/* $(1)/ endef +define Package/gluon-mesh-batman-adv/postinst +#!/bin/sh +$(call GluonCheckSite,check_site.lua) +endef + + $(eval $(call BuildPackage,gluon-mesh-batman-adv)) diff --git a/package/gluon-mesh-batman-adv/check_site.lua b/package/gluon-mesh-batman-adv/check_site.lua new file mode 100644 index 00000000..36619564 --- /dev/null +++ b/package/gluon-mesh-batman-adv/check_site.lua @@ -0,0 +1,10 @@ +need_string('regdom') + +for _, config in ipairs({'wifi24', 'wifi5'}) do + need_string(config .. '.ssid') + need_number(config .. '.channel') + need_string(config .. '.htmode') + need_string(config .. '.mesh_ssid') + need_string_match(config .. '.mesh_bssid', '^%x[02468aAcCeE]:%x%x:%x%x:%x%x:%x%x:%x%x$') + need_number(config .. '.mesh_mcast_rate') +end diff --git a/package/gluon-mesh-vpn-fastd/Makefile b/package/gluon-mesh-vpn-fastd/Makefile index 3531b3b1..9290b457 100644 --- a/package/gluon-mesh-vpn-fastd/Makefile +++ b/package/gluon-mesh-vpn-fastd/Makefile @@ -1,11 +1,11 @@ include $(TOPDIR)/rules.mk PKG_NAME:=gluon-mesh-vpn-fastd -PKG_VERSION:=2 +PKG_VERSION:=3 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) -include $(INCLUDE_DIR)/package.mk +include $(GLUONDIR)/include/package.mk define Package/gluon-mesh-vpn-fastd SECTION:=gluon @@ -32,4 +32,9 @@ define Package/gluon-mesh-vpn-fastd/install $(CP) ./files/* $(1)/ endef +define Package/gluon-mesh-vpn-fastd/postinst +#!/bin/sh +$(call GluonCheckSite,check_site.lua) +endef + $(eval $(call BuildPackage,gluon-mesh-vpn-fastd)) diff --git a/package/gluon-mesh-vpn-fastd/check_site.lua b/package/gluon-mesh-vpn-fastd/check_site.lua new file mode 100644 index 00000000..6c817137 --- /dev/null +++ b/package/gluon-mesh-vpn-fastd/check_site.lua @@ -0,0 +1,13 @@ +need_string_array 'fastd_mesh_vpn.methods' +need_number 'fastd_mesh_vpn.mtu' +need_number 'fastd_mesh_vpn.backbone.limit' + + +local function check_peer(k, _) + local prefix = string.format('fastd_mesh_vpn.backbone.peers[%q].', k) + + need_string(prefix .. 'key') + need_string_array(prefix .. 'remotes') +end + +need_table('fastd_mesh_vpn.backbone.peers', check_peer) diff --git a/package/gluon-next-node/Makefile b/package/gluon-next-node/Makefile index ee0e0920..f906bbd5 100644 --- a/package/gluon-next-node/Makefile +++ b/package/gluon-next-node/Makefile @@ -1,11 +1,11 @@ include $(TOPDIR)/rules.mk PKG_NAME:=gluon-next-node -PKG_VERSION:=2 +PKG_VERSION:=3 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) -include $(INCLUDE_DIR)/package.mk +include $(GLUONDIR)/include/package.mk define Package/gluon-next-node SECTION:=gluon @@ -32,4 +32,9 @@ define Package/gluon-next-node/install $(CP) ./files/* $(1)/ endef +define Package/gluon-next-node/postinst +#!/bin/sh +$(call GluonCheckSite,check_site.lua) +endef + $(eval $(call BuildPackage,gluon-next-node)) diff --git a/package/gluon-next-node/check_site.lua b/package/gluon-next-node/check_site.lua new file mode 100644 index 00000000..83889a8e --- /dev/null +++ b/package/gluon-next-node/check_site.lua @@ -0,0 +1,4 @@ +need_string_match('next_node.ip4', '^%d+.%d+.%d+.%d+$') +need_string_match('next_node.ip6', '^[%x:]+$') + +need_string_match('next_node.mac', '^%x[02468aAcCeE]:%x%x:%x%x:%x%x:%x%x:%x%x$')