]>
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 'ipfire' => '(ipfire: )',
53 'red' => '(red:|pppd\[.*\]: |chat\[.*\]|pppoe\[.*\]|pptp\[.*\]|pppoa\[.*\]|pppoa3\[.*\]|pppoeci\[.*\]|ipppd|ipppd\[.*\]|kernel: ippp\d|kernel: isdn.*|ibod\[.*\]|dhcpcd\[.*\]|modem_run\[.*\])',
54 'ddns' => '(ddns\[\d+\]:)',
55 'dns' => '(dnsmasq\[.*\]: )',
56 'dhcp' => '(dhcpd: )',
57 'clamav' => '(clamd\[.*\]: |freshclam\[.*\]: )',
58 'collectd' => '(collectd\[.*\]: )',
59 'cron' => '(fcron\[.*\]: )',
60 'ntp' => '(ntpd(?:ate)?\[.*\]: )',
61 'ssh' => '(sshd(?:\(.*\))?\[.*\]: )',
62 'auth' => '(\w+\(pam_unix\)\[.*\]: )',
63 'kernel' => '(kernel: (?!DROP_))',
64 'ipsec' => '(ipsec_[\w_]+: |pluto\[.*\]: |charon: |vpnwatch: )',
65 'openvpn' => '(openvpnserver\[.*\]: |.*n2n\[.*\]: )',
66 'pakfire' => '(pakfire:) ',
67 'wireless' => '(hostapd:|kernel: ath.*:|kernel: wifi[0-9]:) '
70 # Translations for the %sections array.
74 'ddns' => $Lang::tr
{'dynamic dns'},
76 'dhcp' => "$Lang::tr{'dhcp server'}",
78 'collectd' => 'Collectd',
82 'auth' => "$Lang::tr{'loginlogout'}",
83 'kernel' => "$Lang::tr{'kernel'}",
85 'openvpn' => 'OpenVPN',
86 'pakfire' => 'Pakfire',
87 'wireless' => 'Wireless'
91 &Header
::getcgihash
(\
%cgiparams);
92 $logsettings{'LOGVIEW_REVERSE'} = 'off';
93 &General
::readhash
("${General::swroot}/logging/settings", \
%logsettings);
94 ${Header
::viewsize
} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ?
$logsettings{'LOGVIEW_VIEWSIZE'} : 150;
96 my $start = ($logsettings{'LOGVIEW_REVERSE'} eq 'on') ?
0x7FFFF000 : 0; #index of firts line number to display
98 if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr
{'update'})
100 my @temp = split(',',$ENV{'QUERY_STRING'});
102 $cgiparams{'MONTH'} = $temp[1];
103 $cgiparams{'DAY'} = $temp[2];
104 $cgiparams{'SECTION'} = $temp[3];
107 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
108 !($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)$/))
110 $cgiparams{'DAY'} = $now[3];
111 $cgiparams{'MONTH'} = $now[4];
113 elsif($cgiparams{'ACTION'} eq '>>')
116 my @temp_now = localtime(time);
117 $temp_now[4] = $cgiparams{'MONTH'};
118 $temp_now[3] = $cgiparams{'DAY'};
119 if ($cgiparams{'DAY'}) {
120 @temp_then = localtime(POSIX
::mktime
(@temp_now) + 86400);
121 ## Retrieve the same time on the next day +
122 ## 86400 seconds in a day
125 $temp_now[4] = ($temp_now[4]+1) %12;
126 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
129 $cgiparams{'MONTH'} = $temp_then[4];
130 $cgiparams{'DAY'} = $temp_then[3];
132 elsif($cgiparams{'ACTION'} eq '<<')
135 my @temp_now = localtime(time);
136 $temp_now[4] = $cgiparams{'MONTH'};
137 $temp_now[3] = $cgiparams{'DAY'};
138 if ($cgiparams{'DAY'}) {
139 @temp_then = localtime(POSIX
::mktime
(@temp_now) - 86400);
140 ## Retrieve the same time on the next day -
141 ## 86400 seconds in a day
144 $temp_now[4] = ($temp_now[4]-1) %12;
145 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
148 $cgiparams{'MONTH'} = $temp_then[4];
149 $cgiparams{'DAY'} = $temp_then[3];
152 # Find in which file.gz is the log. Can be calculated because WEEKLY ROTATING of access.log
154 my $date = $cgiparams{'DAY'} == 0 ?
'' : $cgiparams{'DAY'} <= 9 ?
"0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
159 # Calculate time. If future date, calculate for past year !!!
160 if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
161 ( $cgiparams{'MONTH'} > $now[4] ) ) {
162 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 );
163 $date = "$longmonths[$cgiparams{'MONTH'}] $date, ". int($year-1);
165 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 );
166 $date = "$longmonths[$cgiparams{'MONTH'}] $date, $year";
169 # calculate end of active week (saturday 23H59)
171 @then = localtime(time());
172 my $sunday = POSIX
::mktime
( 0, 0, 0, $then[3], $then[4], $then[5]);
173 $sunday += (6-$then[6]) * 86400;
175 # Convert delta in second to full weeks
176 $gzindex = int (($sunday-$xday)/604800 );
179 my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
180 my $daystr = $cgiparams{'DAY'} == 0 ?
'..' : $cgiparams{'DAY'} <= 9 ?
" $cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
181 my $section = $sections{$cgiparams{'SECTION'}};
188 my $lastdatetime; # for debug
189 my $search_for_end = 0;
191 while ($gzindex >=0 && $loop) {
192 # calculate file name
194 $filestr = "/var/log/messages";
196 $filestr = "/var/log/messages.$gzindex";
197 $filestr = "$filestr.gz" if -f
"$filestr.gz";
199 # now read file if existing
200 if (open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr))) {
201 #&General::log("reading $filestr");
202 READ
:while (<FILE
>) {
204 if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w\-]+ ${section}(.*)/) {
205 # when standart viewing, just keep in memory the correct slice
206 # it starts a '$start' and size is $viewport
207 # If export, then keep all lines...
208 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'}){
209 $log[$lines++] = "$line";
211 if ($lines++ < ($start + $Header::viewsize
)) {
213 if (@log > $Header::viewsize
) {
216 #} else { dont do this optimisation, need to count lines !
217 # $datetime = $maxtime; # we have read viewsize lines, stop main loop
218 # last READ; # exit read file
221 $search_for_end = 1; # we find the start of slice, can look for end now
223 if ($search_for_end == 1) {
224 #finish read files when date is over (test month equality only)
225 $line =~ /^(...) (..) ..:..:..*$/;
226 $loop = 0 if ( ($1 ne $monthstr) || ( ($daystr ne '..') && ($daystr ne $2) ) );
232 $gzindex--; # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped
236 # $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
238 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'})
240 print "Content-type: text/plain\n\n";
241 print "IPFire diagnostics\r\n";
242 print "$Lang::tr{'section'}: $cgiparams{'SECTION'}\n";
243 print "$Lang::tr{'date'}: $date\r\n\r\n";
245 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
249 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
252 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
253 print "$time $3 $4\r\n";
258 &Header
::showhttpheaders
();
260 &Header
::openpage
($Lang::tr
{'system logs'}, 1, '');
262 &Header
::openbigbox
('100%', 'left', '', $errormessage);
265 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
266 print "<font class='base'>$errormessage </font>\n";
270 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}:");
273 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
276 <td width='10%' class='base'>$Lang::tr{'section'}: </td>
278 <select name='SECTION'>
281 foreach $section (keys %sections) {
283 if ($section eq $cgiparams{'SECTION'}) {
284 print "selected='selected' "; }
285 print "value='$section'>$trsections{$section}</option>\n";
290 <td width='10%' class='base' align='right'>$Lang::tr{'month'}: </td>
292 <select name='MONTH'>
295 for (my $month = 0; $month < 12; $month++)
298 if ($month == $cgiparams{'MONTH'}) {
299 print "selected='selected' "; }
300 print "value='$month'>$longmonths[$month]</option>\n";
305 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
310 print "<option value='0'>$Lang::tr{'all'}</option>\n";
311 for (my $day = 1; $day <= 31; $day++)
314 if ($day == $cgiparams{'DAY'}) {
315 print "selected='selected' "; }
316 print "value='$day'>$day</option>\n";
321 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
322 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
323 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
324 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
333 &Header
::openbox
('100%', 'left', $Lang::tr
{'log'});
334 print "<p><b>$Lang::tr{'total hits for log section'} $cgiparams{'SECTION'} $date: $lines</b></p>";
336 $start = $lines - ${Header
::viewsize
} if ($start >= $lines - ${Header
::viewsize
});
337 $start = 0 if ($start < 0);
343 $prev = $start - ${Header
::viewsize
};
344 $prev = 0 if ( $prev < 0);
348 if ($start == $lines - ${Header
::viewsize
}) {
351 $next = $start + ${Header
::viewsize
};
352 $next = $lines - ${Header
::viewsize
} if ($next >= $lines - ${Header
::viewsize
});
355 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
356 if ($lines != 0) { &oldernewer
(); }
359 <table width='100%' class='tbl'>
361 <th width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></th>
362 <th width='10%' align='center' class='boldbase'><b>$Lang::tr{'section'}</b></th>
363 <th width='80%'> </th>
372 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
375 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
378 # correct the cut position, just when section=RED
379 if (($cgiparams{'SECTION'} eq 'red' ) && ($sec =~ /(kernel:)(.*)/)) {
381 $data = $2.': '.$data;
383 my $d = substr ($data,0,80);
384 while (length($data)>80){ #very basic breaking of lines...
385 $data = substr ($data,80); #permit correct display in table cell
386 $d .= ' ' . substr ($data,0,80);
392 $col="bgcolor='$color{'color20'}'"; }
395 $col="bgcolor='$color{'color22'}'"; }
396 print "<td $col>$time<td $col>$sec<td $col>" .&Header
::cleanhtml
("$d", 'y') . "</td></tr>\n";
406 &Header
::closebigbox
();
408 &Header
::closepage
();
418 print "<td align='center' width='50%'>";
420 print "<a href='/cgi-bin/logs.cgi/log.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'older'}</a>"; }
422 print "$Lang::tr{'older'}"; }
425 print "<td align='center' width='50%'>";
427 print "<a href='/cgi-bin/logs.cgi/log.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'newer'}</a>"; }
429 print "$Lang::tr{'newer'}"; }