]>
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 'dma' => '(dma\[.*\]: )',
57 'dhcp' => '(dhcpd: )',
58 'clamav' => '(clamd\[.*\]: |freshclam\[.*\]: )',
59 'collectd' => '(collectd\[.*\]: )',
60 'cron' => '(fcron\[.*\]: )',
61 'ntp' => '(ntpd(?:ate)?\[.*\]: )',
62 'ssh' => '(sshd(?:\(.*\))?\[.*\]: )',
63 'auth' => '(\w+\(pam_unix\)\[.*\]: )',
64 'kernel' => '(kernel: (?!DROP_))',
65 'ipsec' => '(ipsec_[\w_]+: |pluto\[.*\]: |charon: |vpnwatch: )',
66 'openvpn' => '(openvpnserver\[.*\]: |.*n2n\[.*\]: )',
67 'pakfire' => '(pakfire:) ',
68 'wireless' => '(hostapd:|kernel: ath.*:|kernel: wifi[0-9]:) '
71 # Translations for the %sections array.
75 'ddns' => $Lang::tr
{'dynamic dns'},
78 'dhcp' => "$Lang::tr{'dhcp server'}",
80 'collectd' => 'Collectd',
84 'auth' => "$Lang::tr{'loginlogout'}",
85 'kernel' => "$Lang::tr{'kernel'}",
87 'openvpn' => 'OpenVPN',
88 'pakfire' => 'Pakfire',
89 'wireless' => 'Wireless'
93 &Header
::getcgihash
(\
%cgiparams);
94 $logsettings{'LOGVIEW_REVERSE'} = 'off';
95 &General
::readhash
("${General::swroot}/logging/settings", \
%logsettings);
96 ${Header
::viewsize
} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ?
$logsettings{'LOGVIEW_VIEWSIZE'} : 150;
98 my $start = ($logsettings{'LOGVIEW_REVERSE'} eq 'on') ?
0x7FFFF000 : 0; #index of firts line number to display
100 if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr
{'update'})
102 my @temp = split(',',$ENV{'QUERY_STRING'});
104 $cgiparams{'MONTH'} = $temp[1];
105 $cgiparams{'DAY'} = $temp[2];
106 $cgiparams{'SECTION'} = $temp[3];
109 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
110 !($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)$/))
112 $cgiparams{'DAY'} = $now[3];
113 $cgiparams{'MONTH'} = $now[4];
115 elsif($cgiparams{'ACTION'} eq '>>')
118 my @temp_now = localtime(time);
119 $temp_now[4] = $cgiparams{'MONTH'};
120 $temp_now[3] = $cgiparams{'DAY'};
121 if ($cgiparams{'DAY'}) {
122 @temp_then = localtime(POSIX
::mktime
(@temp_now) + 86400);
123 ## Retrieve the same time on the next day +
124 ## 86400 seconds in a day
127 $temp_now[4] = ($temp_now[4]+1) %12;
128 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
131 $cgiparams{'MONTH'} = $temp_then[4];
132 $cgiparams{'DAY'} = $temp_then[3];
134 elsif($cgiparams{'ACTION'} eq '<<')
137 my @temp_now = localtime(time);
138 $temp_now[4] = $cgiparams{'MONTH'};
139 $temp_now[3] = $cgiparams{'DAY'};
140 if ($cgiparams{'DAY'}) {
141 @temp_then = localtime(POSIX
::mktime
(@temp_now) - 86400);
142 ## Retrieve the same time on the next day -
143 ## 86400 seconds in a day
146 $temp_now[4] = ($temp_now[4]-1) %12;
147 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
150 $cgiparams{'MONTH'} = $temp_then[4];
151 $cgiparams{'DAY'} = $temp_then[3];
154 # Find in which file.gz is the log. Can be calculated because WEEKLY ROTATING of access.log
156 my $date = $cgiparams{'DAY'} == 0 ?
'' : $cgiparams{'DAY'} <= 9 ?
"0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
161 # Calculate time. If future date, calculate for past year !!!
162 if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
163 ( $cgiparams{'MONTH'} > $now[4] ) ) {
164 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 );
165 $date = "$longmonths[$cgiparams{'MONTH'}] $date, ". int($year-1);
167 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 );
168 $date = "$longmonths[$cgiparams{'MONTH'}] $date, $year";
171 # calculate end of active week (saturday 23H59)
173 @then = localtime(time());
174 my $sunday = POSIX
::mktime
( 0, 0, 0, $then[3], $then[4], $then[5]);
175 $sunday += (6-$then[6]) * 86400;
177 # Convert delta in second to full weeks
178 $gzindex = int (($sunday-$xday)/604800 );
181 my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
182 my $daystr = $cgiparams{'DAY'} == 0 ?
'..' : $cgiparams{'DAY'} <= 9 ?
" $cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
183 my $section = $sections{$cgiparams{'SECTION'}};
190 my $lastdatetime; # for debug
191 my $search_for_end = 0;
193 while ($gzindex >=0 && $loop) {
194 # calculate file name
196 $filestr = "/var/log/messages";
197 $filestr = "/var/log/mail" if (${section
} =~ 'dma');
199 $filestr = "/var/log/messages.$gzindex";
200 $filestr = "/var/log/mail.$gzindex" if (${section
} =~ 'dma');
201 $filestr = "$filestr.gz" if -f
"$filestr.gz";
203 # now read file if existing
204 if (open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr))) {
205 #&General::log("reading $filestr");
206 READ
:while (<FILE
>) {
208 if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w\-]+ ${section}(.*)/) {
209 # when standart viewing, just keep in memory the correct slice
210 # it starts a '$start' and size is $viewport
211 # If export, then keep all lines...
212 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'}){
213 $log[$lines++] = "$line";
215 if ($lines++ < ($start + $Header::viewsize
)) {
217 if (@log > $Header::viewsize
) {
220 #} else { dont do this optimisation, need to count lines !
221 # $datetime = $maxtime; # we have read viewsize lines, stop main loop
222 # last READ; # exit read file
225 $search_for_end = 1; # we find the start of slice, can look for end now
227 if ($search_for_end == 1) {
228 #finish read files when date is over (test month equality only)
229 $line =~ /^(...) (..) ..:..:..*$/;
230 $loop = 0 if ( ($1 ne $monthstr) || ( ($daystr ne '..') && ($daystr ne $2) ) );
236 $gzindex--; # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped
240 # $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
242 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'})
244 print "Content-type: text/plain\n\n";
245 print "IPFire diagnostics\r\n";
246 print "$Lang::tr{'section'}: $cgiparams{'SECTION'}\n";
247 print "$Lang::tr{'date'}: $date\r\n\r\n";
249 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
253 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
256 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
257 print "$time $3 $4\r\n";
262 &Header
::showhttpheaders
();
264 &Header
::openpage
($Lang::tr
{'system logs'}, 1, '');
266 &Header
::openbigbox
('100%', 'left', '', $errormessage);
269 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
270 print "<font class='base'>$errormessage </font>\n";
274 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}:");
277 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
280 <td width='10%' class='base'>$Lang::tr{'section'}: </td>
282 <select name='SECTION'>
285 foreach $section (keys %sections) {
287 if ($section eq $cgiparams{'SECTION'}) {
288 print "selected='selected' "; }
289 print "value='$section'>$trsections{$section}</option>\n";
294 <td width='10%' class='base' align='right'>$Lang::tr{'month'}: </td>
296 <select name='MONTH'>
299 for (my $month = 0; $month < 12; $month++)
302 if ($month == $cgiparams{'MONTH'}) {
303 print "selected='selected' "; }
304 print "value='$month'>$longmonths[$month]</option>\n";
309 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
314 print "<option value='0'>$Lang::tr{'all'}</option>\n";
315 for (my $day = 1; $day <= 31; $day++)
318 if ($day == $cgiparams{'DAY'}) {
319 print "selected='selected' "; }
320 print "value='$day'>$day</option>\n";
325 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
326 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
327 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
328 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
337 &Header
::openbox
('100%', 'left', $Lang::tr
{'log'});
338 print "<p><b>$Lang::tr{'total hits for log section'} $cgiparams{'SECTION'} $date: $lines</b></p>";
340 $start = $lines - ${Header
::viewsize
} if ($start >= $lines - ${Header
::viewsize
});
341 $start = 0 if ($start < 0);
347 $prev = $start - ${Header
::viewsize
};
348 $prev = 0 if ( $prev < 0);
352 if ($start == $lines - ${Header
::viewsize
}) {
355 $next = $start + ${Header
::viewsize
};
356 $next = $lines - ${Header
::viewsize
} if ($next >= $lines - ${Header
::viewsize
});
359 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
360 if ($lines != 0) { &oldernewer
(); }
363 <table width='100%' class='tbl'>
365 <th width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></th>
366 <th width='10%' align='center' class='boldbase'><b>$Lang::tr{'section'}</b></th>
367 <th width='80%'> </th>
376 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
379 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
382 # correct the cut position, just when section=RED
383 if (($cgiparams{'SECTION'} eq 'red' ) && ($sec =~ /(kernel:)(.*)/)) {
385 $data = $2.': '.$data;
387 my $d = substr ($data,0,80);
388 while (length($data)>80){ #very basic breaking of lines...
389 $data = substr ($data,80); #permit correct display in table cell
390 $d .= ' ' . substr ($data,0,80);
396 $col="bgcolor='$color{'color20'}'"; }
399 $col="bgcolor='$color{'color22'}'"; }
400 print "<td $col>$time<td $col>$sec<td $col>" .&Header
::cleanhtml
("$d", 'y') . "</td></tr>\n";
410 &Header
::closebigbox
();
412 &Header
::closepage
();
422 print "<td align='center' width='50%'>";
424 print "<a href='/cgi-bin/logs.cgi/log.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'older'}</a>"; }
426 print "$Lang::tr{'older'}"; }
429 print "<td align='center' width='50%'>";
431 print "<a href='/cgi-bin/logs.cgi/log.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'newer'}</a>"; }
433 print "$Lang::tr{'newer'}"; }