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 @@
* 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()
{
$services = array();
foreach (plugin_scan() as $name => $path) {
foreach (plugins_scan() as $name => $path) {
require_once $path;
$func = sprintf('%s_services', $name);
if (function_exists($func)) {
......@@ -44,6 +71,24 @@ function plugins_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.
* Every <plugin>_interface should return a named array containing the interface unique identifier and properties.
......@@ -56,7 +101,7 @@ function plugins_interfaces()
$registered_interfaces = array();
// register / update interfaces
foreach (plugin_scan() as $name => $path) {
foreach (plugins_scan() as $name => $path) {
require_once $path;
$func = sprintf('%s_interfaces', $name);
if (function_exists($func)) {
......@@ -105,7 +150,7 @@ function plugins_interfaces()
function plugins_configure()
{
foreach (plugin_scan() as $name => $path) {
foreach (plugins_scan() as $name => $path) {
require_once $path;
$func = sprintf('%s_configure', $name);
if (function_exists($func)) {
......
......@@ -840,43 +840,36 @@ function system_syslogd_start()
if (isset($syslogcfg)) {
$syslogconf = '';
// create structure with log section definitions and config tags for remote usage
$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);
$syslogconfs['ppps'] = array("facility" => array('ppp'), "remote" => null);
$syslogconfs['ipsec'] = array("facility" => array('charon'), "remote" => null);
$syslogconfs['openvpn'] = array("facility" => array('openvpn'), "remote" => "vpn");
$syslogconfs['gateways'] = array("facility" => array('apinger'), "remote" => "apinger");
$syslogconfs['resolver'] = array("facility" => array('dnsmasq','filterdns','unbound'), "remote" => null);
$syslogconfs['dhcpd'] = array("facility" => array('dhcpd','dhcrelay','dhclient','dhcp6c'), "remote" => "dhcp");
$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 remove after the call path is safe */
require_once 'plugins.inc';
if (function_exists('plugins_syslog')) {
/* only pull plugins if plugins.inc was included before */
foreach (plugins_syslog() as $plugin_name => $plugin_details) {
$syslogconfs[$plugin_name] = $plugin_details;
}
}
/*
* 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();
foreach ($syslogconfs as $logTopic => $logConfig) {
$syslogconf .= "!".implode(',', $logConfig['facility'])."\n";
......@@ -884,9 +877,12 @@ function system_syslogd_start()
if (!isset($syslogcfg['disablelocallogging'])) {
$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, "*.*");
}
if (isset($logConfig['local'])) {
$syslogd_extra .= system_syslogd_extra_local($logConfig['local']);
}
}
asort($separatelogfacilities);
......@@ -938,8 +934,6 @@ EOD;
}
unset($syslogconf);
$syslogd_extra .= system_syslogd_extra_local("{$g['dhcpd_chroot_path']}/var/run/log");
if (!empty($syslogcfg['sourceip'])) {
if ($syslogcfg['ipproto'] == "ipv6") {
$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) {
}
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