chiark / gitweb /
Initial commit as found
[modbot-mtm.git] / xlog / bin / report
1 #!/usr/bin/perl -w
2
3 our ($ng,@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_*/;
10
11 our @lines= ();
12 our @s;
13
14 our ($processline,$needmap);
15 our ($selectmid,$selectnum);
16
17 sub processlog ($$) {
18     my ($taccat, $fn)= @_;
19     open F, "$taccat $fn |" or die $!;
20     while (<F>) {
21         chomp;
22         @s= split /\t/;
23         $s[0]= strftime "%Y-%m-%d %H:%M:%S %Z", localtime $s[0];
24         &$processline();
25     }
26 }
27 sub processlogs ($) {
28     my ($taccat) = @_;
29     my (@logs) = qw(event.log.0 event.log);
30     @logs= reverse @logs if $taccat eq 'tac';
31     processlog($taccat, $_) foreach @logs;
32 }
33
34 sub processline_print () {
35     my @sp= @s;
36     $sp[3] =~ s/\@\w{0,2}/ at .. /;
37     my @sp= map { escapeHTML($_) } @sp;
38     my @spu= map {
39         s/\W/ sprintf "%%%02x", ord $& /ge;
40         $_;
41     } @s;
42     if (length $s[1] && length $s[2]) {
43         my $url= url().'/message/'.$spu[1].'/'.$spu[2];
44         foreach my $i (qw(1 2)) {
45             $sp[$i]= a({ href=>$url }, $sp[$i] );
46         }
47     }
48 #print STDERR join('|',@sp),"\n";
49     print Tr(td([@sp]));
50 }
51
52 sub processline_print_ifsingle () {
53     return unless $s[1] eq $selectnum
54                or $s[2] eq $selectmid;
55     processline_print();
56 }
57
58 our (%done_num,%done_id,%num2id,%id2num);
59 sub processline_queue_prescan () {
60     my ($num,$id,$e) = @s[1..2,5];
61     if (length $id and length $num) {
62         $id2num{$id}= $num;
63         $num2id{$num}= $id;
64     }
65     return unless $e =~ m/^decide reject discard|^notify reject|^post/;
66 #print STDERR "finishing $e $s[1] $s[2]\n";
67     $num= $id2num{$id} if !length $num;
68     $id= $num2id{$num} if !length $id;
69 #print STDERR "finishing $e $num $id\n";
70     $done_num{$num}++ if defined $num;
71     $done_id{$id}++ if defined $id;
72 }
73 sub processline_queue () {
74     return if $done_num{$s[1]};
75     return if $done_id{$s[2]};
76     processline_print();
77 }
78
79 my $pi= path_info();
80 our $title;
81
82 $needmap= 0;
83 $processline= \&processline_print;
84
85 if ($pi =~ m,^/message/(\d+)/(.*)$,) {
86     ($selectnum, $selectmid) = ($1,$2);
87     $title= "Single message ".escapeHTML($selectmid);
88     $processline= \&processline_print_ifsingle;
89 } elsif ($pi =~ m/^$/) {
90     $title= "Recent activity";
91 } elsif ($pi =~ m,^/queue,) {
92     $title= "Activity regarding still-queued messages";
93     $processline= \&processline_queue_prescan;
94     processlogs('cat');
95     $processline= \&processline_queue;
96 }
97
98 print header(), start_html($title), h1($title), table();
99
100 print Tr(td([map { strong($_) } (qw(
101                                 Date
102                                 Reference
103                                 Message-ID
104                                 From
105                                 Subject
106                                 Event
107                             ))]));
108
109 processlogs('tac');
110
111 print end_table();
112 print p();
113
114 print a({ href=>url() }, "All recent activity"), '; ';
115 print a({ href=>url().'/queue' }, "Unfinished business");
116
117 print end_html();