2 ##--------------------------------------------------------------------------##
4 ## $Id: mesg.cgi.in.dist,v 1.1 2002/09/03 16:30:47 ehood Exp $
6 ## Earl Hood earl@earlhood.com
9 ##--------------------------------------------------------------------------##
10 ## Copyright (C) 2002 Earl Hood <earl@earlhood.com>
12 ## This program is free software; you can redistribute it and/or modify
13 ## it under the terms of the GNU General Public License as published by
14 ## the Free Software Foundation; either version 2 of the License, or
15 ## (at your option) any later version.
17 ## This program is distributed in the hope that it will be useful,
18 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ## GNU General Public License for more details.
22 ## You should have received a copy of the GNU General Public License
23 ## along with this program; if not, write to the Free Software
24 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 ##--------------------------------------------------------------------------##
28 package MHArc
::mesg_cgi
;
30 use lib
'/home/mharc/lib';
41 #############################################################################
42 ## BEGIN: Config Section
43 #############################################################################
45 ## Full pathname to where html archives are located.
46 my $html_archive_root = '/home/mharc/html';
48 #############################################################################
49 ## END: Config Section
50 #############################################################################
52 $ENV{'PATH'} = '/usr/local/bin:/bin:/usr/bin';
54 ## Query argument name to contain name of archive
55 my $argname_archive = 'a';
57 ## Query argument name to contain message-id
60 ## Namazu conf file (should be the same used by namazu.cgi)
61 my $namazurc = '.namazurc';
64 my $form = MHArc
::CGI
::parse_input
();
65 my $archive = $form->{$argname_archive} || "";
66 my $id = $form->{$argname_id} || "";
67 my $host = $ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'} ||
68 $ENV{'SERVER_ADDR'} || "localhost";
69 my $port = $ENV{'SERVER_PORT'} || "";
70 if ($port && $port ne '80') {
75 my $server_url= "http://$host$port";
78 if (($id !~ /.\@./) ||
80 ($archive =~ /\.\./) ||
81 (! -d
($list_dir = join('/', $html_archive_root,$archive)))) {
82 warn qq/Invalid arguments: a=$archive, i=$id\n/;
83 MHArc
::CGI
::print_input_error
();
87 my $nmzrc = nmz_load_rc
($namazurc);
88 if (!defined($nmzrc)) {
89 MHArc
::CGI
::print_script_error
();
93 my $pathname = find_id
($list_dir, $id);
94 if (!defined($pathname)) {
95 MHArc
::CGI
::print_not_found_error
();
99 warn qq/"$pathname" does not exist\n/;
100 MHArc
::CGI
::print_not_found_error
();
104 # Apply replace string to pathname
106 foreach my $r (@
{$nmzrc->{'replace'}}) {
107 my $pos = index($pathname, $r->[0]);
109 $url = $r->[1] . substr($pathname, length($r->[0]));
114 # Print out message page
116 if (!open(MESG
, $pathname)) {
117 warn qq/Unable top open "$pathname": $!\n/;
118 MHArc
::CGI
::print_script_error
();
122 MHArc
::CGI
::print_content_type
('text/html');
125 foreach $str (<MESG
>) {
128 if ($str =~ /<head>/i) {
129 print STDOUT
'<base href="'. $server_url . $url . '">', "\n";
136 #############################################################################
137 ## Generic subroutines for CGI use
138 #############################################################################
141 my $list_dir = shift;
144 my $docid = nmz_msg_id_search
($list_dir, $id);
148 return nmz_get_field
($list_dir, $docid, 'uri');
151 ########################################################################
156 mesg.cgi - mharc CGI program to retrieve a message by message-id
160 http://.../cgi-bin/mesg.cgi?a=<archive-name>&i=<message-id>
164 This CGI program retrieves a message from a specified archive with
165 a give message-id. The CGI program's main purpose is to provide
166 a persistent URL to archived messages that is immune to archive
169 The CGI program will output the retrieved message to the web client.
170 The message will have a C<E<lt>base hrefE<gt>> tag added so relative
171 links in the message page will function properly.
179 The name of the archive. Archive names are defined by C<lists.def>.
189 C<$Id: mesg.cgi.in.dist,v 1.1 2002/09/03 16:30:47 ehood Exp $>
193 Earl Hood, earl@earlhood.com
195 This module is part of the mharc archiving system and comes with
196 ABSOLUTELY NO WARRANTY and may be copied only under the terms of
197 the GNU General Public License, which may be found in the MHArc