]>
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/".$mainsettings{'THEME'}."/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\[.*\]: )',
61 'guardian' => '(guardian\[.*\]: )',
62 'ipfire' => '(ipfire: )',
63 'ipsec' => '(ipsec_[\w_]+: |pluto\[.*\]: |charon: |vpnwatch: )',
64 'kernel' => '(kernel: (?!DROP_))',
65 'ntp' => '(ntpd(?:ate)?\[.*\]: )',
66 'oinkmaster' => '(oinkmaster\[.*\]: )',
67 'openvpn' => '(openvpnserver\[.*\]: |.*n2n\[.*\]: )',
68 'pakfire' => '(pakfire:)',
69 'red' => '(red:|pppd\[.*\]: |chat\[.*\]|pppoe\[.*\]|pptp\[.*\]|pppoa\[.*\]|pppoa3\[.*\]|pppoeci\[.*\]|ipppd|ipppd\[.*\]|kernel: ippp\d|kernel: isdn.*|ibod\[.*\]|dhcpcd\[.*\]|modem_run\[.*\])',
70 'suricata' => '(suricata\[.*\]: )',
71 'squid' => '(squid\[.*\]: |squid: )',
72 'ssh' => '(sshd(?:\(.*\))?\[.*\]: )',
73 'unbound' => '(unbound: \[.*:.*\])(.*:.*$)',
74 'urlfilter bl' => '(installpackage\[urlfilter\]: )',
75 'wireless' => '(hostapd:|kernel: ath.*:|kernel: wifi[0-9]:)'
78 # Translations for the %sections array.
80 'auth' => "$Lang::tr{'loginlogout'}",
81 'wio' => 'Who Is Online?',
82 'captive' => $Lang::tr
{'Captive'},
84 'collectd' => 'Collectd',
86 'ddns' => "$Lang::tr{'dynamic dns'}",
87 'dhcp' => "$Lang::tr{'dhcp server'}",
89 'guardian' => "$Lang::tr{'guardian'}",
92 'kernel' => "$Lang::tr{'kernel'}",
94 'oinkmaster' => 'Oinkmaster',
95 'openvpn' => 'OpenVPN',
96 'pakfire' => 'Pakfire',
98 'suricata' => "$Lang::tr{'intrusion detection'}",
99 'squid' => "$Lang::tr{'web proxy'}",
101 'unbound' => 'DNS: Unbound',
102 'urlfilter bl' => 'URLFilter Blacklist',
103 'wireless' => 'Wireless'
107 &Header
::getcgihash
(\
%cgiparams);
108 $logsettings{'LOGVIEW_REVERSE'} = 'off';
109 &General
::readhash
("${General::swroot}/logging/settings", \
%logsettings);
110 ${Header
::viewsize
} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ?
$logsettings{'LOGVIEW_VIEWSIZE'} : 150;
112 my $start = ($logsettings{'LOGVIEW_REVERSE'} eq 'on') ?
0x7FFFF000 : 0; #index of firts line number to display
114 if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr
{'update'})
116 my @temp = split(',',$ENV{'QUERY_STRING'});
118 $cgiparams{'MONTH'} = $temp[1];
119 $cgiparams{'DAY'} = $temp[2];
120 $cgiparams{'SECTION'} = $temp[3];
123 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
124 !($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)$/))
126 $cgiparams{'DAY'} = $now[3];
127 $cgiparams{'MONTH'} = $now[4];
129 elsif($cgiparams{'ACTION'} eq '>>')
132 my @temp_now = localtime(time);
133 $temp_now[4] = $cgiparams{'MONTH'};
134 $temp_now[3] = $cgiparams{'DAY'};
135 if ($cgiparams{'DAY'}) {
136 @temp_then = localtime(POSIX
::mktime
(@temp_now) + 86400);
137 ## Retrieve the same time on the next day +
138 ## 86400 seconds in a day
141 $temp_now[4] = ($temp_now[4]+1) %12;
142 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
145 $cgiparams{'MONTH'} = $temp_then[4];
146 $cgiparams{'DAY'} = $temp_then[3];
148 elsif($cgiparams{'ACTION'} eq '<<')
151 my @temp_now = localtime(time);
152 $temp_now[4] = $cgiparams{'MONTH'};
153 $temp_now[3] = $cgiparams{'DAY'};
154 if ($cgiparams{'DAY'}) {
155 @temp_then = localtime(POSIX
::mktime
(@temp_now) - 86400);
156 ## Retrieve the same time on the next day -
157 ## 86400 seconds in a day
160 $temp_now[4] = ($temp_now[4]-1) %12;
161 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
164 $cgiparams{'MONTH'} = $temp_then[4];
165 $cgiparams{'DAY'} = $temp_then[3];
168 # Find in which file.gz is the log. Can be calculated because WEEKLY ROTATING of access.log
170 my $date = $cgiparams{'DAY'} == 0 ?
'' : $cgiparams{'DAY'} <= 9 ?
"0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
175 # Calculate time. If future date, calculate for past year !!!
176 if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
177 ( $cgiparams{'MONTH'} > $now[4] ) ) {
178 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 );
179 $date = "$longmonths[$cgiparams{'MONTH'}] $date, ". int($year-1);
181 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 );
182 $date = "$longmonths[$cgiparams{'MONTH'}] $date, $year";
185 # calculate end of active week (saturday 23H59)
187 @then = localtime(time());
188 my $sunday = POSIX
::mktime
( 0, 0, 0, $then[3], $then[4], $then[5]);
189 $sunday += (6-$then[6]) * 86400;
191 # Convert delta in second to full weeks
192 $gzindex = int (($sunday-$xday)/604800 );
195 my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
196 my $daystr = $cgiparams{'DAY'} == 0 ?
'..' : $cgiparams{'DAY'} <= 9 ?
" $cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
197 my $section = $sections{$cgiparams{'SECTION'}};
204 my $lastdatetime; # for debug
205 my $search_for_end = 0;
207 while ($gzindex >=0 && $loop) {
208 # calculate file name
210 $filestr = "/var/log/messages";
211 $filestr = "/var/log/mail" if (${section
} =~ 'dma');
213 $filestr = "/var/log/messages.$gzindex";
214 $filestr = "/var/log/mail.$gzindex" if (${section
} =~ 'dma');
215 $filestr = "$filestr.gz" if -f
"$filestr.gz";
217 # now read file if existing
218 if (open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr))) {
219 #&General::log("reading $filestr");
220 READ
:while (<FILE
>) {
222 if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w\-]+ ${section}(.*)/) {
223 # when standard viewing, just keep in memory the correct slice
224 # it starts a '$start' and size is $viewport
225 # If export, then keep all lines...
226 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'}){
227 $log[$lines++] = "$line";
229 if ($lines++ < ($start + $Header::viewsize
)) {
231 if (@log > $Header::viewsize
) {
234 #} else { don't do this optimisation, need to count lines !
235 # $datetime = $maxtime; # we have read viewsize lines, stop main loop
236 # last READ; # exit read file
239 $search_for_end = 1; # we find the start of slice, can look for end now
241 if ($search_for_end == 1) {
242 #finish read files when date is over (test month equality only)
243 $line =~ /^(...) (..) ..:..:..*$/;
244 $loop = 0 if ( ($1 ne $monthstr) || ( ($daystr ne '..') && ($daystr ne $2) ) );
250 $gzindex--; # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped
254 # $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
256 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'})
258 print "Content-type: text/plain\n\n";
259 print "IPFire diagnostics\r\n";
260 print "$Lang::tr{'section'}: $cgiparams{'SECTION'}\n";
261 print "$Lang::tr{'date'}: $date\r\n\r\n";
263 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
267 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
270 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
271 print "$time $3 $4\r\n";
276 &Header
::showhttpheaders
();
278 &Header
::openpage
($Lang::tr
{'system logs'}, 1, '');
280 &Header
::openbigbox
('100%', 'left', '', $errormessage);
283 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
284 print "<font class='base'>$errormessage </font>\n";
288 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}:");
291 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
294 <td width='10%' class='base'>$Lang::tr{'section'}: </td>
296 <select name='SECTION'>
299 foreach $section (sort {$trsections{$a} cmp $trsections{$b}} keys %sections) {
301 if ($section eq $cgiparams{'SECTION'}) {
302 print "selected='selected' "; }
303 print "value='$section'>$trsections{$section}</option>\n";
308 <td width='10%' class='base' align='right'>$Lang::tr{'month'}: </td>
310 <select name='MONTH'>
313 for (my $month = 0; $month < 12; $month++)
316 if ($month == $cgiparams{'MONTH'}) {
317 print "selected='selected' "; }
318 print "value='$month'>$longmonths[$month]</option>\n";
323 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
328 print "<option value='0'>$Lang::tr{'all'}</option>\n";
329 for (my $day = 1; $day <= 31; $day++)
332 if ($day == $cgiparams{'DAY'}) {
333 print "selected='selected' "; }
334 print "value='$day'>$day</option>\n";
339 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
340 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
341 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
342 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
351 &Header
::openbox
('100%', 'left', $Lang::tr
{'log'});
352 print "<p><b>$Lang::tr{'total hits for log section'} $cgiparams{'SECTION'} $date: $lines</b></p>";
354 $start = $lines - ${Header
::viewsize
} if ($start >= $lines - ${Header
::viewsize
});
355 $start = 0 if ($start < 0);
361 $prev = $start - ${Header
::viewsize
};
362 $prev = 0 if ( $prev < 0);
366 if ($start == $lines - ${Header
::viewsize
}) {
369 $next = $start + ${Header
::viewsize
};
370 $next = $lines - ${Header
::viewsize
} if ($next >= $lines - ${Header
::viewsize
});
373 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
374 if ($lines != 0) { &oldernewer
(); }
377 <table width='100%' class='tbl'>
379 <th width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></th>
380 <th width='15%' align='center' class='boldbase'><b>$Lang::tr{'section'}</b></th>
381 <th width='75%'> </th>
390 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
393 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
396 # correct the cut position, just when section=RED
397 if (($cgiparams{'SECTION'} eq 'red' ) && ($sec =~ /(kernel:)(.*)/)) {
399 $data = $2.': '.$data;
401 my $d = substr ($data,0,80);
402 while (length($data)>80){ #very basic breaking of lines...
403 $data = substr ($data,80); #permit correct display in table cell
404 $d .= ' ' . substr ($data,0,80);
410 $col="bgcolor='$color{'color20'}'"; }
413 $col="bgcolor='$color{'color22'}'"; }
414 print "<td $col>$time<td $col>$sec<td $col>" .&Header
::cleanhtml
("$d", 'y') . "</td></tr>\n";
424 &Header
::closebigbox
();
426 &Header
::closepage
();
436 print "<td align='center' width='50%'>";
438 print "<a href='/cgi-bin/logs.cgi/log.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'older'}</a>"; }
440 print "$Lang::tr{'older'}"; }
443 print "<td align='center' width='50%'>";
445 print "<a href='/cgi-bin/logs.cgi/log.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'newer'}</a>"; }
447 print "$Lang::tr{'newer'}"; }