From 459d1e03b4fd03df32cf3d09319cddf445022203 Mon Sep 17 00:00:00 2001 From: Jan-Tarek Butt Date: Fri, 24 Aug 2018 14:43:25 +0200 Subject: [PATCH] gluon-hoodselector: use VPN abstraction layer. the hoodselectore does not need to know about all individual VPN protocols. --- .../luasrc/usr/lib/lua/hoodselector/util.lua | 14 -------- .../luasrc/usr/sbin/hoodselector | 34 ++----------------- 2 files changed, 3 insertions(+), 45 deletions(-) diff --git a/package/gluon-hoodselector/luasrc/usr/lib/lua/hoodselector/util.lua b/package/gluon-hoodselector/luasrc/usr/lib/lua/hoodselector/util.lua index 8f928759..cce97788 100644 --- a/package/gluon-hoodselector/luasrc/usr/lib/lua/hoodselector/util.lua +++ b/package/gluon-hoodselector/luasrc/usr/lib/lua/hoodselector/util.lua @@ -46,20 +46,6 @@ function M.getDefaultHood(jhood) return nil end -function M.fastd_installed() - if io.open("/usr/bin/fastd", 'r') ~= nil then - return true - end - return false -end - -function M.tunneldigger_installed() - if io.open("/usr/bin/tunneldigger", 'r') ~= nil then - return true - end - return false -end - -- bool if direct VPN. The detection is realised by searching the fastd network interface inside the originator table function M.directVPN(vpnIfaceList) for _,vpnIface in ipairs(vpnIfaceList) do diff --git a/package/gluon-hoodselector/luasrc/usr/sbin/hoodselector b/package/gluon-hoodselector/luasrc/usr/sbin/hoodselector index b9cb1a4d..20ea9b32 100755 --- a/package/gluon-hoodselector/luasrc/usr/sbin/hoodselector +++ b/package/gluon-hoodselector/luasrc/usr/sbin/hoodselector @@ -3,8 +3,8 @@ local bit = require('bit') local unistd = require('posix.unistd') local fcntl = require('posix.fcntl') -local uci = require('simple-uci').cursor() -local hoodutil = require("hoodselector.util") +local vpn_util = require('gluon.vpn-util') +local hoodutil = require('hoodselector.util') -- PID file to ensure the hoodselector isn't running parallel local lockfile = '/var/lock/hoodselector.lock' @@ -30,41 +30,13 @@ if not ok then os.exit(1) end --- initialisation done --- -local function get_mesh_vpn_interface() - local ret = {} - if hoodutil.fastd_installed() then - local vpnifac = uci:get('fastd', 'mesh_vpn_backbone', 'net') - if vpnifac ~= nil then - vpnifac = vpnifac:gsub("%_",'-') - table.insert(ret,vpnifac) - else - hoodutil.log("fastd uci config broken! abort...") - os.exit(1) - end - end - if hoodutil.tunneldigger_installed() then - local vpnifac = uci:get('tunneldigger', 'mesh_vpn', 'interface') - if vpnifac ~= nil then - table.insert(ret,vpnifac) - else - hoodutil.log("tunneldigger uci config broken! abort...") - os.exit(1) - end - end - return ret -end - --- INITIALISE AND PREPARE DATA -- - -- VPN MODE -- If we have a VPN connection we will try to get the node's location and -- select the hood coresponding to this location. -- If no hood for the location has been defined, we will select -- the default hood. -- If we can't determine the node's location, we will continue to the next mode. -if hoodutil.directVPN(get_mesh_vpn_interface()) then +if hoodutil.directVPN(vpn_util.get_mesh_vpn_interface()) then io.stdout:write('VPN connection found.\n') local geo = hoodutil.getGeolocation() if geo.lat ~= nil and geo.lon ~= nil then