mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-18 02:25:05 +00:00
plugins: add plugins_devices() facility for device plugging
This commit is contained in:
parent
2afb3777b8
commit
f2d6a44b4c
@ -53,14 +53,24 @@ function timeout($timer = 5)
|
||||
|
||||
function is_interface_mismatch()
|
||||
{
|
||||
$patterns = array('^impossiblecontrolmatch$'); /* XXX */
|
||||
$mismatch = false;
|
||||
|
||||
foreach (legacy_config_get_interfaces(array("virtual" => false)) as $ifname => $ifcfg) {
|
||||
foreach (plugins_devices() as $device) {
|
||||
if (!$device['critical']) {
|
||||
$patterns[] = "({$device['pattern']})";
|
||||
}
|
||||
}
|
||||
|
||||
/* XXX we can match known devices names, much easier as soon as it is provided */
|
||||
$regex = '/' . implode('|', $patterns) . '/';
|
||||
|
||||
foreach (legacy_config_get_interfaces(['virtual' => false]) as $ifname => $ifcfg) {
|
||||
if (!empty($ifcfg['lock'])) {
|
||||
/* Do not mismatch if any lock was issued */
|
||||
$mismatch = false;
|
||||
break;
|
||||
} elseif (preg_match('/^enc|^cua|^tun|^tap|^l2tp|^pptp|^ppp|^ovpn|^ocvpn|^tinc|^wg|^zt|^ue|^gif|^gre|^lagg|^bridge|^ipsec|vlan|_wlan|_stf/i', $ifcfg['if'])) {
|
||||
} elseif (preg_match($regex, $ifcfg['if'])) {
|
||||
/* Do not check these interfaces */
|
||||
continue;
|
||||
} elseif (does_interface_exist($ifcfg['if']) == false) {
|
||||
|
||||
@ -91,6 +91,27 @@ function plugins_services()
|
||||
return $services;
|
||||
}
|
||||
|
||||
function plugins_devices()
|
||||
{
|
||||
$devices = array();
|
||||
|
||||
foreach (plugins_scan() as $name => $path) {
|
||||
try {
|
||||
include_once $path;
|
||||
} catch (ParseError $e) {
|
||||
error_log($e);
|
||||
}
|
||||
$func = sprintf('%s_devices', $name);
|
||||
if (function_exists($func)) {
|
||||
foreach ($func() as $work) {
|
||||
$devices[] = $work;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $devices;
|
||||
}
|
||||
|
||||
function plugins_cron()
|
||||
{
|
||||
$jobs = array();
|
||||
|
||||
@ -104,6 +104,35 @@ function core_services()
|
||||
return $services;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
return $devices;
|
||||
}
|
||||
|
||||
function core_cron()
|
||||
{
|
||||
global $config;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user