]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - html/cgi-bin/logs.cgi/log.dat
WUI log-section Mail: bugfix for dma
[ipfire-2.x.git] / html / cgi-bin / logs.cgi / log.dat
index 5a2ef9b5271cb0412b8ac6c5d5a67f94e02e0f64..7074a4a612dbcf0f3c57e0e6285edbbd0dc44f88 100644 (file)
@@ -12,8 +12,8 @@
 use strict;
 
 # enable only the following on debugging purpose
-#use warnings;
-#use CGI::Carp 'fatalsToBrowser';
+use warnings;
+use CGI::Carp 'fatalsToBrowser';
 
 require '/var/ipfire/general-functions.pl';
 require "${General::swroot}/lang.pl";
@@ -26,10 +26,6 @@ my %mainsettings = ();
 
 use POSIX();
 
-#workaround to suppress a warning when a variable is used only once
-my @dummy = ( ${Header::table2colour} );
-undef (@dummy);
-
 my %cgiparams=();
 my %logsettings=();
 my $errormessage = '';
@@ -53,34 +49,58 @@ $cgiparams{'ACTION'} = '';
 $cgiparams{'SECTION'} = 'ipfire';
 
 my %sections = (
-        'ipfire' => '(ipfire)',
-        'red' => '(red.*|kernel: usb.*|pppd\[.*\]|chat\[.*\]|pppoe\[.*\]|pptp\[.*\]|pppoa\[.*\]|pppoa3\[.*\]|pppoeci\[.*\]|ipppd|ipppd\[.*\]|kernel: ippp\d|kernel: isdn.*|ibod\[.*\]|kernel: eth.*|dhcpcd\[.*\]|modem_run\[.*\])',
-        'dns' => '(dnsmasq\[.*\])',
-        'dhcp' => '(dhcpd)',
-        'cron' => '(fcron\[.*\])',
-        'ntp' => '(ntpd(?:ate)?\[.*\])',
-        'ssh' => '(sshd(?:\(.*\))?\[.*\])',
-        'auth' => '(\w+\(pam_unix\)\[.*\])',
-        'kernel' => '(kernel)',
-        'ipsec' => '(ipsec_[\w_]+|pluto\[.*\]|vpnwatch)',
-        'snort' => '(snort)',
-        'openvpn' => '(openvpnserver)\[.*\]'
+        'auth' => '(\w+\(pam_unix\)\[.*\]: )',
+               'wio' => '(wio:|wio\[.*\])',
+        'captive' => '(Captive:)',
+        'clamav' => '(clamd\[.*\]: |freshclam\[.*\]: )',
+        'collectd' => '(collectd\[.*\]: )',
+        'cron' => '(fcron\[.*\]: )',
+        'ddns' => '(ddns\[\d+\]:)',
+        'dhcp' => '(dhcpd: )',
+        'dma' => '(dma: |dma\[.*\]: )',
+        'guardian' => '(guardian\[.*\]: )',
+        'ipfire' => '(ipfire: )',
+        'ipsec' => '(ipsec_[\w_]+: |pluto\[.*\]: |charon: |vpnwatch: )',
+        'kernel' => '(kernel: (?!DROP_))',
+        'ntp' => '(ntpd(?:ate)?\[.*\]: )',
+       'oinkmaster' => '(oinkmaster\[.*\]: )',
+        'openvpn' => '(openvpnserver\[.*\]: |.*n2n\[.*\]: )',
+        'pakfire' => '(pakfire:)',
+        'red' => '(red:|pppd\[.*\]: |chat\[.*\]|pppoe\[.*\]|pptp\[.*\]|pppoa\[.*\]|pppoa3\[.*\]|pppoeci\[.*\]|ipppd|ipppd\[.*\]|kernel: ippp\d|kernel: isdn.*|ibod\[.*\]|dhcpcd\[.*\]|modem_run\[.*\])',
+        'suricata' => '(suricata: )',
+        'squid' => '(squid\[.*\]: |squid: )',
+        'ssh' => '(sshd(?:\(.*\))?\[.*\]: )',
+        'unbound' => '(unbound: \[.*:.*\])(.*:.*$)',
+        'urlfilter bl' => '(installpackage\[urlfilter\]: )',
+        'wireless' => '(hostapd:|kernel: ath.*:|kernel: wifi[0-9]:)'
         );
 
 # Translations for the %sections array.
 my %trsections = (
-        'ipfire' => 'IPFire',
-        'red' => 'RED',
-        'dns' => 'DNS',
-        'dhcp' => "$Lang::tr{'dhcp server'}",
-        'cron' => 'Cron',
-        'ntp' => 'NTP',
-        'ssh' => 'SSH',
         'auth' => "$Lang::tr{'loginlogout'}",
-        'kernel' => "$Lang::tr{'kernel'}",
+               'wio' => 'Who Is Online?',
+        'captive' => $Lang::tr{'Captive'},
+        'clamav' => 'ClamAV',
+        'collectd' => 'Collectd',
+        'cron' => 'Cron',
+        'ddns' => "$Lang::tr{'dynamic dns'}",
+        'dhcp' => "$Lang::tr{'dhcp server'}",
+        'dma' => 'Mail',
+        'guardian' => "$Lang::tr{'guardian'}",
+        'ipfire' => 'IPFire',
         'ipsec' => 'IPSec',
+        'kernel' => "$Lang::tr{'kernel'}",
+        'ntp' => 'NTP',
+       'oinkmaster' => 'Oinkmaster',
         'openvpn' => 'OpenVPN',
-        'snort' => 'Snort'
+        'pakfire' => 'Pakfire',
+        'red' => 'RED',
+        'suricata' => "$Lang::tr{'intrusion detection'}",
+        'squid' => "$Lang::tr{'web proxy'}",
+        'ssh' => 'SSH',
+        'unbound' => 'DNS: Unbound',
+        'urlfilter bl' => 'URLFilter Blacklist',
+        'wireless' => 'Wireless'
        );
 
 
