]>
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\[.*\]: |unbound\[.*\]: )',
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\[.*\]: )',
71 'guardian' => '(guardian\[.*\]: )'
74 # Translations for the %sections array.
78 'ddns' => "$Lang::tr{'dynamic dns'}",
81 'dhcp' => "$Lang::tr{'dhcp server'}",
83 'collectd' => 'Collectd',
87 'auth' => "$Lang::tr{'loginlogout'}",
88 'kernel' => "$Lang::tr{'kernel'}",
90 'openvpn' => 'OpenVPN',
91 'pakfire' => 'Pakfire',
92 'wireless' => 'Wireless',
93 'squid' => "$Lang::tr{'web proxy'}",
94 'snort' => "$Lang::tr{'intrusion detection'}",
95 'guardian' => "$Lang::tr{'guardian'}"
99 &Header
::getcgihash
(\
%cgiparams);
100 $logsettings{'LOGVIEW_REVERSE'} = 'off';
101 &General
::readhash
("${General::swroot}/logging/settings", \
%logsettings);
102 ${Header
::viewsize
} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ?
$logsettings{'LOGVIEW_VIEWSIZE'} : 150;
104 my $start = ($logsettings{'LOGVIEW_REVERSE'} eq 'on') ?
0x7FFFF000 : 0; #index of firts line number to display
106 if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr
{'update'})
108 my @temp = split(',',$ENV{'QUERY_STRING'});
110 $cgiparams{'MONTH'} = $temp[1];
111 $cgiparams{'DAY'} = $temp[2];
112 $cgiparams{'SECTION'} = $temp[3];
115 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
116 !($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)$/))
118 $cgiparams{'DAY'} = $now[3];
119 $cgiparams{'MONTH'} = $now[4];
121 elsif($cgiparams{'ACTION'} eq '>>')
124 my @temp_now = localtime(time);
125 $temp_now[4] = $cgiparams{'MONTH'};
126 $temp_now[3] = $cgiparams{'DAY'};
127 if ($cgiparams{'DAY'}) {
128 @temp_then = localtime(POSIX
::mktime
(@temp_now) + 86400);
129 ## Retrieve the same time on the next day +
130 ## 86400 seconds in a day
133 $temp_now[4] = ($temp_now[4]+1) %12;
134 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
137 $cgiparams{'MONTH'} = $temp_then[4];
138 $cgiparams{'DAY'} = $temp_then[3];
140 elsif($cgiparams{'ACTION'} eq '<<')
143 my @temp_now = localtime(time);
144 $temp_now[4] = $cgiparams{'MONTH'};
145 $temp_now[3] = $cgiparams{'DAY'};
146 if ($cgiparams{'DAY'}) {
147 @temp_then = localtime(POSIX
::mktime
(@temp_now) - 86400);
148 ## Retrieve the same time on the next day -
149 ## 86400 seconds in a day
152 $temp_now[4] = ($temp_now[4]-1) %12;
153 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
156 $cgiparams{'MONTH'} = $temp_then[4];
157 $cgiparams{'DAY'} = $temp_then[3];
160 # Find in which file.gz is the log. Can be calculated because WEEKLY ROTATING of access.log
162 my $date = $cgiparams{'DAY'} == 0 ?
'' : $cgiparams{'DAY'} <= 9 ?
"0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
167 # Calculate time. If future date, calculate for past year !!!
168 if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
169 ( $cgiparams{'MONTH'} > $now[4] ) ) {
170 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 );
171 $date = "$longmonths[$cgiparams{'MONTH'}] $date, ". int($year-1);
173 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 );
174 $date = "$longmonths[$cgiparams{'MONTH'}] $date, $year";
177 # calculate end of active week (saturday 23H59)
179 @then = localtime(time());
180 my $sunday = POSIX
::mktime
( 0, 0, 0, $then[3], $then[4], $then[5]);
181 $sunday += (6-$then[6]) * 86400;
183 # Convert delta in second to full weeks
184 $gzindex = int (($sunday-$xday)/604800 );
187 my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
188 my $daystr = $cgiparams{'DAY'} == 0 ?
'..' : $cgiparams{'DAY'} <= 9 ?
" $cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
189 my $section = $sections{$cgiparams{'SECTION'}};
196 my $lastdatetime; # for debug
197 my $search_for_end = 0;
199 while ($gzindex >=0 && $loop) {
200 # calculate file name
202 $filestr = "/var/log/messages";
203 $filestr = "/var/log/mail" if (${section
} =~ 'dma');
205 $filestr = "/var/log/messages.$gzindex";
206 $filestr = "/var/log/mail.$gzindex" if (${section
} =~ 'dma');
207 $filestr = "$filestr.gz" if -f
"$filestr.gz";
209 # now read file if existing
210 if (open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr))) {
211 #&General::log("reading $filestr");
212 READ
:while (<FILE
>) {
214 if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w\-]+ ${section}(.*)/) {
215 # when standart viewing, just keep in memory the correct slice
216 # it starts a '$start' and size is $viewport
217 # If export, then keep all lines...
218 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'}){
219 $log[$lines++] = "$line";
221 if ($lines++ < ($start + $Header::viewsize
)) {
223 if (@log > $Header::viewsize
) {
226 #} else { dont do this optimisation, need to count lines !
227 # $datetime = $maxtime; # we have read viewsize lines, stop main loop
228 # last READ; # exit read file
231 $search_for_end = 1; # we find the start of slice, can look for end now
233 if ($search_for_end == 1) {
234 #finish read files when date is over (test month equality only)
235 $line =~ /^(...) (..) ..:..:..*$/;
236 $loop = 0 if ( ($1 ne $monthstr) || ( ($daystr ne '..') && ($daystr ne $2) ) );
242 $gzindex--; # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped
246 # $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
248 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'})
250 print "Content-type: text/plain\n\n";
251 print "IPFire diagnostics\r\n";
252 print "$Lang::tr{'section'}: $cgiparams{'SECTION'}\n";
253 print "$Lang::tr{'date'}: $date\r\n\r\n";
255 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
259 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
262 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
263 print "$time $3 $4\r\n";
268 &Header
::showhttpheaders
();
270 &Header
::openpage
($Lang::tr
{'system logs'}, 1, '');
272 &Header
::openbigbox
('100%', 'left', '', $errormessage);
275 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
276 print "<font class='base'>$errormessage </font>\n";
280 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}:");
283 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
286 <td width='10%' class='base'>$Lang::tr{'section'}: </td>
288 <select name='SECTION'>
291 foreach $section (keys %sections) {
293 if ($section eq $cgiparams{'SECTION'}) {
294 print "selected='selected' "; }
295 print "value='$section'>$trsections{$section}</option>\n";
300 <td width='10%' class='base' align='right'>$Lang::tr{'month'}: </td>
302 <select name='MONTH'>
305 for (my $month = 0; $month < 12; $month++)
308 if ($month == $cgiparams{'MONTH'}) {
309 print "selected='selected' "; }
310 print "value='$month'>$longmonths[$month]</option>\n";
315 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
320 print "<option value='0'>$Lang::tr{'all'}</option>\n";
321 for (my $day = 1; $day <= 31; $day++)
324 if ($day == $cgiparams{'DAY'}) {
325 print "selected='selected' "; }
326 print "value='$day'>$day</option>\n";
331 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
332 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
333 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
334 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
343 &Header
::openbox
('100%', 'left', $Lang::tr
{'log'});
344 print "<p><b>$Lang::tr{'total hits for log section'} $cgiparams{'SECTION'} $date: $lines</b></p>";
346 $start = $lines - ${Header
::viewsize
} if ($start >= $lines - ${Header
::viewsize
});
347 $start = 0 if ($start < 0);
353 $prev = $start - ${Header
::viewsize
};
354 $prev = 0 if ( $prev < 0);
358 if ($start == $lines - ${Header
::viewsize
}) {
361 $next = $start + ${Header
::viewsize
};
362 $next = $lines - ${Header
::viewsize
} if ($next >= $lines - ${Header
::viewsize
});
365 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
366 if ($lines != 0) { &oldernewer
(); }
369 <table width='100%' class='tbl'>
371 <th width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></th>
372 <th width='10%' align='center' class='boldbase'><b>$Lang::tr{'section'}</b></th>
373 <th width='80%'> </th>
382 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
385 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
388 # correct the cut position, just when section=RED
389 if (($cgiparams{'SECTION'} eq 'red' ) && ($sec =~ /(kernel:)(.*)/)) {
391 $data = $2.': '.$data;
393 my $d = substr ($data,0,80);
394 while (length($data)>80){ #very basic breaking of lines...
395 $data = substr ($data,80); #permit correct display in table cell
396 $d .= ' ' . substr ($data,0,80);
402 $col="bgcolor='$color{'color20'}'"; }
405 $col="bgcolor='$color{'color22'}'"; }
406 print "<td $col>$time<td $col>$sec<td $col>" .&Header
::cleanhtml
("$d", 'y') . "</td></tr>\n";
416 &Header
::closebigbox
();
418 &Header
::closepage
();
428 print "<td align='center' width='50%'>";
430 print "<a href='/cgi-bin/logs.cgi/log.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'older'}</a>"; }
432 print "$Lang::tr{'older'}"; }
435 print "<td align='center' width='50%'>";
437 print "<a href='/cgi-bin/logs.cgi/log.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'newer'}</a>"; }
439 print "$Lang::tr{'newer'}"; }