From d9e7c7c5f01238a8a97cc547879f15fa0753ac18 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 20 Apr 2010 17:54:30 +0100 Subject: [PATCH] Support querying and downloading of decision reasons by moderators --- get-settings | 4 +- webstump/scripts/html_output.pl | 118 ++++++++++++++++++++++++++++++- webstump/scripts/webstump.lib.pl | 3 + 3 files changed, 122 insertions(+), 3 deletions(-) diff --git a/get-settings b/get-settings index 5c71c46..746a2e1 100644 --- a/get-settings +++ b/get-settings @@ -5,10 +5,12 @@ pas="$paskeys" for k in $pas; do eval "$k=''"; export $k; done DIVERTPOSTINGS='' +MODLOGSEARCH=false +MODLOGDOWNLOAD=false . settings export GROUP ABBREV INFOHEADER MODEMAIL GROUPURL REJECTIONSLIST -export DIVERTPOSTINGS +export DIVERTPOSTINGS MODLOGSEARCH MODLOGDOWNLOAD . ../global-settings export ROOTBASEDIR CGIBASEURL DOMAIN SLIMYDOMAIN OURUSER ADMIN diff --git a/webstump/scripts/html_output.pl b/webstump/scripts/html_output.pl index 59a6423..aca0509 100644 --- a/webstump/scripts/html_output.pl +++ b/webstump/scripts/html_output.pl @@ -7,6 +7,7 @@ # use POSIX; +use CGI qw/escapeHTML/; sub begin_html { my $title = pop( @_ ); @@ -612,7 +613,7 @@ No articles present in the queue print "
"; &html_print_credentials; print " - +
"; &end_html; @@ -630,6 +631,98 @@ sub html_print_credentials { \n"; } +# logs + +sub scanlogs ($$$) { + my ($forwards, $gotr, $callback) = @_; + my $dir= "$webstump_home/.."; + opendir LOGSDIR, "$dir" or die "$dir $!"; + my $num= sub { + local ($_) = @_; + return $forwards * ( + m/^errs$/ ? -1 : + m/^errs\.(\d+)(?:\.gz$)$/ ? $1 : + undef + ); + }; + foreach my $leaf ( + sort { $num->($a) <=> $num->($b) } + grep { defined $num->($_) } + readdir LOGSDIR + ) { + my $file= "$dir/$leaf"; + if ($file =~ m/\.gz$/) { + open LOGFILE, "zcat $file |" or die "zcat $file $!"; + } else { + open LOGFILE, "< $file" or die "$file $!"; + } + while () { + my $tgot= $callback->(); + next unless $tgot; + $$gotr= $tgot if $tgot > $$gotr; + last if $tgot > 1; + } + $!=0; $?=0; close LOGFILE or die "$file $? $!"; + last if $$gotr > 1; + } + closedir LOGSDIR or die "$dir $!"; +} + +sub html_search_logs { + &begin_html("Search logs for $request{'newsgroup'}"); + my $reqnum; + my $forwards=1; + my $min= 9; + if ($request{'download_logs'}) { + print "

Complete log download

\n"; + $min= 2; + } elsif ($request{'messagenum'} =~ m/^(\d+)$/) { + $reqnum= $1; + $forwards= -1; + $min= 1; + print "

Log entry for single message $reqnum

\n"; + } else { + print "

Log lookup - bad reference

+Please supply the numerical reference as found in the \"recent activity\" +log or message headers. Reference numbers consist entirely of digits, +and are often quoted in message headers in [square brackets].

+ "; + &end_html; + return; + } + if ($mod_log_access < $min) { + print "Not permitted [$mod_log_access<$min]. Consult administrator.\n"; + &end_html; + return; + } + + my $sofar= 0; + &scanlogs($forwards, \$sofar, sub { + return 0 unless chomp; + return 0 unless m/^DECISION: /; + my @vals = split / \| /, $'; + return 0 unless @vals >= 5; + my $subj= pop @vals; + my ($group,$dir,$act,$reason) = @vals; + return 0 unless $group eq $request{'newsgroup'}; + return 0 unless $subj =~ m,/(\d+)$,; + my $treqnum= $1; + return 0 if defined($reqnum) and $treqnum ne $reqnum; + print "\n" + unless $sofar; + print "", (map { "\n"; + return defined($reqnum) ? 2 : 1; + }); + if ($sofar) { + print "
ReferenceDisposalReason
".escapeHTML($_) } $treqnum,$act,$reason); + print "
" if $sofar; + print "\n"; + } else { + print "Reference not found."; + } + &end_html; +} + # newsgroup admin page sub html_newsgroup_management { &begin_html( "Administer $request{'newsgroup'}" ); @@ -681,8 +774,29 @@ sub html_newsgroup_management { &link_to_help( "filter-lists", "filtering lists" ); + print "


"; + + if ($mod_log_access) { + print "
+ Use this form to search logs of past moderation decisions: +
+ + "; + + &html_print_credentials; + + print " + Reference number: + "; + + print " + " + if $mod_log_access >= 2; + + print "

\n"; + } + print " -
List of current moderators:

diff --git a/webstump/scripts/webstump.lib.pl b/webstump/scripts/webstump.lib.pl index e19be93..3e9e0ef 100644 --- a/webstump/scripts/webstump.lib.pl +++ b/webstump/scripts/webstump.lib.pl @@ -712,6 +712,9 @@ sub processWebRequest { } elsif( $action eq "change_password" ) { &authenticate( $newsgroup, $moderator, $password ); &html_change_password; + } elsif( $action eq "search_logs" ) { + &authenticate( $newsgroup, $moderator, $password ); + &html_search_logs; } elsif( $action eq "validate_change_password" ) { &authenticate( $newsgroup, $moderator, $password ); &validate_change_password; -- 2.30.2