]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/logs.cgi/log.dat
5 # This code is distributed under the terms of the GPL
7 # (c) The SmoothWall Team
9 # $Id: log.dat,v 1.6.2.22 2006/01/03 12:47:17 franck78 Exp $
14 # enable only the following on debugging purpose
16 use CGI
::Carp
'fatalsToBrowser';
18 require '/var/ipfire/general-functions.pl';
19 require "${General::swroot}/lang.pl";
20 require "${General::swroot}/header.pl";
23 my %mainsettings = ();
24 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
25 &General
::readhash
("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \
%color);
31 my $errormessage = '';
33 my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
34 'Sep', 'Oct', 'Nov', 'Dec' );
35 my @longmonths = ( $Lang::tr
{'january'}, $Lang::tr
{'february'}, $Lang::tr
{'march'},
36 $Lang::tr
{'april'}, $Lang::tr
{'may'}, $Lang::tr
{'june'}, $Lang::tr
{'july'}, $Lang::tr
{'august'},
37 $Lang::tr
{'september'}, $Lang::tr
{'october'}, $Lang::tr
{'november'},
38 $Lang::tr
{'december'} );
40 my @now = localtime();
44 my $year = $now[5]+1900;
46 $cgiparams{'DAY'} = $now[3];
47 $cgiparams{'MONTH'} = $now[4];
48 $cgiparams{'ACTION'} = '';
49 $cgiparams{'SECTION'} = 'ipfire';
52 'auth' => '(\w+\(pam_unix\)\[.*\]: )',
53 'wio' => '(wio:|wio\[.*\])',
54 'captive' => '(Captive:)',
55 'clamav' => '(clamd\[.*\]: |freshclam\[.*\]: )',
56 'collectd' => '(collectd\[.*\]: )',
57 'cron' => '(fcron\[.*\]: )',
58 'ddns' => '(ddns\[\d+\]:)',
59 'dhcp' => '(dhcpd: )',
60 'dma' => '(dma: |dma\[.*\]: |postfix/\w*\[\d*\]: )',
61 'guardian' => '(guardian\[.*\]: )',
62 'ipblocklist' => '(ipblocklist: )',
63 'ipfire' => '(ipfire: )',
64 'ipsec' => '(ipsec_[\w_]+: |pluto\[.*\]: |charon: |vpnwatch: )',
65 'kernel' => '(kernel: (?!DROP_))',
66 'monit' => '(monit\[.*?\]: )',
67 'ntp' => '(ntpd(?:ate)?\[.*\]: )',
68 'oinkmaster' => '(oinkmaster\[.*\]: )',
69 'openvpn' => '(openvpnserver\[.*\]: |.*n2n\[.*\]: )',
70 'pakfire' => '(pakfire:)',
71 'red' => '(red:|pppd\[.*\]: |chat\[.*\]|pppoe\[.*\]|pptp\[.*\]|pppoa\[.*\]|pppoa3\[.*\]|pppoeci\[.*\]|ipppd|ipppd\[.*\]|kernel: ippp\d|kernel: isdn.*|ibod\[.*\]|dhcpcd\[.*\]|modem_run\[.*\])',
72 'samba' => '(nmbd|smbd|winbind)\[\d+\]:',
73 'suricata' => '(suricata: )',
74 'squid' => '(squid\[.*\]: |squid: )',
75 'ssh' => '(sshd(?:\(.*\))?\[.*\]: )',
76 'unbound' => '(unbound: \[.*:.*\])(.*:.*$)',
77 'urlfilter bl' => '(installpackage\[urlfilter\]: )',
78 'wireless' => '(hostapd:|kernel: ath.*:|kernel: wifi[0-9]:)'
81 # Translations for the %sections array.
83 'auth' => "$Lang::tr{'loginlogout'}",
84 'wio' => 'Who Is Online?',
85 'captive' => $Lang::tr
{'Captive'},
87 'collectd' => 'Collectd',
89 'ddns' => "$Lang::tr{'dynamic dns'}",
90 'dhcp' => "$Lang::tr{'dhcp server'}",
92 'guardian' => "$Lang::tr{'guardian'}",
93 'ipblocklist' => "$Lang::tr{'ipblocklist'}",
96 'kernel' => "$Lang::tr{'kernel'}",
99 'oinkmaster' => 'Oinkmaster',
100 'openvpn' => 'OpenVPN',
101 'pakfire' => 'Pakfire',
103 'samba' => $Lang::tr
{'samba'},
104 'suricata' => "$Lang::tr{'intrusion detection'}",
105 'squid' => "$Lang::tr{'web proxy'}",
107 'unbound' => 'DNS: Unbound',
108 'urlfilter bl' => 'URLFilter Blacklist',
109 'wireless' => 'Wireless'
113 &Header
::getcgihash
(\
%cgiparams);
114 $logsettings{'LOGVIEW_REVERSE'} = 'off';
115 &General
::readhash
("${General::swroot}/logging/settings", \
%logsettings);
116 ${Header
::viewsize
} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ?
$logsettings{'LOGVIEW_VIEWSIZE'} : 150;
118 my $start = ($logsettings{'LOGVIEW_REVERSE'} eq 'on') ?
0x7FFFF000 : 0; #index of firts line number to display
120 if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr
{'update'})
122 my @temp = split(',',$ENV{'QUERY_STRING'});
124 $cgiparams{'MONTH'} = $temp[1];
125 $cgiparams{'DAY'} = $temp[2];
126 $cgiparams{'SECTION'} = $temp[3];
129 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
130 !($cgiparams{'DAY'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31)$/))
132 $cgiparams{'DAY'} = $now[3];
133 $cgiparams{'MONTH'} = $now[4];
135 elsif($cgiparams{'ACTION'} eq '>>')
138 my @temp_now = localtime(time);
139 $temp_now[4] = $cgiparams{'MONTH'};
140 $temp_now[3] = $cgiparams{'DAY'};
141 if ($cgiparams{'DAY'}) {
142 @temp_then = localtime(POSIX
::mktime
(@temp_now) + 86400);
143 ## Retrieve the same time on the next day +
144 ## 86400 seconds in a day
147 $temp_now[4] = ($temp_now[4]+1) %12;
148 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
151 $cgiparams{'MONTH'} = $temp_then[4];
152 $cgiparams{'DAY'} = $temp_then[3];
154 elsif($cgiparams{'ACTION'} eq '<<')
157 my @temp_now = localtime(time);
158 $temp_now[4] = $cgiparams{'MONTH'};
159 $temp_now[3] = $cgiparams{'DAY'};
160 if ($cgiparams{'DAY'}) {
161 @temp_then = localtime(POSIX
::mktime
(@temp_now) - 86400);
162 ## Retrieve the same time on the next day -
163 ## 86400 seconds in a day
166 $temp_now[4] = ($temp_now[4]-1) %12;
167 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
170 $cgiparams{'MONTH'} = $temp_then[4];
171 $cgiparams{'DAY'} = $temp_then[3];
174 # Find in which file.gz is the log. Can be calculated because WEEKLY ROTATING of access.log
176 my $date = $cgiparams{'DAY'} == 0 ?
'' : $cgiparams{'DAY'} <= 9 ?
"0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
181 # Calculate time. If future date, calculate for past year !!!
182 if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
183 ( $cgiparams{'MONTH'} > $now[4] ) ) {
184 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 );
185 $date = "$longmonths[$cgiparams{'MONTH'}] $date, ". int($year-1);
187 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 );
188 $date = "$longmonths[$cgiparams{'MONTH'}] $date, $year";
191 # calculate end of active week (saturday 23H59)
193 @then = localtime(time());
194 my $sunday = POSIX
::mktime
( 0, 0, 0, $then[3], $then[4], $then[5]);
195 $sunday += (6-$then[6]) * 86400;
197 # Convert delta in second to full weeks
198 $gzindex = int (($sunday-$xday)/604800 );
201 my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
202 my $daystr = $cgiparams{'DAY'} == 0 ?
'..' : $cgiparams{'DAY'} <= 9 ?
" $cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
203 my $section = $sections{$cgiparams{'SECTION'}};
210 my $lastdatetime; # for debug
211 my $search_for_end = 0;
213 while ($gzindex >=0 && $loop) {
214 # calculate file name
216 $filestr = "/var/log/messages";
217 $filestr = "/var/log/mail" if (${section
} =~ 'dma');
219 $filestr = "/var/log/messages.$gzindex";
220 $filestr = "/var/log/mail.$gzindex" if (${section
} =~ 'dma');
221 $filestr = "$filestr.gz" if -f
"$filestr.gz";
223 # now read file if existing
224 if (open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr))) {
225 #&General::log("reading $filestr");
226 READ
:while (<FILE
>) {
228 if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w\-]+ ${section}(.*)/) {
229 # when standard viewing, just keep in memory the correct slice
230 # it starts a '$start' and size is $viewport
231 # If export, then keep all lines...
232 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'}){
233 $log[$lines++] = "$line";
235 if ($lines++ < ($start + $Header::viewsize
)) {
237 if (@log > $Header::viewsize
) {
240 #} else { don't do this optimisation, need to count lines !
241 # $datetime = $maxtime; # we have read viewsize lines, stop main loop
242 # last READ; # exit read file
245 $search_for_end = 1; # we find the start of slice, can look for end now
247 if ($search_for_end == 1) {
248 #finish read files when date is over (test month equality only)
249 $line =~ /^(...) (..) ..:..:..*$/;
250 $loop = 0 if ( ($1 ne $monthstr) || ( ($daystr ne '..') && ($daystr ne $2) ) );
256 $gzindex--; # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped
260 # $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
262 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'})
264 print "Content-type: text/plain\n\n";
265 print "IPFire diagnostics\r\n";
266 print "$Lang::tr{'section'}: $cgiparams{'SECTION'}\n";
267 print "$Lang::tr{'date'}: $date\r\n\r\n";
269 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
273 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
276 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
277 print "$time $3 $4\r\n";
282 &Header
::showhttpheaders
();
284 &Header
::openpage
($Lang::tr
{'system logs'}, 1, '');
286 &Header
::openbigbox
('100%', 'left', '', $errormessage);
289 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
290 print "<font class='base'>$errormessage </font>\n";
294 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}:");
297 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
300 <td width='10%' class='base'>$Lang::tr{'section'}: </td>
302 <select name='SECTION'>
305 foreach $section (sort {$trsections{$a} cmp $trsections{$b}} keys %sections) {
307 if ($section eq $cgiparams{'SECTION'}) {
308 print "selected='selected' "; }
309 print "value='$section'>$trsections{$section}</option>\n";
314 <td width='10%' class='base' align='right'>$Lang::tr{'month'}: </td>
316 <select name='MONTH'>
319 for (my $month = 0; $month < 12; $month++)
322 if ($month == $cgiparams{'MONTH'}) {
323 print "selected='selected' "; }
324 print "value='$month'>$longmonths[$month]</option>\n";
329 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
334 print "<option value='0'>$Lang::tr{'all'}</option>\n";
335 for (my $day = 1; $day <= 31; $day++)
338 if ($day == $cgiparams{'DAY'}) {
339 print "selected='selected' "; }
340 print "value='$day'>$day</option>\n";
345 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
346 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
347 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
348 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
357 &Header
::openbox
('100%', 'left', $Lang::tr
{'log'});
358 print "<p><b>$Lang::tr{'total hits for log section'} $cgiparams{'SECTION'} $date: $lines</b></p>";
360 $start = $lines - ${Header
::viewsize
} if ($start >= $lines - ${Header
::viewsize
});
361 $start = 0 if ($start < 0);
367 $prev = $start - ${Header
::viewsize
};
368 $prev = 0 if ( $prev < 0);
372 if ($start == $lines - ${Header
::viewsize
}) {
375 $next = $start + ${Header
::viewsize
};
376 $next = $lines - ${Header
::viewsize
} if ($next >= $lines - ${Header
::viewsize
});
379 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
380 if ($lines != 0) { &oldernewer
(); }
383 <table width='100%' class='tbl'>
385 <th width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></th>
386 <th width='15%' align='center' class='boldbase'><b>$Lang::tr{'section'}</b></th>
387 <th width='75%'> </th>
396 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
399 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
402 # correct the cut position, just when section=RED
403 if (($cgiparams{'SECTION'} eq 'red' ) && ($sec =~ /(kernel:)(.*)/)) {
405 $data = $2.': '.$data;
407 my $d = substr ($data,0,80);
408 while (length($data)>80){ #very basic breaking of lines...
409 $data = substr ($data,80); #permit correct display in table cell
410 $d .= ' ' . substr ($data,0,80);
416 $col="bgcolor='$color{'color20'}'"; }
419 $col="bgcolor='$color{'color22'}'"; }
420 print "<td $col>$time<td $col>$sec<td $col>" .&Header
::cleanhtml
("$d", 'y') . "</td></tr>\n";
430 &Header
::closebigbox
();
432 &Header
::closepage
();
442 print "<td align='center' width='50%'>";
444 print "<a href='/cgi-bin/logs.cgi/log.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'older'}</a>"; }
446 print "$Lang::tr{'older'}"; }
449 print "<td align='center' width='50%'>";
451 print "<a href='/cgi-bin/logs.cgi/log.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'newer'}</a>"; }
453 print "$Lang::tr{'newer'}"; }