chiark / gitweb /
Remove options to add subjects, words, posters to any of the following
[modbot-uram.git] / webstump / scripts / html_output.pl
1 #
2 # This is a module with functions for HTML output.
3 #
4 # I separate it from the main STUMP stuff because these functions are
5 # bulky and not very interesting.
6 #
7 #
8
9 use POSIX;
10 use CGI qw/escapeHTML/;
11
12 sub begin_html {
13   my $title = pop( @_ );
14   print 
15 "Content-Type: text/html\n\n
16 <TITLE>$title</TITLE>
17 <BODY>
18 <H1>$title</H1>\n\n";
19
20   if( &is_demo_mode ) {
21     print "<B> You are operating in demonstration mode. User actions will have no effect.</B><HR>\n";
22   }
23   
24 }
25
26 sub end_html {
27   print "\n<HR>Thank you for using <A HREF=$STUMP_URL>STUMP Robomoderator</A>.
28 <!-- <BR>
29 Click <A HREF=$base_address>here</A> to return to WebSTUMP. -->
30 ";
31 }
32
33 # prints a link to help
34 # accepts topic id and topic name.
35 #
36 sub link_to_help {
37   my $topic_name = pop( @_ );
38   my $topic = pop( @_ );
39
40   #&print_image( "help.gif", "" );
41
42   print "<A HREF=$base_address?action=help&topic=$topic TARGET=new>Click here for help on $topic_name</A>\n";
43 }
44
45 #
46 # prints image and an alt text
47 #
48 sub print_image { # image_file, alt_text
49   my $alt = pop( @_ );
50   my $file = pop( @_ );
51
52   print "<IMG SRC=$base_address_for_files/images/$file ALT=\"$alt\" ALIGN=BOTTOMP>\n";
53 }
54
55 # prints the welcome page and login screen.
56 sub html_welcome_page {
57   &begin_html( "Welcome to WebSTUMP" );
58
59   print 
60
61 "Welcome to WebSTUMP, the moderators' front end for <A
62 HREF=http://www.algebra.com/~ichudov/stump>STUMP</A> users -- USENET newsgroup
63 moderators. Only authorized users are allowed to log into this
64 program.
65
66 <HR>";
67
68   my $motd_file = "$webstump_home/config/motd";
69
70   if( -f $motd_file && -r $motd_file ){
71     open( MOTD, $motd_file );
72     print "<B>Message of the Day:</B><BR><PRE>\n";
73     print while( <MOTD> );
74     close( MOTD );
75     print "</PRE><HR>\n";
76   }
77
78   print "
79 Newsgroups Status:<BR>
80 <TABLE BORDER=3>\n";
81
82   for( sort @newsgroups_array ) {
83     print "<TR><TD>";
84     
85     my $count = &get_article_count( $_ );
86
87     print " <A HREF=$base_address?action=login_screen\&newsgroup=$_>$_</A>";
88     &print_image( "smiley.gif", "" ) if $count;
89     print "</TD>";
90
91
92     print "<TD>$count messages in queue<BR></TD>";
93 #    print "<TD><A HREF=$base_address?action=init_request_newsgroup_creation\&newsgroup=$_>Request creation</A></TD>\n";
94   }
95
96   print "</TABLE>\n";
97   print "<HR>Note: click on the newsgroup to login in as moderator. 
98 <!-- Click on 'Request Creation' to ask a sysadmin at a specific domain
99 to carry your newsgroup. -->\n<HR>
100 <A HREF=$base_address?action=admin_login>Click here to administer this WebSTUMP installation</A>
101 ";
102   &end_html;
103 }
104
105 # prints the login screen for newsgroup.
106 sub html_login_screen {
107   my $newsgroup = $request{'newsgroup'} || &error( "newsgroup not defined" );
108
109   my $count = &get_article_count( $newsgroup );
110
111
112   if( $count ) {
113     &begin_html( "$count articles in queue for $newsgroup" );
114   } else {
115     &begin_html( "Empty Queue for $newsgroup" );
116   }
117
118   print
119 " Welcome to the Moderation  Center for  $newsgroup. Please bookmark
120 this page. <HR>";
121
122
123   my $color = "", $end_color = "";
124
125   if( $count ) {
126     $color = "<font color=red>";
127     $end_color = "<font color=black>";
128   }
129
130   print 
131 "<FORM METHOD=$request_method action=$base_address>
132  <INPUT NAME=action VALUE=moderation_screen TYPE=hidden>
133   $color ($count ";
134   
135   &print_image( "new_tiny2.gif", "new" ) if $count;
136
137   print " articles available)<BR> $end_color
138  Login: <INPUT NAME=moderator VALUE=\"\" SIZE=20>
139  <BR>
140  Password: <INPUT NAME=password TYPE=password VALUE=\"\" SIZE=20>
141  <BR>
142  <INPUT TYPE=submit VALUE=\"Proceed with Login\">
143  <INPUT TYPE=reset VALUE=\"Reset\">
144  <INPUT NAME=newsgroup VALUE=\"$newsgroup\" TYPE=hidden>
145  </FORM><HR>
146   Please log into $newsgroup. You can only log in if you know your login id
147   and know the secret password. You should not give your password to any
148   unauthorized user. Your login id and password are NOT case sentitive, 
149   which means that,
150   for example, \"xyzzy\" and \"XyZZY\" are equally valid.<P>
151 ";
152
153 #  print "
154 # Log in as \"admin\" if you want to 
155 #<UL>
156 #  <LI> edit filtering lists.";
157 #
158 #  &link_to_help( "filter-lists", "Filter Lists" );
159 #
160 #  print "
161 #  <LI> add/delete users or change their passwords.
162 #  <LI> First Time Users: You have to log in as admin and add a moderator user
163 #  who will be able to moderate the newsgroup. Then log in again as that
164 #  user. If you are a new user, you have to have your admin password assigned to
165 #  you by the administrator.
166 #</UL>
167 #
168 #";
169   &end_html;
170 }
171
172 # prints the login screen for newsgroup.
173 sub admin_login_screen {
174   &begin_html( "Administrative login" );
175
176   print
177 "
178 Attention: this page is only for the maintainer of the whole WebSTUMP
179 installation. Please return to the main page if you are not the maintainer
180 of this installation. <HR>
181 ";
182
183   print 
184 "<FORM METHOD=$request_method action=$base_address>
185  <INPUT NAME=action VALUE=webstump_admin_screen TYPE=hidden>
186  Password: <INPUT NAME=password TYPE=password VALUE=\"\" SIZE=20>
187  <BR>
188  <INPUT TYPE=submit VALUE=\"Proceed with Login\">
189  <INPUT TYPE=reset VALUE=\"Reset\">
190  </FORM>
191 ";
192
193   &end_html;
194 }
195
196 # main moderation page -- old version
197 sub html_moderate_article {
198   my $newsgroup = &required_parameter( 'newsgroup' );
199   my $moderator = $request{'moderator'};
200   my $password = $request{'password'};
201   my $file = shift @_ || &required_parameter('file');
202
203   &begin_html( "Main Moderation Screen: $newsgroup" );
204   print "<HR>\n";
205
206   &read_rejection_reasons;
207
208   my $dir = "$queues_dir/$newsgroup";
209
210   if( -d "$dir/$file" && open( TEXT_FILES, "$dir/$file/text.files.lst" ) ) {
211
212       print "<HR>\n" if &print_article_warning( $file );
213
214       print "<PRE>\n";
215       my $filename;
216       my $inhead= 1;
217       while( $filename = <TEXT_FILES> ) {
218         open( ARTICLE, "$dir/$file/$filename" );
219         while( <ARTICLE> ) {
220           $embolden= m/^(?:from|subject)\s*\:/i;
221           s/\&/&amp;/g;
222           s/</&lt;/g;
223           s/>/&gt;/g;
224           $_= "<strong>$_</strong>" if $embolden;
225           print;
226           $inhead= 0 unless m/\S/;
227         }
228         close( ARTICLE );
229         $inhead= 0;
230       }
231
232       print "\n</PRE>\n\n";
233
234       &print_images( $newsgroup, "$dir/$file", $file);
235
236   } else {
237     print "This message ($dir/$file) no longer exists -- maybe it was " .
238           "approved or rejected by another moderator.";
239   }
240
241       print "<HR>
242 <FORM NAME=decision METHOD=$request_method action=$base_address>
243 ";
244
245   print "
246 <INPUT NAME=action VALUE=approval_decision TYPE=hidden>";
247   &html_print_credentials;
248   print "<SELECT NAME=\"decision_$file\">
249 <OPTION VALUE=\"approve\">Approve</OPTION>
250 <OPTION VALUE=\"leave\" SELECTED>Put to back of queue</OPTION>
251 <OPTION VALUE=\"consider\">Back of queue, adding mark requesting further consideration</OPTION>
252 ";
253
254       foreach (sort(keys %rejection_reasons)) {
255         print "<OPTION VALUE=\"reject $_\">Reject -- $rejection_reasons{$_}</OPTION>\n";
256       }
257
258       print "<BR>";
259
260       print "</SELECT><BR> Comment: <INPUT NAME=comment VALUE=\"\" SIZE=80><BR>";
261
262   print "<BR>
263 <INPUT TYPE=radio NAME=poster_decision VALUE=nothing CHECKED>Don't change poster's status</INPUT>
264 <INPUT TYPE=radio NAME=poster_decision VALUE=preapprove 
265 >White-list poster</INPUT>
266 <INPUT TYPE=radio NAME=poster_decision VALUE=ban 
267   ONCLICK=\"alert( 'Banning a poster is a controversial practice'); \"
268 > Ban All Posts by this Person (Careful!)</INPUT>
269 <BR><BR>
270 <INPUT TYPE=radio NAME=thread_decision VALUE=nothing CHECKED>Don't change thread's status</INPUT>
271 <!-- <INPUT TYPE=radio NAME=thread_decision VALUE=preapprove>Preapprove thread, by Subject:</INPUT> -->
272 <BR>
273
274 <!-- <INPUT TYPE=radio NAME=thread_decision VALUE=ban
275   ONCLICK=\"alert( 'Banning a thread is a controversial practice'); \"
276 >Ban Entire Thread By Subject (Careful!)</INPUT> -->
277 <!-- <INPUT TYPE=radio NAME=thread_decision VALUE=watch>Put Entire thread on a Watch, by Subject:</INPUT> -->
278
279 <BR><BR>
280 <I>
281 NOTE: Decisions to ban and whitelist posters can be reversed by 
282 logging in as \"admin\" and editing respective lists of whitelisted
283 and banned threads.
284 ";
285
286   &link_to_help( "filter-lists", "automatic filtering and filter lists, blacklisting and preapproved threads." );
287
288   print "Be really careful about blacklisting of everyone except spammers.</I><BR><BR>
289
290 <INPUT TYPE=radio NAME=next_screen VALUE=single CHECKED> 
291         Review ONE article in next screen
292 <INPUT TYPE=radio NAME=next_screen VALUE=multiple> 
293         Review multiple articles in next screen
294 <HR>
295
296 <INPUT TYPE=submit VALUE=\"Submit\">
297 <INPUT TYPE=submit NAME=skip_submit VALUE=\"Skip\">
298 <INPUT TYPE=reset VALUE=\"Reset\">
299 ";
300
301       print "</FORM>\n\n";
302   print "<BR><A HREF=$base_address?action=change_password&newsgroup=$newsgroup&" .
303         "moderator=$moderator&password=$password>Change Password</A>";
304
305   closedir( QUEUE );
306   &end_html;
307 }
308
309 # WebSTUMP administrative screen
310 sub webstump_admin_screen {
311
312   &verify_admin_password;
313
314   my $password = $request{'password'};
315
316   &begin_html( "WebSTUMP Administration" );
317   print "
318 <FORM METHOD=$request_method action=$base_address>
319 <INPUT NAME=action VALUE=admin_add_newsgroup TYPE=hidden>
320 <INPUT NAME=password VALUE=\"$password\" TYPE=hidden>\n";
321
322
323   print "
324 <HR>
325 Create a new newsgroup on the server:<BR>
326
327 Newsgroup:<BR> <INPUT NAME=newsgroup_name VALUE=\"\" SIZE=50><BR>
328 Address to send approved/rejected messages <BR>
329         <INPUT NAME=newsgroup_approved_address VALUE=\"\" SIZE=30><BR>
330 Admin Password For this group:<BR> <INPUT NAME=newsgroup_password VALUE=\"\" SIZE=10><BR>
331 <INPUT TYPE=submit VALUE=\"Submit\">
332 <INPUT TYPE=reset VALUE=\"Reset\"><HR>
333 ";
334
335       print "</FORM>\n\n<PRE>\n";
336
337   &end_html;
338 }
339
340 # WebSTUMP "add newsgroup" function
341 sub admin_add_newsgroup {
342
343   &verify_admin_password;
344
345   my $newsgroup = &required_parameter( 'newsgroup_name' );
346
347   $newsgroup =~ s/\///g;
348   $newsgroup = &untaint( $newsgroup );
349
350   my $address = &required_parameter( 'newsgroup_approved_address' );
351   my $password = &required_parameter( 'newsgroup_password' );
352
353   &user_error( "Newsgroup $newsgroup already exists" )
354     if defined $newsgroups_index{$newsgroup};
355
356   &user_error( "Password may only contain letters and digits" )
357     if( ! ($password =~ /^[a-zA-Z0-9]+$/ ) );
358
359   &begin_html( "WebSTUMP Administration: Newsgroup created" );
360
361   print "<PRE>\n\n";
362
363   print "Adding $newsgroup to $webstump_home/config/newsgroups.lst...";
364   mkdir "$webstump_home/queues/$newsgroup", 0755;
365   print " done.\n";
366   
367   $dir = "$webstump_home/config/newsgroups/$newsgroup";
368   
369   print "Creating $dir...";
370   mkdir $dir, 0755;
371   print " done.\n";
372   
373   print "Creating files in $dir...";
374   
375   &append_to_file( "$dir/address.txt", "$address\n" );
376   &append_to_file( "$dir/moderators", "ADMIN \U$password\n" );
377   &append_to_file( "$dir/rejection-reasons",
378 "offtopic::a blatantly offtopic article, spam
379 harassing::message of harassing content
380 charter::message poorly formatted
381 " );
382   print " done.\n";
383
384
385   print "</PRE>\n";
386
387   &end_html;
388 }
389
390 #
391 #
392 sub print_images {
393   $web_subdir = pop( @_ );
394   $subdir = pop( @_ );
395   $newsgroup = pop( @_ );
396
397   opendir( SUBDIR, $subdir );
398
399   my $count = 0;
400
401   while( $_ = readdir( SUBDIR ) ) {
402     my $file = "$subdir/$_";
403     next if( ! -f $file || ! -r $file );
404     my $extension = $file;
405     $extension =~ s/^.*\.//;
406     $extension = "\L$extension";
407     
408     if( $extension eq "gif" || $extension eq "jpg" || $extension eq "jpeg" ) {
409       print "<CENTER> <IMG SRC=$base_address_for_files/queues/$newsgroup/$web_subdir/$_></CENTER><HR>\n";
410       $count++;
411     } else {
412       my $filename = $_;
413       $filename =~ s/^.*\///;
414       next if $filename eq "skeleton.skeleton" 
415               || $filename eq "headers.txt"
416               || $filename eq "full_message.txt"
417               || $filename eq "text.files.lst"
418               || $filename eq "stump-prolog.txt"
419               || $filename eq "stump-warning.txt"
420               || $filename =~ /msg-.*\.doc/;
421       
422       &print_image( "no_image.gif", "security warning" );
423       print "<B>Non-image attachment:</B><CODE>$filename</CODE> NOT SHOWN for security reasons.<BR>\n";
424     }
425   }
426   return $count;
427 }
428
429 # prints warning if there is warning stored about the article
430 sub print_article_warning { # short-subdir
431   my $file = pop( @_ );
432
433   my $warning_file = &article_file_name( $file ) . "/stump-warning.txt";
434
435   if( -r $warning_file ) {
436     open( WARNING, $warning_file );
437     while ($warning = <WARNING>) {
438         next unless $warning =~ m/\S/;
439         $warning =~ s/\&/&amp;/g;
440         $warning =~ s/</&lt;/g;
441         $warning =~ s/>/&gt;/g;
442         &print_image( "star.gif", "warning" );
443         print "<FONT COLOR=red>$warning</FONT><br>\n";
444     }
445     close( WARNING );
446     return 1;
447   }
448
449   return 0;
450 }
451
452 sub get_queue_list ($) {
453     my ($newsgroup) = @_;
454     my $dir = "$queues_dir/$newsgroup";
455     my %sortkeys;
456
457     opendir(QUEUED, $dir) or &error("could not open directory $dir");
458
459     for (;;) {
460         $!=0;
461         my $subdir= scalar readdir(QUEUED);
462         last unless defined $subdir;
463
464         my $subpath= "$dir/$subdir";
465         next if $subdir =~ /^\.+/;
466         next unless -d $subpath;
467         my $sortkey;
468         if (!stat "$subpath/stump-warning.txt") {
469             $!==&ENOENT or die "$subpath $!";
470             $sortkey= 0;
471         } else {
472             $sortkey= (stat _)[9];
473         }
474         $sortkeys{$subdir}= $sortkey;
475     }
476     closedir( QUEUED );
477     my @articles= sort { $sortkeys{$a} <=> $sortkeys{$b} } keys %sortkeys;
478     return ($dir, @articles);
479 }
480
481 # main moderation page
482 sub html_moderation_screen {
483   my $newsgroup = &required_parameter( 'newsgroup' );
484   my $moderator = $request{'moderator'};
485   my $password = $request{'password'};
486
487
488   if( $request{'next_screen'} eq 'single' ) {
489     # we show a single article if the user so requested.
490     # just get the first article from the queue if any, otherwise show 
491     # an empty main screen.
492    
493     my ($dir, @articles)= get_queue_list($newsgroup);
494
495     my $i;
496     for ($i=0; $i<@articles; $i++) {
497         my $subdir= shift @articles;
498         push @articles, $subdir;
499         last if $request{"decision_$subdir"};
500     }
501
502     while( $subdir = shift @articles ) {
503       if( -d "$dir/$subdir" && !($subdir =~ /^\.+/) 
504           && open( PROLOG, "$dir/$subdir/stump-prolog.txt" ) ) {
505               &html_moderate_article( $subdir );
506               return;
507       }
508     }
509   } else {
510         # otherwise just show the moderator an empty main screen.
511   }
512     
513   &begin_html( "Main Moderation Screen: $newsgroup" );
514   print "Welcome to the main moderation screen. Its main purpose is to 
515 help you process most messages extremely quickly. For every message, it 
516 presents you who sent it, as well as the first three non-blank lines.
517 For those messages where the decision is obvious, simply select your
518 decision (approve/reject etc) and click submit. For those messages which
519 you would like to review in more details, do not select anything and
520 use Review/Comment function from this screen or from a subsequent screen.
521 Remember that if you do not make any decision, the article would stay in the
522 queue.\n";
523
524   &read_rejection_reasons;
525
526   my ($dir, @articles)= get_queue_list($newsgroup);
527
528   print "
529   <FORM METHOD=$request_method action=$base_address>
530   <INPUT NAME=action VALUE=approval_decision TYPE=hidden>";
531     &html_print_credentials;
532   
533   my $file, $subject = "No Subject", $from = "From nobody";
534   my $form_not_empty = "";
535   my $article_count = 0;
536   my $warning = "";
537   while( ($subdir = shift @articles) && $article_count++ < 40 ) {
538     $file=$subdir;
539     if( -d "$dir/$subdir" && !($subdir =~ /^\.+/) 
540         && open( PROLOG, "$dir/$subdir/stump-prolog.txt" ) ) {
541         while( <PROLOG> ) {
542           chop;
543           if( /^Real-Subject: /i ) {
544             s/\&/&amp;/g;
545             s/</&lt;/g;
546             s/>/&gt;/g;
547             s/^Real-Subject: //g;
548             $subject = substr( $_, 0, 50 );
549           } elsif( /^From: /i ){
550             s/\&/&amp;/g;
551             s/</&lt;/g;
552             s/>/&gt;/g;
553             $from = substr( $_, 0, 50 );
554           } elsif( /^$/ ) {
555             last;
556           }
557         }
558
559         print "<HR><B>$from: $subject</B>(";
560         print "<A HREF=$base_address?action=moderate_article&newsgroup=$newsgroup&" .
561               "moderator=$moderator&password=$password&file=$subdir>Review/Comment/Whitelist</A>)<BR>\n";
562         print "<INPUT TYPE=radio NAME=\"decision_$file\" VALUE=approve>Approve\n";
563         print "<INPUT TYPE=radio NAME=\"decision_$file\" VALUE=skip>Leave\n";
564         print "<INPUT TYPE=radio NAME=\"decision_$file\" VALUE=leave>Back of queue\n";
565         foreach (@short_rejection_reasons) {
566           print "<INPUT TYPE=radio NAME=\"decision_$file\" VALUE=\"reject $_\">Reject \u$_\n";
567         }
568
569         print "<BR>\n";
570
571         &print_article_warning( $file );
572
573         print "<PRE>\n";
574
575         my $i = 0;
576
577         while( ($_ = <PROLOG>) && $i < 5 ) {
578             chop;
579             next if m/^\>/;
580             s/\&/&amp;/g;
581             s/</&lt;/g;
582             s/>/&gt;/g;
583             if( $_ ne "" ) {
584               print "]  " . substr( $_, 0, 75 ) . "\n";
585               $i++;
586             }
587         }
588
589         print "</PRE>";
590         $form_not_empty = "yes";
591         close( PROLOG );
592         $article_count += &print_images( $newsgroup, "$dir/$subdir", $subdir );
593     }
594   }
595
596   if( $form_not_empty ) {
597     print "<HR> <INPUT TYPE=submit VALUE=Submit>
598 <INPUT TYPE=reset VALUE=Reset>
599 ";
600   } else {
601     print "
602 <HR>
603 No articles present in the queue
604 <INPUT TYPE=submit VALUE=Refresh>
605 <HR>\n";
606   }
607
608   print "<A HREF=$base_address?action=change_password&newsgroup=$newsgroup&" .
609         "moderator=$moderator&password=$password>Change Password</A>";
610
611   print "</FORM>\n\n";
612
613   print "<FORM METHOD=$request_method action=$base_address>";
614   &html_print_credentials;
615   print "<INPUT NAME=action VALUE=moderator_admin TYPE=hidden>
616          <INPUT TYPE=submit VALUE=\"Management\">
617          </FORM>";
618
619   &end_html;
620 }
621
622 # prints hidden fields -- credentials
623 sub html_print_credentials {
624   my $newsgroup = $request{'newsgroup'};
625   my $moderator = $request{'moderator'};
626   my $password = $request{'password'};
627
628   print "
629  <INPUT NAME=newsgroup VALUE=\"$newsgroup\" TYPE=hidden>
630  <INPUT NAME=moderator VALUE=\"$moderator\" TYPE=hidden>
631  <INPUT NAME=password VALUE=\"$password\" TYPE=hidden>\n";
632 }
633
634 # logs
635
636 sub scanlogs ($$$) {
637     my ($forwards, $gotr, $callback) = @_;
638     my $dir= "$webstump_home/..";
639     opendir LOGSDIR, "$dir" or die "$dir $!";
640     my $num= sub {
641         local ($_) = @_;
642         return $forwards * (
643             m/^errs$/ ? -1 :
644             m/^errs\.(\d+)(?:\.gz$)$/ ? $1 :
645             undef
646                            );
647     };
648     foreach my $leaf (
649                       sort { $num->($a) <=> $num->($b) }
650                       grep { defined $num->($_) }
651                       readdir LOGSDIR
652                       ) {
653         my $file= "$dir/$leaf";
654         if ($file =~ m/\.gz$/) {
655             open LOGFILE, "zcat $file |" or die "zcat $file $!";
656         } else {
657             open LOGFILE, "< $file" or die "$file $!";
658         }
659         while (<LOGFILE>) {
660             my $tgot= $callback->();
661             next unless $tgot;
662             $$gotr= $tgot if $tgot > $$gotr;
663             last if $tgot > 1;
664         }
665         $!=0; $?=0; close LOGFILE or die "$file $? $!";
666         last if $$gotr > 1;
667     }
668     closedir LOGSDIR or die "$dir $!";
669 }        
670
671 sub html_search_logs {
672   &begin_html("Search logs for $request{'newsgroup'}");
673   my $reqnum;
674   my $forwards=1;
675   my $min= 9;
676   if ($request{'download_logs'}) {
677       print "<h2>Complete log download</h2>\n";
678       $min= 2;
679   } elsif ($request{'messagenum'} =~ m/^\s*(\d+)\s*$/) {
680       $reqnum= $1;
681       $forwards= -1;
682       $min= 1;
683       print "<h2>Log entry for single message $reqnum</h2>\n";
684   } else {
685       print "<h2>Log lookup - bad reference</h2>
686 Please supply the numerical reference as found in the \"recent activity\"
687 log or message headers.  Reference numbers consist entirely of digits,
688 and are often quoted in message headers in [square brackets].<p>
689         ";
690       &end_html;
691       return;
692   }
693   if ($mod_log_access < $min) {
694       print "Not permitted [$mod_log_access<$min].  Consult administrator.\n";
695       &end_html;
696       return;
697   }
698
699   my $sofar= 0;
700   &scanlogs($forwards, \$sofar, sub {
701       return 0 unless chomp;
702       return 0 unless m/^DECISION: /;
703       my @vals = split / \| /, $';
704       return 0 unless @vals >= 5;
705       my $subj= pop @vals;
706       my ($group,$dir,$act,$reason,$timet) = @vals;
707       my $date= $timet ? (strftime "%Y-%m-%d %H:%M:%S GMT", gmtime $timet)
708           : "(unknown)";
709       return 0 unless $group eq $request{'newsgroup'};
710       return 0 unless $subj =~ m,/(\d+)$,;
711       my $treqnum= $1;
712       return 0 if defined($reqnum) and $treqnum ne $reqnum;
713       print "<table rules=all><tr><th>Date<th>Reference<th>Disposal<th>Reason</tr>\n"
714           unless $sofar;
715       print "<tr>", (map { "<td>".escapeHTML($_) }
716                      $date,$treqnum,$act,$reason);
717       print "</tr>\n";
718       return defined($reqnum) ? 2 : 1;
719   });
720   if ($sofar) {
721       print "</table>" if $sofar;
722       print "\n";
723   } else {
724       print "Reference not found.".
725           "  (Perhaps message has expired, or is still in the queue?)";
726   }
727   &end_html;
728 }
729
730 # newsgroup admin page
731 sub html_newsgroup_management {
732   &begin_html( "Administer $request{'newsgroup'}" );
733
734   print "All usernames and passwords are not case sensitive.\n";
735   print "<HR>Use this form to add new moderators or change passwords:<BR>
736  <FORM METHOD=$request_method action=$base_address>
737  <INPUT NAME=action VALUE=add_user TYPE=hidden>";
738   &html_print_credentials;
739   print "
740  Username: <INPUT NAME=user VALUE=\"\" SIZE=20>
741  <BR>
742  Password: <INPUT NAME=new_password VALUE=\"\" SIZE=20>
743  <BR>
744  <INPUT TYPE=submit VALUE=\"Add/Change\">
745  <INPUT TYPE=reset VALUE=Reset>
746  </FORM>
747 ";
748
749   print "<HR>Use this form to delete moderators:<BR>
750  <FORM METHOD=$request_method action=$base_address>
751  <INPUT NAME=action VALUE=delete_user TYPE=hidden>";
752   &html_print_credentials;
753   print "
754  Username: <INPUT NAME=user VALUE=\"\" SIZE=20>
755  <BR>
756  <INPUT TYPE=submit VALUE=\"Delete Moderator\">
757  <INPUT TYPE=reset VALUE=Reset>
758  </FORM><HR>
759
760  <FORM METHOD=$request_method action=$base_address>
761  <INPUT NAME=action VALUE=edit_list TYPE=hidden>";
762   &html_print_credentials;
763   print "
764   Configuration List: <SELECT NAME=list_to_edit>
765
766     <OPTION VALUE=good.posters.list>Good Posters List
767     <OPTION VALUE=bad.posters.list>Banned Posters List
768     <OPTION VALUE=watch.words.list>Suspicious Words List
769
770   </SELECT>
771   <INPUT TYPE=submit VALUE=\"Edit\">
772   <INPUT TYPE=reset VALUE=Reset>";
773
774   &link_to_help( "filter-lists", "filtering lists" );
775
776   print "</FORM><HR>";
777
778   if ($mod_log_access) {
779       print "<form>
780         Use this form to search logs of past moderation decisions:
781         <br>
782         <form method=$request_method action=$base_address>
783         <input name=action value=search_logs type=hidden>";
784
785       &html_print_credentials;
786
787       print "
788         Reference number: <input name=messagenum size=30>
789         <input type=submit value=\"Lookup\">";
790
791       print "
792         <input type=submit value=\"Download all logs\" name=\"download_logs\">"
793         if $mod_log_access >= 2;
794
795       print "</form><hr>\n";
796   }
797
798   print "
799
800   List of current moderators:<P>
801
802   <UL>\n";
803
804   foreach (keys %moderators) {
805       print "<LI> $_\n";
806   }
807
808   print "</UL>\n";
809
810   &end_html;
811 }
812
813
814 # edit config list
815 sub edit_configuration_list {
816
817   my $list_to_edit = &required_parameter( 'list_to_edit' );
818
819   $list_to_edit = &check_config_list( $list_to_edit );
820
821   my $list_file = &full_config_file_name( $list_to_edit );
822
823   my $list_content = "";
824
825   if( open( LIST, $list_file ) ) {
826     $list_content .= $_ while( <LIST> );
827     close( LIST );
828   }
829
830   $list_content =~ s/\&/&amp;/g;
831   $list_content =~ s/</&lt;/g;
832   $list_content =~ s/>/&gt/g;
833
834   &begin_html( "Edit $list_to_edit" );
835
836   print
837 " <FORM METHOD=$request_method action=$base_address>
838  <INPUT NAME=action VALUE=set_config_list TYPE=hidden>
839  <INPUT NAME=list_to_edit VALUE=$list_to_edit TYPE=hidden>";
840   &html_print_credentials;
841   &link_to_help( $list_to_edit, "$list_to_edit" );
842   print "
843  Edit this list: <HR>
844 <TEXTAREA NAME=list rows=20 COLS=50>
845 $list_content</TEXTAREA>
846
847  <BR>
848  <INPUT TYPE=submit VALUE=\"Set\">
849  </FORM>
850 ";
851
852   &end_html;
853 }
854
855 # password change page
856 sub html_change_password{
857   &begin_html( "Change Password" );
858
859   print "All usernames and passwords are not case sensitive.\n";
860   print "<HR>Use this form to change your password:<BR>
861  <FORM METHOD=$request_method action=$base_address>
862  <INPUT NAME=action VALUE=validate_change_password TYPE=hidden>";
863   &html_print_credentials;
864   print "
865  <BR>
866  New Password: <INPUT NAME=new_password VALUE=\"\" SIZE=20>
867  <BR>
868  <INPUT TYPE=submit VALUE=Submit>
869  <INPUT TYPE=reset VALUE=Reset>
870  </FORM>
871 ";
872
873   &end_html;
874 }
875
876
877 # newsgroup creation form
878 sub init_request_newsgroup_creation{
879   my $newsgroup = &required_parameter( 'newsgroup' );
880
881   &begin_html( "Request Creation of $newsgroup" );
882
883   print "This page helps you ask the system administrator of your domain
884 to create <B>$newsgroup</B> on your server. Type in your domain name and
885 click SUBMIT. An email will be sent to news\@domain and usenet\@domain
886 and postmaster\@domain
887 asking them to create your newsgroup. Please do NOT abuse this system.
888 NOTE: You can give the URL of this page to your group readers so that 
889 they could request creation of their newsgroups by themselves.\n";
890
891   print "<HR>
892  <FORM METHOD=$request_method action=$base_address>
893  <INPUT NAME=action VALUE=complete_newsgroup_creation_request TYPE=hidden>\n";
894   &html_print_credentials;
895   print "
896  <BR>
897  Domain Name ONLY: <INPUT NAME=domain_name VALUE=\"\" SIZE=40>
898  <BR>
899  <INPUT TYPE=submit VALUE=Submit>
900  <INPUT TYPE=reset VALUE=Reset>
901  </FORM>
902 ";
903
904   &end_html;
905 }
906
907
908 # newsgroup creation completion
909 sub complete_newsgroup_creation_request{
910   my $newsgroup = &required_parameter( 'newsgroup' );
911   my $domain_name = &required_parameter( 'domain_name' );
912
913   if( !($domain_name =~ /(^[a-zA-Z0-9\.-_]+$)/) ) {
914     &user_error( "invalid domain name" );
915   }
916
917   $domain_name = $1;
918
919
920   my $request = "To: news\@$domain_name, usenet\@$domain_name, postmaster\@$domain_name
921 Subject: Please create $newsgroup (Moderated)
922 From: devnull\@algebra.com ($newsgroup Moderator)
923 Organization: stump.algebra.com
924
925 Dear News Administrator:
926
927 A user of $domain_name has requested that you create a newsgroup
928
929         $newsgroup (Moderated) 
930
931 on your server. $newsgroup
932 is a legitimately created moderated newsgroup that is available worldwide.
933
934 Thank you very much for your help and cooperation.
935
936 Sincerely,
937
938         - Moderator of $newsgroup.
939
940 ";
941
942   &email_message( $request, "news\@$domain_name" );
943   &email_message( $request, "usenet\@$domain_name" );
944   &email_message( $request, "postmaster\@$domain_name" );
945
946   &begin_html( "Request to create $newsgroup sent" );
947
948   print "The following request has been sent:<HR><PRE>\n";
949
950   print "$request</PRE>\n";
951
952   &end_html;
953 }
954
955 # displays help
956 sub display_help {
957   my $topic_name = &required_parameter( "topic" );
958
959   $topic_name =~ s/\///g;
960   $topic_name =~ s/\.\.//g;
961   $topic_name = &untaint( $topic_name );
962
963   my $file = "$webstump_home/doc/help/$topic_name.html";
964
965   &error( "Topic $topic_name not found in $file." ) 
966         if ! -r $file;
967
968   open( FILE, "$file" );
969   my $help = "";
970   $help .= $_ while( <FILE> );
971   close( FILE );
972
973   $help =~ s/##/$base_address?action=help&topic=/g;
974
975   &begin_html( "$topic_name" );
976
977   print $help;
978
979   print "<HR>";
980 }
981
982
983
984
985
986
987
988 1;