Merge pull request #83 from kokel/node-role
add section "system" to gluon-node-info with new option "role" and luci package to change role via config mode
This commit is contained in:
		
						commit
						71c498edd2
					
				
							
								
								
									
										37
									
								
								package/gluon-luci-node-role/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								package/gluon-luci-node-role/Makefile
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,37 @@
 | 
			
		||||
include $(TOPDIR)/rules.mk
 | 
			
		||||
 | 
			
		||||
PKG_NAME:=gluon-luci-node-role
 | 
			
		||||
PKG_VERSION:=0.1
 | 
			
		||||
PKG_RELEASE:=1
 | 
			
		||||
 | 
			
		||||
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
 | 
			
		||||
 | 
			
		||||
include $(GLUONDIR)/include/package.mk
 | 
			
		||||
 | 
			
		||||
define Package/gluon-luci-node-role
 | 
			
		||||
  SECTION:=gluon
 | 
			
		||||
  CATEGORY:=Gluon
 | 
			
		||||
  DEPENDS:=+gluon-luci-admin +gluon-node-info
 | 
			
		||||
  TITLE:=UI for specifying node role
 | 
			
		||||
endef
 | 
			
		||||
 | 
			
		||||
define Build/Prepare
 | 
			
		||||
	mkdir -p $(PKG_BUILD_DIR)
 | 
			
		||||
endef
 | 
			
		||||
 | 
			
		||||
define Build/Configure
 | 
			
		||||
endef
 | 
			
		||||
 | 
			
		||||
define Build/Compile
 | 
			
		||||
endef
 | 
			
		||||
 | 
			
		||||
