]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/logs.cgi/log.dat
01c382a0dfbe8bee524b1ffa009a58b7c7ff2af9
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 'apcupsd' => '(apcupsd\[.*?\]: )',
53 'auth' => '(\w+\(pam_unix\)\[.*\]: )',
54 'wio' => '(wio:|wio\[.*\])',
55 'captive' => '(Captive:)',
56 'clamav' => '(clamd\[.*\]: |freshclam\[.*\]: )',
57 'collectd' => '(collectd\[.*\]: )',
58 'cron' => '(fcron\[.*\]: )',
59 'ddns' => '(ddns\[\d+\]:)',
60 'dhcp' => '(dhcpd: )',
61 'dma' => '(dma: |dma\[.*\]: |postfix/\w*\[\d*\]: )',
62 'guardian' => '(guardian\[.*\]: )',
63 'haproxy' => '(haproxy\[.*?\]: )',
64 'ipblocklist' => '(ipblocklist: )',
65 'ipfire' => '(ipfire: )',
66 'ipsec' => '(ipsec_[\w_]+: |pluto\[.*\]: |charon: |vpnwatch: )',
67 'kernel' => '(kernel: (?!DROP_))',
68 'monit' => '(monit\[.*?\]: )',
69 'ntp' => '(ntpd(?:ate)?\[.*\]: )',
70 'nut' => '(upsmon\[.*?\]: )',
71 'oinkmaster' => '(oinkmaster\[.*\]: )',
72 'openvpn' => '(openvpnserver\[.*\]: |.*n2n\[.*\]: )',
73 'pakfire' => '(pakfire:)',
74 'red' => '(red:|pppd\[.*\]: |chat\[.*\]|pppoe\[.*\]|pptp\[.*\]|pppoa\[.*\]|pppoa3\[.*\]|pppoeci\[.*\]|ipppd|ipppd\[.*\]|kernel: ippp\d|kernel: isdn.*|ibod\[.*\]|dhcpcd\[.*\]|modem_run\[.*\])',
75 'samba' => '(nmbd|smbd|winbind)\[\d+\]:',
76 'suricata' => '(suricata: )',
77 'squid' => '(squid\[.*\]: |squid: )',
78 'ssh' => '(sshd(?:\(.*\))?\[.*\]: )',
79 'unbound' => '(unbound: \[.*?\])(.*:.*$)',
80 'urlfilter bl' => '(installpackage\[urlfilter\]: )',
81 'wireless' => '(hostapd:|kernel: ath.*:|kernel: wifi[0-9]:)',
82 'zabbix_agentd' => '(zabbix_agentd\[.*?\]: )'
85 # Translations for the %sections array.
87 'apcupsd' => 'APCUPS',
88 'auth' => "$Lang::tr{'loginlogout'}",
89 'wio' => 'Who Is Online?',
90 'captive' => $Lang::tr
{'Captive'},
92 'collectd' => 'Collectd',
94 'ddns' => "$Lang::tr{'dynamic dns'}",
95 'dhcp' => "$Lang::tr{'dhcp server'}",
97 'guardian' => "$Lang::tr{'guardian'}",
98 'haproxy' => 'HAProxy',
99 'ipblocklist' => "$Lang::tr{'ipblocklist'}",
100 'ipfire' => 'IPFire',
102 'kernel' => "$Lang::tr{'kernel'}",
106 'oinkmaster' => 'Oinkmaster',
107 'openvpn' => 'OpenVPN',
108 'pakfire' => 'Pakfire',
110 'samba' => $Lang::tr
{'samba'},
111 'suricata' => "$Lang::tr{'intrusion detection'}",
112 'squid' => "$Lang::tr{'web proxy'}",
114 'unbound' => 'DNS: Unbound',
115 'urlfilter bl' => 'URLFilter Blacklist',
116 'wireless' => 'Wireless',
117 'zabbix_agentd' => 'Zabbix Agent'
121 &Header
::getcgihash
(\
%cgiparams);
122 $logsettings{'LOGVIEW_REVERSE'} = 'off';
123 &General
::readhash
("${General::swroot}/logging/settings", \
%logsettings);
124 ${Header
::viewsize
} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ?
$logsettings{'LOGVIEW_VIEWSIZE'} : 150;
126 my $start = ($logsettings{'LOGVIEW_REVERSE'} eq 'on') ?
0x7FFFF000 : 0; #index of firts line number to display
128 if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr
{'update'})
130 my @temp = split(',',$ENV{'QUERY_STRING'});
132 $cgiparams{'MONTH'} = $temp[1];
133 $cgiparams{'DAY'} = $temp[2];
134 $cgiparams{'SECTION'} = $temp[3];
137 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
138 !($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)$/))
140 $cgiparams{'DAY'} = $now[3];
141 $cgiparams{'MONTH'} = $now[4];
143 elsif($cgiparams{'ACTION'} eq '>>')
146 my @temp_now = localtime(time);
147 $temp_now[4] = $cgiparams{'MONTH'};
148 $temp_now[3] = $cgiparams{'DAY'};
149 if ($cgiparams{'DAY'}) {
150 @temp_then = localtime(POSIX
::mktime
(@temp_now) + 86400);
151 ## Retrieve the same time on the next day +
152 ## 86400 seconds in a day
155 $temp_now[4] = ($temp_now[4]+1) %12;
156 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
159 $cgiparams{'MONTH'} = $temp_then[4];
160 $cgiparams{'DAY'} = $temp_then[3];
162 elsif($cgiparams{'ACTION'} eq '<<')
165 my @temp_now = localtime(time);
166 $temp_now[4] = $cgiparams{'MONTH'};
167 $temp_now[3] = $cgiparams{'DAY'};
168 if ($cgiparams{'DAY'}) {
169 @temp_then = localtime(POSIX
::mktime
(@temp_now) - 86400);
170 ## Retrieve the same time on the next day -
171 ## 86400 seconds in a day
174 $temp_now[4] = ($temp_now[4]-1) %12;
175 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
178 $cgiparams{'MONTH'} = $temp_then[4];
179 $cgiparams{'DAY'} = $temp_then[3];
182 # Find in which file.gz is the log. Can be calculated because WEEKLY ROTATING of access.log
184 my $date = $cgiparams{'DAY'} == 0 ?
'' : $cgiparams{'DAY'} <= 9 ?
"0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
189 # Calculate time. If future date, calculate for past year !!!
190 if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
191 ( $cgiparams{'MONTH'} > $now[4] ) ) {
192 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 );
193 $date = "$longmonths[$cgiparams{'MONTH'}] $date, ". int($year-1);
195 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 );
196 $date = "$longmonths[$cgiparams{'MONTH'}] $date, $year";
199 # calculate end of active week (saturday 23H59)
201 @then = localtime(time());
202 my $sunday = POSIX
::mktime
( 0, 0, 0, $then[3], $then[4], $then[5]);
203 $sunday += (6-$then[6]) * 86400;
205 # Convert delta in second to full weeks
206 $gzindex = int (($sunday-$xday)/604800 );
209 my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
210 my $daystr = $cgiparams{'DAY'} == 0 ?
'..' : $cgiparams{'DAY'} <= 9 ?
" $cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
211 my $section = $sections{$cgiparams{'SECTION'}};
218 my $lastdatetime; # for debug
219 my $search_for_end = 0;
221 while ($gzindex >=0 && $loop) {
222 # calculate file name
224 $filestr = "/var/log/messages";
225 $filestr = "/var/log/mail" if (${section
} =~ 'dma');
227 $filestr = "/var/log/messages.$gzindex";
228 $filestr = "/var/log/mail.$gzindex" if (${section
} =~ 'dma');
229 $filestr = "$filestr.gz" if -f
"$filestr.gz";
231 # now read file if existing
232 if (open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr))) {
233 #&General::log("reading $filestr");
234 READ
:while (<FILE
>) {
236 if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w\-\.]+ ${section}(.*)/) {
237 # when standard viewing, just keep in memory the correct slice
238 # it starts a '$start' and size is $viewport
239 # If export, then keep all lines...
240 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'}){
241 $log[$lines++] = "$line";
243 if ($lines++ < ($start + $Header::viewsize
)) {
245 if (@log > $Header::viewsize
) {
248 #} else { don't do this optimisation, need to count lines !
249 # $datetime = $maxtime; # we have read viewsize lines, stop main loop
250 # last READ; # exit read file
253 $search_for_end = 1; # we find the start of slice, can look for end now
255 if ($search_for_end == 1) {
256 #finish read files when date is over (test month equality only)
257 $line =~ /^(...) (..) ..:..:..*$/;
258 $loop = 0 if ( ($1 ne $monthstr) || ( ($daystr ne '..') && ($daystr ne $2) ) );
264 $gzindex--; # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped
268 # $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
270 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'})
272 print "Content-type: text/plain\n\n";
273 print "IPFire diagnostics\r\n";
274 print "$Lang::tr{'section'}: $cgiparams{'SECTION'}\n";
275 print "$Lang::tr{'date'}: $date\r\n\r\n";
277 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
281 /^... (..) (..:..:..) [\w\-\.]+ ${section}(.*)$/;
284 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
285 print "$time $3 $4\r\n";
290 &Header
::showhttpheaders
();
292 &Header
::openpage
($Lang::tr
{'system logs'}, 1, '');
294 &Header
::openbigbox
('100%', 'left', '', $errormessage);
297 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
298 print "<font class='base'>$errormessage </font>\n";
302 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}:");
305 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
308 <td width='10%' class='base'>$Lang::tr{'section'}: </td>
310 <select name='SECTION'>
313 foreach $section (sort {$trsections{$a} cmp $trsections{$b}} keys %sections) {
315 if ($section eq $cgiparams{'SECTION'}) {
316 print "selected='selected' "; }
317 print "value='$section'>$trsections{$section}</option>\n";
322 <td width='10%' class='base' align='right'>$Lang::tr{'month'}: </td>
324 <select name='MONTH'>
327 for (my $month = 0; $month < 12; $month++)
330 if ($month == $cgiparams{'MONTH'}) {
331 print "selected='selected' "; }
332 print "value='$month'>$longmonths[$month]</option>\n";
337 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
342 print "<option value='0'>$Lang::tr{'all'}</option>\n";
343 for (my $day = 1; $day <= 31; $day++)
346 if ($day == $cgiparams{'DAY'}) {
347 print "selected='selected' "; }
348 print "value='$day'>$day</option>\n";
353 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
354 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
355 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
356 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
365 &Header
::openbox
('100%', 'left', $Lang::tr
{'log'});
366 print "<p><b>$Lang::tr{'total hits for log section'} $cgiparams{'SECTION'} $date: $lines</b></p>";
368 $start = $lines - ${Header
::viewsize
} if ($start >= $lines - ${Header
::viewsize
});
369 $start = 0 if ($start < 0);
375 $prev = $start - ${Header
::viewsize
};
376 $prev = 0 if ( $prev < 0);
380 if ($start == $lines - ${Header
::viewsize
}) {
383 $next = $start + ${Header
::viewsize
};
384 $next = $lines - ${Header
::viewsize
} if ($next >= $lines - ${Header
::viewsize
});
387 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
388 if ($lines != 0) { &oldernewer
(); }
391 <table width='100%' class='tbl'>
393 <th width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></th>
394 <th width='15%' align='center' class='boldbase'><b>$Lang::tr{'section'}</b></th>
395 <th width='75%'> </th>
404 /^... (..) (..:..:..) [\w\-\.]+ ${section}(.*)$/;
407 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
410 # correct the cut position, just when section=RED
411 if (($cgiparams{'SECTION'} eq 'red' ) && ($sec =~ /(kernel:)(.*)/)) {
413 $data = $2.': '.$data;
415 my $d = substr ($data,0,80);
416 while (length($data)>80){ #very basic breaking of lines...
417 $data = substr ($data,80); #permit correct display in table cell
418 $d .= ' ' . substr ($data,0,80);
424 $col="bgcolor='$color{'color20'}'"; }
427 $col="bgcolor='$color{'color22'}'"; }
428 print "<td $col>$time<td $col>$sec<td $col>" .&Header
::cleanhtml
("$d", 'y') . "</td></tr>\n";
438 &Header
::closebigbox
();
440 &Header
::closepage
();
450 print "<td align='center' width='50%'>";
452 print "<a href='/cgi-bin/logs.cgi/log.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'older'}</a>"; }
454 print "$Lang::tr{'older'}"; }
457 print "<td align='center' width='50%'>";
459 print "<a href='/cgi-bin/logs.cgi/log.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'newer'}</a>"; }
461 print "$Lang::tr{'newer'}"; }