]>
git.ipfire.org Git - 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 'ipfire' => '(ipfire: )',
53 'red' => '(red:|pppd\[.*\]: |chat\[.*\]|pppoe\[.*\]|pptp\[.*\]|pppoa\[.*\]|pppoa3\[.*\]|pppoeci\[.*\]|ipppd|ipppd\[.*\]|kernel: ippp\d|kernel: isdn.*|ibod\[.*\]|dhcpcd\[.*\]|modem_run\[.*\])',
54 'dns' => '(dnsmasq\[.*\]: )',
55 'dhcp' => '(dhcpd: )',
56 'clamav' => '(clamd\[.*\]: |freshclam\[.*\]: )',
57 'collectd' => '(collectd\[.*\]: )',
58 'cron' => '(fcron\[.*\]: )',
59 'ntp' => '(ntpd(?:ate)?\[.*\]: )',
60 'ssh' => '(sshd(?:\(.*\))?\[.*\]: )',
61 'auth' => '(\w+\(pam_unix\)\[.*\]: )',
62 'kernel' => '(kernel: (?!DROP_))',
63 'ipsec' => '(ipsec_[\w_]+: |pluto\[.*\]: |charon: |vpnwatch: )',
64 'openvpn' => '(openvpnserver\[.*\]: |.*n2n\[.*\]: )',
65 'pakfire' => '(pakfire:) ',
66 'wireless' => '(hostapd:|kernel: ath.*:|kernel: wifi[0-9]:) '
69 # Translations for the %sections array.
74 'dhcp' => "$Lang::tr{'dhcp server'}",
76 'collectd' => 'Collectd',
80 'auth' => "$Lang::tr{'loginlogout'}",
81 'kernel' => "$Lang::tr{'kernel'}",
83 'openvpn' => 'OpenVPN',
84 'pakfire' => 'Pakfire',
85 'wireless' => 'Wireless'
89 &Header
::getcgihash
(\
%cgiparams);
90 $logsettings{'LOGVIEW_REVERSE'} = 'off';
91 &General
::readhash
("${General::swroot}/logging/settings", \
%logsettings);
92 ${Header
::viewsize
} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ?
$logsettings{'LOGVIEW_VIEWSIZE'} : 150;
94 my $start = ($logsettings{'LOGVIEW_REVERSE'} eq 'on') ?
0x7FFFF000 : 0; #index of firts line number to display
96 if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr
{'update'})
98 my @temp = split(',',$ENV{'QUERY_STRING'});
100 $cgiparams{'MONTH'} = $temp[1];
101 $cgiparams{'DAY'} = $temp[2];
102 $cgiparams{'SECTION'} = $temp[3];
105 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
106 !($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)$/))
108 $cgiparams{'DAY'} = $now[3];
109 $cgiparams{'MONTH'} = $now[4];
111 elsif($cgiparams{'ACTION'} eq '>>')
114 my @temp_now = localtime(time);
115 $temp_now[4] = $cgiparams{'MONTH'};
116 $temp_now[3] = $cgiparams{'DAY'};
117 if ($cgiparams{'DAY'}) {
118 @temp_then = localtime(POSIX
::mktime
(@temp_now) + 86400);
119 ## Retrieve the same time on the next day +
120 ## 86400 seconds in a day
123 $temp_now[4] = ($temp_now[4]+1) %12;
124 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
127 $cgiparams{'MONTH'} = $temp_then[4];
128 $cgiparams{'DAY'} = $temp_then[3];
130 elsif($cgiparams{'ACTION'} eq '<<')
133 my @temp_now = localtime(time);
134 $temp_now[4] = $cgiparams{'MONTH'};
135 $temp_now[3] = $cgiparams{'DAY'};
136 if ($cgiparams{'DAY'}) {
137 @temp_then = localtime(POSIX
::mktime
(@temp_now) - 86400);
138 ## Retrieve the same time on the next day -
139 ## 86400 seconds in a day
142 $temp_now[4] = ($temp_now[4]-1) %12;
143 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
146 $cgiparams{'MONTH'} = $temp_then[4];
147 $cgiparams{'DAY'} = $temp_then[3];
150 # Find in which file.gz is the log. Can be calculated because WEEKLY ROTATING of access.log
152 my $date = $cgiparams{'DAY'} == 0 ?
'' : $cgiparams{'DAY'} <= 9 ?
"0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
157 # Calculate time. If future date, calculate for past year !!!
158 if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
159 ( $cgiparams{'MONTH'} > $now[4] ) ) {
160 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 );
161 $date = "$longmonths[$cgiparams{'MONTH'}] $date, ". int($year-1);
163 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 );
164 $date = "$longmonths[$cgiparams{'MONTH'}] $date, $year";
167 # calculate end of active week (saturday 23H59)
169 @then = localtime(time());
170 my $sunday = POSIX
::mktime
( 0, 0, 0, $then[3], $then[4], $then[5]);
171 $sunday += (6-$then[6]) * 86400;
173 # Convert delta in second to full weeks
174 $gzindex = int (($sunday-$xday)/604800 );
177 my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
178 my $daystr = $cgiparams{'DAY'} == 0 ?
'..' : $cgiparams{'DAY'} <= 9 ?
" $cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
179 my $section = $sections{$cgiparams{'SECTION'}};
186 my $lastdatetime; # for debug
187 my $search_for_end = 0;
189 while ($gzindex >=0 && $loop) {
190 # calculate file name
192 $filestr = "/var/log/messages";
194 $filestr = "/var/log/messages.$gzindex";
195 $filestr = "$filestr.gz" if -f
"$filestr.gz";
197 # now read file if existing
198 if (open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr))) {
199 #&General::log("reading $filestr");
200 READ
:while (<FILE
>) {
202 if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w\-]+ ${section}(.*)/) {
203 # when standart viewing, just keep in memory the correct slice
204 # it starts a '$start' and size is $viewport
205 # If export, then keep all lines...
206 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'}){
207 $log[$lines++] = "$line";
209 if ($lines++ < ($start + $Header::viewsize
)) {
211 if (@log > $Header::viewsize
) {
214 #} else { dont do this optimisation, need to count lines !
215 # $datetime = $maxtime; # we have read viewsize lines, stop main loop
216 # last READ; # exit read file
219 $search_for_end = 1; # we find the start of slice, can look for end now
221 if ($search_for_end == 1) {
222 #finish read files when date is over (test month equality only)
223 $line =~ /^(...) (..) ..:..:..*$/;
224 $loop = 0 if ( ($1 ne $monthstr) || ( ($daystr ne '..') && ($daystr ne $2) ) );
230 $gzindex--; # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped
234 # $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
236 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'})
238 print "Content-type: text/plain\n\n";
239 print "IPFire diagnostics\r\n";
240 print "$Lang::tr{'section'}: $cgiparams{'SECTION'}\n";
241 print "$Lang::tr{'date'}: $date\r\n\r\n";
243 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
247 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
250 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
251 print "$time $3 $4\r\n";
256 &Header
::showhttpheaders
();
258 &Header
::openpage
($Lang::tr
{'system logs'}, 1, '');
260 &Header
::openbigbox
('100%', 'left', '', $errormessage);
263 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
264 print "<font class='base'>$errormessage </font>\n";
268 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}:");
271 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
274 <td width='10%' class='base'>$Lang::tr{'section'}: </td>
276 <select name='SECTION'>
279 foreach $section (keys %sections) {
281 if ($section eq $cgiparams{'SECTION'}) {
282 print "selected='selected' "; }
283 print "value='$section'>$trsections{$section}</option>\n";
288 <td width='10%' class='base' align='right'>$Lang::tr{'month'}: </td>
290 <select name='MONTH'>
293 for (my $month = 0; $month < 12; $month++)
296 if ($month == $cgiparams{'MONTH'}) {
297 print "selected='selected' "; }
298 print "value='$month'>$longmonths[$month]</option>\n";
303 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
308 print "<option value='0'>$Lang::tr{'all'}</option>\n";
309 for (my $day = 1; $day <= 31; $day++)
312 if ($day == $cgiparams{'DAY'}) {
313 print "selected='selected' "; }
314 print "value='$day'>$day</option>\n";
319 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
320 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
321 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
322 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
331 &Header
::openbox
('100%', 'left', $Lang::tr
{'log'});
332 print "<p><b>$Lang::tr{'total hits for log section'} $cgiparams{'SECTION'} $date: $lines</b></p>";
334 $start = $lines - ${Header
::viewsize
} if ($start >= $lines - ${Header
::viewsize
});
335 $start = 0 if ($start < 0);
341 $prev = $start - ${Header
::viewsize
};
342 $prev = 0 if ( $prev < 0);
346 if ($start == $lines - ${Header
::viewsize
}) {
349 $next = $start + ${Header
::viewsize
};
350 $next = $lines - ${Header
::viewsize
} if ($next >= $lines - ${Header
::viewsize
});
353 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
354 if ($lines != 0) { &oldernewer
(); }
359 <td width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></td>
360 <td width='10%' align='center' class='boldbase'><b>$Lang::tr{'section'}</b></td>
361 <td width='80%'> </td>
370 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
373 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
376 # correct the cut position, just when section=RED
377 if (($cgiparams{'SECTION'} eq 'red' ) && ($sec =~ /(kernel:)(.*)/)) {
379 $data = $2.': '.$data;
381 my $d = substr ($data,0,80);
382 while (length($data)>80){ #very basic breaking of lines...
383 $data = substr ($data,80); #permit correct display in table cell
384 $d .= ' ' . substr ($data,0,80);
389 print "<tr bgcolor='$color{'color20'}'>"; }
391 print "<tr bgcolor='$color{'color22'}'>"; }
392 print "<td>$time<td>$sec<td>" .&Header
::cleanhtml
("$d", 'y') . "</td></tr>\n";
402 &Header
::closebigbox
();
404 &Header
::closepage
();
414 print "<td align='center' width='50%'>";
416 print "<a href='/cgi-bin/logs.cgi/log.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'older'}</a>"; }
418 print "$Lang::tr{'older'}"; }
421 print "<td align='center' width='50%'>";
423 print "<a href='/cgi-bin/logs.cgi/log.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'newer'}</a>"; }
425 print "$Lang::tr{'newer'}"; }