@@ -151,7 +171,7 @@ my $date = $cgiparams{'DAY'} == 0 ? '' :  $cgiparams{'DAY'} <= 9 ? "0$cgiparams{
 
 {
     my $xday;
-    
+
     # Calculate time. If future date, calculate for past year !!!
     if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
         ( $cgiparams{'MONTH'}  > $now[4] ) ) {
@@ -165,13 +185,13 @@ my $date = $cgiparams{'DAY'} == 0 ? '' :  $cgiparams{'DAY'} <= 9 ? "0$cgiparams{
     # calculate end of active week (saturday 23H59)
     my @then = ();
     @then = localtime(time());
-    my $sunday = POSIX::mktime( 0, 0, 0, @then[3], @then[4], @then[5]);
+    my $sunday = POSIX::mktime( 0, 0, 0, $then[3], $then[4], $then[5]);
     $sunday += (6-$then[6]) * 86400;
 
     # Convert delta in second to full weeks
        $gzindex = int (($sunday-$xday)/604800 );
 }
-                                                                                          
+
 my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
 my $daystr =  $cgiparams{'DAY'} == 0 ?  '..' : $cgiparams{'DAY'} <= 9 ? " $cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
 my $section = $sections{$cgiparams{'SECTION'}};
@@ -183,13 +203,15 @@ my $loop = 1;
 my $filestr = 0;
 my $lastdatetime;           # for debug
 my $search_for_end = 0;
