3 # Run calamaris on the squid logfile(s)
5 require './squid-lib.pl';
6 $access{'calamaris'} || &error($text{'calamaris_ecannot'});
7 &ui_print_header(undef, $text{'calamaris_title'}, "");
9 # is calamaris installed?
10 if (!&has_command($config{'calamaris'})) {
11 print &text('calamaris_eprog', "<tt>$config{'calamaris'}</tt>",
12 "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
13 &ui_print_footer("", $text{'index_return'});
17 # Work out Calamaris version and args
18 if (`$config{'calamaris'} -V 2>&1` =~ /(revision:|Calamaris)\s+(\d\S+)/i) {
21 $args = $config{'cal_all'} ? " -a" : "";
23 if ($config{'cal_fmt'} eq 'w') {
31 $args .= " -".$config{'cal_fmt'};
33 $args .= " $config{'cal_extra'}";
35 # are there any logfiles to analyse?
36 $ld = $config{'log_dir'};
38 while($f = readdir(DIR)) {
39 local @st = stat("$ld/$f");
40 if ($f =~ /^access.log.*gz$/) {
41 push(@files, [ "gunzip -c $ld/$f |", $st[9] ]);
43 elsif ($f =~ /^access.log.*Z$/) {
44 push(@files, [ "uncompress -c $ld/$f |", $st[9] ]);
46 elsif ($f =~ /^access.log/) {
47 push(@files, [ "$ld/$f", $st[9] ]);
52 print &text('calamaris_elogs', "<tt>$ld</tt>",
53 "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
54 &ui_print_footer("", $text{'index_return'});
58 # run calamaris, parsing newest files and records first
60 open(CAL, "| $config{'calamaris'} $args >$temp 2>/dev/null");
61 if ($config{'cal_max'}) {
62 # read only the last N lines
63 print &text('calamaris_last', $config{'cal_max'}),"<p>\n";
64 @files = sort { $b->[1] <=> $a->[1] } @files;
67 $left = $config{'cal_max'} - $lnum;
69 if ($f->[0] =~ /\|$/) {
70 open(LOG, "$f->[0] tail -$left |");
73 open(LOG, "tail -$left $f->[0] |");
83 # read all the log files
86 while(read(LOG, $buf, 1024) > 0) {
94 # Put the calamaris output into a nice webmin like table.
95 $date = &make_date(time());
96 print &ui_table_start(&text('calamaris_gen', $date), undef, 2);
100 if ($config{'cal_fmt'} eq 'm') {
103 $html .= &html_escape($_);
109 if (/<\s*\/head/i || /<\s*body/i) { $inbody = 1; }
110 elsif (/<\s*\/body/i) { $inbody = 0; }
111 elsif ($inbody) { $html .= $_; }
118 print &ui_table_row(undef, $html, 2);
119 print &ui_table_end();
121 &ui_print_footer("", $text{'index_return'});