# syslog-lib.pl # Functions for the syslog module BEGIN { push(@INC, ".."); }; use WebminCore; &init_config(); %access = &get_module_acl(); # 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, $cfile); local @lines = <CONF>; close(CONF); foreach my $line (@lines) { local $slnum = $lnum; $line =~ s/\r|\n//g; if ($line =~ /\\$/) { # continuation .. get the next lines $line =~ s/\\$//; while($cont = <CONF>) { $lnum++; $cont =~ s/^[#\s]+//; $cont =~ s/\r|\n//g; $line .= $cont; last if ($line !~ s/\\$//); } } if ($line =~ /^\$IncludeConfig\s+(\S+)/ || $line =~ /^include\(file="([^"]+)"/) { # 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+/) { # rsyslog if statement .. ignored too } elsif ($line =~ /^(#*)\s*([^#\s]+\.\S+)\s+(\S+)$/ || $line =~ /^(#*)\s*([^#\s]+\.\S+)\s+(\|.*)$/) { # Regular log destination local $act = $3; local $log = { 'active' => !$1, 'sel' => [ split(/;/, $2) ], 'cfile' => $cfile, 'line' => $slnum, 'eline' => $lnum }; if ($act =~ /^\-(\/\S+)$/) { $log->{'file'} = $1; $log->{'sync'} = 0; } elsif ($act =~ /^\|(.*)$/) { $log->{'pipe'} = $1; } elsif ($act =~ /^(\/\S+)$/) { $log->{'file'} = $1; $log->{'sync'} = 1; } elsif ($act =~ /^\@\@(\S+)$/) { $log->{'socket'} = $1; } elsif ($act =~ /^\@(\S+)$/) { $log->{'host'} = $1; } elsif ($act eq '*') { $log->{'all'} = 1; } else { $log->{'users'} = [ split(/,/, $act) ]; } $log->{'index'} = scalar(@rv); $log->{'section'} = $tag; $tag->{'eline'} = $lnum; if ($log->{'file'} =~ s/^(\/\S+);(\S+)$/$1/ || $log->{'pipe'} =~ s/^(\/\S+);(\S+)$/$1/) { # rsyslog file format $log->{'format'} = $2; } push(@rv, $log); } elsif ($line =~ /^(#?)!(\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++; } return \@rv; } # create_log(&log) sub create_log { local $lref = &read_file_lines($config{'syslog_conf'}); if ($config{'tags'}) { splice(@$lref, $_[0]->{'section'}->{'eline'}+1, 0, &log_line($_[0])); } else { push(@$lref, &log_line($_[0])); } &flush_file_lines(); } # update_log(&old, &log) sub update_log { 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, &log_line($_[1])); splice(@$lref, $_[0]->{'line'}, $_[0]->{'eline'} - $_[0]->{'line'} + 1); } else { splice(@$lref, $_[0]->{'line'}, $_[0]->{'eline'} - $_[0]->{'line'} + 1); splice(@$lref, $_[1]->{'section'}->{'eline'}+1, 0, &log_line($_[1])); } } else { splice(@$lref, $_[0]->{'line'}, $_[0]->{'eline'} - $_[0]->{'line'} + 1, &log_line($_[1])); } &flush_file_lines(); } # delete_log(&log) sub delete_log { local $lref = &read_file_lines($_[0]->{'cfile'} || $config{'syslog_conf'}); splice(@$lref, $_[0]->{'line'}, $_[0]->{'eline'} - $_[0]->{'line'} + 1); &flush_file_lines(); } sub log_line { local $d; if ($_[0]->{'file'}) { $d = ($_[0]->{'sync'} || !$config{'sync'} ? "" : "-").$_[0]->{'file'}; } elsif ($_[0]->{'pipe'}) { $d = '|'.$_[0]->{'pipe'}; } elsif ($_[0]->{'host'}) { $d = '@'.$_[0]->{'host'}; } elsif ($_[0]->{'users'}) { $d = join(",", @{$_[0]->{'users'}}); } elsif ($_[0]->{'socket'}) { $d = '@@'.$_[0]->{'socket'}; } else { $d = '*'; } if ($_[0]->{'format'}) { # Add rsyslog format $d .= ";".$_[0]->{'format'}; } return ($_[0]->{'active'} ? "" : "#").join(";", @{$_[0]->{'sel'}})."\t".$d; } # list_priorities() # Returns a list of all priorities sub list_priorities { return ( 'debug', 'info', 'notice', 'warning', 'err', 'crit', 'alert', 'emerg' ); } # can_edit_log(&log|file) # Returns 1 if some log can be viewed/edited, 0 if not sub can_edit_log { return 1 if (!$access{'logs'}); local @files = split(/\s+/, $access{'logs'}); local $lf; if (ref($_[0])) { $lf = $_[0]->{'file'} || $_[0]->{'pipe'} || $_[0]->{'host'} || $_[0]->{'socket'} || $_[0]->{'cmd'} || ($_[0]->{'all'} ? "*" : "users"); } else { $lf = $_[0]; } foreach $f (@files) { return 1 if ($f eq $lf || &is_under_directory($f, $lf)); } return 0; } sub needs_m4 { local $oldslash = $/; $/ = undef; &open_readfile(CONF, $config{'syslog_conf'}); local $conf1 = <CONF>; close(CONF); &open_execute_command(CONF, "$config{'m4_path'} $config{'syslog_conf'}", 1, 1); local $conf2 = <CONF>; close(CONF); $/ = $oldslash; return $conf1 ne $conf2; } # get_syslog_pid(pid) # Returns the syslog PID file sub get_syslog_pid { my ($pid) = &find_byname("syslogd"); ($pid) = &find_byname("rsyslogd") if (!$pid); if (!$pid && $config{'pid_file'}) { foreach my $pfile (map { glob($_) } split(/\s+/, $config{'pid_file'})) { my $poss = &check_pid_file($pfile); if ($poss) { $pid = $poss; last; } } } return $pid; } # restart_syslog() # Stop and re-start the syslog server. Returns an error message on failure. sub restart_syslog { if ($config{'restart_cmd'}) { &system_logged("$config{'restart_cmd'} >/dev/null 2>/dev/null </dev/null"); } else { local $pid = &get_syslog_pid(); $pid && &kill_logged('TERM', $pid) || return &text('restart_ekill', $pid, $!); sleep(2); if ($config{'start_cmd'}) { &system_logged("$config{'start_cmd'} >/dev/null 2>/dev/null </dev/null"); } else { &system_logged("cd / ; $config{'syslogd'} >/dev/null 2>/dev/null </dev/null &"); } } return undef; } # signal_syslog() # Tell the syslog server to re-open it's log files sub signal_syslog { if ($config{'signal_cmd'}) { &system_logged("$config{'signal_cmd'} >/dev/null 2>/dev/null </dev/null"); } else { # Use HUP signal local $pid = &get_syslog_pid(); if ($pid) { &kill_logged('HUP', $pid); } } } # all_log_files(file) # Given a filename, returns all rotated versions, ordered by oldest first sub all_log_files { $_[0] =~ /^(.*)\/([^\/]+)$/; local $dir = $1; local $base = $2; local ($f, @rv); opendir(DIR, &translate_filename($dir)); foreach $f (readdir(DIR)) { local $trans = &translate_filename("$dir/$f"); if ($f =~ /^\Q$base\E/ && -f $trans && $f !~ /\.offset$/) { push(@rv, "$dir/$f"); $mtime{"$dir/$f"} = [ stat($trans) ]; } } closedir(DIR); return sort { $mtime{$a}->[9] <=> $mtime{$b}->[9] } @rv; } # get_other_module_logs([module]) # Returns a list of logs supplied by other modules sub get_other_module_logs { local ($mod) = @_; local @rv; local %done; foreach my $minfo (&get_all_module_infos()) { next if ($mod && $minfo->{'dir'} ne $mod); next if (!$minfo->{'syslog'}); next if (!&foreign_installed($minfo->{'dir'})); local $mdir = &module_root_directory($minfo->{'dir'}); next if (!-r "$mdir/syslog_logs.pl"); &foreign_require($minfo->{'dir'}, "syslog_logs.pl"); local $j = 0; foreach my $l (&foreign_call($minfo->{'dir'}, "syslog_getlogs")) { local $fc = $l->{'file'} || $l->{'cmd'}; next if ($done{$fc}++); $l->{'minfo'} = $minfo; $l->{'mod'} = $minfo->{'dir'}; $l->{'mindex'} = $j++; push(@rv, $l); } } @rv = sort { $a->{'minfo'}->{'desc'} cmp $b->{'minfo'}->{'desc'} } @rv; local $i = 0; foreach my $l (@rv) { $l->{'index'} = $i++; } return @rv; } # catter_command(file) # Given a file that may be compressed, returns the command to output it in # plain text, or undef if impossible sub catter_command { local ($l) = @_; local $q = quotemeta($l); if ($l =~ /\.gz$/i) { return &has_command("gunzip") ? "gunzip -c $q" : undef; } elsif ($l =~ /\.Z$/i) { return &has_command("uncompress") ? "uncompress -c $q" : undef; } elsif ($l =~ /\.bz2$/i) { return &has_command("bunzip2") ? "bunzip2 -c $q" : undef; } elsif ($l =~ /\.xz$/i) { return &has_command("xz") ? "xz -d -c $q" : undef; } else { return "cat $q"; } } # extra_log_files() # Returns a list of extra log files available to the current Webmin user. No filtering # based on allowed directory is done though! sub extra_log_files { local @rv; foreach my $fd (split(/\t+/, $config{'extras'}), split(/\t+/, $access{'extras'})) { if ($fd =~ /^"(\S+)"\s+"(\S.*)"$/) { push(@rv, { 'file' => $1, 'desc' => $2 }); } elsif ($fd =~ /^"(\S+)"$/) { push(@rv, { 'file' => $1 }); } elsif ($fd =~ /^(\S+)\s+(\S.*)$/) { push(@rv, { 'file' => $1, 'desc' => $2 }); } else { push(@rv, { 'file' => $fd }); } } return @rv; } 1;
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
images | Folder | 0755 |
|
|
lang | Folder | 0755 |
|
|
CHANGELOG | File | 1.43 KB | 0644 |
|
acl_security.pl | File | 1.47 KB | 0755 |
|
backup_config.pl | File | 643 B | 0755 |
|
cgi_args.pl | File | 799 B | 0755 |
|
config-AlmaLinux-6.0-ALL | File | 701 B | 0644 |
|
config-CentOS-Linux-6.0-ALL | File | 681 B | 0644 |
|
config-CentOS-Stream-Linux-8.0-ALL | File | 701 B | 0644 |
|
config-CloudLinux-8.0-ALL | File | 701 B | 0644 |
|
config-Oracle-Linux-8.0-ALL | File | 701 B | 0644 |
|
config-Redhat-Enterprise-Linux-6.0-ALL | File | 701 B | 0644 |
|
config-Rocky-Linux-6.0-ALL | File | 701 B | 0644 |
|
config-Ubuntu-Linux-10.04-ALL | File | 442 B | 0644 |
|
config-aix | File | 324 B | 0644 |
|
config-cobalt-linux | File | 410 B | 0644 |
|
config-coherent-linux | File | 676 B | 0644 |
|
config-corel-linux | File | 399 B | 0644 |
|
config-debian-linux | File | 399 B | 0644 |
|
config-debian-linux-3.1-3.2 | File | 443 B | 0644 |
|
config-debian-linux-4.0 | File | 471 B | 0644 |
|
config-debian-linux-5.0-9.0 | File | 475 B | 0644 |
|
config-debian-linux-9.0-ALL | File | 442 B | 0644 |
|
config-freebsd | File | 337 B | 0644 |
|
config-generic-linux | File | 330 B | 0644 |
|
config-gentoo-linux | File | 330 B | 0644 |
|
config-hpux | File | 304 B | 0644 |
|
config-irix | File | 293 B | 0644 |
|
config-macos | File | 389 B | 0644 |
|
config-mandrake-linux | File | 662 B | 0644 |
|
config-msc-linux | File | 672 B | 0644 |
|
config-netbsd | File | 308 B | 0644 |
|
config-open-linux | File | 634 B | 0644 |
|
config-openSUSE-Linux-15.0-ALL | File | 362 B | 0644 |
|
config-openbsd | File | 337 B | 0644 |
|
config-openserver | File | 311 B | 0644 |
|
config-pardus-linux | File | 330 B | 0644 |
|
config-redhat-linux-16.0-23.0 | File | 671 B | 0644 |
|
config-redhat-linux-24.0-ALL | File | 701 B | 0644 |
|
config-slackware-linux | File | 330 B | 0644 |
|
config-sol-linux | File | 330 B | 0644 |
|
config-solaris | File | 444 B | 0644 |
|
config-solaris-9-10 | File | 448 B | 0644 |
|
config-suse-linux | File | 330 B | 0644 |
|
config-suse-linux-11-ALL | File | 364 B | 0644 |
|
config-suse-linux-7.2-8.0 | File | 326 B | 0644 |
|
config-suse-linux-8.2-10.9 | File | 361 B | 0644 |
|
config-trustix-linux | File | 666 B | 0644 |
|
config-turbo-linux | File | 326 B | 0644 |
|
config-united-linux | File | 326 B | 0644 |
|
config-unixware | File | 324 B | 0644 |
|
config.info | File | 1.29 KB | 0644 |
|
config.info.bg | File | 2.24 KB | 0644 |
|
config.info.ca | File | 1.39 KB | 0644 |
|
config.info.cs | File | 752 B | 0644 |
|
config.info.de | File | 1.41 KB | 0644 |
|
config.info.el | File | 2.16 KB | 0644 |
|
config.info.es | File | 1.17 KB | 0644 |
|
config.info.fr | File | 1.2 KB | 0644 |
|
config.info.hu | File | 871 B | 0644 |
|
config.info.it | File | 1.34 KB | 0644 |
|
config.info.ja | File | 1.63 KB | 0644 |
|
config.info.ko | File | 1.2 KB | 0644 |
|
config.info.nl | File | 1.28 KB | 0644 |
|
config.info.no | File | 1.18 KB | 0644 |
|
config.info.pl | File | 1.34 KB | 0644 |
|
config.info.ru | File | 1.68 KB | 0644 |
|
config.info.sv | File | 609 B | 0644 |
|
config.info.tr | File | 1.12 KB | 0644 |
|
config.info.uk | File | 1.71 KB | 0644 |
|
config.info.zh | File | 555 B | 0644 |
|
config.info.zh_TW | File | 615 B | 0644 |
|
defaultacl | File | 31 B | 0644 |
|
edit_log.cgi | File | 5.01 KB | 0755 |
|
index.cgi | File | 4.96 KB | 0755 |
|
install_check.pl | File | 333 B | 0755 |
|
log_parser.pl | File | 722 B | 0755 |
|
m4.cgi | File | 804 B | 0755 |
|
module.info | File | 255 B | 0644 |
|
module.info.af | File | 0 B | 0644 |
|
module.info.af.auto | File | 116 B | 0644 |
|
module.info.ar | File | 0 B | 0644 |
|
module.info.ar.auto | File | 167 B | 0644 |
|
module.info.be | File | 0 B | 0644 |
|
module.info.be.auto | File | 205 B | 0644 |
|
module.info.bg | File | 0 B | 0644 |
|
module.info.bg.auto | File | 231 B | 0644 |
|
module.info.ca | File | 124 B | 0644 |
|
module.info.ca.auto | File | 15 B | 0644 |
|
module.info.cs | File | 25 B | 0644 |
|
module.info.cs.auto | File | 110 B | 0644 |
|
module.info.da | File | 0 B | 0644 |
|
module.info.da.auto | File | 113 B | 0644 |
|
module.info.de | File | 111 B | 0644 |
|
module.info.de.auto | File | 15 B | 0644 |
|
module.info.el | File | 0 B | 0644 |
|
module.info.el.auto | File | 213 B | 0644 |
|
module.info.es | File | 39 B | 0644 |
|
module.info.es.auto | File | 102 B | 0644 |
|
module.info.eu | File | 0 B | 0644 |
|
module.info.eu.auto | File | 144 B | 0644 |
|
module.info.fa | File | 0 B | 0644 |
|
module.info.fa.auto | File | 225 B | 0644 |
|
module.info.fi | File | 0 B | 0644 |
|
module.info.fi.auto | File | 145 B | 0644 |
|
module.info.fr | File | 26 B | 0644 |
|
module.info.fr.auto | File | 110 B | 0644 |
|
module.info.he | File | 0 B | 0644 |
|
module.info.he.auto | File | 170 B | 0644 |
|
module.info.hr | File | 0 B | 0644 |
|
module.info.hr.auto | File | 144 B | 0644 |
|
module.info.hu | File | 35 B | 0644 |
|
module.info.hu.auto | File | 114 B | 0644 |
|
module.info.it | File | 28 B | 0644 |
|
module.info.it.auto | File | 108 B | 0644 |
|
module.info.ja | File | 28 B | 0644 |
|
module.info.ja.auto | File | 121 B | 0644 |
|
module.info.ko | File | 25 B | 0644 |
|
module.info.ko.auto | File | 110 B | 0644 |
|
module.info.lt | File | 0 B | 0644 |
|
module.info.lt.auto | File | 146 B | 0644 |
|
module.info.lv | File | 0 B | 0644 |
|
module.info.lv.auto | File | 128 B | 0644 |
|
module.info.ms | File | 105 B | 0644 |
|
module.info.ms.auto | File | 15 B | 0644 |
|
module.info.mt | File | 0 B | 0644 |
|
module.info.mt.auto | File | 136 B | 0644 |
|
module.info.nl | File | 21 B | 0644 |
|
module.info.nl.auto | File | 101 B | 0644 |
|
module.info.no | File | 22 B | 0644 |
|
module.info.no.auto | File | 90 B | 0644 |
|
module.info.pl | File | 23 B | 0644 |
|
module.info.pl.auto | File | 104 B | 0644 |
|
module.info.pt | File | 30 B | 0644 |
|
module.info.pt.auto | File | 104 B | 0644 |
|
module.info.pt_BR | File | 33 B | 0644 |
|
module.info.pt_BR.auto | File | 110 B | 0644 |
|
module.info.ro | File | 0 B | 0644 |
|
module.info.ro.auto | File | 137 B | 0644 |
|
module.info.ru | File | 40 B | 0644 |
|
module.info.ru.auto | File | 184 B | 0644 |
|
module.info.sk | File | 0 B | 0644 |
|
module.info.sk.auto | File | 142 B | 0644 |
|
module.info.sl | File | 0 B | 0644 |
|
module.info.sl.auto | File | 136 B | 0644 |
|
module.info.sv | File | 21 B | 0644 |
|
module.info.sv.auto | File | 95 B | 0644 |
|
module.info.th | File | 0 B | 0644 |
|
module.info.th.auto | File | 216 B | 0644 |
|
module.info.tr | File | 27 B | 0644 |
|
module.info.tr.auto | File | 131 B | 0644 |
|
module.info.uk | File | 0 B | 0644 |
|
module.info.uk.auto | File | 203 B | 0644 |
|
module.info.ur | File | 0 B | 0644 |
|
module.info.ur.auto | File | 176 B | 0644 |
|
module.info.vi | File | 0 B | 0644 |
|
module.info.vi.auto | File | 203 B | 0644 |
|
module.info.zh | File | 21 B | 0644 |
|
module.info.zh.auto | File | 94 B | 0644 |
|
module.info.zh_TW | File | 24 B | 0644 |
|
module.info.zh_TW.auto | File | 100 B | 0644 |
|
prefs.info | File | 60 B | 0644 |
|
rbac-mapping | File | 119 B | 0644 |
|
restart.cgi | File | 253 B | 0755 |
|
safeacl | File | 33 B | 0644 |
|
save_log.cgi | File | 8.79 KB | 0755 |
|
start.cgi | File | 372 B | 0755 |
|
syslog-lib.pl | File | 8.94 KB | 0755 |
|