version 1.8, 2003/11/19 15:07:25
|
version 1.18, 2012/04/19 02:13:00
|
Line 1
|
Line 1
|
#!/usr/bin/perl |
#!/usr/bin/perl |
# |
# |
|
# $Id$ |
# |
# |
# Copyright Michigan State University Board of Trustees |
# Copyright Michigan State University Board of Trustees |
# $Id |
|
# |
# |
# This file is part of the LearningOnline Network with CAPA (LON-CAPA). |
# This file is part of the LearningOnline Network with CAPA (LON-CAPA). |
# |
# |
Line 27
|
Line 27
|
# The LearningOnline Network with CAPA |
# The LearningOnline Network with CAPA |
# |
# |
# A CGI script that decompresses compressed files for mass uploading into |
# A CGI script that decompresses compressed files for mass uploading into |
# construction space |
# construction space or into a course. |
#### |
#### |
use strict; |
use strict; |
use lib '/home/httpd/lib/perl'; |
use lib '/home/httpd/lib/perl'; |
use LONCAPA::loncgi (); |
use Apache::lonnet; |
if(! &LONCAPA::loncgi::check_cookie_and_load_env()) |
use Apache::lonlocal; |
{ |
use LONCAPA::loncgi; |
print "Content-type: text/html\n\n"; |
|
print <<END; |
my %location_of; |
<html><body>NO COOKIE!</body></html> |
foreach my $program ('tar','gunzip','bunzip2','unzip') { |
END |
foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/', |
|
'/usr/sbin/') { |
|
if (-x $dir.$program) { |
|
$location_of{$program} = $dir.$program; |
|
} |
|
} |
} |
} |
else |
|
{ |
print("Content-type: text/html\n\n"); |
print "Content-type: text/html\n\n"; |
|
if(! $ENV{'cgi.file'} || ! $ENV{'cgi.dir'}) |
if (!&LONCAPA::loncgi::check_cookie_and_load_env()) { |
{ |
&Apache::lonlocal::get_language_handle(); |
print <<END; |
print(&LONCAPA::loncgi::missing_cookie_msg()); |
<html><body>Bad Enviroment!</body></html> |
} else { |
|
&Apache::lonlocal::get_language_handle(); |
|
my %lt = &Apache::lonlocal::texthash ( |
|
bade => 'Invalid file or directory name', |
|
outo => 'Output of decompress:', |
|
comp => 'Decompress complete.', |
|
erro => 'An error occurred.', |
|
extf => 'Extraction failed.', |
|
); |
|
my $file=$Apache::lonnet::env{'cgi.file'}; |
|
my $dir=$Apache::lonnet::env{'cgi.dir'}; |
|
if (!$file || !$dir) { |
|
print(<<END); |
|
<html><body><span class="LC_error">$lt{'extf'} $lt{'bade'}</span></body></html> |
END |
END |
} |
} elsif (!-d $dir) { |
else |
print('<html><body><span class="LC_error">'.$lt{'extf'}.' '."\n". |
{ |
&Apache::lonlocal::mt('The specified directory "[_1]" is invalid.',$dir). |
print <<END; |
'</span></body></html>'); |
<html><body><b>Output of decompress:</b><br /><br /> |
} else { |
|
my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'}; |
|
my $lonuserroot = $Apache::lonnet::perlvar{'lonUsersDir'}; |
|
if (($dir !~ /^\Qlondocroot\E/) && ($dir !~ /^\Q$lonuserroot\E/)) { |
|
print('<html><body><span class="LC_error">'.$lt{'extf'}.'<br />'."\n". |
|
&Apache::lonlocal::mt('The specified directory "[_1]" is invalid',$dir). |
|
'</span></body></html>'); |
|
} elsif (chdir($dir)) { |
|
if (-e $file) { |
|
print(<<END); |
|
<html><body><p><b>$lt{'outo'}</b></p> |
END |
END |
chdir $ENV{'cgi.dir'}; |
my @cmd; |
if ($ENV{'cgi.file'} =~ m|zip|) |
if ($file =~ m|\.zip$|) { |
{ |
@cmd = ($location_of{'unzip'},"-o"); |
open(OUTPUT, "unzip $ENV{'cgi.file'} 2> /dev/null |"); |
} elsif ($file =~ m|\.tar\.gz$| |
while (<OUTPUT>) |
|| $file =~ m|\.tgz$| ) { |
{ |
@cmd = ($location_of{'tar'},"-zxpvf"); |
print "$_<br />"; |
} elsif ($file =~ m|\.tar\.bz2$|) { |
} |
@cmd = ($location_of{'tar'},"-jxpvf"); |
close(TRACE); |
} elsif ($file =~ m|\.bz2$|) { |
} |
@cmd = ($location_of{'bunzip2'}); |
elsif ($ENV{'cgi.file'} =~ m|tar.gz|) |
} elsif ($file =~ m|\.gz$|) { |
{ |
@cmd = ($location_of{'gunzip'}); |
open(OUTPUT, "tar -zxpvf $ENV{'cgi.file'} 2> /dev/null |"); |
} elsif ($file =~ m|\.tar$|) { |
while (<OUTPUT>) |
@cmd = ($location_of{'tar'},"-xpvf"); |
{ |
} |
print "$_<br />"; |
if (@cmd) { |
} |
undef($!); |
close(TRACE); |
undef($@); |
} |
open(OUTPUT,"-|", @cmd, $file); |
elsif ($ENV{'cgi.file'} =~ m|tar.bz2|) |
while (my $line = <OUTPUT>) { print("$line<br />"); } |
{ |
close(OUTPUT); |
open(OUTPUT, "tar -jxpvf $ENV{'cgi.file'} 2> /dev/null |"); |
print("<p><b>$lt{'comp'}</b></p>"); |
while (<OUTPUT>) |
if ($! || $@) { |
{ |
print('<p><span class="LC_error">'.$lt{'erro'}.'<br />'.$!."\n". |
print "$_<br />"; |
'<br />'.$@.'</span></p>'); |
} |
} else { |
close(TRACE); |
&Apache::lonnet::appenv({'cgi.decompressed' => 'ok'}); |
} |
} |
elsif ($ENV{'cgi.file'} =~ m|bz2|) |
} else { |
{ |
print('<span class="LC_error">'. |
open(OUTPUT, "bunzip2 $ENV{'cgi.file'} 2> /dev/null |"); |
&Apache::lonlocal::mt('There has been an error in determining the file type of [_1], please check the name.',$file).'</span>'); |
while (<OUTPUT>) |
} |
{ |
print('</body></html>'); |
print "$_<br />"; |
} else { |
} |
print('<html><body><span class="LC_error">'.$lt{'extf'}.'<br />'."\n". |
close(TRACE); |
&Apache::lonlocal::mt('The specified file "[_1]" does not exist.',$file). |
} |
'</span></body></html>'); |
elsif ($ENV{'cgi.file'} =~ m|tgz|) |
} |
{ |
} else { |
open(OUTPUT, "tar -zxpvf $ENV{'cgi.file'} 2> /dev/null |"); |
print('<html><body><span class="LC_error">'.$lt{'extf'}.'<br />'."\n". |
while (<OUTPUT>) |
&Apache::lonlocal::mt('Could not change working directory to "[_1]".',$dir). |
{ |
'</span></body></html>'); |
print "$_<br />"; |
|
} |
|
close(TRACE); |
|
} |
|
elsif ($ENV{'cgi.file'} =~ m|gz|) |
|
{ |
|
open(OUTPUT, "gunzip $ENV{'cgi.file'} 2> /dev/null |"); |
|
while (<OUTPUT>) |
|
{ |
|
print "$_<br />"; |
|
} |
|
close(TRACE); |
|
} |
|
elsif ($ENV{'cgi.file'} =~ m|tar|) |
|
{ |
|
open(OUTPUT, "tar -xpvf $ENV{'cgi.file'} 2> /dev/null |"); |
|
while (<OUTPUT>) |
|
{ |
|
print "$_<br />"; |
|
} |
|
close(TRACE); |
|
} |
|
else |
|
{ |
|
print "There has been an error in determining the file type of $ENV{'cgi.file'}, please check name"; |
|
} |
} |
print "<br /><b>Decompress complete!</b><br /></body></html>"; |
|
} |
} |
} |
} |
|
|