]>
git.ipfire.org Git - people/ummeegge/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'} = 'ipfire';
56 'ipfire' => '(ipfire)',
57 'red' => '(red.*|kernel: usb.*|pppd\[.*\]|chat\[.*\]|pppoe\[.*\]|pptp\[.*\]|pppoa\[.*\]|pppoa3\[.*\]|pppoeci\[.*\]|ipppd|ipppd\[.*\]|kernel: ippp\d|kernel: isdn.*|ibod\[.*\]|kernel: eth.*|dhcpcd\[.*\]|modem_run\[.*\])',
58 'dns' => '(dnsmasq\[.*\])',
60 'cron' => '(fcron\[.*\])',
61 'ntp' => '(ntpd(?:ate)?\[.*\])',
62 'ssh' => '(sshd(?:\(.*\))?\[.*\])',
63 'auth' => '(\w+\(pam_unix\)\[.*\])',
64 'kernel' => '(kernel)',
65 'ipsec' => '(ipsec_[\w_]+|pluto\[.*\])',
67 'openvpn' => '(openvpnserver)\[.*\]'
70 # Translations for the %sections array.
75 'dhcp' => "$Lang::tr{'dhcp server'}",
79 'auth' => "$Lang::tr{'loginlogout'}",
80 'kernel' => "$Lang::tr{'kernel'}",
82 'openvpn' => 'OpenVPN',
87 &Header
::getcgihash
(\
%cgiparams);
88 $logsettings{'LOGVIEW_REVERSE'} = 'off';
89 &General
::readhash
("${General::swroot}/logging/settings", \
%logsettings);
90 ${Header
::viewsize
} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ?
$logsettings{'LOGVIEW_VIEWSIZE'} : 150;
92 my $start = ($logsettings{'LOGVIEW_REVERSE'} eq 'on') ?
0x7FFFF000 : 0; #index of firts line number to display
94 if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr
{'update'})
96 my @temp = split(',',$ENV{'QUERY_STRING'});
98 $cgiparams{'MONTH'} = $temp[1];
99 $cgiparams{'DAY'} = $temp[2];
100 $cgiparams{'SECTION'} = $temp[3];
103 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
104 !($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)$/))
106 $cgiparams{'DAY'} = $now[3];
107 $cgiparams{'MONTH'} = $now[4];
109 elsif($cgiparams{'ACTION'} eq '>>')
112 my @temp_now = localtime(time);
113 $temp_now[4] = $cgiparams{'MONTH'};
114 $temp_now[3] = $cgiparams{'DAY'};
115 if ($cgiparams{'DAY'}) {
116 @temp_then = localtime(POSIX
::mktime
(@temp_now) + 86400);
117 ## Retrieve the same time on the next day +
118 ## 86400 seconds in a day
121 $temp_now[4] = ($temp_now[4]+1) %12;
122 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
125 $cgiparams{'MONTH'} = $temp_then[4];
126 $cgiparams{'DAY'} = $temp_then[3];
128 elsif($cgiparams{'ACTION'} eq '<<')
131 my @temp_now = localtime(time);
132 $temp_now[4] = $cgiparams{'MONTH'};
133 $temp_now[3] = $cgiparams{'DAY'};
134 if ($cgiparams{'DAY'}) {
135 @temp_then = localtime(POSIX
::mktime
(@temp_now) - 86400);
136 ## Retrieve the same time on the next day -
137 ## 86400 seconds in a day
140 $temp_now[4] = ($temp_now[4]-1) %12;
141 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
144 $cgiparams{'MONTH'} = $temp_then[4];
145 $cgiparams{'DAY'} = $temp_then[3];
148 # Find in which file.gz is the log. Can be calculated because WEEKLY ROTATING of access.log
150 my $date = $cgiparams{'DAY'} == 0 ?
'' : $cgiparams{'DAY'} <= 9 ?
"0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
155 # Calculate time. If future date, calculate for past year !!!
156 if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
157 ( $cgiparams{'MONTH'} > $now[4] ) ) {
158 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 );
159 $date = "$longmonths[$cgiparams{'MONTH'}] $date, ". int($year-1);
161 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 );
162 $date = "$longmonths[$cgiparams{'MONTH'}] $date, $year";
165 # calculate end of active week (saturday 23H59)
167 @then = localtime(time());
168 my $sunday = POSIX
::mktime
( 0, 0, 0, @then[3], @then[4], @then[5]);
169 $sunday += (6-$then[6]) * 86400;
171 # Convert delta in second to full weeks
172 $gzindex = int (($sunday-$xday)/604800 );
175 my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
176 my $daystr = $cgiparams{'DAY'} == 0 ?
'..' : $cgiparams{'DAY'} <= 9 ?
" $cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
177 my $section = $sections{$cgiparams{'SECTION'}};
184 my $lastdatetime; # for debug
185 my $search_for_end = 0;
187 while ($gzindex >=0 && $loop) {
188 # calculate file name
190 $filestr = "/var/log/messages";
192 $filestr = "/var/log/messages.$gzindex";
193 $filestr = "$filestr.gz" if -f
"$filestr.gz";
195 # now read file if existing
196 if (open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr))) {
197 #&General::log("reading $filestr");
198 READ
:while (<FILE
>) {
200 if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w\-]+ ${section}: (.*)/) {
201 # when standart viewing, just keep in memory the correct slice
202 # it starts a '$start' and size is $viewport
203 # If export, then keep all lines...
204 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'}){
205 $log[$lines++] = "$line";
207 if ($lines++ < ($start + $Header::viewsize
)) {
209 if (@log > $Header::viewsize
) {
212 #} else { dont do this optimisation, need to count lines !
213 # $datetime = $maxtime; # we have read viewsize lines, stop main loop
214 # last READ; # exit read file
217 $search_for_end = 1; # we find the start of slice, can look for end now
219 if ($search_for_end == 1) {
220 #finish read files when date is over (test month equality only)
221 $line =~ /^(...) (..) ..:..:..*$/;
222 $loop = 0 if ( ($1 ne $monthstr) || ( ($daystr ne '..') && ($daystr ne $2) ) );
228 $gzindex--; # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped
232 # $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
234 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'})
236 print "Content-type: text/plain\n\n";
237 print "IPFire diagnostics\r\n";
238 print "$Lang::tr{'section'}: $cgiparams{'SECTION'}\n";
239 print "$Lang::tr{'date'}: $date\r\n\r\n";
241 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
245 /^... (..) (..:..:..) [\w\-]+ ${section}: (.*)$/;
248 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
249 print "$time $3 $4\r\n";
254 &Header
::showhttpheaders
();
256 &Header
::openpage
($Lang::tr
{'system logs'}, 1, '');
258 &Header
::openbigbox
('100%', 'left', '', $errormessage);
261 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
262 print "<font class='base'>$errormessage </font>\n";
266 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}:");
269 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
272 <td width='10%' class='base'>$Lang::tr{'section'}: </td>
274 <select name='SECTION'>
277 foreach $section (keys %sections) {
279 if ($section eq $cgiparams{'SECTION'}) {
280 print "selected='selected' "; }
281 print "value='$section'>$trsections{$section}</option>\n";
286 <td width='10%' class='base' align='right'>$Lang::tr{'month'}: </td>
288 <select name='MONTH'>
291 for (my $month = 0; $month < 12; $month++)
294 if ($month == $cgiparams{'MONTH'}) {
295 print "selected='selected' "; }
296 print "value='$month'>$longmonths[$month]</option>\n";
301 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
306 print "<option value='0'>$Lang::tr{'all'}</option>\n";
307 for (my $day = 1; $day <= 31; $day++)
310 if ($day == $cgiparams{'DAY'}) {
311 print "selected='selected' "; }
312 print "value='$day'>$day</option>\n";
317 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
318 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
319 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
320 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
329 &Header
::openbox
('100%', 'left', $Lang::tr
{'log'});
330 print "<p><b>$Lang::tr{'total hits for log section'} $cgiparams{'SECTION'} $date: $lines</b></p>";
332 $start = $lines - ${Header
::viewsize
} if ($start >= $lines - ${Header
::viewsize
});
333 $start = 0 if ($start < 0);
339 $prev = $start - ${Header
::viewsize
};
340 $prev = 0 if ( $prev < 0);
344 if ($start == $lines - ${Header
::viewsize
}) {
347 $next = $start + ${Header
::viewsize
};
348 $next = $lines - ${Header
::viewsize
} if ($next >= $lines - ${Header
::viewsize
});
351 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
352 if ($lines != 0) { &oldernewer
(); }
357 <td width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></td>
358 <td width='10%' align='center' class='boldbase'><b>$Lang::tr{'section'}</b></td>
359 <td width='80%'> </td>
368 /^... (..) (..:..:..) [\w\-]+ ${section}: (.*)$/;
371 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
374 # correct the cut position, just when section=RED
375 if (($cgiparams{'SECTION'} eq 'red' ) && ($sec =~ /(kernel:)(.*)/)) {
377 $data = $2.': '.$data;
379 my $d = substr ($data,0,80);
380 while (length($data)>80){ #very basic breaking of lines...
381 $data = substr ($data,80); #permit correct display in table cell
382 $d .= ' ' . substr ($data,0,80);
387 print "<tr bgcolor='$color{'color20'}'>"; }
389 print "<tr bgcolor='$color{'color22'}'>"; }
390 print "<td>$time<td>$sec<td>" .&Header
::cleanhtml
("$d", 'y') . "</td></tr>\n";
400 &Header
::closebigbox
();
402 &Header
::closepage
();
412 print "<td align='center' width='50%'>";
414 print "<a href='/cgi-bin/logs.cgi/log.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'older'}</a>"; }
416 print "$Lang::tr{'older'}"; }
419 print "<td align='center' width='50%'>";
421 print "<a href='/cgi-bin/logs.cgi/log.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'newer'}</a>"; }
423 print "$Lang::tr{'newer'}"; }