]>
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);
29 #workaround to suppress a warning when a variable is used only once
30 my @dummy = ( ${Header
::table2colour
} );
35 my $errormessage = '';
37 my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
38 'Sep', 'Oct', 'Nov', 'Dec' );
39 my @longmonths = ( $Lang::tr
{'january'}, $Lang::tr
{'february'}, $Lang::tr
{'march'},
40 $Lang::tr
{'april'}, $Lang::tr
{'may'}, $Lang::tr
{'june'}, $Lang::tr
{'july'}, $Lang::tr
{'august'},
41 $Lang::tr
{'september'}, $Lang::tr
{'october'}, $Lang::tr
{'november'},
42 $Lang::tr
{'december'} );
44 my @now = localtime();
48 my $year = $now[5]+1900;
50 $cgiparams{'DAY'} = $now[3];
51 $cgiparams{'MONTH'} = $now[4];
52 $cgiparams{'ACTION'} = '';
53 $cgiparams{'SECTION'} = 'kernel';
56 'ipfire' => '(ipfire: )',
57 'red' => '(red:|pppd\[.*\]: |chat\[.*\]|pppoe\[.*\]|pptp\[.*\]|pppoa\[.*\]|pppoa3\[.*\]|pppoeci\[.*\]|ipppd|ipppd\[.*\]|kernel: ippp\d|kernel: isdn.*|ibod\[.*\]|dhcpcd\[.*\]|modem_run\[.*\])',
58 'dns' => '(dnsmasq\[.*\]: )',
59 'dhcp' => '(dhcpd: )',
60 'cron' => '(fcron\[.*\]: )',
61 'ntp' => '(ntpd(?:ate)?\[.*\]: )',
62 'ssh' => '(sshd(?:\(.*\))?\[.*\]: )',
63 'auth' => '(\w+\(pam_unix\)\[.*\]: )',
64 'kernel' => '(kernel: (?!DROP-))',
65 'ipsec' => '(ipsec_[\w_]+: |pluto\[.*\]: |vpnwatch: )',
66 'openvpn' => '(openvpnserver)\[.*\]: '
69 # Translations for the %sections array.
74 'dhcp' => "$Lang::tr{'dhcp server'}",
78 'auth' => "$Lang::tr{'loginlogout'}",
79 'kernel' => "$Lang::tr{'kernel'}",
81 'openvpn' => 'OpenVPN',
85 &Header
::getcgihash
(\
%cgiparams);
86 $logsettings{'LOGVIEW_REVERSE'} = 'off';
87 &General
::readhash
("${General::swroot}/logging/settings", \
%logsettings);
88 ${Header
::viewsize
} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ?
$logsettings{'LOGVIEW_VIEWSIZE'} : 150;
90 my $start = ($logsettings{'LOGVIEW_REVERSE'} eq 'on') ?
0x7FFFF000 : 0; #index of firts line number to display
92 if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr
{'update'})
94 my @temp = split(',',$ENV{'QUERY_STRING'});
96 $cgiparams{'MONTH'} = $temp[1];
97 $cgiparams{'DAY'} = $temp[2];
98 $cgiparams{'SECTION'} = $temp[3];
101 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
102 !($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)$/))
104 $cgiparams{'DAY'} = $now[3];
105 $cgiparams{'MONTH'} = $now[4];
107 elsif($cgiparams{'ACTION'} eq '>>')
110 my @temp_now = localtime(time);
111 $temp_now[4] = $cgiparams{'MONTH'};
112 $temp_now[3] = $cgiparams{'DAY'};
113 if ($cgiparams{'DAY'}) {
114 @temp_then = localtime(POSIX
::mktime
(@temp_now) + 86400);
115 ## Retrieve the same time on the next day +
116 ## 86400 seconds in a day
119 $temp_now[4] = ($temp_now[4]+1) %12;
120 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
123 $cgiparams{'MONTH'} = $temp_then[4];
124 $cgiparams{'DAY'} = $temp_then[3];
126 elsif($cgiparams{'ACTION'} eq '<<')
129 my @temp_now = localtime(time);
130 $temp_now[4] = $cgiparams{'MONTH'};
131 $temp_now[3] = $cgiparams{'DAY'};
132 if ($cgiparams{'DAY'}) {
133 @temp_then = localtime(POSIX
::mktime
(@temp_now) - 86400);
134 ## Retrieve the same time on the next day -
135 ## 86400 seconds in a day
138 $temp_now[4] = ($temp_now[4]-1) %12;
139 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
142 $cgiparams{'MONTH'} = $temp_then[4];
143 $cgiparams{'DAY'} = $temp_then[3];
146 # Find in which file.gz is the log. Can be calculated because WEEKLY ROTATING of access.log
148 my $date = $cgiparams{'DAY'} == 0 ?
'' : $cgiparams{'DAY'} <= 9 ?
"0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
153 # Calculate time. If future date, calculate for past year !!!
154 if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
155 ( $cgiparams{'MONTH'} > $now[4] ) ) {
156 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 );
157 $date = "$longmonths[$cgiparams{'MONTH'}] $date, ". int($year-1);
159 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 );
160 $date = "$longmonths[$cgiparams{'MONTH'}] $date, $year";
163 # calculate end of active week (saturday 23H59)
165 @then = localtime(time());
166 my $sunday = POSIX
::mktime
( 0, 0, 0, @then[3], @then[4], @then[5]);
167 $sunday += (6-$then[6]) * 86400;
169 # Convert delta in second to full weeks
170 $gzindex = int (($sunday-$xday)/604800 );
173 my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
174 my $daystr = $cgiparams{'DAY'} == 0 ?
'..' : $cgiparams{'DAY'} <= 9 ?
" $cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
175 my $section = $sections{$cgiparams{'SECTION'}};
182 my $lastdatetime; # for debug
183 my $search_for_end = 0;
185 while ($gzindex >=0 && $loop) {
186 # calculate file name
188 $filestr = "/var/log/messages";
190 $filestr = "/var/log/messages.$gzindex";
191 $filestr = "$filestr.gz" if -f
"$filestr.gz";
193 # now read file if existing
194 if (open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr))) {
195 #&General::log("reading $filestr");
196 READ
:while (<FILE
>) {
198 if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w\-]+ ${section}(.*)/) {
199 # when standart viewing, just keep in memory the correct slice
200 # it starts a '$start' and size is $viewport
201 # If export, then keep all lines...
202 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'}){
203 $log[$lines++] = "$line";
205 if ($lines++ < ($start + $Header::viewsize
)) {
207 if (@log > $Header::viewsize
) {
210 #} else { dont do this optimisation, need to count lines !
211 # $datetime = $maxtime; # we have read viewsize lines, stop main loop
212 # last READ; # exit read file
215 $search_for_end = 1; # we find the start of slice, can look for end now
217 if ($search_for_end == 1) {
218 #finish read files when date is over (test month equality only)
219 $line =~ /^(...) (..) ..:..:..*$/;
220 $loop = 0 if ( ($1 ne $monthstr) || ( ($daystr ne '..') && ($daystr ne $2) ) );
226 $gzindex--; # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped
230 # $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
232 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'})
234 print "Content-type: text/plain\n\n";
235 print "IPFire diagnostics\r\n";
236 print "$Lang::tr{'section'}: $cgiparams{'SECTION'}\n";
237 print "$Lang::tr{'date'}: $date\r\n\r\n";
239 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
243 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
246 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
247 print "$time $3 $4\r\n";
252 &Header
::showhttpheaders
();
254 &Header
::openpage
($Lang::tr
{'system logs'}, 1, '');
256 &Header
::openbigbox
('100%', 'left', '', $errormessage);
259 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
260 print "<font class='base'>$errormessage </font>\n";
264 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}:");
267 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
270 <td width='10%' class='base'>$Lang::tr{'section'}: </td>
272 <select name='SECTION'>
275 foreach $section (keys %sections) {
277 if ($section eq $cgiparams{'SECTION'}) {
278 print "selected='selected' "; }
279 print "value='$section'>$trsections{$section}</option>\n";
284 <td width='10%' class='base' align='right'>$Lang::tr{'month'}: </td>
286 <select name='MONTH'>
289 for (my $month = 0; $month < 12; $month++)
292 if ($month == $cgiparams{'MONTH'}) {
293 print "selected='selected' "; }
294 print "value='$month'>$longmonths[$month]</option>\n";
299 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
304 print "<option value='0'>$Lang::tr{'all'}</option>\n";
305 for (my $day = 1; $day <= 31; $day++)
308 if ($day == $cgiparams{'DAY'}) {
309 print "selected='selected' "; }
310 print "value='$day'>$day</option>\n";
315 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
316 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
317 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
318 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
327 &Header
::openbox
('100%', 'left', $Lang::tr
{'log'});
328 print "<p><b>$Lang::tr{'total hits for log section'} $cgiparams{'SECTION'} $date: $lines</b></p>";
330 $start = $lines - ${Header
::viewsize
} if ($start >= $lines - ${Header
::viewsize
});
331 $start = 0 if ($start < 0);
337 $prev = $start - ${Header
::viewsize
};
338 $prev = 0 if ( $prev < 0);
342 if ($start == $lines - ${Header
::viewsize
}) {
345 $next = $start + ${Header
::viewsize
};
346 $next = $lines - ${Header
::viewsize
} if ($next >= $lines - ${Header
::viewsize
});
349 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
350 if ($lines != 0) { &oldernewer
(); }
355 <td width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></td>
356 <td width='10%' align='center' class='boldbase'><b>$Lang::tr{'section'}</b></td>
357 <td width='80%'> </td>
366 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
369 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
372 # correct the cut position, just when section=RED
373 if (($cgiparams{'SECTION'} eq 'red' ) && ($sec =~ /(kernel:)(.*)/)) {
375 $data = $2.': '.$data;
377 my $d = substr ($data,0,80);
378 while (length($data)>80){ #very basic breaking of lines...
379 $data = substr ($data,80); #permit correct display in table cell
380 $d .= ' ' . substr ($data,0,80);
385 print "<tr bgcolor='$color{'color20'}'>"; }
387 print "<tr bgcolor='$color{'color22'}'>"; }
388 print "<td>$time<td>$sec<td>" .&Header
::cleanhtml
("$d", 'y') . "</td></tr>\n";
398 &Header
::closebigbox
();
400 &Header
::closepage
();
410 print "<td align='center' width='50%'>";
412 print "<a href='/cgi-bin/logs.cgi/log.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'older'}</a>"; }
414 print "$Lang::tr{'older'}"; }
417 print "<td align='center' width='50%'>";
419 print "<a href='/cgi-bin/logs.cgi/log.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'newer'}</a>"; }
421 print "$Lang::tr{'newer'}"; }