#!/usr/bin/perl ##--------------------------------------------------------------------------## ## File: ## $Id: mnav.cgi.in.dist,v 1.5 2002/10/17 03:11:31 ehood Exp $ ## Author: ## Earl Hood earl@earlhood.com ## Description: ## POD at end-of-file. ##--------------------------------------------------------------------------## ## Copyright (C) 2001-2002 Earl Hood ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ## 02111-1307, USA ##--------------------------------------------------------------------------## package mnav_cgi; use lib '/home/mharc/lib'; use CGI::Carp; use MHArc::CGI; ############################################################################# ## BEGIN: Config Section ############################################################################# ## Full pathname to where HTML archives are located. my $html_archive_root = '/home/mharc/html'; ## URL pathname to where HTML archives are located. my $url_archive_root = '/archive/html'; ############################################################################# ## END: Config Section ############################################################################# ## Query argument name to contain name of archive my $argname_archive = 'a'; ## Query argumant name to contain nav direction ('next' or 'prev') my $argname_direction = 'd'; ## Query argument name to contain month my $argname_month = 'm'; ## Query argument name to contain type of index my $argname_type = 't'; MAIN: { my $form = MHArc::CGI::parse_input(); my $archive = $form->{$argname_archive}; my $direction = $form->{$argname_direction}; my $month = $form->{$argname_month}; my $type = $form->{$argname_type}; my $host = $ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'} || $ENV{'SERVER_ADDR'} || 'localhost'; my $port = $ENV{'SERVER_PORT'} || ""; my $http = ($ENV{'HTTPS'} eq 'on') ? 'https' : 'http'; if ($port && $port ne '80') { $port = ":$port"; } else { $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); my $url = $server_url . join('/', $url_archive_root, $archive); local(*DIR); if (!opendir(DIR, $dir)) { warn qq/Unable to open "$dir": $!\n/; MHArc::CGI::print_location($url); last MAIN; } my @months = sort grep { /^\d+(?:-\d+)?/ } readdir(DIR); close(DIR); if (scalar(@months) <= 0) { # No month directories, so jump to top index MHArc::CGI::print_location($url); last MAIN; } # Search for current month in listing my($i); for ($i=0; $i <= $#months; ++$i) { last if $month eq $months[$i]; } # Adjust offset according to direction if ($direction =~ /prev/) { --$i; } else { ++$i; } if (($i < 0) || ($i > $#months)) { # Hit bounds, so jump user to top index MHArc::CGI::print_location($url); last MAIN; } # Redirect user to new month $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=&m=&d=&t= =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 The name of the archive. Archive names are defined by C. =item C The direction. Possible values are "C" or "C". =item C The period in YYYY-MM or YYYY format. =item C The type of index to goto. For thread index, the value should be set to "C". If not set, or set to something else, date indexes are used. =back =head1 VERSION C<$Id: mnav.cgi.in.dist,v 1.5 2002/10/17 03:11:31 ehood Exp $> =head1 AUTHOR Earl Hood, earl@earlhood.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