Support include directives from rsyslog
authorJamie Cameron <jcameron@webmin.com>
Wed, 14 Oct 2009 06:59:49 +0000 (23:59 -0700)
committerJamie Cameron <jcameron@webmin.com>
Wed, 14 Oct 2009 06:59:49 +0000 (23:59 -0700)
syslog/CHANGELOG
syslog/save_log.cgi
syslog/syslog-lib.pl

index d6baccd..1fba4f3 100644 (file)
@@ -14,3 +14,5 @@ On Fedora 8, use rsyslog by default instead of syslog.
 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.
index 5d78e7d..3cc4dc5 100755 (executable)
@@ -9,13 +9,13 @@ $conf = &get_config();
 
 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'}) {
@@ -128,7 +128,6 @@ 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'});
@@ -204,16 +203,21 @@ else {
        $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+)$/;
index 020840c..93b2d57 100755 (executable)
@@ -6,19 +6,23 @@ use WebminCore;
 &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 =~ /\\$/) {
@@ -32,7 +36,19 @@ while($line = <CONF>) {
                        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+/) {
@@ -44,6 +60,7 @@ while($line = <CONF>) {
                local $act = $3;
                local $log = { 'active' => !$1,
                               'sel' => [ split(/;/, $2) ],
+                              'cfile' => $cfile,
                               'line' => $slnum,
                               'eline' => $lnum };
                if ($act =~ /^\-(\/\S+)$/) {
@@ -83,13 +100,13 @@ while($line = <CONF>) {
                # 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;
 }
 
@@ -109,7 +126,7 @@ else {
 # 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,
@@ -134,7 +151,7 @@ else {
 # 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();
 }