-           
+
 while ($gzindex >=0 && $loop) {
         # calculate file name
         if ($gzindex == 0) {
             $filestr = "/var/log/messages";
+            $filestr = "/var/log/mail" if (${section} =~ 'dma');
         } else {
             $filestr = "/var/log/messages.$gzindex";
+            $filestr = "/var/log/mail.$gzindex" if (${section} =~ 'dma');
            $filestr = "$filestr.gz" if -f "$filestr.gz";
         }
        # now read file if existing
@@ -197,8 +219,8 @@ while ($gzindex >=0 && $loop) {
            #&General::log("reading $filestr");
            READ:while (<FILE>) {
                my $line = $_;
-               if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w\-]+ ${section}(.*)/) {
-                   # when standart viewing, just keep in memory the correct slice
+               if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w\-]+ ${section}(.*)/) {
+                   # when standard viewing, just keep in memory the correct slice
                    # it starts a '$start' and size is $viewport
                    # If export, then keep all lines...
                    if ($cgiparams{'ACTION'} eq $Lang::tr{'export'}){
@@ -209,7 +231,7 @@ while ($gzindex >=0 && $loop) {
                            if (@log > $Header::viewsize) {
                                shift (@log);
                            }
-                       #} else { dont do this optimisation, need to count lines !
+                       #} else { don't do this optimisation, need to count lines !
                            #    $datetime = $maxtime; # we have read viewsize lines, stop main loop
                            #    last READ;           # exit read file
                        }
@@ -242,11 +264,11 @@ if ($cgiparams{'ACTION'} eq $Lang::tr{'export'})
 
        foreach $_ (@log)
        {
-               /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
+               /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
                my $day =  $1;
                $day =~ tr / /0/;
                my $time = $cgiparams{'DAY'} ? "$2" : "$day/$2" ;
-               print "$time $3 $4\r\n";
+  print "$time $3 $4\r\n";
        }
        exit 0;
 }
@@ -274,7 +296,7 @@ print <<END
        <select name='SECTION'>
 END
 ;
-foreach $section (keys %sections) {
+foreach $section (sort {$trsections{$a} cmp $trsections{$b}} keys %sections) {
        print "\t<option ";
        if ($section eq $cgiparams{'SECTION'}) {
                print "selected='selected' "; }
@@ -304,7 +326,7 @@ print <<END
 END
 ;
 print "<option value='0'>$Lang::tr{'all'}</option>\n";
-for (my $day = 1; $day <= 31; $day++) 
+for (my $day = 1; $day <= 31; $day++)
 {
        print "\t<option ";
        if ($day == $cgiparams{'DAY'}) {
@@ -339,7 +361,7 @@ my $prev;
        $prev = $start - ${Header::viewsize};
        $prev = 0 if ( $prev < 0);
     }
-                                   
+
 my $next;
     if ($start == $lines - ${Header::viewsize}) {
         $next = -1;
@@ -352,11 +374,11 @@ if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
 if ($lines != 0) { &oldernewer(); }
 
 print <<END
-<table width='100%'>
+<table width='100%' class='tbl'>
 <tr>
-       <td width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></td>
-       <td width='10%' align='center' class='boldbase'><b>$Lang::tr{'section'}</b></td>
-       <td width='80%'>&nbsp;</td>
+       <th width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></th>
+       <th width='15%' align='center' class='boldbase'><b>$Lang::tr{'section'}</b></th>
+       <th width='75%'>&nbsp;</th>
 </tr>
 END
 ;
@@ -365,7 +387,7 @@ $lines = 0;
 #print '<tt>';
 foreach $_ (@log)
 {
-       /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
+       /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
        my $day =  $1;
        $day =~ tr / /0/;
        my $time = $cgiparams{'DAY'} ? "$2" : "$day/$2" ;
@@ -381,13 +403,15 @@ foreach $_ (@log)
            $data = substr ($data,80);  #permit correct display in table cell
            $d .=  ' ' . substr ($data,0,80);
        }
-
+       my $col="";
 
        if ($lines % 2) {
-               print "<tr bgcolor='$color{'color20'}'>"; }
+               print "<tr>";
+               $col="bgcolor='$color{'color20'}'"; }
        else {
-               print "<tr bgcolor='$color{'color22'}'>"; }
-       print "<td>$time<td>$sec<td>" .&Header::cleanhtml ("$d", 'y') . "</td></tr>\n";
+               print "<tr>";
+               $col="bgcolor='$color{'color22'}'"; }
+       print "<td $col>$time<td $col>$sec<td $col>" .&Header::cleanhtml ("$d", 'y') . "</td></tr>\n";
        $lines++;
 }
 #print '</tt>';