]>
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/ipfire/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 'monit' => '(monit\[.*\]: )',
66 'ntp' => '(ntpd(?:ate)?\[.*\]: )',
67 'oinkmaster' => '(oinkmaster\[.*\]: )',
68 'openvpn' => '(openvpnserver\[.*\]: |.*n2n\[.*\]: )',
69 'pakfire' => '(pakfire:)',
70 'red' => '(red:|pppd\[.*\]: |chat\[.*\]|pppoe\[.*\]|pptp\[.*\]|pppoa\[.*\]|pppoa3\[.*\]|pppoeci\[.*\]|ipppd|ipppd\[.*\]|kernel: ippp\d|kernel: isdn.*|ibod\[.*\]|dhcpcd\[.*\]|modem_run\[.*\])',
71 'samba' => '(nmbd|smbd|winbind)\[\d+\]:',
72 'suricata' => '(suricata: )',
73 'squid' => '(squid\[.*\]: |squid: )',
74 'ssh' => '(sshd(?:\(.*\))?\[.*\]: )',
75 'unbound' => '(unbound: \[.*:.*\])(.*:.*$)',
76 'urlfilter bl' => '(installpackage\[urlfilter\]: )',
77 'wireless' => '(hostapd:|kernel: ath.*:|kernel: wifi[0-9]:)'
80 # Translations for the %sections array.
82 'auth' => "$Lang::tr{'loginlogout'}",
83 'wio' => 'Who Is Online?',
84 'captive' => $Lang::tr
{'Captive'},
86 'collectd' => 'Collectd',
88 'ddns' => "$Lang::tr{'dynamic dns'}",
89 'dhcp' => "$Lang::tr{'dhcp server'}",
91 'guardian' => "$Lang::tr{'guardian'}",
94 'kernel' => "$Lang::tr{'kernel'}",
97 'oinkmaster' => 'Oinkmaster',
98 'openvpn' => 'OpenVPN',
99 'pakfire' => 'Pakfire',
101 'samba' => $Lang::tr
{'samba'},
102 'suricata' => "$Lang::tr{'intrusion detection'}",
103 'squid' => "$Lang::tr{'web proxy'}",
105 'unbound' => 'DNS: Unbound',
106 'urlfilter bl' => 'URLFilter Blacklist',
107 'wireless' => 'Wireless'
111 &Header
::getcgihash
(\
%cgiparams);
112 $logsettings{'LOGVIEW_REVERSE'} = 'off';
113 &General
::readhash
("${General::swroot}/logging/settings", \
%logsettings);
114 ${Header
::viewsize
} = defined ($logsettings{'LOGVIEW_VIEWSIZE'}) ?
$logsettings{'LOGVIEW_VIEWSIZE'} : 150;
116 my $start = ($logsettings{'LOGVIEW_REVERSE'} eq 'on') ?
0x7FFFF000 : 0; #index of firts line number to display
118 if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr
{'update'})
120 my @temp = split(',',$ENV{'QUERY_STRING'});
122 $cgiparams{'MONTH'} = $temp[1];
123 $cgiparams{'DAY'} = $temp[2];
124 $cgiparams{'SECTION'} = $temp[3];
127 if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
128 !($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)$/))
130 $cgiparams{'DAY'} = $now[3];
131 $cgiparams{'MONTH'} = $now[4];
133 elsif($cgiparams{'ACTION'} eq '>>')
136 my @temp_now = localtime(time);
137 $temp_now[4] = $cgiparams{'MONTH'};
138 $temp_now[3] = $cgiparams{'DAY'};
139 if ($cgiparams{'DAY'}) {
140 @temp_then = localtime(POSIX
::mktime
(@temp_now) + 86400);
141 ## Retrieve the same time on the next day +
142 ## 86400 seconds in a day
145 $temp_now[4] = ($temp_now[4]+1) %12;
146 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
149 $cgiparams{'MONTH'} = $temp_then[4];
150 $cgiparams{'DAY'} = $temp_then[3];
152 elsif($cgiparams{'ACTION'} eq '<<')
155 my @temp_now = localtime(time);
156 $temp_now[4] = $cgiparams{'MONTH'};
157 $temp_now[3] = $cgiparams{'DAY'};
158 if ($cgiparams{'DAY'}) {
159 @temp_then = localtime(POSIX
::mktime
(@temp_now) - 86400);
160 ## Retrieve the same time on the next day -
161 ## 86400 seconds in a day
164 $temp_now[4] = ($temp_now[4]-1) %12;
165 @temp_then = localtime(POSIX
::mktime
(@temp_now) );
168 $cgiparams{'MONTH'} = $temp_then[4];
169 $cgiparams{'DAY'} = $temp_then[3];
172 # Find in which file.gz is the log. Can be calculated because WEEKLY ROTATING of access.log
174 my $date = $cgiparams{'DAY'} == 0 ?
'' : $cgiparams{'DAY'} <= 9 ?
"0$cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
179 # Calculate time. If future date, calculate for past year !!!
180 if (( $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
181 ( $cgiparams{'MONTH'} > $now[4] ) ) {
182 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 );
183 $date = "$longmonths[$cgiparams{'MONTH'}] $date, ". int($year-1);
185 $xday = POSIX
::mktime
( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 );
186 $date = "$longmonths[$cgiparams{'MONTH'}] $date, $year";
189 # calculate end of active week (saturday 23H59)
191 @then = localtime(time());
192 my $sunday = POSIX
::mktime
( 0, 0, 0, $then[3], $then[4], $then[5]);
193 $sunday += (6-$then[6]) * 86400;
195 # Convert delta in second to full weeks
196 $gzindex = int (($sunday-$xday)/604800 );
199 my $monthstr = $shortmonths[$cgiparams{'MONTH'}];
200 my $daystr = $cgiparams{'DAY'} == 0 ?
'..' : $cgiparams{'DAY'} <= 9 ?
" $cgiparams{'DAY'}" : "$cgiparams{'DAY'}";
201 my $section = $sections{$cgiparams{'SECTION'}};
208 my $lastdatetime; # for debug
209 my $search_for_end = 0;
211 while ($gzindex >=0 && $loop) {
212 # calculate file name
214 $filestr = "/var/log/messages";
215 $filestr = "/var/log/mail" if (${section
} =~ 'dma');
217 $filestr = "/var/log/messages.$gzindex";
218 $filestr = "/var/log/mail.$gzindex" if (${section
} =~ 'dma');
219 $filestr = "$filestr.gz" if -f
"$filestr.gz";
221 # now read file if existing
222 if (open (FILE
,($filestr =~ /.gz$/ ?
"gzip -dc $filestr |" : $filestr))) {
223 #&General::log("reading $filestr");
224 READ
:while (<FILE
>) {
226 if ($line =~ /^${monthstr} ${daystr} ..:..:.. [\w\-]+ ${section}(.*)/) {
227 # when standard viewing, just keep in memory the correct slice
228 # it starts a '$start' and size is $viewport
229 # If export, then keep all lines...
230 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'}){
231 $log[$lines++] = "$line";
233 if ($lines++ < ($start + $Header::viewsize
)) {
235 if (@log > $Header::viewsize
) {
238 #} else { don't do this optimisation, need to count lines !
239 # $datetime = $maxtime; # we have read viewsize lines, stop main loop
240 # last READ; # exit read file
243 $search_for_end = 1; # we find the start of slice, can look for end now
245 if ($search_for_end == 1) {
246 #finish read files when date is over (test month equality only)
247 $line =~ /^(...) (..) ..:..:..*$/;
248 $loop = 0 if ( ($1 ne $monthstr) || ( ($daystr ne '..') && ($daystr ne $2) ) );
254 $gzindex--; # will try next gz file eg 40,39,38,.... because it may have holes when ipcop stopped
258 # $errormessage = "$Lang::tr{'date not in logs'}: $filestr $Lang::tr{'could not be opened'}";
260 if ($cgiparams{'ACTION'} eq $Lang::tr
{'export'})
262 print "Content-type: text/plain\n\n";
263 print "IPFire diagnostics\r\n";
264 print "$Lang::tr{'section'}: $cgiparams{'SECTION'}\n";
265 print "$Lang::tr{'date'}: $date\r\n\r\n";
267 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
271 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
274 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
275 print "$time $3 $4\r\n";
280 &Header
::showhttpheaders
();
282 &Header
::openpage
($Lang::tr
{'system logs'}, 1, '');
284 &Header
::openbigbox
('100%', 'left', '', $errormessage);
287 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
288 print "<font class='base'>$errormessage </font>\n";
292 &Header
::openbox
('100%', 'left', "$Lang::tr{'settings'}:");
295 <form method='post' action='$ENV{'SCRIPT_NAME'}'>
298 <td width='10%' class='base'>$Lang::tr{'section'}: </td>
300 <select name='SECTION'>
303 foreach $section (sort {$trsections{$a} cmp $trsections{$b}} keys %sections) {
305 if ($section eq $cgiparams{'SECTION'}) {
306 print "selected='selected' "; }
307 print "value='$section'>$trsections{$section}</option>\n";
312 <td width='10%' class='base' align='right'>$Lang::tr{'month'}: </td>
314 <select name='MONTH'>
317 for (my $month = 0; $month < 12; $month++)
320 if ($month == $cgiparams{'MONTH'}) {
321 print "selected='selected' "; }
322 print "value='$month'>$longmonths[$month]</option>\n";
327 <td width='10%' class='base' align='right'> $Lang::tr{'day'}: </td>
332 print "<option value='0'>$Lang::tr{'all'}</option>\n";
333 for (my $day = 1; $day <= 31; $day++)
336 if ($day == $cgiparams{'DAY'}) {
337 print "selected='selected' "; }
338 print "value='$day'>$day</option>\n";
343 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='<<' /></td>
344 <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='>>' /></td>
345 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
346 <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
355 &Header
::openbox
('100%', 'left', $Lang::tr
{'log'});
356 print "<p><b>$Lang::tr{'total hits for log section'} $cgiparams{'SECTION'} $date: $lines</b></p>";
358 $start = $lines - ${Header
::viewsize
} if ($start >= $lines - ${Header
::viewsize
});
359 $start = 0 if ($start < 0);
365 $prev = $start - ${Header
::viewsize
};
366 $prev = 0 if ( $prev < 0);
370 if ($start == $lines - ${Header
::viewsize
}) {
373 $next = $start + ${Header
::viewsize
};
374 $next = $lines - ${Header
::viewsize
} if ($next >= $lines - ${Header
::viewsize
});
377 if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
378 if ($lines != 0) { &oldernewer
(); }
381 <table width='100%' class='tbl'>
383 <th width='10%' align='center' class='boldbase'><b>$Lang::tr{'time'}</b></th>
384 <th width='15%' align='center' class='boldbase'><b>$Lang::tr{'section'}</b></th>
385 <th width='75%'> </th>
394 /^... (..) (..:..:..) [\w\-]+ ${section}(.*)$/;
397 my $time = $cgiparams{'DAY'} ?
"$2" : "$day/$2" ;
400 # correct the cut position, just when section=RED
401 if (($cgiparams{'SECTION'} eq 'red' ) && ($sec =~ /(kernel:)(.*)/)) {
403 $data = $2.': '.$data;
405 my $d = substr ($data,0,80);
406 while (length($data)>80){ #very basic breaking of lines...
407 $data = substr ($data,80); #permit correct display in table cell
408 $d .= ' ' . substr ($data,0,80);
414 $col="bgcolor='$color{'color20'}'"; }
417 $col="bgcolor='$color{'color22'}'"; }
418 print "<td $col>$time<td $col>$sec<td $col>" .&Header
::cleanhtml
("$d", 'y') . "</td></tr>\n";
428 &Header
::closebigbox
();
430 &Header
::closepage
();
440 print "<td align='center' width='50%'>";
442 print "<a href='/cgi-bin/logs.cgi/log.dat?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'older'}</a>"; }
444 print "$Lang::tr{'older'}"; }
447 print "<td align='center' width='50%'>";
449 print "<a href='/cgi-bin/logs.cgi/log.dat?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'SECTION'}'>$Lang::tr{'newer'}</a>"; }
451 print "$Lang::tr{'newer'}"; }