version 1.12, 2004/06/09 19:04:47
|
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; |
my %origENV=%ENV; |
use Apache::lonlocal; |
if(! &LONCAPA::loncgi::check_cookie_and_load_env()) { |
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; |
|
} |
|
} |
|
} |
|
|
|
print("Content-type: text/html\n\n"); |
|
|
|
if (!&LONCAPA::loncgi::check_cookie_and_load_env()) { |
|
&Apache::lonlocal::get_language_handle(); |
|
print(&LONCAPA::loncgi::missing_cookie_msg()); |
} else { |
} else { |
print "Content-type: text/html\n\n"; |
&Apache::lonlocal::get_language_handle(); |
my $file=$ENV{'cgi.file'}; |
my %lt = &Apache::lonlocal::texthash ( |
my $dir=$ENV{'cgi.dir'}; |
bade => 'Invalid file or directory name', |
%ENV=%origENV; |
outo => 'Output of decompress:', |
if(! $file || ! $dir) { |
comp => 'Decompress complete.', |
print <<END; |
erro => 'An error occurred.', |
<html><body>Bad Enviroment!</body></html> |
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) { |
|
print('<html><body><span class="LC_error">'.$lt{'extf'}.' '."\n". |
|
&Apache::lonlocal::mt('The specified directory "[_1]" is invalid.',$dir). |
|
'</span></body></html>'); |
} else { |
} else { |
print <<END; |
my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'}; |
<html><body><b>Output of decompress:</b><br /><br /> |
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 $dir; |
my @cmd; |
if ($file =~ m|zip|) { |
if ($file =~ m|\.zip$|) { |
open(OUTPUT, "unzip $file 2> /dev/null |"); |
@cmd = ($location_of{'unzip'},"-o"); |
while (<OUTPUT>) { |
} elsif ($file =~ m|\.tar\.gz$| |
print "$_<br />"; |
|| $file =~ m|\.tgz$| ) { |
} |
@cmd = ($location_of{'tar'},"-zxpvf"); |
close(OUTPUT); |
} elsif ($file =~ m|\.tar\.bz2$|) { |
} elsif ($file =~ m|tar.gz|) { |
@cmd = ($location_of{'tar'},"-jxpvf"); |
open(OUTPUT, "tar -zxpvf $file 2> /dev/null |"); |
} elsif ($file =~ m|\.bz2$|) { |
while (<OUTPUT>) { |
@cmd = ($location_of{'bunzip2'}); |
print "$_<br />"; |
} elsif ($file =~ m|\.gz$|) { |
} |
@cmd = ($location_of{'gunzip'}); |
close(OUTPUT); |
} elsif ($file =~ m|\.tar$|) { |
} elsif ($file =~ m|tar.bz2|) { |
@cmd = ($location_of{'tar'},"-xpvf"); |
open(OUTPUT, "tar -jxpvf $file 2> /dev/null |"); |
} |
while (<OUTPUT>) { |
if (@cmd) { |
print "$_<br />"; |
undef($!); |
} |
undef($@); |
close(OUTPUT); |
open(OUTPUT,"-|", @cmd, $file); |
} elsif ($file =~ m|bz2|) { |
while (my $line = <OUTPUT>) { print("$line<br />"); } |
open(OUTPUT, "bunzip2 $file 2> /dev/null |"); |
close(OUTPUT); |
while (<OUTPUT>) { |
print("<p><b>$lt{'comp'}</b></p>"); |
print "$_<br />"; |
if ($! || $@) { |
} |
print('<p><span class="LC_error">'.$lt{'erro'}.'<br />'.$!."\n". |
close(OUTPUT); |
'<br />'.$@.'</span></p>'); |
} elsif ($file =~ m|tgz|) { |
} else { |
open(OUTPUT, "tar -zxpvf $file 2> /dev/null |"); |
&Apache::lonnet::appenv({'cgi.decompressed' => 'ok'}); |
while (<OUTPUT>) { |
} |
print "$_<br />"; |
} else { |
} |
print('<span class="LC_error">'. |
close(OUTPUT); |
&Apache::lonlocal::mt('There has been an error in determining the file type of [_1], please check the name.',$file).'</span>'); |
} elsif ($file =~ m|gz|) { |
} |
open(OUTPUT, "gunzip $file 2> /dev/null |"); |
print('</body></html>'); |
while (<OUTPUT>) { |
} else { |
print "$_<br />"; |
print('<html><body><span class="LC_error">'.$lt{'extf'}.'<br />'."\n". |
} |
&Apache::lonlocal::mt('The specified file "[_1]" does not exist.',$file). |
close(OUTPUT); |
'</span></body></html>'); |
} elsif ($file =~ m|tar|) { |
|
open(OUTPUT, "tar -xpvf $file 2> /dev/null |"); |
|
while (<OUTPUT>) { |
|
print "$_<br />"; |
|
} |
} |
close(OUTPUT); |
|
} else { |
} else { |
print "There has been an error in determining the file type of $file, please check name"; |
print('<html><body><span class="LC_error">'.$lt{'extf'}.'<br />'."\n". |
|
&Apache::lonlocal::mt('Could not change working directory to "[_1]".',$dir). |
|
'</span></body></html>'); |
} |
} |
print "<br /><b>Decompress complete!</b><br /></body></html>"; |
|
} |
} |
} |
} |
|
|