Added support for rsyslogd, as seen by default on Debian 5.0.
---- Changes since 1.480 ----
Rsyslog format tags in the config file are now recogized and preserved, rather than being included in the log filename.
+---- Changes since 1.490 ----
+Added support for rsyslog IncludeConfig directives, which are used to split the config into multiple files, as seen on Ubuntu 9.
if ($in{'delete'}) {
# Deleting a log
- &lock_file($config{'syslog_conf'});
$access{'noedit'} && &error($text{'edit_ecannot'});
$access{'syslog'} || &error($text{'edit_ecannot'});
$log = $conf->[$in{'idx'}];
+ &lock_file($log->{'cfile'});
&can_edit_log($log) || &error($text{'save_ecannot1'});
&delete_log($log);
- &unlock_file($config{'syslog_conf'});
+ &unlock_file($log->{'cfile'});
&redirect("");
}
elsif ($in{'view'}) {
}
else {
# saving or updating a log
- &lock_file($config{'syslog_conf'});
$access{'noedit'} && &error($text{'edit_ecannot'});
$access{'syslog'} || &error($text{'edit_ecannot'});
&error_setup($text{'save_err'});
$log->{'sel'} = \@sel;
if ($in{'new'}) {
&can_edit_log($log) || &error($text{'save_ecannot3'});
+ &lock_file($log->{'cfile'});
+ $log->{'cfile'} = $config{'syslog_conf'};
&create_log($log);
+ &unlock_file($log->{'cfile'});
}
else {
&can_edit_log($log) || &error($text{'save_ecannot4'});
$old = $conf->[$in{'idx'}];
+ $log->{'cfile'} = $old->{'cfile'};
+ &lock_file($old->{'cfile'});
$log->{'format'} = $old->{'format'}; # Copy for now
&can_edit_log($old) || &error($text{'save_ecannot5'});
&update_log($old, $log);
+ &unlock_file($old->{'cfile'});
}
- &unlock_file($config{'syslog_conf'});
&redirect("");
}
&log_line($log) =~ /(\S+)$/;
&init_config();
%access = &get_module_acl();
-# get_config()
+# get_config([file])
# Parses the syslog configuration file into an array ref of hash refs, one
# for each log file or destination
sub get_config
{
+local ($cfile) = @_;
+$cfile ||= $config{'syslog_conf'};
local $lnum = 0;
local ($line, $cont, @rv);
local $tag = { 'tag' => '*',
'index' => 0,
'line' => 0 };
push(@rv, $tag);
-&open_readfile(CONF, $config{'syslog_conf'});
-while($line = <CONF>) {
+&open_readfile(CONF, $cfile);
+local @lines = <CONF>;
+close(CONF);
+foreach my $line (@lines) {
local $slnum = $lnum;
$line =~ s/\r|\n//g;
if ($line =~ /\\$/) {
last if ($line !~ s/\\$//);
}
}
- if ($line =~ /^\$(\S+)\s*(\S*)/) {
+ if ($line =~ /^\$IncludeConfig\s+(\S+)/) {
+ # rsyslog include statement .. follow the money
+ foreach my $icfile (glob($1)) {
+ my $ic = &get_config($icfile);
+ if ($ic) {
+ foreach my $c (@$ic) {
+ $c->{'index'} += scalar(@rv);
+ }
+ push(@rv, @$ic);
+ }
+ }
+ }
+ elsif ($line =~ /^\$(\S+)\s*(\S*)/) {
# rsyslog special directive - ignored for now
}
elsif ($line =~ /^if\s+/) {
local $act = $3;
local $log = { 'active' => !$1,
'sel' => [ split(/;/, $2) ],
+ 'cfile' => $cfile,
'line' => $slnum,
'eline' => $lnum };
if ($act =~ /^\-(\/\S+)$/) {
# Start of tagged section, as seen on BSD
push(@rv, { 'tag' => $2,
'index' => scalar(@rv),
+ 'cfile' => $cfile,
'line' => $lnum,
'eline' => $lnum });
$tag = $rv[@rv-1];
}
$lnum++;
}
-close(CONF);
return \@rv;
}
# update_log(&old, &log)
sub update_log
{
-local $lref = &read_file_lines($config{'syslog_conf'});
+local $lref = &read_file_lines($_[0]->{'cfile'} || $config{'syslog_conf'});
if ($config{'tags'} && $_[0]->{'section'} ne $_[1]->{'section'}) {
if ($_[0]->{'section'}->{'line'} < $_[1]->{'section'}->{'line'}) {
splice(@$lref, $_[1]->{'section'}->{'eline'}+1, 0,
# delete_log(&log)
sub delete_log
{
-local $lref = &read_file_lines($config{'syslog_conf'});
+local $lref = &read_file_lines($_[0]->{'cfile'} || $config{'syslog_conf'});
splice(@$lref, $_[0]->{'line'}, $_[0]->{'eline'} - $_[0]->{'line'} + 1);
&flush_file_lines();
}