From d53e857f1ba83d3ea9958dcf7f37e3bfb02f68f1 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Mon, 14 Nov 2016 09:12:47 +0100 Subject: [PATCH] net/tinc: convert to PLUGIN_enabled() helper This can be useful in the future for core code as we could call these from the upper layers. Also deduplicates and flattens the code a bit. --- .../src/etc/inc/plugins.inc.d/if_tinc.inc | 71 ++++++++++--------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/net/tinc/src/etc/inc/plugins.inc.d/if_tinc.inc b/net/tinc/src/etc/inc/plugins.inc.d/if_tinc.inc index f82abda22..1269474d3 100644 --- a/net/tinc/src/etc/inc/plugins.inc.d/if_tinc.inc +++ b/net/tinc/src/etc/inc/plugins.inc.d/if_tinc.inc @@ -26,6 +26,19 @@ POSSIBILITY OF SUCH DAMAGE. */ +function if_tinc_enabled() +{ + $mdl = new \OPNsense\Tinc\Tinc(); + + foreach ($mdl->networks->network->__items as $network) { + if ($network->enabled == '1') { + return true; + } + } + + return false; +} + function if_tinc_syslog() { $logfacilities = array(); @@ -40,50 +53,40 @@ function if_tinc_syslog() function if_tinc_services() { - global $config; - $services = array(); - $is_enabled = false; - $mdl = new \OPNsense\Tinc\Tinc(); - foreach ($mdl->networks->network->__items as $network) { - if ($network->enabled == "1") { - $is_enabled = true; - break; - } + + if (!if_tinc_enabled()) { + return $services; } - if ($is_enabled) { - $services[] = array( - 'description' => gettext('Tinc server'), - 'configd' => array( - 'restart' => array('tinc restart'), - 'start' => array('tinc start'), - 'stop' => array('tinc stop'), - ), - 'name' => 'tincd', - ); - } + $services[] = array( + 'description' => gettext('Tinc VPN Server'), + 'configd' => array( + 'restart' => array('tinc restart'), + 'start' => array('tinc start'), + 'stop' => array('tinc stop'), + ), + 'name' => 'tincd', + ); return $services; } function if_tinc_interfaces() { - global $config; - $interfaces = array(); - $mdl = new \OPNsense\Tinc\Tinc(); - foreach ($mdl->networks->network->__items as $network) { - if ($network->enabled == "1") { - $oic = array('enable' => true); - $oic['if'] = 'tinc'; - $oic['descr'] = 'TincVPN'; - $oic['type'] = 'none'; - $oic['virtual'] = true; - $oic['networks'] = array(); - $interfaces['tinc'] = $oic; - break; - } + + if (!if_tinc_enabled()) { + return $interfaces; } + + $oic = array('enable' => true); + $oic['if'] = 'tinc'; + $oic['descr'] = 'TincVPN'; + $oic['type'] = 'none'; + $oic['virtual'] = true; + $oic['networks'] = array(); + $interfaces['tinc'] = $oic; + return $interfaces; }