]>
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";
24 #workaround to suppress a warning when a variable is used only once
25 my @dummy = ( ${Header
::table2colour
} );
30 my $errormessage = '';
32 my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
33 'Sep', 'Oct', 'Nov', 'Dec' );
34 my @longmonths = ( $Lang::tr
{'january'}, $Lang::tr
{'february'}, $Lang::tr
{'march'},
35 $Lang::tr
{'april'}, $Lang::tr
{'may'}, $Lang::tr
{'june'}, $Lang::tr
{'july'}, $Lang::tr
{'august'},
36 $Lang::tr
{'september'}, $Lang::tr
{'october'}, $Lang::tr
{'november'},
37 $Lang::tr
{'december'} );
39 my @now = localtime();
43 my $year = $now[5]+1900;
45 $cgiparams{'DAY'} = $now[3];
46 $cgiparams{'MONTH'} = $now[4];
47 $cgiparams{'ACTION'} = '';
48 $cgiparams{'SECTION'} = 'ipfire';
51 'ipfire' => '(ipfire)',
52 'red' => '(red.*|kernel: usb.*|pppd\[.*\]|chat\[.*\]|pppoe\[.*\]|pptp\[.*\]|pppoa\[.*\]|pppoa3\[.*\]|pppoeci\[.*\]|ipppd|ipppd\[.*\]|kernel: ippp\d|kernel: isdn.*|ibod\[.*\]|kernel: eth.*|dhcpcd\[.*\]|modem_run\[.*\])',
53 'dns' => '(dnsmasq\[.*\])',
55 'cron' => '(fcron\[.*\])',
56 'ntp' => '(ntpd(?:ate)?\[.*\])',
57 'ssh' => '(sshd(?:\(.*\))?\[.*\])',
58 'auth' => '(\w+\(pam_unix\)\[.*\])',
59 'kernel' => '(kernel)',
60 'ipsec' => '(ipsec_[\w_]+|pluto\[.*\])',
62 'openvpn' => '(openvpnserver)\[.*\]'
65 # Translations for the %sections array.
70 'dhcp' => "$Lang::tr{'dhcp server'}",
74 'auth' => "$Lang::tr{'loginlogout'}",
75 'kernel' => "$Lang::tr{'kernel'}",
77 'openvpn' => 'OpenVPN',
82 &Header
::getcgihash
(\
%cgiparams);
83 $logsettings{'LOGVIEW_REVERSE'} = 'off';
84 &General
::readhash
("${General::swroot}/logging/settings", \
%logsettings);
85 ${Header
::viewsize
} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ?
$logsettings{'LOGVIEW_VIEWSIZE'} : 150;
87 my $start = ($logsettings{'LOGVIEW_REVERSE'} eq 'on') ?
0x7FFFF000 : 0; #index of firts line number to display
89 if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr
{'update'})
91 my @temp = split(',',$ENV{'QUERY_STRING'});
93 $cgiparams{'MONTH'} = $temp[1];
94 $cgiparams{'DAY'} = $temp[2];
95 $cgiparams{'SECTION'} = $temp[3];
98 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
99 !($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)$/))
101 $cgiparams{'DAY'} = $now[3];
102 $cgiparams{'MONTH'} = $now[4];
104 elsif($cgiparams{'ACTION'} eq '>>')
107 my @temp_now = localtime(time);
108 $temp_now[4] = $cgiparams{'MONTH'};
109 $temp_now[3] = $cgiparams{'DAY'};
110 if ($cgiparams{'DAY'}) {
111 @temp_then = localtime(POSIX
::mktime
(@temp_now) + 86400);
112 ## Retrieve the same time on the next day +
113 ## 86400 seconds in a day
116 $temp_now[4] = ($temp_now[4]+1) %12;
117 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
120 $cgiparams{'MONTH'} = $temp_then[4];
121 $cgiparams{'DAY'} = $temp_then[3];
123 elsif($cgiparams{'ACTION'} eq '<<')
126 my @temp_now = localtime(time);
127 $temp_now[4] = $cgiparams{'MONTH'};
128 $temp_now[3] = $cgiparams{'DAY'};
129 if ($cgiparams{'DAY'}) {
130 @temp_then = localtime(POSIX
::mktime
(@temp_now) - 86400);
131 ## Retrieve the same time on the next day -
132 ## 86400 seconds in a day
135 $temp_now[4] = ($temp_now[4]-1) %12;
136 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
139 $cgiparams{'MONTH'} = $temp_then[4];
140 $cgiparams{'DAY'} = $temp_then[3];
143 # Find in which file.gz is the log. Can be calculated because WEEKLY ROTATING of access.log
145 my $date = $cgiparams{'DAY'} == 0 ?
'' : $cgiparams{'DAY'} <= 9 ?
"0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
150 # Calculate time. If future date, calculate for past year !!!
151 if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
152 ( $cgiparams{'MONTH'} > $now[4] ) ) {
153 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 );
154 $date = "$longmonths[$cgiparams{'MONTH'}] $date, ". int($year-1);
156 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 );
157 $date = "$longmonths[$cgiparams{'MONTH'}] $date, $year";
160 # calculate end of active week (saturday 23H59)
162 @then = localtime(time());
163 my $sunday = POSIX
::mktime
( 0, 0, 0, @then[3], @then[4], @then[5]);
164 $sunday += (6-$then[6]) * 86400;
166 # Convert delta in second to full weeks
167 $gzindex = int (($sunday-$xday)/604800 );
170 my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
171 my $daystr = $cgiparams{'DAY'} == 0 ?
'..' : $cgiparams{'DAY'} <= 9 ?
" $cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
172 my $section = $sections{$cgiparams{'SECTION'}};
179 my $lastdatetime; # for debug
180 my $search_for_end = 0;
182 while ($gzindex >=0 && $loop) {
183 # calculate file name
185 $filestr = "/var/log/messages";
187 $filestr = "/var/log/messages.$gzindex";
188 $filestr = "$filestr.gz" if -f
"$filestr.gz";
190 # now read file if existing
191 if (open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr))) {
192 #&General::log("reading $filestr");
193 READ
:while (<FILE
>) {
195 if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w\-]+ ${section}: (.*)/) {
196 # when standart viewing, just keep in memory the correct slice
197 # it starts a '$start' and size is $viewport
198 # If export, then keep all lines...
199 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'}){
200 $log[$lines++] = "$line";
202 if ($lines++ < ($start + $Header::viewsize
)) {
204 if (@log > $Header::viewsize
) {
207 #} else { dont do this optimisation, need to count lines !
208 # $datetime = $maxtime; # we have read viewsize lines, stop main loop
209 # last READ; # exit read file
212 $search_for_end = 1; # we find the start of slice, can look for end now
214 if ($search_for_end == 1) {
215 #finish read files when date is over (test month equality only)
216 $line =~ /^(...) (..) ..:..:..*$/;
217 $loop = 0 if ( ($1 ne $monthstr) || ( ($daystr ne '..') && ($daystr ne $2) ) );
223 $gzindex--; # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped
227 # $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
229 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'})
231 print "Content-type: text/plain\n\n";
232 print "IPFire diagnostics\r\n";
233 print "$Lang::tr{'section'}: $cgiparams{'SECTION'}\n";
234 print "$Lang::tr{'date'}: $date\r\n\r\n";
236 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
240 /^... (..) (..:..:..) [\w\-]+ ${section}: (.*)$/;
243 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
244 print "$time $3 $4\r\n";
249 &Header
::showhttpheaders
();
251 &Header
::openpage
($Lang::tr
{'system logs'}, 1, '');
253 &Header
::openbigbox
('100%', 'left', '', $errormessage);
256 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
257 print "<font class='base'>$errormessage </font>\n";
261 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}:");
264 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
267 <td width='10%' class='base'>$Lang::tr{'section'}: </td>
269 <select name='SECTION'>
272 foreach $section (keys %sections) {
274 if ($section eq $cgiparams{'SECTION'}) {
275 print "selected='selected' "; }
276 print "value='$section'>$trsections{$section}</option>\n";
281 <td width='10%' class='base' align='right'>$Lang::tr{'month'}: </td>
283 <select name='MONTH'>
286 for (my $month = 0; $month < 12; $month++)
289 if ($month == $cgiparams{'MONTH'}) {
290 print "selected='selected' "; }
291 print "value='$month'>$longmonths[$month]</option>\n";
296 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
301 print "<option value='0'>$Lang::tr{'all'}</option>\n";
302 for (my $day = 1; $day <= 31; $day++)
305 if ($day == $cgiparams{'DAY'}) {
306 print "selected='selected' "; }
307 print "value='$day'>$day</option>\n";
312 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
313 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
314 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
315 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
324 &Header
::openbox
('100%', 'left', $Lang::tr
{'log'});
325 print "<p><b>$Lang::tr{'total hits for log section'} $cgiparams{'SECTION'} $date: $lines</b></p>";
327 $start = $lines - ${Header
::viewsize
} if ($start >= $lines - ${Header
::viewsize
});
328 $start = 0 if ($start < 0);
334 $prev = $start - ${Header
::viewsize
};
335 $prev = 0 if ( $prev < 0);
339 if ($start == $lines - ${Header
::viewsize
}) {
342 $next = $start + ${Header
::viewsize
};
343 $next = $lines - ${Header
::viewsize
} if ($next >= $lines - ${Header
::viewsize
});
346 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
347 if ($lines != 0) { &oldernewer
(); }
352 <td width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></td>
353 <td width='10%' align='center' class='boldbase'><b>$Lang::tr{'section'}</b></td>
354 <td width='80%'> </td>
363 /^... (..) (..:..:..) [\w\-]+ ${section}: (.*)$/;
366 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
369 # correct the cut position, just when section=RED
370 if (($cgiparams{'SECTION'} eq 'red' ) && ($sec =~ /(kernel:)(.*)/)) {
372 $data = $2.': '.$data;
374 my $d = substr ($data,0,80);
375 while (length($data)>80){ #very basic breaking of lines...
376 $data = substr ($data,80); #permit correct display in table cell
377 $d .= ' ' . substr ($data,0,80);
382 print "<tr bgcolor='${Header::table1colour}'>"; }
384 print "<tr bgcolor='${Header::table2colour}'>"; }
385 print "<td>$time<td>$sec<td>" .&Header
::cleanhtml
("$d", 'y') . "</td></tr>\n";
395 &Header
::closebigbox
();
397 &Header
::closepage
();
407 print "<td align='center' width='50%'>";
409 print "<a href='/cgi-bin/logs.cgi/log.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'older'}</a>"; }
411 print "$Lang::tr{'older'}"; }
414 print "<td align='center' width='50%'>";
416 print "<a href='/cgi-bin/logs.cgi/log.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'newer'}</a>"; }
418 print "$Lang::tr{'newer'}"; }