define Package/gluon-luci-node-role/install
 | 
			
		||||
	$(CP) ./files/* $(1)/
 | 
			
		||||
endef
 | 
			
		||||
 | 
			
		||||
define Package/gluon-luci-node-role/postinst
 | 
			
		||||
#!/bin/sh
 | 
			
		||||
$(call GluonCheckSite,check_site.lua)
 | 
			
		||||
endef
 | 
			
		||||
 | 
			
		||||
$(eval $(call BuildPackage,gluon-luci-node-role))
 | 
			
		||||
							
								
								
									
										8
									
								
								package/gluon-luci-node-role/check_site.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								package/gluon-luci-node-role/check_site.lua
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
			
		||||
local function check_role(k, _)
 | 
			
		||||
   local role = string.format('roles.list[%q]', k)
 | 
			
		||||
 | 
			
		||||
   need_string(role)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
need_string('roles.default')
 | 
			
		||||
need_table('roles.list', check_role)
 | 
			
		||||
@ -0,0 +1,5 @@
 | 
			
		||||
module("luci.controller.admin.noderole", package.seeall)
 | 
			
		||||
 | 
			
		||||
function index()
 | 
			
		||||
	entry({"admin", "noderole"}, cbi("admin/noderole"), "Verwendungszweck", 20)
 | 
			
		||||
end
 | 
			
		||||
@ -0,0 +1,36 @@
 | 
			
		||||
local f, s, o
 | 
			
		||||
local site = require 'gluon.site_config'
 | 
			
		||||
local uci = luci.model.uci.cursor()
 | 
			
		||||
local config = 'gluon-node-info'
 | 
			
		||||
 | 
			
		||||
-- where to read the configuration from
 | 
			
		||||
local role = uci:get(config, uci:get_first(config, "system"), "role")
 | 
			
		||||
 | 
			
		||||
f = SimpleForm("role", "Verwendungszweck")
 | 
			
		||||
f.reset = false
 | 
			
		||||
f.template = "admin/expertmode"
 | 
			
		||||
f.submit = "Fertig"
 | 
			
		||||
 | 
			
		||||
s = f:section(SimpleSection, nil, [[
 | 
			
		||||
Wenn dein Freifunk-Router eine besondere Rolle im Freifunk Netz einnimmt, kannst du diese hier angeben.
 | 
			
		||||
Bringe bitte zuvor in Erfahrung welche Auswirkungen die zur Verfügung stehenden Rollen im Freifunk-Netz haben.
 | 
			
		||||
Setze die Rolle nur, wenn du weißt was du machst.
 | 
			
		||||
]])
 | 
			
		||||
 | 
			
		||||
o = s:option(ListValue, "role", "Rolle")
 | 
			
		||||
o.default = role
 | 
			
		||||
o.rmempty = false
 | 
			
		||||
for role, prettyname in pairs(site.roles.list) do
 | 
			
		||||
  o:value(role, prettyname)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function f.handle(self, state, data)
 | 
			
		||||
  if state == FORM_VALID then
 | 
			
		||||
    uci:set(config, uci:get_first(config, "system"), "role", data.role)
 | 
			
		||||
 | 
			
		||||
    uci:save(config)
 | 
			
		||||
    uci:commit(config)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
return f
 | 
			
		||||
@ -6,7 +6,7 @@ PKG_RELEASE:=1
 | 
			
		||||
 | 
			
		||||
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
 | 
			
		||||
 | 
			
		||||
include $(INCLUDE_DIR)/package.mk
 | 
			
		||||
include $(GLUONDIR)/include/package.mk
 | 
			
		||||
 | 
			
		||||
define Package/gluon-node-info
 | 
			
		||||
  SECTION:=gluon
 | 
			
		||||
@ -33,4 +33,9 @@ define Package/gluon-node-info/install
 | 
			
		||||
	$(CP) ./files/* $(1)/
 | 
			
		||||
endef
 | 
			
		||||
 | 
			
		||||
define Package/gluon-node-info/postinst
 | 
			
		||||
#!/bin/sh
 | 
			
		||||
$(call GluonCheckSite,check_site.lua)
 | 
			
		||||
endef
 | 
			
		||||
 | 
			
		||||
$(eval $(call BuildPackage,gluon-node-info))
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										8
									
								
								package/gluon-node-info/check_site.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								package/gluon-node-info/check_site.lua
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
			
		||||
local function check_role(k, _)
 | 
			
		||||
   local role = string.format('roles.list[%q]', k)
 | 
			
		||||
 | 
			
		||||
   need_string(role)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
need_string('roles.default', false)
 | 
			
		||||
need_table('roles.list', check_role, false)
 | 
			
		||||
@ -2,3 +2,5 @@ config location
 | 
			
		||||
	option share_location '0'
 | 
			
		||||
 | 
			
		||||
config owner
 | 
			
		||||
 | 
			
		||||
config system
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,4 @@
 | 
			
		||||
local role = uci:get_first('gluon-node-info', 'system', 'role', '')
 | 
			
		||||
if role ~= '' then
 | 
			
		||||
        return role
 | 
			
		||||
end
 | 
			
		||||
@ -0,0 +1,11 @@
 | 
			
		||||
#!/usr/bin/lua
 | 
			
		||||
 | 
			
		||||
local uci = require('luci.model.uci').cursor()
 | 
			
		||||
 | 
			
		||||
local config = 'gluon-node-info'
 | 
			
		||||
 | 
			
		||||
if not uci:get_first(config, 'system') then
 | 
			
		||||
  uci:section(config, 'system')
 | 
			
		||||
  uci:save(config)
 | 
			
		||||
  uci:commit(config)
 | 
			
		||||
end
 | 
			
		||||
@ -0,0 +1,19 @@
 | 
			
		||||
#!/usr/bin/lua
 | 
			
		||||
 | 
			
		||||
local site = require 'gluon.site_config'
 | 
			
		||||
local uci = require('luci.model.uci').cursor()
 | 
			
		||||
 | 
			
		||||
local config = 'gluon-node-info'
 | 
			
		||||
local role = uci:get(config, uci:get_first(config, 'system'), 'role')
 | 
			
		||||
 | 
			
		||||
if site.roles then
 | 
			
		||||
  default_role = site.roles.default
 | 
			
		||||
else
 | 
			
		||||
  default_role = ''
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
if not role then
 | 
			
		||||
  uci:set(config, uci:get_first(config, 'system'), 'role', default_role)
 | 
			
		||||
  uci:save(config)
 | 
			
		||||
  uci:commit(config)
 | 
			
		||||
end
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user