]>
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 'auth' => '(\w+\(pam_unix\)\[.*\]: )',
53 'wio' => '(wio:|wio\[.*\])',
54 'captive' => '(Captive:)',
55 'clamav' => '(clamd\[.*\]: |freshclam\[.*\]: )',
56 'collectd' => '(collectd\[.*\]: )',
57 'cron' => '(fcron\[.*\]: )',
58 'ddns' => '(ddns\[\d+\]:)',
59 'dhcp' => '(dhcpd: )',
60 'dma' => '(dma: |dma\[.*\]: |postfix/\w*\[\d*\]: )',
61 'guardian' => '(guardian\[.*\]: )',
62 'ipfire' => '(ipfire: )',
63 'ipsec' => '(ipsec_[\w_]+: |pluto\[.*\]: |charon: |vpnwatch: )',
64 'kernel' => '(kernel: (?!DROP_))',
65 'ntp' => '(ntpd(?:ate)?\[.*\]: )',
66 'oinkmaster' => '(oinkmaster\[.*\]: )',
67 'openvpn' => '(openvpnserver\[.*\]: |.*n2n\[.*\]: )',
68 'pakfire' => '(pakfire:)',
69 'red' => '(red:|pppd\[.*\]: |chat\[.*\]|pppoe\[.*\]|pptp\[.*\]|pppoa\[.*\]|pppoa3\[.*\]|pppoeci\[.*\]|ipppd|ipppd\[.*\]|kernel: ippp\d|kernel: isdn.*|ibod\[.*\]|dhcpcd\[.*\]|modem_run\[.*\])',
70 'samba' => '(nmbd|smbd|winbind)\[\d+\]:',
71 'suricata' => '(suricata: )',
72 'squid' => '(squid\[.*\]: |squid: )',
73 'ssh' => '(sshd(?:\(.*\))?\[.*\]: )',
74 'unbound' => '(unbound: \[.*:.*\])(.*:.*$)',
75 'urlfilter bl' => '(installpackage\[urlfilter\]: )',
76 'wireless' => '(hostapd:|kernel: ath.*:|kernel: wifi[0-9]:)'
79 # Translations for the %sections array.
81 'auth' => "$Lang::tr{'loginlogout'}",
82 'wio' => 'Who Is Online?',
83 'captive' => $Lang::tr
{'Captive'},
85 'collectd' => 'Collectd',
87 'ddns' => "$Lang::tr{'dynamic dns'}",
88 'dhcp' => "$Lang::tr{'dhcp server'}",
90 'guardian' => "$Lang::tr{'guardian'}",
93 'kernel' => "$Lang::tr{'kernel'}",
95 'oinkmaster' => 'Oinkmaster',
96 'openvpn' => 'OpenVPN',
97 'pakfire' => 'Pakfire',
99 'samba' => $Lang::tr
{'samba'},
100 'suricata' => "$Lang::tr{'intrusion detection'}",
101 'squid' => "$Lang::tr{'web proxy'}",
103 'unbound' => 'DNS: Unbound',
104 'urlfilter bl' => 'URLFilter Blacklist',
105 'wireless' => 'Wireless'
109 &Header
::getcgihash
(\
%cgiparams);
110 $logsettings{'LOGVIEW_REVERSE'} = 'off';
111 &General
::readhash
("${General::swroot}/logging/settings", \
%logsettings);
112 ${Header
::viewsize
} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ?
$logsettings{'LOGVIEW_VIEWSIZE'} : 150;
114 my $start = ($logsettings{'LOGVIEW_REVERSE'} eq 'on') ?
0x7FFFF000 : 0; #index of firts line number to display
116 if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr
{'update'})
118 my @temp = split(',',$ENV{'QUERY_STRING'});
120 $cgiparams{'MONTH'} = $temp[1];
121 $cgiparams{'DAY'} = $temp[2];
122 $cgiparams{'SECTION'} = $temp[3];
125 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
126 !($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)$/))
128 $cgiparams{'DAY'} = $now[3];
129 $cgiparams{'MONTH'} = $now[4];
131 elsif($cgiparams{'ACTION'} eq '>>')
134 my @temp_now = localtime(time);
135 $temp_now[4] = $cgiparams{'MONTH'};
136 $temp_now[3] = $cgiparams{'DAY'};
137 if ($cgiparams{'DAY'}) {
138 @temp_then = localtime(POSIX
::mktime
(@temp_now) + 86400);
139 ## Retrieve the same time on the next day +
140 ## 86400 seconds in a day
143 $temp_now[4] = ($temp_now[4]+1) %12;
144 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
147 $cgiparams{'MONTH'} = $temp_then[4];
148 $cgiparams{'DAY'} = $temp_then[3];
150 elsif($cgiparams{'ACTION'} eq '<<')
153 my @temp_now = localtime(time);
154 $temp_now[4] = $cgiparams{'MONTH'};
155 $temp_now[3] = $cgiparams{'DAY'};
156 if ($cgiparams{'DAY'}) {
157 @temp_then = localtime(POSIX
::mktime
(@temp_now) - 86400);
158 ## Retrieve the same time on the next day -
159 ## 86400 seconds in a day
162 $temp_now[4] = ($temp_now[4]-1) %12;
163 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
166 $cgiparams{'MONTH'} = $temp_then[4];
167 $cgiparams{'DAY'} = $temp_then[3];
170 # Find in which file.gz is the log. Can be calculated because WEEKLY ROTATING of access.log
172 my $date = $cgiparams{'DAY'} == 0 ?
'' : $cgiparams{'DAY'} <= 9 ?
"0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
177 # Calculate time. If future date, calculate for past year !!!
178 if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
179 ( $cgiparams{'MONTH'} > $now[4] ) ) {
180 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 );
181 $date = "$longmonths[$cgiparams{'MONTH'}] $date, ". int($year-1);
183 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 );
184 $date = "$longmonths[$cgiparams{'MONTH'}] $date, $year";
187 # calculate end of active week (saturday 23H59)
189 @then = localtime(time());
190 my $sunday = POSIX
::mktime
( 0, 0, 0, $then[3], $then[4], $then[5]);
191 $sunday += (6-$then[6]) * 86400;
193 # Convert delta in second to full weeks
194 $gzindex = int (($sunday-$xday)/604800 );
197 my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
198 my $daystr = $cgiparams{'DAY'} == 0 ?
'..' : $cgiparams{'DAY'} <= 9 ?
" $cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
199 my $section = $sections{$cgiparams{'SECTION'}};
206 my $lastdatetime; # for debug
207 my $search_for_end = 0;
209 while ($gzindex >=0 && $loop) {
210 # calculate file name
212 $filestr = "/var/log/messages";
213 $filestr = "/var/log/mail" if (${section
} =~ 'dma');
215 $filestr = "/var/log/messages.$gzindex";
216 $filestr = "/var/log/mail.$gzindex" if (${section
} =~ 'dma');
217 $filestr = "$filestr.gz" if -f
"$filestr.gz";
219 # now read file if existing
220 if (open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr))) {
221 #&General::log("reading $filestr");
222 READ
:while (<FILE
>) {
224 if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w\-]+ ${section}(.*)/) {
225 # when standard viewing, just keep in memory the correct slice
226 # it starts a '$start' and size is $viewport
227 # If export, then keep all lines...
228 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'}){
229 $log[$lines++] = "$line";
231 if ($lines++ < ($start + $Header::viewsize
)) {
233 if (@log > $Header::viewsize
) {
236 #} else { don't do this optimisation, need to count lines !
237 # $datetime = $maxtime; # we have read viewsize lines, stop main loop
238 # last READ; # exit read file
241 $search_for_end = 1; # we find the start of slice, can look for end now
243 if ($search_for_end == 1) {
244 #finish read files when date is over (test month equality only)
245 $line =~ /^(...) (..) ..:..:..*$/;
246 $loop = 0 if ( ($1 ne $monthstr) || ( ($daystr ne '..') && ($daystr ne $2) ) );
252 $gzindex--; # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped
256 # $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
258 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'})
260 print "Content-type: text/plain\n\n";
261 print "IPFire diagnostics\r\n";
262 print "$Lang::tr{'section'}: $cgiparams{'SECTION'}\n";
263 print "$Lang::tr{'date'}: $date\r\n\r\n";
265 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
269 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
272 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
273 print "$time $3 $4\r\n";
278 &Header
::showhttpheaders
();
280 &Header
::openpage
($Lang::tr
{'system logs'}, 1, '');
282 &Header
::openbigbox
('100%', 'left', '', $errormessage);
285 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
286 print "<font class='base'>$errormessage </font>\n";
290 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}:");
293 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
296 <td width='10%' class='base'>$Lang::tr{'section'}: </td>
298 <select name='SECTION'>
301 foreach $section (sort {$trsections{$a} cmp $trsections{$b}} keys %sections) {
303 if ($section eq $cgiparams{'SECTION'}) {
304 print "selected='selected' "; }
305 print "value='$section'>$trsections{$section}</option>\n";
310 <td width='10%' class='base' align='right'>$Lang::tr{'month'}: </td>
312 <select name='MONTH'>
315 for (my $month = 0; $month < 12; $month++)
318 if ($month == $cgiparams{'MONTH'}) {
319 print "selected='selected' "; }
320 print "value='$month'>$longmonths[$month]</option>\n";
325 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
330 print "<option value='0'>$Lang::tr{'all'}</option>\n";
331 for (my $day = 1; $day <= 31; $day++)
334 if ($day == $cgiparams{'DAY'}) {
335 print "selected='selected' "; }
336 print "value='$day'>$day</option>\n";
341 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
342 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
343 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
344 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
353 &Header
::openbox
('100%', 'left', $Lang::tr
{'log'});
354 print "<p><b>$Lang::tr{'total hits for log section'} $cgiparams{'SECTION'} $date: $lines</b></p>";
356 $start = $lines - ${Header
::viewsize
} if ($start >= $lines - ${Header
::viewsize
});
357 $start = 0 if ($start < 0);
363 $prev = $start - ${Header
::viewsize
};
364 $prev = 0 if ( $prev < 0);
368 if ($start == $lines - ${Header
::viewsize
}) {
371 $next = $start + ${Header
::viewsize
};
372 $next = $lines - ${Header
::viewsize
} if ($next >= $lines - ${Header
::viewsize
});
375 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
376 if ($lines != 0) { &oldernewer
(); }
379 <table width='100%' class='tbl'>
381 <th width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></th>
382 <th width='15%' align='center' class='boldbase'><b>$Lang::tr{'section'}</b></th>
383 <th width='75%'> </th>
392 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
395 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
398 # correct the cut position, just when section=RED
399 if (($cgiparams{'SECTION'} eq 'red' ) && ($sec =~ /(kernel:)(.*)/)) {
401 $data = $2.': '.$data;
403 my $d = substr ($data,0,80);
404 while (length($data)>80){ #very basic breaking of lines...
405 $data = substr ($data,80); #permit correct display in table cell
406 $d .= ' ' . substr ($data,0,80);
412 $col="bgcolor='$color{'color20'}'"; }
415 $col="bgcolor='$color{'color22'}'"; }
416 print "<td $col>$time<td $col>$sec<td $col>" .&Header
::cleanhtml
("$d", 'y') . "</td></tr>\n";
426 &Header
::closebigbox
();
428 &Header
::closepage
();
438 print "<td align='center' width='50%'>";
440 print "<a href='/cgi-bin/logs.cgi/log.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'older'}</a>"; }
442 print "$Lang::tr{'older'}"; }
445 print "<td align='center' width='50%'>";
447 print "<a href='/cgi-bin/logs.cgi/log.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'newer'}</a>"; }
449 print "$Lang::tr{'newer'}"; }