Commit 8f08a83c 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.

(cherry picked from commit 8371e3b9)
(cherry picked from commit 87066bbe)
(cherry picked from commit 4cb9fe70)
parent 2309ad61
......@@ -876,43 +876,33 @@ 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;
}
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";
......@@ -920,9 +910,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 (!empty($logConfig['remote']) && !empty($syslogcfg[$logConfig['remote']]) && !empty($syslogcfg['enable'])) {
$syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*");
}
if (!empty($logConfig['local'])) {
$syslogd_extra .= system_syslogd_extra_local($logConfig['local']);
}
}
asort($separatelogfacilities);
......@@ -974,8 +967,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']);
......@@ -1019,6 +1010,47 @@ EOD;
}
}
function system_clear_log($logfile, $restart_syslogd = true)
{
if ($restart_syslogd) {
killbyname('syslogd');
}
foreach (glob($logfile . '.*') as $rotated) {
@unlink($rotated);
}
/* preserve file ownership and permissions */
if (file_exists($logfile)) {
$handle = fopen($logfile, 'r+');
if ($handle) {
ftruncate($handle, 0);
fclose($handle);
}
}
if ($restart_syslogd) {
system_syslogd_start();
}
}
function system_clear_clog($logfile, $restart_syslogd = true)
{
global $config;
if ($restart_syslogd) {
killbyname('syslogd');
}
$log_size = isset($config['syslog']['logfilesize']) ? $config['syslog']['logfilesize'] : '511488';
mwexecf('/usr/local/sbin/clog -i -s %s %s', array($log_size, $logfile));
if ($restart_syslogd) {
system_syslogd_start();
}
}
function system_webgui_configure()
{
global $config;
......@@ -1899,30 +1931,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;
}
......@@ -36,6 +36,7 @@ require_once("filter_log.inc");
require_once("system.inc");
require_once("pfsense-utils.inc");
require_once("interfaces.inc");
require_once("plugins.inc");
/********************************************************************************************************************
* imported from easyrule.inc/php
......@@ -607,7 +608,7 @@ if (isset($filterlogentries_qty) && $filterlogentries_qty != null) {
}
if (isset($_POST['clear'])) {
clear_clog($filter_logfile);
system_clear_clog($filter_logfile);
}
include("head.inc");
......
......@@ -32,6 +32,7 @@ require_once("guiconfig.inc");
require_once("filter_log.inc");
require_once("system.inc");
require_once("interfaces.inc");
require_once("plugins.inc");
$filter_logfile = '/var/log/filter.log';
......@@ -42,7 +43,7 @@ $nentries = 50;
handle_ajax($nentries, $nentries + 20);
if (isset($_POST['clear'])) {
clear_clog($filter_logfile);
system_clear_clog($filter_logfile);
}
$filterlog = conv_log_filter($filter_logfile, $nentries, $nentries + 100);
......
......@@ -31,6 +31,7 @@ require_once("guiconfig.inc");
require_once("filter_log.inc");
require_once("system.inc");
require_once("interfaces.inc");
require_once("plugins.inc");
$filter_logfile = '/var/log/filter.log';
$lines = 5000; // Maximum number of log entries to fetch
......@@ -38,7 +39,7 @@ $entriesperblock = 10; // Maximum elements to show individually
// flush log file
if (!empty($_POST['clear'])) {
clear_clog($filter_logfile);
system_clear_clog($filter_logfile);
}
// Retrieve filter log data
......
......@@ -35,6 +35,7 @@ require_once("filter.inc");
require_once("system.inc");
require_once("pfsense-utils.inc");
require_once("services.inc");
require_once("plugins.inc");
function clear_all_log_files()
{
......@@ -68,12 +69,12 @@ function clear_all_log_files()
);
foreach ($clog_files as $lfile) {
clear_clog("/var/log/{$lfile}.log", false);
system_clear_clog("/var/log/{$lfile}.log", false);
}
foreach ($log_files as $lfile) {
clear_log("/var/log/{$lfile}.log", false);
system_clear_log("/var/log/{$lfile}.log", false);
}
system_syslogd_start();
......
......@@ -32,6 +32,7 @@
require_once("guiconfig.inc");
require_once("system.inc");
require_once("interfaces.inc");
require_once("plugins.inc");
/* expects $logfile to point to the system path */
/* expects $logclog to be true or false */
......@@ -45,9 +46,9 @@ if (isset($config['syslog']['nentries'])) {
if (!empty($_POST['clear'])) {
if ($logclog) {
clear_clog($logfile);
system_clear_clog($logfile);
} else {
clear_log($logfile);
system_clear_log($logfile);
}
if (function_exists(clear_hook)) {
clear_hook();
......
......@@ -40,7 +40,7 @@ if (empty($config['syslog']['nentries'])) {
}
if ($_POST['clear']) {
clear_clog($logfile);
system_clear_clog($logfile);
}
function dump_clog_vpn($logfile, $tail, $logtype)
......
......@@ -355,46 +355,6 @@ function gentitle($breadcrumbs, $navlevelsep = ': ')
return join($navlevelsep, $output);
}
function clear_log($logfile, $restart_syslogd = true)
{
if ($restart_syslogd) {
killbyname('syslogd');
}
foreach (glob($logfile . '.*') as $rotated) {
@unlink($rotated);
}
/* preserve file ownership and permissions */
if (file_exists($logfile)) {
$handle = fopen($logfile, 'r+');
if ($handle) {
ftruncate($handle, 0);
fclose($handle);
}
}
if ($restart_syslogd) {
system_syslogd_start();
}
}
function clear_clog($logfile, $restart_syslogd = true)
{
global $config;
if ($restart_syslogd) {
killbyname('syslogd');
}
$log_size = isset($config['syslog']['logfilesize']) ? $config['syslog']['logfilesize'] : '511488';
mwexecf('/usr/local/sbin/clog -i -s %s %s', array($log_size, $logfile));
if ($restart_syslogd) {
system_syslogd_start();
}
}
function print_dump($logarr)
{
global $config;
......
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