Commit 8371e3b9 authored by Franco Fichtner's avatar Franco Fichtner

plugins: better plugging for syslog-related call

If one deletes "plugins.inc", this way the plugin system can be
disabled.  That's a lot better than removing plugins.inc.d/
content and executing the stubs everytime anyway.
parent 23abe72a
...@@ -26,11 +26,38 @@ ...@@ -26,11 +26,38 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
/**
* scan plugins for legacy system
* @return array
*/
function plugins_scan()
{
$path = '/usr/local/etc/inc/plugins.inc.d/';
$ext = '.inc';
$ret = array();
$plugins = glob($path . '*' . $ext);
if (!is_array($plugins)) {
return $ret;
}
sort($plugins);
foreach ($plugins as $plugin) {
$name = preg_replace('/' . preg_quote($path, '/') . '/', '', $plugin);
$name = preg_replace('/' . preg_quote($ext, '/') . '/', '', $name);
$ret[$name] = $plugin;
}
return $ret;
}
function plugins_services() function plugins_services()
{ {
$services = array(); $services = array();
foreach (plugin_scan() as $name => $path) { foreach (plugins_scan() as $name => $path) {
require_once $path; require_once $path;
$func = sprintf('%s_services', $name); $func = sprintf('%s_services', $name);
if (function_exists($func)) { if (function_exists($func)) {
...@@ -44,6 +71,24 @@ function plugins_services() ...@@ -44,6 +71,24 @@ function plugins_services()
return $services; return $services;
} }
function plugins_syslog()
{
$syslogs = array();
foreach (plugin_scan() as $name => $path) {
require_once $path;
$func = sprintf('%s_syslog', $name);
if (function_exists($func)) {
$workers = $func();
foreach ($workers as $plugin_syslog => $plugin_details) {
$syslogs[$plugin_syslog] = $plugin_details;
}
}
}
return $syslogs;
}
/** /**
* Register new or changed interfaces into config's interfaces section. * Register new or changed interfaces into config's interfaces section.
* Every <plugin>_interface should return a named array containing the interface unique identifier and properties. * Every <plugin>_interface should return a named array containing the interface unique identifier and properties.
...@@ -56,7 +101,7 @@ function plugins_interfaces() ...@@ -56,7 +101,7 @@ function plugins_interfaces()
$registered_interfaces = array(); $registered_interfaces = array();
// register / update interfaces // register / update interfaces
foreach (plugin_scan() as $name => $path) { foreach (plugins_scan() as $name => $path) {
require_once $path; require_once $path;
$func = sprintf('%s_interfaces', $name); $func = sprintf('%s_interfaces', $name);
if (function_exists($func)) { if (function_exists($func)) {
...@@ -105,7 +150,7 @@ function plugins_interfaces() ...@@ -105,7 +150,7 @@ function plugins_interfaces()
function plugins_configure() function plugins_configure()
{ {
foreach (plugin_scan() as $name => $path) { foreach (plugins_scan() as $name => $path) {
require_once $path; require_once $path;
$func = sprintf('%s_configure', $name); $func = sprintf('%s_configure', $name);
if (function_exists($func)) { if (function_exists($func)) {
......
...@@ -840,43 +840,36 @@ function system_syslogd_start() ...@@ -840,43 +840,36 @@ function system_syslogd_start()
if (isset($syslogcfg)) { if (isset($syslogcfg)) {
$syslogconf = ''; $syslogconf = '';
// create structure with log section definitions and config tags for remote usage
$syslogconfs = array(); $syslogconfs = array();
$syslogconfs['routing'] = array("facility" => array('radvd', 'routed', 'olsrd', 'zebra', 'ospfd', 'bgpd', 'miniupnpd') , "remote" => null);
$syslogconfs['ntpd'] = array("facility" => array('ntp', 'ntpd', 'ntpdate'), "remote" => null); /* XXX remove after the call path is safe */
$syslogconfs['ppps'] = array("facility" => array('ppp'), "remote" => null); require_once 'plugins.inc';
$syslogconfs['ipsec'] = array("facility" => array('charon'), "remote" => null);
$syslogconfs['openvpn'] = array("facility" => array('openvpn'), "remote" => "vpn"); if (function_exists('plugins_syslog')) {
$syslogconfs['gateways'] = array("facility" => array('apinger'), "remote" => "apinger"); /* only pull plugins if plugins.inc was included before */
$syslogconfs['resolver'] = array("facility" => array('dnsmasq','filterdns','unbound'), "remote" => null); foreach (plugins_syslog() as $plugin_name => $plugin_details) {
$syslogconfs['dhcpd'] = array("facility" => array('dhcpd','dhcrelay','dhclient','dhcp6c'), "remote" => "dhcp"); $syslogconfs[$plugin_name] = $plugin_details;
$syslogconfs['relayd'] = array("facility" => array('relayd'), "remote" => "relayd");
$syslogconfs['wireless'] = array("facility" => array('hostapd'), "remote" => "hostapd");
$syslogconfs['filter'] = array("facility" => array('filterlog'), "remote" => "filter");
$syslogconfs['portalauth'] = array("facility" => array('captiveportal'), "remote" => "portalauth");
// XXX should be in plugins.inc
// probe syslog facilities in plugins
foreach (plugin_scan() as $name => $path) {
require_once $path;
$func = sprintf('%s_syslog', $name);
if (function_exists($func)) {
$workers = $func();
foreach ($workers as $plugin_syslog => $plugin_details) {
if (!array_key_exists($plugin_syslog, $syslogconfs)) {
$syslogconfs[$plugin_syslog] = array();
$syslogconfs[$plugin_syslog]['facility'] = array();
$syslogconfs[$plugin_syslog]['remote'] = $plugin_details['remote'];
if (isset($plugin_details['local'])) {
$syslogd_extra .= system_syslogd_extra_local($plugin_details['local']);
}
}
$tmp = array_merge($syslogconfs[$plugin_syslog]['facility'], $plugin_details['facility']);
$syslogconfs[$plugin_syslog]['facility'] = $tmp;
}
} }
} }
/*
* XXX Standard syslog configs overwrite plugins, but we can
* get rid of this behaviour by wrapping this local array using
* the key as a "name" entry in the array...
*/
$syslogconfs['dhcpd'] = array('facility' => array('dhcpd', 'dhcrelay', 'dhclient', 'dhcp6c'), 'local' => "{$g['dhcpd_chroot_path']}/var/run/log", 'remote' => 'dhcp');
$syslogconfs['filter'] = array('facility' => array('filterlog'), 'remote' => 'filter');
$syslogconfs['gateways'] = array('facility' => array('apinger'), 'remote' => 'apinger');
$syslogconfs['ipsec'] = array('facility' => array('charon'));
$syslogconfs['ntpd'] = array('facility' => array('ntp', 'ntpd', 'ntpdate'));
$syslogconfs['openvpn'] = array('facility' => array('openvpn'), 'remote' => 'vpn');
$syslogconfs['portalauth'] = array('facility' => array('captiveportal'), 'remote' => 'portalauth');
$syslogconfs['ppps'] = array('facility' => array('ppp'));
$syslogconfs['relayd'] = array('facility' => array('relayd'), 'remote' => 'relayd');
$syslogconfs['resolver'] = array('facility' => array('dnsmasq', 'filterdns', 'unbound'));
$syslogconfs['routing'] = array('facility' => array('radvd', 'routed', 'olsrd', 'zebra', 'ospfd', 'bgpd', 'miniupnpd'));
$syslogconfs['wireless'] = array('facility' => array('hostapd'), 'remote' => 'hostapd');
$separatelogfacilities = array(); $separatelogfacilities = array();
foreach ($syslogconfs as $logTopic => $logConfig) { foreach ($syslogconfs as $logTopic => $logConfig) {
$syslogconf .= "!".implode(',', $logConfig['facility'])."\n"; $syslogconf .= "!".implode(',', $logConfig['facility'])."\n";
...@@ -884,9 +877,12 @@ function system_syslogd_start() ...@@ -884,9 +877,12 @@ function system_syslogd_start()
if (!isset($syslogcfg['disablelocallogging'])) { if (!isset($syslogcfg['disablelocallogging'])) {
$syslogconf .= "*.* {$log_directive}/var/log/{$logTopic}.log\n"; $syslogconf .= "*.* {$log_directive}/var/log/{$logTopic}.log\n";
} }
if ($logConfig['remote'] != null && !empty($syslogcfg[$logConfig['remote']]) && !empty($syslogcfg['enable'])) { if (isset($logConfig['remote']) && !empty($syslogcfg[$logConfig['remote']]) && !empty($syslogcfg['enable'])) {
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*"); $syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*");
} }
if (isset($logConfig['local'])) {
$syslogd_extra .= system_syslogd_extra_local($logConfig['local']);
}
} }
asort($separatelogfacilities); asort($separatelogfacilities);
...@@ -938,8 +934,6 @@ EOD; ...@@ -938,8 +934,6 @@ EOD;
} }
unset($syslogconf); unset($syslogconf);
$syslogd_extra .= system_syslogd_extra_local("{$g['dhcpd_chroot_path']}/var/run/log");
if (!empty($syslogcfg['sourceip'])) { if (!empty($syslogcfg['sourceip'])) {
if ($syslogcfg['ipproto'] == "ipv6") { if ($syslogcfg['ipproto'] == "ipv6") {
$ifaddr = is_ipaddr($syslogcfg['sourceip']) ? $syslogcfg['sourceip'] : get_interface_ipv6($syslogcfg['sourceip']); $ifaddr = is_ipaddr($syslogcfg['sourceip']) ? $syslogcfg['sourceip'] : get_interface_ipv6($syslogcfg['sourceip']);
...@@ -1863,30 +1857,3 @@ function get_possible_traffic_source_addresses($include_ipv6_link_local=false) { ...@@ -1863,30 +1857,3 @@ function get_possible_traffic_source_addresses($include_ipv6_link_local=false) {
} }
return $sourceips; return $sourceips;
} }
/**
* scan plugins for legacy system
* @return array
*/
function plugin_scan()
{
$path = '/usr/local/etc/inc/plugins.inc.d/';
$ext = '.inc';
$ret = array();
$plugins = glob($path . '*' . $ext);
if (!is_array($plugins)) {
return $ret;
}
sort($plugins);
foreach ($plugins as $plugin) {
$name = preg_replace('/' . preg_quote($path, '/') . '/', '', $plugin);
$name = preg_replace('/' . preg_quote($ext, '/') . '/', '', $name);
$ret[$name] = $plugin;
}
return $ret;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment