mhonarc-commits
[Top] [All Lists]

CVS: mharc/cgi-bin mesg.cgi.in.dist,NONE,1.1 extract-mesg.cgi.in.dist,1.2,1...

2002-09-03 09:31:02
Update of /cvsroot/mhonarc/mharc/cgi-bin
In directory subversions:/tmp/cvs-serv3998/cgi-bin

Modified Files:
	extract-mesg.cgi.in.dist mnav.cgi.in.dist 
Added Files:
	mesg.cgi.in.dist 
Log Message:
* bin/extract-mesg-date:
  . Added check for new MSG_DATE_FIELDS config.sh variable denoting
    the message header fields to extract the date from.  The
    value of MSG_DATE_FIELDS is used if -datefields is not specified.
* bin/filter-spool:
  . If there is no mail in the spool, but .newmail exists,
    filter-spool will still process .newmail.  .newmail is the
    messages copied from the spool when filter-spool is executing.
    In the past, even if .newmail exists, no mail in the spool
    will cause filter-spool to exit.
* bin/web-archive:
  . Added check for MSG_DATE_FIELDS config.sh variable.  If set,
    its value will passed to MHonArc via the DATEFIELDS resource.
  . Define $MESG-CGI$ resource variable for use within MHonArc
    resource files.
* cgi-bin/extract-mesg.cgi.in.dist:
  . Internal changes so its uses new MHArc::CGI utility routines.
  . POD added.
* cgi-bin/mesg.cgi.in.dist:
  . NEW: New CGI program to extract a message from an archive based
    upon message-id.  This allows for persistent URLs to messages
    that are immune to archive rebuilds that could change MHonArc
    message numbers.
    This CGI is referenced in the updated lib/common.mrc.in.dist
    resource file via the $MESG-CGI$ resource variable.  It is
    used for the new [Bookmark Link] on message pages.
* cgi-bin/mnav.cgi.in.dist:
  . Added some sanity checks to argument input.
  . Internal changes so its uses new MHArc::CGI utility routines.
  . POD added.
* lib/common.mrc.in.dist:
  . Added "[Bookmark Link]" to message page layout to provide a
    persistent link to the message.  The link provided makes use
    of the new mesg.cgi CGI script.
* lib/config.sh.dist:
  . Added MSG_DATE_FIELDS: List of message header fields to extract
    the date for a message.
  . Added MESG_CGI: URL to persistent message reference CGI program
    (mesg.cgi).
* lib/MHArc/CGI.pm:
  . NEW: Shared CGI utility routines for mharc CGI scripts.
* lib/MHArc/MailUtil.pm:
  . extract_date() routine changed to handle indexed header fields
    in date fields argument.
    CAUTION: Only use indexed field specification if you are using
    a version of MHonArc *newer than* 2.5.11.  MHonArc v2.5.11,
    and earlier versions, do not support indexed fields for the
    DATEFIELDS resource.
* lib/MHArc/Namazu.pm:
  . NEW: Collection of routines related to Namazu.


***** Error reading new file: [Errno 2] No such file or directory: 'mesg.cgi.in.dist'
Index: extract-mesg.cgi.in.dist
===================================================================
RCS file: /cvsroot/mhonarc/mharc/cgi-bin/extract-mesg.cgi.in.dist,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** extract-mesg.cgi.in.dist	31 Jul 2002 04:53:21 -0000	1.2
--- extract-mesg.cgi.in.dist	3 Sep 2002 16:30:47 -0000	1.3
***************
*** 6,12 ****
  ##      Earl Hood       earl(_at_)earlhood(_dot_)com
  ##  Description:
! ##	CGI program to extract original raw message from archive.
! ##	Error reporting is very minimal.  Attempts are made to check
! ##	against malicious input.
  ##--------------------------------------------------------------------------##
  ##  Copyright (C) 2002	Earl Hood <earl(_at_)earlhood(_dot_)com>
--- 6,10 ----
  ##      Earl Hood       earl(_at_)earlhood(_dot_)com
  ##  Description:
! ##	POD at end-of-file.
  ##--------------------------------------------------------------------------##
  ##  Copyright (C) 2002	Earl Hood <earl(_at_)earlhood(_dot_)com>
***************
*** 30,34 ****
--- 28,35 ----
  package MHArc::extract_mesg_cgi;
  
+ use lib '@@SW_ROOT@@/lib';
+ 
  use CGI::Carp;
+ use MHArc::CGI;
  
  #############################################################################
