]>
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";
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]:) ',
69 'squid' => '(squid\[.*\]: |squid: )',
70 'snort' => '(snort\[.*\]: )'
73 # Translations for the %sections array.
77 'ddns' => "$Lang::tr{'dynamic dns'}",
80 'dhcp' => "$Lang::tr{'dhcp server'}",
82 'collectd' => 'Collectd',
86 'auth' => "$Lang::tr{'loginlogout'}",
87 'kernel' => "$Lang::tr{'kernel'}",
89 'openvpn' => 'OpenVPN',
90 'pakfire' => 'Pakfire',
91 'wireless' => 'Wireless',
92 'squid' => "$Lang::tr{'web proxy'}",
93 'snort' => "$Lang::tr{'intrusion detection'}"
97 &Header
::getcgihash
(\
%cgiparams);
98 $logsettings{'LOGVIEW_REVERSE'} = 'off';
99 &General
::readhash
("${General::swroot}/logging/settings", \
%logsettings);
100 ${Header
::viewsize
} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ?
$logsettings{'LOGVIEW_VIEWSIZE'} : 150;
102 my $start = ($logsettings{'LOGVIEW_REVERSE'} eq 'on') ?
0x7FFFF000 : 0; #index of firts line number to display
104 if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr
{'update'})
106 my @temp = split(',',$ENV{'QUERY_STRING'});
108 $cgiparams{'MONTH'} = $temp[1];
109 $cgiparams{'DAY'} = $temp[2];
110 $cgiparams{'SECTION'} = $temp[3];
113 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
114 !($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)$/))
116 $cgiparams{'DAY'} = $now[3];
117 $cgiparams{'MONTH'} = $now[4];
119 elsif($cgiparams{'ACTION'} eq '>>')
122 my @temp_now = localtime(time);
123 $temp_now[4] = $cgiparams{'MONTH'};
124 $temp_now[3] = $cgiparams{'DAY'};
125 if ($cgiparams{'DAY'}) {
126 @temp_then = localtime(POSIX
::mktime
(@temp_now) + 86400);
127 ## Retrieve the same time on the next day +
128 ## 86400 seconds in a day
131 $temp_now[4] = ($temp_now[4]+1) %12;
132 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
135 $cgiparams{'MONTH'} = $temp_then[4];
136 $cgiparams{'DAY'} = $temp_then[3];
138 elsif($cgiparams{'ACTION'} eq '<<')
141 my @temp_now = localtime(time);
142 $temp_now[4] = $cgiparams{'MONTH'};
143 $temp_now[3] = $cgiparams{'DAY'};
144 if ($cgiparams{'DAY'}) {
145 @temp_then = localtime(POSIX
::mktime
(@temp_now) - 86400);
146 ## Retrieve the same time on the next day -
147 ## 86400 seconds in a day
150 $temp_now[4] = ($temp_now[4]-1) %12;
151 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
154 $cgiparams{'MONTH'} = $temp_then[4];
155 $cgiparams{'DAY'} = $temp_then[3];
158 # Find in which file.gz is the log. Can be calculated because WEEKLY ROTATING of access.log
160 my $date = $cgiparams{'DAY'} == 0 ?
'' : $cgiparams{'DAY'} <= 9 ?
"0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
165 # Calculate time. If future date, calculate for past year !!!
166 if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
167 ( $cgiparams{'MONTH'} > $now[4] ) ) {
168 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 );
169 $date = "$longmonths[$cgiparams{'MONTH'}] $date, ". int($year-1);
171 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 );
172 $date = "$longmonths[$cgiparams{'MONTH'}] $date, $year";
175 # calculate end of active week (saturday 23H59)
177 @then = localtime(time());
178 my $sunday = POSIX
::mktime
( 0, 0, 0, $then[3], $then[4], $then[5]);
179 $sunday += (6-$then[6]) * 86400;
181 # Convert delta in second to full weeks
182 $gzindex = int (($sunday-$xday)/604800 );
185 my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
186 my $daystr = $cgiparams{'DAY'} == 0 ?
'..' : $cgiparams{'DAY'} <= 9 ?
" $cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
187 my $section = $sections{$cgiparams{'SECTION'}};
194 my $lastdatetime; # for debug
195 my $search_for_end = 0;
197 while ($gzindex >=0 && $loop) {
198 # calculate file name
200 $filestr = "/var/log/messages";
201 $filestr = "/var/log/mail" if (${section
} =~ 'dma');
203 $filestr = "/var/log/messages.$gzindex";
204 $filestr = "/var/log/mail.$gzindex" if (${section
} =~ 'dma');
205 $filestr = "$filestr.gz" if -f
"$filestr.gz";
207 # now read file if existing
208 if (open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr))) {
209 #&General::log("reading $filestr");
210 READ
:while (<FILE
>) {
212 if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w\-]+ ${section}(.*)/) {
213 # when standart viewing, just keep in memory the correct slice
214 # it starts a '$start' and size is $viewport
215 # If export, then keep all lines...
216 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'}){
217 $log[$lines++] = "$line";
219 if ($lines++ < ($start + $Header::viewsize
)) {
221 if (@log > $Header::viewsize
) {
224 #} else { dont do this optimisation, need to count lines !
225 # $datetime = $maxtime; # we have read viewsize lines, stop main loop
226 # last READ; # exit read file
229 $search_for_end = 1; # we find the start of slice, can look for end now
231 if ($search_for_end == 1) {
232 #finish read files when date is over (test month equality only)
233 $line =~ /^(...) (..) ..:..:..*$/;
234 $loop = 0 if ( ($1 ne $monthstr) || ( ($daystr ne '..') && ($daystr ne $2) ) );
240 $gzindex--; # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped
244 # $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
246 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'})
248 print "Content-type: text/plain\n\n";
249 print "IPFire diagnostics\r\n";
250 print "$Lang::tr{'section'}: $cgiparams{'SECTION'}\n";
251 print "$Lang::tr{'date'}: $date\r\n\r\n";
253 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
257 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
260 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
261 print "$time $3 $4\r\n";
266 &Header
::showhttpheaders
();
268 &Header
::openpage
($Lang::tr
{'system logs'}, 1, '');
270 &Header
::openbigbox
('100%', 'left', '', $errormessage);
273 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
274 print "<font class='base'>$errormessage </font>\n";
278 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}:");
281 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
284 <td width='10%' class='base'>$Lang::tr{'section'}: </td>
286 <select name='SECTION'>
289 foreach $section (keys %sections) {
291 if ($section eq $cgiparams{'SECTION'}) {
292 print "selected='selected' "; }
293 print "value='$section'>$trsections{$section}</option>\n";
298 <td width='10%' class='base' align='right'>$Lang::tr{'month'}: </td>
300 <select name='MONTH'>
303 for (my $month = 0; $month < 12; $month++)
306 if ($month == $cgiparams{'MONTH'}) {
307 print "selected='selected' "; }
308 print "value='$month'>$longmonths[$month]</option>\n";
313 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
318 print "<option value='0'>$Lang::tr{'all'}</option>\n";
319 for (my $day = 1; $day <= 31; $day++)
322 if ($day == $cgiparams{'DAY'}) {
323 print "selected='selected' "; }
324 print "value='$day'>$day</option>\n";
329 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
330 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
331 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
332 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
341 &Header
::openbox
('100%', 'left', $Lang::tr
{'log'});
342 print "<p><b>$Lang::tr{'total hits for log section'} $cgiparams{'SECTION'} $date: $lines</b></p>";
344 $start = $lines - ${Header
::viewsize
} if ($start >= $lines - ${Header
::viewsize
});
345 $start = 0 if ($start < 0);
351 $prev = $start - ${Header
::viewsize
};
352 $prev = 0 if ( $prev < 0);
356 if ($start == $lines - ${Header
::viewsize
}) {
359 $next = $start + ${Header
::viewsize
};
360 $next = $lines - ${Header
::viewsize
} if ($next >= $lines - ${Header
::viewsize
});
363 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
364 if ($lines != 0) { &oldernewer
(); }
367 <table width='100%' class='tbl'>
369 <th width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></th>
370 <th width='10%' align='center' class='boldbase'><b>$Lang::tr{'section'}</b></th>
371 <th width='80%'> </th>
380 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
383 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
386 # correct the cut position, just when section=RED
387 if (($cgiparams{'SECTION'} eq 'red' ) && ($sec =~ /(kernel:)(.*)/)) {
389 $data = $2.': '.$data;
391 my $d = substr ($data,0,80);
392 while (length($data)>80){ #very basic breaking of lines...
393 $data = substr ($data,80); #permit correct display in table cell
394 $d .= ' ' . substr ($data,0,80);
400 $col="bgcolor='$color{'color20'}'"; }
403 $col="bgcolor='$color{'color22'}'"; }
404 print "<td $col>$time<td $col>$sec<td $col>" .&Header
::cleanhtml
("$d", 'y') . "</td></tr>\n";
414 &Header
::closebigbox
();
416 &Header
::closepage
();
426 print "<td align='center' width='50%'>";
428 print "<a href='/cgi-bin/logs.cgi/log.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'older'}</a>"; }
430 print "$Lang::tr{'older'}"; }
433 print "<td align='center' width='50%'>";
435 print "<a href='/cgi-bin/logs.cgi/log.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'newer'}</a>"; }
437 print "$Lang::tr{'newer'}"; }