chiark / gitweb /
default option on one-article screen is back of queue
[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:%S %Z", localtime $s[0];
26         &$processline();
27         $oddeven =~ y/oe/eo/;
28     }
29 }
30 sub processlogs ($) {
31     my ($taccat) = @_;
32     my (@logs) = qw(event.log.0 event.log);
33     @logs= reverse @logs if $taccat eq 'tac';
34     processlog($taccat, $_) foreach @logs;
35 }
36
37 sub processline_print () {
38     my @sp= @s;
39     $sp[3] =~ s/\@\w{0,2}/ at .. /;
40     @sp= map { escapeHTML($_) } @sp[0..5];
41     $sp[3] =~ s/&lt;/\<br>&lt;/;
42     $sp[2]=~s/\@/\@<span class='hole'><\/span>/;
43     my @spu= map {
44         s/\W/ sprintf "%%%02x", ord $& /ge;
45         $_;
46     } @s;
47     if (length $s[1] && length $s[2]) {
48         my $url= url().'/message/'.$spu[1].'/'.$spu[2];
49         foreach my $i (qw(1 2)) {
50             $sp[$i]= a({ href=>$url }, $sp[$i]."<br>" );
51         }
52     }
53     if (length $s[6]) {
54         $sp[5]= a({ href=>"$staticfiles/nr-$s[6].txt" }, $sp[5] );
55     }
56
57     print "<tr class='$oddeven'><td>$sp[0]</td>";
58     print "<td class='ref'>$sp[1] $sp[2]</td>";
59     print td([@sp[3..5]]),"</tr>\n";
60 }
61
62 sub processline_print_ifsingle () {
63     return unless $s[1] eq $selectnum
64                or $s[2] eq $selectmid;
65     processline_print();
66 }
67
68 our (%done_num,%done_id,%num2id,%id2num);
69 sub processline_queue_prescan () {
70     my ($num,$id,$e) = @s[1..2,5];
71     if (length $id and length $num) {
72         $id2num{$id}= $num;
73         $num2id{$num}= $id;
74     }
75     return unless $e =~ m/^decide reject discard|^notify reject|^post/;
76 #print STDERR "finishing $e $s[1] $s[2]\n";
77     $num= $id2num{$id} if !length $num;
78     $id= $num2id{$num} if !length $id;
79 #print STDERR "finishing $e $num $id\n";
80     $done_num{$num}++ if defined $num;
81     $done_id{$id}++ if defined $id;
82 }
83 sub processline_queue () {
84     return if $done_num{$s[1]};
85     return if $done_id{$s[2]};
86     processline_print();
87 }
88
89 my $pi= path_info();
90 our $title;
91
92 $needmap= 0;
93 $processline= \&processline_print;
94
95 if ($pi =~ m,^/message/(\d+)/(.*)$,) {
96     ($selectnum, $selectmid) = ($1,$2);
97     $title= "Single message ".escapeHTML($selectmid);
98     $processline= \&processline_print_ifsingle;
99 } elsif ($pi =~ m/^$/) {
100     $title= "Recent activity - $ng";
101 } elsif ($pi =~ m,^/queue,) {
102     $title= "Activity regarding still-queued messages";
103     $processline= \&processline_queue_prescan;
104     processlogs('cat');
105     $processline= \&processline_queue;
106 }
107
108 my $css=<<EOJ;
109 span.hole:before { content: " "; }
110 td.ref { font-size: 0.75em; }
111 tr.o { background: #ddddff; }
112 EOJ
113
114 print header(),
115   start_html(-title=>$title, -style=>{'-code'=>$css}),
116   h1($title), start_table();
117
118 print Tr(td([map { strong($_) } (qw(
119                                 Date
120                                 Reference/Message-ID
121                                 From
122                                 Subject
123                                 Event
124                             ))]));
125
126 processlogs('tac');
127
128 print end_table();
129 print p();
130
131 print a({ href=>url() }, "All recent activity"), '; ';
132 print a({ href=>url().'/queue' }, "Unfinished business");
133
134 print end_html();