***************
*** 65,69 ****
  
  MAIN: {
!   my $form 	= parse_input();
    my $archive 	= $form->{$argname_archive} || "";
    my $month 	= $form->{$argname_month} || "";
--- 66,70 ----
  
  MAIN: {
!   my $form 	= MHArc::CGI::parse_input();
    my $archive 	= $form->{$argname_archive} || "";
    my $month 	= $form->{$argname_month} || "";
***************
*** 77,81 ****
        (! -d ($list_dir = join('/', $mbox_archive_root,$archive)))) {
      warn qq/Invalid arguments: a=$archive, m=$month, i=$id\n/;
!     print_input_error();
      last MAIN;
    }
--- 78,82 ----
        (! -d ($list_dir = join('/', $mbox_archive_root,$archive)))) {
      warn qq/Invalid arguments: a=$archive, m=$month, i=$id\n/;
!     MHArc::CGI::print_input_error();
      last MAIN;
    }
***************
*** 89,93 ****
    if (! -e $mbox_file) {
      warn qq/"$mbox_file" does not exist\n/;
!     print_input_error();
      last MAIN;
    }
--- 90,94 ----
    if (! -e $mbox_file) {
      warn qq/"$mbox_file" does not exist\n/;
!     MHArc::CGI::print_input_error();
      last MAIN;
    }
***************
*** 97,101 ****
      if (!open(MBOX, "gzip -dc '$mbox_file' |")) {
        warn qq/Unable to exec "gzip -dc '$mbox_file'": $!\n/;
!       print_error();
        last MAIN;
      }
--- 98,102 ----
      if (!open(MBOX, "gzip -dc '$mbox_file' |")) {
        warn qq/Unable to exec "gzip -dc '$mbox_file'": $!\n/;
!       MHArc::CGI::print_error();
        last MAIN;
      }
***************
*** 103,107 ****
      if (!open(MBOX, $mbox_file)) {
        warn qq/Unable to open "$mbox_file": $!\n/;
!       print_error();
        last MAIN;
      }
--- 104,108 ----
      if (!open(MBOX, $mbox_file)) {
        warn qq/Unable to open "$mbox_file": $!\n/;
!       MHArc::CGI::print_error();
        last MAIN;
      }
***************
*** 142,151 ****
  
    if (!$found) {
!     print_not_found_error();
      close(MBOX);
      last MAIN;
    }
  
!   print_content_type($message_media_type);
    print STDOUT $cache;
    while (<MBOX>) {
--- 143,152 ----
  
    if (!$found) {
!     MHArc::CGI::print_not_found_error();
      close(MBOX);
      last MAIN;
    }
  
!   MHArc::CGI::print_content_type($message_media_type);
    print STDOUT $cache;
    while (<MBOX>) {
***************
*** 156,222 ****
  }
  
! #############################################################################
! ##	Generic subroutines for CGI use
! #############################################################################
  
! sub print_input_error {
!   print_content_type('text/plain');
!   print STDOUT "Input Error\n";
! }
  
! sub print_error {
!   print_content_type('text/plain');
!   print STDOUT "Script Error\n";
! }
  
! sub print_not_found_error {
!   print_content_type('text/plain');
!   print STDOUT "Message Not Found\n";
! }
  
! sub print_location {
!   print STDOUT 'Location: ', $_[0], "\r\n\r\n";
! }
  
! sub parse_input {
!     my($method) = ($ENV{"REQUEST_METHOD"}) || 'GET';
!     my($data);
!     if ($method eq "GET") {
! 	$data = $ENV{"QUERY_STRING"} || "";
!     } elsif ($method eq "POST") {
! 	read(STDIN, $data, $ENV{"CONTENT_LENGTH"});
!     } else {
! 	warn qq/Unknown method: $method/;
! 	return undef;
!     }
  
!     my(@pairs, $name, $value);
!     local $_;
  
!     my $form = { };
!     if ($data ne '') {
! 	@pairs = split(/&/, $data);
! 	foreach (@pairs) {
! 	    ($name, $value) = split(/=/);
! 	    $name = expandstr($name);
! 	    $value = expandstr($value);
! 	    $form->{$name} = $value;
! 	}
!     }
!     $form;
! }
  
! sub print_content_type {
!     my($type) = shift;
!     print STDOUT "Content-type: $type\n\n";
! }
  
! sub expandstr {
!     my($str) = shift;
!     $str =~ tr/+/ /;
!     $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/ge;
!     $str;
! }
  
- ########################################################################
- __END__
--- 157,209 ----
  }
  
! ########################################################################
! __END__
  
! =head1 NAME
  
! extract-mesg.cgi - mharc CGI program to retrieve raw version of a message
  
! =head1 SYNOPSIS
  
!   http://.../cgi-bin/extract-mesg.cgi?a=<archive-name>&m=<period>&i=<message-id>
  
! =head1 DESCRIPTION
  
! This CGI program retrieves the raw version of a message from an
! archive archived at a specified period and with a specified message-id.
  
! The CGI program will output the retrieved message to the web client.
  
! =head1 CGI OPTIONS
  
! =over
! 
! =item C<a>
! 
! The name of the archive.  Archive names are defined by C<lists.def>.
! 
! =item C<i>
! 
! The message-id.
! 
! =item C<m>
! 
! The period in YYYY-MM or YYYY format.
! 
! =back
! 
! =head1 VERSION
! 
! C<$Id$>
! 
! =head1 AUTHOR
! 
! Earl Hood, earl(_at_)earlhood(_dot_)com
! 
! This module is part of the mharc archiving system and comes with
! ABSOLUTELY NO WARRANTY and may be copied only under the terms of
! the GNU General Public License, which may be found in the MHArc
! distribution.
! 
! =cut
  

Index: mnav.cgi.in.dist
===================================================================
RCS file: /cvsroot/mhonarc/mharc/cgi-bin/mnav.cgi.in.dist,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** mnav.cgi.in.dist	6 Mar 2002 22:45:14 -0000	1.3
--- mnav.cgi.in.dist	3 Sep 2002 16:30:47 -0000	1.4
***************
*** 6,17 ****
  ##      Earl Hood       earl(_at_)earlhood(_dot_)com
  ##  Description:
! ##	Simple CGI program to handle prev/next month navigation.
! ##	This program sends an appropriate redirect to an HTTP client
! ##	to the next/prev month index.  If no prev/next month exists
! ##	from provided reference month, client is redirected to
! ##	top index of list archive.
! ##
! ##	Error detection is very minimal.  There is a dependency that
! ##	this script is called with appropriate arguments.
  ##--------------------------------------------------------------------------##
  ##  Copyright (C) 2001-2002	Earl Hood <earl(_at_)earlhood(_dot_)com>
--- 6,10 ----
  ##      Earl Hood       earl(_at_)earlhood(_dot_)com
  ##  Description:
! ##	POD at end-of-file.
  ##--------------------------------------------------------------------------##
  ##  Copyright (C) 2001-2002	Earl Hood <earl(_at_)earlhood(_dot_)com>
***************
*** 35,39 ****
--- 28,35 ----
  package mnav_cgi;
  
+ use lib '@@SW_ROOT@@/lib';
+ 
  use CGI::Carp;
+ use MHArc::CGI;
  
  #############################################################################
