gluon/package/gluon-hoodselector/luasrc/usr/sbin/hoodselector

55 lines
1.7 KiB
Plaintext
Raw Normal View History

add gluon-hoodselector: Integrate geolocation mode This MR includs only the VPN MODE of the hoodselector whitch simply set hoods base on their geopositions. Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> check_site.lua: fix language syntax muss -> must rage -> range at lease -> at least coordiantes -> coordinates realaise -> realised gluon-hoodselector: fix language syntax in hoodselector can not -> can't routers -> router's continure -> continue to next -> to the next TMP -> temporary for current -> for the current continure -> continue with next -> with the next thier -> there provides -> provide possition -> position therfore -> therefore gluon-hoodselector: fix language syntax in util.lua realaise -> realised gluon-hoodselector: fix language syntax and use autoupdate lock mechanism. gluon-hoodselector: fix spelling/grammar gluon-hoodselector: automatically set SECTION and CATEGORY for Gluon packages gluon-hoodselector-add-VPN-MODE: add micrond & libjson-c dependency gluon-hoodselector-add-VPN-MODE: check running hoodselector before loading lua gluon-hoodselector-add-VPN-MODE: remove nixio dependency from hoodselector util Revert "gluon-hoodselector-add-VPN-MODE: check running hoodselector before loading lua" This reverts commit 535b0a1b2fb73e563bf6a44b568a796440bd307f. add luaposix and luabitop to pakage dependency sbin/hoodselector: remove nixio requiemend sbin/hoodselector: load hoods only if necessary gluon-hoodselector: use VPN abstraction layer. the hoodselectore does not need to know about all individual VPN protocols. gluon-hoodselector: Makefile add gluon-mesh-vpn-core as dependency gluon-hoodselector: apply changes of mesh vpn lib gluon-hoodselector: remove outdated comments package/gluon-hoodselector: check_site.lua rm domain seed check thus its already checked by gluon-core package/gluon-hoodselector: util.lua code cleanup and refactoring package/gluon-hoodselector: hoodselector code cleanup and refactoring gluon-hoodselector: util.lua, use taps instead of spaces. Use posix.unistd.access instead of io.open Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> gluon-hoodselector: hoodselector, use taps instead of spaces. Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> gluon-hoodselector: check_site.lua: replace hood with domain Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> gluon-hoodselector: drop VPN mode and rename hood to domain. Furthermore implement geolocator mode as neorayder way Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: rm duplicated print output Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector util: fix wrong function signature Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> small typo fixes small typo fixes Update util.lua processes are really restarted now. new (old) problem: nodes will not forget their former ipv6-addresses. watchdog could here with that. gluon-hoodselector util.lua: replace i iterator with _ Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> Update util.lua now polygons with holes are recognized correctly. also a mix of nested polygons and boxes should be possible as shapes[] package/gluon-hoodselector: hoodselector use gluon-reload for daemon restarts/reloads Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: util.lua use math-polygon lib and rm restart_services function. Rectengles will be converted into polygons now Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: Makefile rewrite description update depends list Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: check_site.lua reduce complexity Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: use : for gluon_version Val Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: fix if equal syntax Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> luasrc/usr/lib/lua/hoodselector/util.lua: check_site.lua simplify checksite script and fix if logic Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: set space after comma, rm unnecessary error handling Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: use only brackes on require function no mixup Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: check_site.lua rm unuse variables and fix non std global function Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: util.lua rm unuse include Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: rm comment return nil in function get_geolocation() Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: Makefile refactor pkg description Signed-off-by: Jan-Tarek Butt <tarek@ring0.de>
2018-05-12 15:48:32 +00:00
#!/usr/bin/lua
local bit = require('bit')
local util = require ('gluon.util')
add gluon-hoodselector: Integrate geolocation mode This MR includs only the VPN MODE of the hoodselector whitch simply set hoods base on their geopositions. Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> check_site.lua: fix language syntax muss -> must rage -> range at lease -> at least coordiantes -> coordinates realaise -> realised gluon-hoodselector: fix language syntax in hoodselector can not -> can't routers -> router's continure -> continue to next -> to the next TMP -> temporary for current -> for the current continure -> continue with next -> with the next thier -> there provides -> provide possition -> position therfore -> therefore gluon-hoodselector: fix language syntax in util.lua realaise -> realised gluon-hoodselector: fix language syntax and use autoupdate lock mechanism. gluon-hoodselector: fix spelling/grammar gluon-hoodselector: automatically set SECTION and CATEGORY for Gluon packages gluon-hoodselector-add-VPN-MODE: add micrond & libjson-c dependency gluon-hoodselector-add-VPN-MODE: check running hoodselector before loading lua gluon-hoodselector-add-VPN-MODE: remove nixio dependency from hoodselector util Revert "gluon-hoodselector-add-VPN-MODE: check running hoodselector before loading lua" This reverts commit 535b0a1b2fb73e563bf6a44b568a796440bd307f. add luaposix and luabitop to pakage dependency sbin/hoodselector: remove nixio requiemend sbin/hoodselector: load hoods only if necessary gluon-hoodselector: use VPN abstraction layer. the hoodselectore does not need to know about all individual VPN protocols. gluon-hoodselector: Makefile add gluon-mesh-vpn-core as dependency gluon-hoodselector: apply changes of mesh vpn lib gluon-hoodselector: remove outdated comments package/gluon-hoodselector: check_site.lua rm domain seed check thus its already checked by gluon-core package/gluon-hoodselector: util.lua code cleanup and refactoring package/gluon-hoodselector: hoodselector code cleanup and refactoring gluon-hoodselector: util.lua, use taps instead of spaces. Use posix.unistd.access instead of io.open Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> gluon-hoodselector: hoodselector, use taps instead of spaces. Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> gluon-hoodselector: check_site.lua: replace hood with domain Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> gluon-hoodselector: drop VPN mode and rename hood to domain. Furthermore implement geolocator mode as neorayder way Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: rm duplicated print output Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector util: fix wrong function signature Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> small typo fixes small typo fixes Update util.lua processes are really restarted now. new (old) problem: nodes will not forget their former ipv6-addresses. watchdog could here with that. gluon-hoodselector util.lua: replace i iterator with _ Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> Update util.lua now polygons with holes are recognized correctly. also a mix of nested polygons and boxes should be possible as shapes[] package/gluon-hoodselector: hoodselector use gluon-reload for daemon restarts/reloads Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: util.lua use math-polygon lib and rm restart_services function. Rectengles will be converted into polygons now Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: Makefile rewrite description update depends list Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: check_site.lua reduce complexity Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: use : for gluon_version Val Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: fix if equal syntax Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> luasrc/usr/lib/lua/hoodselector/util.lua: check_site.lua simplify checksite script and fix if logic Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: set space after comma, rm unnecessary error handling Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: use only brackes on require function no mixup Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: check_site.lua rm unuse variables and fix non std global function Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: util.lua rm unuse include Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: rm comment return nil in function get_geolocation() Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: Makefile refactor pkg description Signed-off-by: Jan-Tarek Butt <tarek@ring0.de>
2018-05-12 15:48:32 +00:00
local unistd = require('posix.unistd')
local fcntl = require('posix.fcntl')
local hoodutil = require('hoodselector.util')
-- PID file to ensure the hoodselector isn't running parallel
local lockfile = '/var/lock/hoodselector.lock'
local lockfd, err = fcntl.open(lockfile, bit.bor(fcntl.O_WRONLY, fcntl.O_CREAT), 384) -- mode 0600
if not lockfd then
util.log(err, true)
add gluon-hoodselector: Integrate geolocation mode This MR includs only the VPN MODE of the hoodselector whitch simply set hoods base on their geopositions. Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> check_site.lua: fix language syntax muss -> must rage -> range at lease -> at least coordiantes -> coordinates realaise -> realised gluon-hoodselector: fix language syntax in hoodselector can not -> can't routers -> router's continure -> continue to next -> to the next TMP -> temporary for current -> for the current continure -> continue with next -> with the next thier -> there provides -> provide possition -> position therfore -> therefore gluon-hoodselector: fix language syntax in util.lua realaise -> realised gluon-hoodselector: fix language syntax and use autoupdate lock mechanism. gluon-hoodselector: fix spelling/grammar gluon-hoodselector: automatically set SECTION and CATEGORY for Gluon packages gluon-hoodselector-add-VPN-MODE: add micrond & libjson-c dependency gluon-hoodselector-add-VPN-MODE: check running hoodselector before loading lua gluon-hoodselector-add-VPN-MODE: remove nixio dependency from hoodselector util Revert "gluon-hoodselector-add-VPN-MODE: check running hoodselector before loading lua" This reverts commit 535b0a1b2fb73e563bf6a44b568a796440bd307f. add luaposix and luabitop to pakage dependency sbin/hoodselector: remove nixio requiemend sbin/hoodselector: load hoods only if necessary gluon-hoodselector: use VPN abstraction layer. the hoodselectore does not need to know about all individual VPN protocols. gluon-hoodselector: Makefile add gluon-mesh-vpn-core as dependency gluon-hoodselector: apply changes of mesh vpn lib gluon-hoodselector: remove outdated comments package/gluon-hoodselector: check_site.lua rm domain seed check thus its already checked by gluon-core package/gluon-hoodselector: util.lua code cleanup and refactoring package/gluon-hoodselector: hoodselector code cleanup and refactoring gluon-hoodselector: util.lua, use taps instead of spaces. Use posix.unistd.access instead of io.open Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> gluon-hoodselector: hoodselector, use taps instead of spaces. Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> gluon-hoodselector: check_site.lua: replace hood with domain Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> gluon-hoodselector: drop VPN mode and rename hood to domain. Furthermore implement geolocator mode as neorayder way Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: rm duplicated print output Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector util: fix wrong function signature Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> small typo fixes small typo fixes Update util.lua processes are really restarted now. new (old) problem: nodes will not forget their former ipv6-addresses. watchdog could here with that. gluon-hoodselector util.lua: replace i iterator with _ Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> Update util.lua now polygons with holes are recognized correctly. also a mix of nested polygons and boxes should be possible as shapes[] package/gluon-hoodselector: hoodselector use gluon-reload for daemon restarts/reloads Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: util.lua use math-polygon lib and rm restart_services function. Rectengles will be converted into polygons now Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: Makefile rewrite description update depends list Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: check_site.lua reduce complexity Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: use : for gluon_version Val Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: fix if equal syntax Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> luasrc/usr/lib/lua/hoodselector/util.lua: check_site.lua simplify checksite script and fix if logic Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: set space after comma, rm unnecessary error handling Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: use only brackes on require function no mixup Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: check_site.lua rm unuse variables and fix non std global function Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: util.lua rm unuse include Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: rm comment return nil in function get_geolocation() Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: Makefile refactor pkg description Signed-off-by: Jan-Tarek Butt <tarek@ring0.de>
2018-05-12 15:48:32 +00:00
os.exit(1)
end
local ok, _ = fcntl.fcntl(lockfd, fcntl.F_SETLK, {
l_start = 0,
l_len = 0,
l_type = fcntl.F_WRLCK,
l_whence = unistd.SEEK_SET,
})
if not ok then
io.stderr:write(string.format(
"Unable to lock file %s. Make sure there is no other instance of the hoodselector running.\n",
lockfile
))
os.exit(1)
end
-- geolocation mode
-- If we have a location we will try to select the domain corresponding to this location.
-- If no domain for the location has been defined or if we can't determine the node's location,
-- we will select the default domain as last fallback instance.
local geo = hoodutil.get_geolocation()
if geo.lat ~= nil and geo.lon ~= nil then
io.stdout:write('Position found. Enter "geolocation mode" ...\n')
local jdomains = hoodutil.get_domains()
local geo_base_domain = hoodutil.get_domain_by_geo(jdomains, geo)
if geo_base_domain ~= nil then
if hoodutil.set_domain_config(geo_base_domain) then
util.log('Domain set by geolocation mode.', true)
add gluon-hoodselector: Integrate geolocation mode This MR includs only the VPN MODE of the hoodselector whitch simply set hoods base on their geopositions. Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> check_site.lua: fix language syntax muss -> must rage -> range at lease -> at least coordiantes -> coordinates realaise -> realised gluon-hoodselector: fix language syntax in hoodselector can not -> can't routers -> router's continure -> continue to next -> to the next TMP -> temporary for current -> for the current continure -> continue with next -> with the next thier -> there provides -> provide possition -> position therfore -> therefore gluon-hoodselector: fix language syntax in util.lua realaise -> realised gluon-hoodselector: fix language syntax and use autoupdate lock mechanism. gluon-hoodselector: fix spelling/grammar gluon-hoodselector: automatically set SECTION and CATEGORY for Gluon packages gluon-hoodselector-add-VPN-MODE: add micrond & libjson-c dependency gluon-hoodselector-add-VPN-MODE: check running hoodselector before loading lua gluon-hoodselector-add-VPN-MODE: remove nixio dependency from hoodselector util Revert "gluon-hoodselector-add-VPN-MODE: check running hoodselector before loading lua" This reverts commit 535b0a1b2fb73e563bf6a44b568a796440bd307f. add luaposix and luabitop to pakage dependency sbin/hoodselector: remove nixio requiemend sbin/hoodselector: load hoods only if necessary gluon-hoodselector: use VPN abstraction layer. the hoodselectore does not need to know about all individual VPN protocols. gluon-hoodselector: Makefile add gluon-mesh-vpn-core as dependency gluon-hoodselector: apply changes of mesh vpn lib gluon-hoodselector: remove outdated comments package/gluon-hoodselector: check_site.lua rm domain seed check thus its already checked by gluon-core package/gluon-hoodselector: util.lua code cleanup and refactoring package/gluon-hoodselector: hoodselector code cleanup and refactoring gluon-hoodselector: util.lua, use taps instead of spaces. Use posix.unistd.access instead of io.open Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> gluon-hoodselector: hoodselector, use taps instead of spaces. Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> gluon-hoodselector: check_site.lua: replace hood with domain Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> gluon-hoodselector: drop VPN mode and rename hood to domain. Furthermore implement geolocator mode as neorayder way Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: rm duplicated print output Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector util: fix wrong function signature Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> small typo fixes small typo fixes Update util.lua processes are really restarted now. new (old) problem: nodes will not forget their former ipv6-addresses. watchdog could here with that. gluon-hoodselector util.lua: replace i iterator with _ Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> Update util.lua now polygons with holes are recognized correctly. also a mix of nested polygons and boxes should be possible as shapes[] package/gluon-hoodselector: hoodselector use gluon-reload for daemon restarts/reloads Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: util.lua use math-polygon lib and rm restart_services function. Rectengles will be converted into polygons now Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: Makefile rewrite description update depends list Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: check_site.lua reduce complexity Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: use : for gluon_version Val Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: fix if equal syntax Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> luasrc/usr/lib/lua/hoodselector/util.lua: check_site.lua simplify checksite script and fix if logic Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: set space after comma, rm unnecessary error handling Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: use only brackes on require function no mixup Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: check_site.lua rm unuse variables and fix non std global function Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: util.lua rm unuse include Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: rm comment return nil in function get_geolocation() Signed-off-by: Jan-Tarek Butt <tarek@ring0.de> package/gluon-hoodselector: Makefile refactor pkg description Signed-off-by: Jan-Tarek Butt <tarek@ring0.de>
2018-05-12 15:48:32 +00:00
end
return
end
io.stdout:write('No domain has been defined for the current position. Continue with default domain mode\n')
else
io.stdout:write('No position found. Continue with default domain mode\n')
end
-- default domain mode
hoodutil.set_domain_config(hoodutil.get_default_domain(hoodutil.get_domains()))