chiark / gitweb /
suppress seconds and minutes units
[modbot-mtm.git] / xlog / bin / report
1 #!/usr/bin/perl -w
2
3 our ($ng,$staticfiles,@ARGV) = @ARGV;
4 chdir $ng or die $!;
5
6 use strict (qw(vars));
7 use IO::Handle;
8 use POSIX;
9 use CGI qw/:standard *table end_* -no_xhtml/;
10
11 our @lines= ();
12 our @s;
13 our $oddeven = "o";
14
15 our ($processline,$needmap);
16 our ($selectmid,$selectnum);
17
18 sub processlog ($$) {
19     my ($taccat, $fn)= @_;
20     open F, "$taccat $fn |" or die $!;
21     while (<F>) {
22         chomp;
23         @s= split /\t/;
24         push @s, '' if @s<=6;
25         $s[0]= strftime "%Y-%m-%d %H:%M %Z", localtime $s[0];
26         $s[0] =~ s/(\d+\:\d)\d/${1}x/;
27         &$processline();
28         $oddeven =~ y/oe/eo/;
29     }
30 }
31 sub processlogs ($) {
32     my ($taccat) = @_;
33     my (@logs) = qw(event.log.0 event.log);
34     @logs= reverse @logs if $taccat eq 'tac';
35     processlog($taccat, $_) foreach @logs;
36 }
37
38 sub processline_print () {
39     my @sp= @s;
40     $sp[3] =~ s/\@\w{0,2}/ at .. /;
41     @sp= map { escapeHTML($_) } @sp[0..5];
42     $sp[3] =~ s/&lt;/\<br>&lt;/;
43     $sp[2]=~s/\@/\@<span class='hole'><\/span>/;
44     my @spu= map {
45         s/\W/ sprintf "%%%02x", ord $& /ge;
46         $_;
47     } @s;
48     if (length $s[1] && length $s[2]) {
49         my $url= url().'/message/'.$spu[1].'/'.$spu[2];
50         foreach my $i (qw(1 2)) {
51             $sp[$i]= a({ href=>$url }, $sp[$i]."<br>" );
52         }
53     }
54     if (length $s[6]) {
55         $sp[5]= a({ href=>"$staticfiles/nr-$s[6].txt" }, $sp[5] );
56     }
57
58     print "<tr class='$oddeven'><td>$sp[0]</td>";
59     print "<td class='ref'>$sp[1] $sp[2]</td>";
60     print td([@sp[3..5]]),"</tr>\n";
61 }
62
63 sub processline_print_ifsingle () {
64     return unless $s[1] eq $selectnum
65                or $s[2] eq $selectmid;
66     processline_print();
67 }
68
69 our (%done_num,%done_id,%num2id,%id2num);
70 sub processline_queue_prescan () {
71     my ($num,$id,$e) = @s[1..2,5];
72     if (length $id and length $num) {
73         $id2num{$id}= $num;
74         $num2id{$num}= $id;
75     }
76     return unless $e =~ m/^decide reject discard|^notify reject|^post/;
77 #print STDERR "finishing $e $s[1] $s[2]\n";
78     $num= $id2num{$id} if !length $num;
79     $id= $num2id{$num} if !length $id;
80 #print STDERR "finishing $e $num $id\n";
81     $done_num{$num}++ if defined $num;
82     $done_id{$id}++ if defined $id;
83 }
84 sub processline_queue () {
85     return if $done_num{$s[1]};
86     return if $done_id{$s[2]};
87     processline_print();
88 }
89
90 my $pi= path_info();
91 our $title;
92
93 $needmap= 0;
94 $processline= \&processline_print;
95
96 if ($pi =~ m,^/message/(\d+)/(.*)$,) {
97     ($selectnum, $selectmid) = ($1,$2);
98     $title= "Single message ".escapeHTML($selectmid);
99     $processline= \&processline_print_ifsingle;
100 } elsif ($pi =~ m/^$/) {
101     $title= "Recent activity - $ng";
102 } elsif ($pi =~ m,^/queue,) {
103     $title= "Activity regarding still-queued messages";
104     $processline= \&processline_queue_prescan;
105     processlogs('cat');
106     $processline= \&processline_queue;
107 }
108
109 my $css=<<EOJ;
110 span.hole:before { content: " "; }
111 td.ref { font-size: 0.75em; }
112 tr.o { background: #ddddff; }
113 EOJ
114
115 print header(),
116   start_html(-title=>$title, -style=>{'-code'=>$css}),
117   h1($title), start_table();
118
119 print Tr(td([map { strong($_) } (qw(
120                                 Date
121                                 Reference/Message-ID
122                                 From
123                                 Subject
124                                 Event
125                             ))]));
126
127 processlogs('tac');
128
129 print end_table();
130 print p();
131
132 print a({ href=>url() }, "All recent activity"), '; ';
133 print a({ href=>url().'/queue' }, "Unfinished business");
134
135 print end_html();