mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user