From b97789b2d9ea717a2e70b1c2f7a42cfbbdbebf0c Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Fri, 1 Nov 2019 15:31:49 +0100 Subject: [PATCH] plugins: extend reach to "configurable" reject spots --- src/etc/inc/console.inc | 2 +- src/etc/inc/plugins.inc.d/core.inc | 40 +++++++++++++++--------------- src/www/interfaces.php | 9 +++++-- src/www/interfaces_assign.php | 15 +++++++---- 4 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/etc/inc/console.inc b/src/etc/inc/console.inc index 1208c6516..4248efd7d 100644 --- a/src/etc/inc/console.inc +++ b/src/etc/inc/console.inc @@ -57,7 +57,7 @@ function is_interface_mismatch() $mismatch = false; foreach (plugins_devices() as $device) { - if (!$device['critical']) { + if (!empty($device['volatile'])) { $patterns[] = "({$device['pattern']})"; } } diff --git a/src/etc/inc/plugins.inc.d/core.inc b/src/etc/inc/plugins.inc.d/core.inc index 25f61e6c6..6f3e1b124 100644 --- a/src/etc/inc/plugins.inc.d/core.inc +++ b/src/etc/inc/plugins.inc.d/core.inc @@ -109,26 +109,26 @@ function core_devices() $devices = array(); # XXX is a plugin collection... - $devices[] = array('pattern' => '^bridge', 'critical' => false); - $devices[] = array('pattern' => '^cua', 'critical' => false); - $devices[] = array('pattern' => '^enc', 'critical' => false); - $devices[] = array('pattern' => '^gif', 'critical' => false); - $devices[] = array('pattern' => '^gre', 'critical' => false); - $devices[] = array('pattern' => '^ipsec', 'critical' => false); - $devices[] = array('pattern' => '^l2tp', 'critical' => false); - $devices[] = array('pattern' => '^lagg', 'critical' => false); - $devices[] = array('pattern' => '^ocvpn', 'critical' => false); - $devices[] = array('pattern' => '^ovpn', 'critical' => false); - $devices[] = array('pattern' => '^ppp', 'critical' => false); - $devices[] = array('pattern' => '^pptp', 'critical' => false); - $devices[] = array('pattern' => '^tinc', 'critical' => false); - $devices[] = array('pattern' => '^tun|^tap', 'critical' => false); - $devices[] = array('pattern' => '^ue', 'critical' => false); - $devices[] = array('pattern' => '^wg', 'critical' => false); - $devices[] = array('pattern' => '^zt', 'critical' => false); - $devices[] = array('pattern' => '_stf', 'critical' => false); - $devices[] = array('pattern' => '_wlan', 'critical' => false); - $devices[] = array('pattern' => 'vlan', 'critical' => false); + $devices[] = array('pattern' => '^bridge', 'volatile' => true); + $devices[] = array('pattern' => '^cua', 'volatile' => true); + $devices[] = array('pattern' => '^enc', 'volatile' => true); + $devices[] = array('pattern' => '^gif', 'volatile' => true, 'configurable' => false); + $devices[] = array('pattern' => '^gre', 'volatile' => true, 'configurable' => false); + $devices[] = array('pattern' => '^ipsec', 'volatile' => true, 'configurable' => false); + $devices[] = array('pattern' => '^l2tp', 'volatile' => true); + $devices[] = array('pattern' => '^lagg', 'volatile' => true); + $devices[] = array('pattern' => '^ocvpn', 'volatile' => true); + $devices[] = array('pattern' => '^ovpn', 'volatile' => true, 'configurable' => false); + $devices[] = array('pattern' => '^ppp', 'volatile' => true); + $devices[] = array('pattern' => '^pptp', 'volatile' => true); + $devices[] = array('pattern' => '^tinc', 'volatile' => true); + $devices[] = array('pattern' => '^tun|^tap', 'volatile' => true); + $devices[] = array('pattern' => '^ue', 'volatile' => true); + $devices[] = array('pattern' => '^wg', 'volatile' => true); + $devices[] = array('pattern' => '^zt', 'volatile' => true); + $devices[] = array('pattern' => '_stf', 'volatile' => true); + $devices[] = array('pattern' => '_wlan', 'volatile' => true); + $devices[] = array('pattern' => 'vlan', 'volatile' => true); return $devices; } diff --git a/src/www/interfaces.php b/src/www/interfaces.php index 81854b4d3..6b7e6eeed 100644 --- a/src/www/interfaces.php +++ b/src/www/interfaces.php @@ -667,8 +667,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } if ($pconfig['type'] != 'none' || $pconfig['type6'] != 'none') { - if (strstr($pconfig['if'], 'gre') || strstr($pconfig['if'], 'gif') || strstr($pconfig['if'], 'ovpn') || strstr($pconfig['if'], 'ipsec')) { - $input_errors[] = gettext('Cannot assign an IP configuration type to a tunnel interface.'); + foreach (plugins_devices() as $device) { + if (!isset($device['configurable']) || $device['configurable'] == true) { + continue; + } + if (preg_match('/' . $device['pattern'] . '/', $ifport)) { + $input_errors[] = gettext('Cannot assign an IP configuration type to a tunnel interface.'); + } } } diff --git a/src/www/interfaces_assign.php b/src/www/interfaces_assign.php index ca2a50ff2..bf093ac3e 100644 --- a/src/www/interfaces_assign.php +++ b/src/www/interfaces_assign.php @@ -279,11 +279,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $config['interfaces'][$ifname]['ipaddr'] = $interfaces[$ifport]['type']; } - if (strstr($ifport, 'gre') || strstr($ifport, 'gif') || strstr($ifport, 'ovpn') || strstr($ifport, 'ipsec')) { - unset($config['interfaces'][$ifname]['ipaddr']); - unset($config['interfaces'][$ifname]['subnet']); - unset($config['interfaces'][$ifname]['ipaddrv6']); - unset($config['interfaces'][$ifname]['subnetv6']); + foreach (plugins_devices() as $device) { + if (!isset($device['configurable']) || $device['configurable'] == true) { + continue; + } + if (preg_match('/' . $device['pattern'] . '/', $ifport)) { + unset($config['interfaces'][$ifname]['ipaddr']); + unset($config['interfaces'][$ifname]['subnet']); + unset($config['interfaces'][$ifname]['ipaddrv6']); + unset($config['interfaces'][$ifname]['subnetv6']); + } } /* check for wireless interfaces, set or clear ['wireless'] */