2 ##--------------------------------------------------------------------------##
4 ## $Id: mnav.cgi.in.dist,v 1.5 2002/10/17 03:11:31 ehood Exp $
6 ## Earl Hood earl@earlhood.com
9 ##--------------------------------------------------------------------------##
10 ## Copyright (C) 2001-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 ##--------------------------------------------------------------------------##
30 use lib
'/home/mharc/lib';
35 #############################################################################
36 ## BEGIN: Config Section
37 #############################################################################
39 ## Full pathname to where HTML archives are located.
40 my $html_archive_root = '/home/mharc/html';
42 ## URL pathname to where HTML archives are located.
43 my $url_archive_root = '/archive/html';
45 #############################################################################
46 ## END: Config Section
47 #############################################################################
49 ## Query argument name to contain name of archive
50 my $argname_archive = 'a';
52 ## Query argumant name to contain nav direction ('next' or 'prev')
53 my $argname_direction = 'd';
55 ## Query argument name to contain month
56 my $argname_month = 'm';
58 ## Query argument name to contain type of index
59 my $argname_type = 't';
62 my $form = MHArc
::CGI
::parse_input
();
63 my $archive = $form->{$argname_archive};
64 my $direction = $form->{$argname_direction};
65 my $month = $form->{$argname_month};
66 my $type = $form->{$argname_type};
67 my $host = $ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'} ||
68 $ENV{'SERVER_ADDR'} || 'localhost';
69 my $port = $ENV{'SERVER_PORT'} || "";
70 my $http = ($ENV{'HTTPS'} eq 'on') ?
'https' : 'http';
71 if ($port && $port ne '80') {
77 if (($archive =~ /\.\./) || ($archive =~ /[\\\/]/)) {
78 warn qq/Fishy looking archive setting: $archive\n/;
79 MHArc
::CGI
::print_input_error
();
82 if ($month !~ /^\d+(?:-\d+)?/) {
83 warn qq/Invalid month: $month\n/;
84 MHArc
::CGI
::print_input_error
();
88 my $server_url= "$http://$host$port";
89 my $dir = join('/', $html_archive_root, $archive);
90 my $url = $server_url . join('/', $url_archive_root, $archive);
93 if (!opendir(DIR
, $dir)) {
94 warn qq/Unable to open "$dir": $!\n/;
95 MHArc
::CGI
::print_location
($url);
99 my @months = sort grep { /^\d+(?:-\d+)?/ } readdir(DIR
);
101 if (scalar(@months) <= 0) {
102 # No month directories, so jump to top index
103 MHArc
::CGI
::print_location
($url);
107 # Search for current month in listing
109 for ($i=0; $i <= $#months; ++$i) {
110 last if $month eq $months[$i];
112 # Adjust offset according to direction
113 if ($direction =~ /prev/) { --$i; } else { ++$i; }
114 if (($i < 0) || ($i > $#months)) {
115 # Hit bounds, so jump user to top index
116 MHArc
::CGI
::print_location
($url);
120 # Redirect user to new month
121 $url .= '/' . $months[$i] . '/' .
122 ($type eq 't' ?
'threads.html' : 'index.html');
123 MHArc
::CGI
::print_location
($url)
126 ########################################################################
131 mnav.cgi - mharc CGI program to navigate between period indexes
135 http://.../cgi-bin/mnav?a=<archive>&m=<period>&d=<direction>&t=<type>
139 This CGI program is used for the next/prev period navigation for
142 The CGI program will send a client redirect URL to the period index
143 determined by specified input.
151 The name of the archive. Archive names are defined by C<lists.def>.
155 The direction. Possible values are "C<prev>" or "C<next>".
159 The period in YYYY-MM or YYYY format.
163 The type of index to goto. For thread index, the value should be
164 set to "C<t>". If not set, or set to something else, date indexes
171 C<$Id: mnav.cgi.in.dist,v 1.5 2002/10/17 03:11:31 ehood Exp $>
175 Earl Hood, earl@earlhood.com
177 This module is part of the mharc archiving system and comes with
178 ABSOLUTELY NO WARRANTY and may be copied only under the terms of
179 the GNU General Public License, which may be found in the MHArc