#!/usr/local/bin/perl
# download.cgi
# Get a perl module from somewhere
require './cpan-lib.pl';
if ($ENV{REQUEST_METHOD} eq "POST") { &ReadParseMime(); }
else { &ReadParse(); $no_upload = 1; }
&error_setup($text{'download_err'});
if ($in{'source'} >= 2) {
&ui_print_unbuffered_header(undef, $text{'download_title'}, "");
}
else {
&ui_print_header(undef, $text{'download_title'}, "");
}
&tempname();
if ($in{'source'} == 0) {
# installing from local file (or maybe directory)
if (!$in{'local'})
{ &install_error($text{'download_elocal'}); }
if (!-r $in{'local'})
{ &install_error(&text('download_elocal2', $in{'local'})); }
$source = $in{'local'};
@pfile = ( $in{'local'} );
$need_unlink = 0;
}
elsif ($in{'source'} == 1) {
# installing from upload .. store file in temp location
if ($no_upload) {
&install_error($text{'download_eupload'});
}
$in{'upload_filename'} =~ /([^\/\\]+$)/;
@pfile = ( &tempname("$1") );
open(PFILE, ">$pfile[0]");
print PFILE $in{'upload'};
close(PFILE);
$source = $in{'upload_filename'};
$need_unlink = 1;
}
elsif ($in{'source'} == 2) {
# installing from URL.. store downloaded file in temp location
$in{'url'} =~ /\/([^\/]+)\/*$/;
@pfile = ( &tempname("$1") );
$progress_callback_url = $in{'url'};
if ($in{'url'} =~ /^(http|https):\/\/([^\/]+)(\/.*)$/) {
# Make a HTTP request
$ssl = $1 eq 'https';
$host = $2; $page = $3; $port = $ssl ? 443 : 80;
if ($host =~ /^(.*):(\d+)$/) { $host = $1; $port = $2; }
&http_download($host, $port, $page, $pfile[0], \$error,
\&progress_callback, $ssl);
}
elsif ($in{'url'} =~ /^ftp:\/\/([^\/]+)(:21)?(\/.*)$/) {
$host = $1; $file = $3;
&ftp_download($host, $file, $pfile[0], \$error,
\&progress_callback);
}
else { &install_error(&text('download_eurl', $in{'url'})); }
&install_error($error) if ($error);
$source = $in{'url'};
$need_unlink = 1;
}
elsif ($in{'source'} == 3) {
# installing from CPAN.. find the module, and then install it
$in{'cpan'} || &error($text{'download_emodname'});
@cpan = split(/\s+|\0/, $in{'cpan'});
# First check if YUM or APT can install this module for us
if ($config{'incyum'}) {
@yum = &list_packaged_modules();
foreach $c (@cpan) {
($yum) = grep { lc($_->{'mod'}) eq lc($c) } @yum;
push(@cpanyum, $yum) if ($yum);
}
}
if (scalar(@cpan) == scalar(@cpanyum)) {
# Can install from YUM or APT .. do it!
$i = 0;
foreach $yum (@cpanyum) {
print &text('download_yum', "$cpan[$i]",
"$yum->{'package'}"),"
\n";
print "
\n";
# Make sure it is valid
open(PFILE, $packages_file);
read(PFILE, $two, 2);
close(PFILE);
if ($two ne "\037\213") {
&install_error(&text('download_ecpangz',
"$config{'packages'}"));
}
}
# Find each module in the modules list
open(LIST, "gunzip -c $packages_file |");
while( \n";
&ui_print_footer("", $text{'index_return'});
exit;
}
) {
s/\r|\n//g;
if ($_ eq '') { $found_blank++; }
elsif ($found_blank && /^(\S+)\s+(\S+)\s+(.*)/) {
local $i = &indexof($1, @cpan);
if ($i >= 0 && !$source[$i]) {
$source[$i] = "$config{'cpan'}/$3";
$source[$i] =~ /\/perl-[0-9\.]+\.tar\.gz$/ &&
&install_error(&text('download_eisperl',
"$in{'cpan'}"));
$sourcec++;
}
}
}
close(LIST);
for($i=0; $i<@cpan; $i++) {
push(@missing, "$cpan[$i]") if (!$source[$i]);
}
&install_error(&text('download_ecpan', join(" ", @missing)))
if (@missing);
$source = join("
", @source);
# Download the actual modules
foreach $m (@source) {
$m =~ /\/([^\/]+)\/*$/;
$pfile = &tempname("$1");
$progress_callback_url = $m;
if ($m =~ /^http:\/\/([^\/]+)(\/.*)$/) {
# Make a HTTP request
$host = $1; $page = $2; $port = 80;
if ($host =~ /^(.*):(\d+)$/) { $host = $1; $port = $2; }
&http_download($host, $port, $page, $pfile, \$error,
\&progress_callback);
}
elsif ($m =~ /^ftp:\/\/([^\/]+)(:21)?(\/.*)$/) {
$host = $1; $file = $3;
&ftp_download($host, $file, $pfile, \$error,
\&progress_callback);
}
else { &install_error(&text('download_eurl', $m)); }
&install_error($error) if ($error);
push(@pfile, $pfile);
}
$need_unlink = 1;
}
# Check if the file looks like a perl module
foreach $pfile (@pfile) {
open(TAR, "( gunzip -c $pfile | tar tf - ) 2>&1 |");
while($line =
$main::whatfailed : $_[0]