From 168be32071ea4739ddab0aef5dd53ade49544c66 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Sun, 21 Apr 2019 19:27:45 +0200 Subject: [PATCH] system: provided by legacy bindings are facilities... ... which are bound to MVC code. Move remaining "pure" gateway functions to the legacy_bindings and use plugins_run() stub to get to the dpinger data... The data could later be coalesced or split up, but for now that seems reasonable enough (provided it works ok and @adschellevis more or less likes this direction). --- src/etc/inc/interfaces.inc | 1 - src/etc/inc/legacy_bindings.inc | 33 +++++++++++++++++++ src/etc/inc/plugins.inc.d/dpinger.inc | 30 +++++------------ .../scripts/OPNsense/Monit/gateway_alert | 2 -- 4 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index 6fbda71b3..7477a525c 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -31,7 +31,6 @@ */ require_once("interfaces.lib.inc"); -require_once("plugins.inc.d/dpinger.inc"); /* XXX remove me */ /* * converts a string like "a,b,c,d" diff --git a/src/etc/inc/legacy_bindings.inc b/src/etc/inc/legacy_bindings.inc index f6680810e..d33fb7354 100644 --- a/src/etc/inc/legacy_bindings.inc +++ b/src/etc/inc/legacy_bindings.inc @@ -159,3 +159,36 @@ function get_alias_description($name) { return OPNsense\Firewall\Util::aliasDescription($name); } + +function return_gateways_status() +{ + /* XXX quick and dirty compat layer */ + $result = plugins_run('return_gateways_status'); + + if (!empty($result['dpinger'])) { + return $result['dpinger']; + } + + return []; +} + +function return_down_gateways() +{ + $result = array(); + foreach (return_gateways_status() as $gwname => $stat) { + if (strpos($stat['status'], 'down') !== false) { + $result[] = $gwname; + } + } + return $result ; +} + +/* + * Return an array with all gateway groups with name as key + * All gateway groups will be processed before returning the array. + */ +function return_gateway_groups_array() +{ + $gateways = new \OPNsense\Routing\Gateways(legacy_interfaces_details()); + return $gateways->getGroups(return_gateways_status()); +} diff --git a/src/etc/inc/plugins.inc.d/dpinger.inc b/src/etc/inc/plugins.inc.d/dpinger.inc index 81bb0790e..bc5d92fa6 100644 --- a/src/etc/inc/plugins.inc.d/dpinger.inc +++ b/src/etc/inc/plugins.inc.d/dpinger.inc @@ -298,7 +298,14 @@ function dpinger_configure_do($verbose = false, $gwname = null) } } -function return_gateways_status() +function dpinger_run() +{ + return array( + 'return_gateways_status' => array('dpinger_status'), + ); +} + +function dpinger_status($verbose = false, $status) { $status = array(); @@ -396,27 +403,6 @@ function return_gateways_status() return $status; } -function return_down_gateways() -{ - $result = array(); - foreach (return_gateways_status() as $gwname => $stat) { - if (strpos($stat['status'], 'down') !== false) { - $result[] = $gwname; - } - } - return $result ; -} - -/* - * Return an array with all gateway groups with name as key - * All gateway groups will be processed before returning the array. - */ -function return_gateway_groups_array() -{ - $gateways = new \OPNsense\Routing\Gateways(legacy_interfaces_details()); - return $gateways->getGroups(return_gateways_status()); -} - function dpinger_processes() { $result = array(); diff --git a/src/opnsense/scripts/OPNsense/Monit/gateway_alert b/src/opnsense/scripts/OPNsense/Monit/gateway_alert index 11bfb9979..0edf0e4e1 100755 --- a/src/opnsense/scripts/OPNsense/Monit/gateway_alert +++ b/src/opnsense/scripts/OPNsense/Monit/gateway_alert @@ -28,9 +28,7 @@ */ require_once('config.inc'); -require_once('interfaces.inc'); require_once('util.inc'); -require_once('plugins.inc.d/dpinger.inc'); /* XXX remove me */ /** * @param string $status