chiark / gitweb /
Do not XMLishly autoclose the log table
[modbot-ulm.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_*/;
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     @sp= map { escapeHTML($_) } @sp[0..5];
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     if (length $s[6]) {
49         $sp[5]= a({ href=>"$staticfiles/nr-$s[6].txt" }, $sp[5] );
50     }
51 #print STDERR join('|',@sp),"\n";
52     print Tr(td([@sp]));
53 }
54
55 sub processline_print_ifsingle () {
56     return unless $s[1] eq $selectnum
57                or $s[2] eq $selectmid;
58     processline_print();
59 }
60
61 our (%done_num,%done_id,%num2id,%id2num);
62 sub processline_queue_prescan () {
63     my ($num,$id,$e) = @s[1..2,5];
64     if (length $id and length $num) {
65         $id2num{$id}= $num;
66         $num2id{$num}= $id;
67     }
68     return unless $e =~ m/^decide reject discard|^notify reject|^post/;
69 #print STDERR "finishing $e $s[1] $s[2]\n";
70     $num= $id2num{$id} if !length $num;
71     $id= $num2id{$num} if !length $id;
72 #print STDERR "finishing $e $num $id\n";
73     $done_num{$num}++ if defined $num;
74     $done_id{$id}++ if defined $id;
75 }
76 sub processline_queue () {
77     return if $done_num{$s[1]};
78     return if $done_id{$s[2]};
79     processline_print();
80 }
81
82 my $pi= path_info();
83 our $title;
84
85 $needmap= 0;
86 $processline= \&processline_print;
87
88 if ($pi =~ m,^/message/(\d+)/(.*)$,) {
89     ($selectnum, $selectmid) = ($1,$2);
90     $title= "Single message ".escapeHTML($selectmid);
91     $processline= \&processline_print_ifsingle;
92 } elsif ($pi =~ m/^$/) {
93     $title= "Recent activity - $ng";
94 } elsif ($pi =~ m,^/queue,) {
95     $title= "Activity regarding still-queued messages";
96     $processline= \&processline_queue_prescan;
97     processlogs('cat');
98     $processline= \&processline_queue;
99 }
100
101 print header(), start_html($title), h1($title), start_table();
102
103 print Tr(td([map { strong($_) } (qw(
104                                 Date
105                                 Reference
106                                 Message-ID
107                                 From
108                                 Subject
109                                 Event
110                             ))]));
111
112 processlogs('tac');
113
114 print end_table();
115 print p();
116
117 print a({ href=>url() }, "All recent activity"), '; ';
118 print a({ href=>url().'/queue' }, "Unfinished business");
119
120 print end_html();