#!/usr/local/bin/perl
#
# Aminet Download Utility
# (c)1996 Mark Rigby-Jones for mrjsw
# mark.rigby-jones@keble.oxford.ac.uk
# http://users.ox.ac.uk/~kebl0206/
#
# Usage:
# http://some.site.net/cgi-bin/safeperl/username/aminet?dir.subdir[&filename[&filename[&...]]]

# Parse the input

$query = $ENV{QUERY_STRING};
@query = split('&', $query);
$dir = shift(@query);
$dir =~ s|\.|/|;

# Output the top of the HTML document

print(<<"BACK_TO_PERL");
Content-type: text/html

<html>
<head>
<link rev=made href="mailto:mark.rigby-jones\@keble.oxford.ac.uk">
<title>Aminet Download</title>
</head>
<body bgcolor=#FFFFFF>
<h1 align=center><img src="/~kebl0206/aminet.gif" width=84 height=84><br>Aminet Download</h1>
<p align=center>This page will allow you to download the requested file(s) from any of the full aminet mirrors. Pick the site which is closest to 
you. You may need to shift-click on the links to force your browser to download the file properly.</p>
<hr size=4>
BACK_TO_PERL

# Do links for each of the aminet sites

&link("ftp.wustl.edu","Washington University in St.Louis (USA)");
&link("ftp.netnet.net","NetNet (USA)");
&link("ftp.amigalib.com","AmigaLib (USA)");
&link("ftp.doc.ic.ac.uk","SunSITE, Imperial College (UK)");
&link("ftp.uni-paderborn.de","Universit&auml;t-GH Paderborn (Germany)");
&link("ftp.luth.se","Lule&aring; University (Scandanavia)");
&link("ftp.unina.it","Universita' degli Studi di Napoli (Italy)");
#&link("ftp.eunet.ch","EUnet (Switzerland)");
#&link("ftp.livewire.com.au","LiveWire (Australia)");

# Output the bottom of the HTML document

print(<<"BACK_TO_PERL");
<hr size=4>
<address>
<p align=center>&copy;1996 <a href="/~kebl0206/">Mark Rigby-Jones</a><br>
<a href="mailto:mark.rigby-jones\@keble.oxford.ac.uk">mark.rigby-jones\@keble.oxford.ac.uk</a></p>
</address>
</body>
</html>
BACK_TO_PERL

# Subroutine to print out links etc

sub link {
    ($server,$desc) = @_;
    @files = @query;
    print("<h2 align=center>$desc</h2>\n<p align=center>");
    if ($#files == -1) {
	print("<a href=\"ftp://$server/pub/aminet/$dir/\">ftp://$server/pub/aminet/$dir/</a></p>\n");
    } else {
	while ($file = shift(@files)) {
	    print("<a href=\"ftp://$server/pub/aminet/$dir/$file\">ftp://$server/pub/aminet/$dir/$file</a><br>");
	}
	print("</p>\n");
    }
}
	
