chiark / gitweb /
default option on one-article screen is back of queue
[modbot-mtm.git] / webstump / scripts / html_output.pl
index 59a6423de6674f7aca397a73b28a386225296980..5503b4ae6104a3566e993c03f5ad1f69b87c9281 100644 (file)
@@ -7,6 +7,7 @@
 #
 
 use POSIX;
+use CGI qw/escapeHTML/;
 
 sub begin_html {
   my $title = pop( @_ );
@@ -246,7 +247,7 @@ sub html_moderate_article {
   &html_print_credentials;
   print "<SELECT NAME=\"decision_$file\">
 <OPTION VALUE=\"approve\">Approve</OPTION>
-<OPTION VALUE=\"leave\">Put to back of queue</OPTION>
+<OPTION VALUE=\"leave\" SELECTED>Put to back of queue</OPTION>
 <OPTION VALUE=\"consider\">Back of queue, adding mark requesting further consideration</OPTION>
 ";
 
@@ -612,7 +613,7 @@ No articles present in the queue
   print "<FORM METHOD=$request_method action=$base_address>";
   &html_print_credentials;
   print "<INPUT NAME=action VALUE=moderator_admin TYPE=hidden>
-         <INPUT TYPE=submit VALUE=\"Manage pass/grey/block-lists\">
+         <INPUT TYPE=submit VALUE=\"Management\">
          </FORM>";
 
   &end_html;
@@ -630,6 +631,102 @@ sub html_print_credentials {
  <INPUT NAME=password VALUE=\"$password\" TYPE=hidden>\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 (<LOGFILE>) {
+            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 "<h2>Complete log download</h2>\n";
+      $min= 2;
+  } elsif ($request{'messagenum'} =~ m/^\s*(\d+)\s*$/) {
+      $reqnum= $1;
+      $forwards= -1;
+      $min= 1;
+      print "<h2>Log entry for single message $reqnum</h2>\n";
+  } else {
+      print "<h2>Log lookup - bad reference</h2>
+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].<p>
+        ";
+      &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,$timet) = @vals;
+      my $date= $timet ? (strftime "%Y-%m-%d %H:%M:%S GMT", gmtime $timet)
+          : "(unknown)";
+      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 "<table rules=all><tr><th>Date<th>Reference<th>Disposal<th>Reason</tr>\n"
+          unless $sofar;
+      print "<tr>", (map { "<td>".escapeHTML($_) }
+                     $date,$treqnum,$act,$reason);
+      print "</tr>\n";
+      return defined($reqnum) ? 2 : 1;
+  });
+  if ($sofar) {
+      print "</table>" if $sofar;
+      print "\n";
+  } else {
+      print "Reference not found.".
+          "  (Perhaps message has expired, or is still in the queue?)";
+  }
+  &end_html;
+}
+
 # newsgroup admin page
 sub html_newsgroup_management {
   &begin_html( "Administer $request{'newsgroup'}" );
@@ -681,8 +778,29 @@ sub html_newsgroup_management {
 
   &link_to_help( "filter-lists", "filtering lists" );
 
+  print "</FORM><HR>";
+
+  if ($mod_log_access) {
+      print "<form>
+        Use this form to search logs of past moderation decisions:
+        <br>
+        <form method=$request_method action=$base_address>
+        <input name=action value=search_logs type=hidden>";
+
+      &html_print_credentials;
+
+      print "
+        Reference number: <input name=messagenum size=30>
+        <input type=submit value=\"Lookup\">";
+
+      print "
+        <input type=submit value=\"Download all logs\" name=\"download_logs\">"
+        if $mod_log_access >= 2;
+
+      print "</form><hr>\n";
+  }
+
   print "
-  </FORM><HR>
 
   List of current moderators:<P>