***************
*** 64,68 ****
  
  MAIN: {
!   my $form 	= parse_input();
    my $archive 	= $form->{$argname_archive};
    my $direction = $form->{$argname_direction};
--- 60,64 ----
  
  MAIN: {
!   my $form 	= MHArc::CGI::parse_input();
    my $archive 	= $form->{$argname_archive};
    my $direction = $form->{$argname_direction};
***************
*** 70,74 ****
    my $type 	= $form->{$argname_type};
    my $host	= $ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'} ||
! 		  $ENV{'SERVER_ADDR'};
    my $port	= $ENV{'SERVER_PORT'} || "";
    if ($port && $port ne '80') {
--- 66,70 ----
    my $type 	= $form->{$argname_type};
    my $host	= $ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'} ||
! 		  $ENV{'SERVER_ADDR'} || 'localhost';
    my $port	= $ENV{'SERVER_PORT'} || "";
    if ($port && $port ne '80') {
***************
*** 77,80 ****
--- 73,88 ----
      $port = "";
    }
+ 
+   if (($archive =~ /\.\./) || ($archive =~ /[\\\/]/)) {
+     warn qq/Fishy looking archive setting: $archive\n/;
+     MHArc::CGI::print_input_error();
+     last MAIN;
+   }
+   if ($month !~ /^\d+(?:-\d+)?/) {
+     warn qq/Invalid month: $month\n/;
+     MHArc::CGI::print_input_error();
+     last MAIN;
+   }
+ 
    my $server_url= "http://$host$port";;
    my $dir	= join('/', $html_archive_root, $archive);
***************
*** 84,88 ****
    if (!opendir(DIR, $dir)) {
        warn qq/Unable to open "$dir": $!\n/;
!       print_location($url);
        last MAIN;
    }
--- 92,96 ----
    if (!opendir(DIR, $dir)) {
        warn qq/Unable to open "$dir": $!\n/;
!       MHArc::CGI::print_location($url);
        last MAIN;
    }
***************
*** 92,96 ****
    if (scalar(@months) <= 0) {
      # No month directories, so jump to top index
!     print_location($url);
      last MAIN;
    }
--- 100,104 ----
    if (scalar(@months) <= 0) {
      # No month directories, so jump to top index
!     MHArc::CGI::print_location($url);
      last MAIN;
    }
***************
*** 105,109 ****
    if (($i < 0) || ($i > $#months)) {
      # Hit bounds, so jump user to top index
!     print_location($url);
      last MAIN;
    }
--- 113,117 ----
    if (($i < 0) || ($i > $#months)) {
      # Hit bounds, so jump user to top index
!     MHArc::CGI::print_location($url);
      last MAIN;
    }
***************
*** 112,176 ****
    $url .= '/' . $months[$i] . '/' .
  	  ($type eq 't' ? 'threads.html' : 'index.html');
!   print_location($url)
  }
  
! #############################################################################
! ##	Generic subroutines for CGI use
! #############################################################################
  
! sub print_location {
!   print STDOUT 'Location: ', $_[0], "\r\n\r\n";
! }
  
! #-----------------------------------------------------------------------
! #	Converts the input data into a hash.
! #
! sub parse_input {
!     my($method) = ($ENV{"REQUEST_METHOD"});
!     my($data);
!     if ($method eq "GET") {
! 	$data = $ENV{"QUERY_STRING"};
!     } elsif ($method eq "POST") {
! 	read(STDIN, $data, $ENV{"CONTENT_LENGTH"});
!     } else {
! 	warn qq/Unknown method: $method/;
! 	return undef;
!     }
! 
!     my(@pairs, $name, $value);
!     local $_;
! 
!     my $form = { };
!     if ($data ne '') {
! 	@pairs = split(/&/, $data);
! 	foreach (@pairs) {
! 	    ($name, $value) = split(/=/);
! 	    $name = expandstr($name);
! 	    $value = expandstr($value);
! 	    $form->{$name} = $value;
! 	}
!     }
!     $form;
! }
  
! #-----------------------------------------------------------------------
! #	Prints out specified content-type header back
! #	to client
! #
! sub print_content_type {
!     my($type) = shift;
!     print STDOUT "Content-type: $type\r\n\r\n";
! }
  
! #-----------------------------------------------------------------------
! #	expandstr translates hex codes to characters
! #
! sub expandstr {
!     my($str) = shift;
!     $str =~ tr/+/ /;
!     $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/ge;
!     $str;
! }
  
- ########################################################################
- __END__
--- 120,182 ----
    $url .= '/' . $months[$i] . '/' .
  	  ($type eq 't' ? 'threads.html' : 'index.html');
!   MHArc::CGI::print_location($url)
  }
  
! ########################################################################
! __END__
  
! =head1 NAME
  
! mnav.cgi - mharc CGI program to navigate between period indexes
  
! =head1 SYNOPSIS
  
!   http://.../cgi-bin/mnav?a=<archive>&m=<period>&d=<direction>&t=<type>
! 
! =head1 DESCRIPTION
! 
! This CGI program is used for the next/prev period navigation for
! an archive.
! 
! The CGI program will send a client redirect URL to the period index
! determined by specified input.
! 
! =head1 CGI OPTIONS
! 
! =over
! 
! =item C<a>
! 
! The name of the archive.  Archive names are defined by C<lists.def>.
! 
! =item C<d>
! 
! The direction.  Possible values are "C<prev>" or "C<next>".
! 
! =item C<m>
! 
! The period in YYYY-MM or YYYY format.
! 
! =item C<t>
! 
! The type of index to goto.  For thread index, the value should be
! set to "C<t>".  If not set, or set to something else, date indexes
! are used.
! 
! =back
! 
! =head1 VERSION
! 
! C<$Id$>
! 
! =head1 AUTHOR
! 
! Earl Hood, earl(_at_)earlhood(_dot_)com
! 
! This module is part of the mharc archiving system and comes with
! ABSOLUTELY NO WARRANTY and may be copied only under the terms of
! the GNU General Public License, which may be found in the MHArc
! distribution.
! 
! =cut
  

---------------------------------------------------------------------
To sign-off this list, send email to majordomo(_at_)mhonarc(_dot_)org with the
message text UNSUBSCRIBE MHONARC-DEV