version 1.4, 2003/10/20 22:38:28
|
version 1.17, 2008/11/28 20:42:20
|
Line 1
|
Line 1
|
#!/usr/bin/perl |
#!/usr/bin/perl |
# |
# |
# |
# |
# 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 28
|
Line 29
|
# 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 |
#### |
#### |
|
use strict; |
use lib '/home/httpd/lib/perl'; |
use lib '/home/httpd/lib/perl'; |
use LONCAPA::Configuration; |
use Apache::lonnet; |
use LONCAPA::loncgi(); |
use Apache::lonlocal; |
|
use LONCAPA::loncgi; |
|
|
if(! &LONCAPA::loncgi::check_cookie_and_load_env()){ |
my %location_of; |
print "Content-type: text/html\n\n"; |
foreach my $program ('tar','gunzip','bunzip2','unzip') { |
print <<END; |
foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/', |
<html><body>NO COOKIE!</body></html> |
'/usr/sbin/') { |
END |
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 { |
$url = $ENV{'HTTP_REFERER'}; |
&Apache::lonlocal::get_language_handle(); |
$url =~ m|/{2}|; |
my %lt = &Apache::lonlocal::texthash ( |
$url = $'; #' stupid emacs |
bade => 'Bad Environment!', |
$url =~ m|/{1}|; |
outo => 'Output of decompress:', |
$referer = $`; |
comp => 'Decompress complete.', |
if($referer ne $ENV{'SERVER_NAME'}) { |
erro => 'An error occurred', |
print "Content-type: text/html\n\n"; |
); |
print "<html><body>You are trying something that is not allowed, go to the real homeserver and try again</body></html>"; |
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{'bade'}</span></body></html> |
|
END |
} else { |
} else { |
$url = $'; #' stupid emacs |
print(<<END); |
$url =~ m|$ENV{'user.name'}/{1}|; |
<html><body><p><b>$lt{'outo'}</b></p> |
$url = $'; #' stupid emacs |
END |
$url =~ m|\?{1}|; |
chdir($dir); |
$url = $`; |
my @cmd; |
$path ="/home/$ENV{'user.name'}/public_html/"; |
if ($file =~ m|\.zip$|) { |
$back_path = ""; |
@cmd = ($location_of{'unzip'},"-o"); |
while($url =~ m|/|) { |
} elsif ($file =~ m|\.tar\.gz$| |
$path .= $`; |
|| $file =~ m|\.tgz$| ) { |
$back_path .= $`; |
@cmd = ($location_of{'tar'},"-zxpvf"); |
$path .= "/"; |
} elsif ($file =~ m|\.tar\.bz2$|) { |
$back_path .= "/"; |
@cmd = ($location_of{'tar'},"-jxpvf"); |
$url = $'; #' stupid emacs |
} elsif ($file =~ m|\.bz2$|) { |
} |
@cmd = ($location_of{'bunzip2'}); |
chdir $path; |
} elsif ($file =~ m|\.gz$|) { |
$filename=$url; |
@cmd = ($location_of{'gunzip'}); |
if ($url =~ m|zip|) { |
} elsif ($file =~ m|\.tar$|) { |
system "unzip -qq $filename &> /dev/null"; |
@cmd = ($location_of{'tar'},"-xpvf"); |
} elsif ($url =~ m|tar.gz|) { |
} else { |
system "tar -zxpvf $filename &> /dev/null"; |
print('<span class="LC_error">'.&Apache::lonlocal::mt('There has been an error in determining the file type of [_1], please check the name',$file).'</span>'); |
} elsif ($url =~ m|tar.bz2|){ |
} |
system "tar -jxpvf $filename &> /dev/null"; |
if (@cmd) { |
} elsif ($url =~ m|bz2|){ |
undef($!); |
system "bunzip2 $filename &> /dev/null"; |
undef($@); |
} elsif ($url =~ m|tgz|){ |
open(OUTPUT,"-|", @cmd, $file); |
system "tar -zxpvf $filename &> /dev/null"; |
while (my $line = <OUTPUT>) { print("$line<br />"); } |
} elsif ($url =~ m|gz|){ |
close(OUTPUT); |
system "gunzip $filename &> /dev/null"; |
print("<p><b>$lt{'comp'}</b></p>"); |
} elsif ($url =~ m|tar|){ |
if ($! || $@) { |
system "tar -xpvf $filename &> /dev/null"; |
print('<p><span class="LC_error">'.$lt{'erro'}.'<br />'.$!.'<br />'.$@.'</span></p>'); |
|
} |
} |
} |
|
print('</body></html>'); |
} |
} |
} |
} |
print "Content-type: text/html\n\n"; |
|
print '<html><head>'; |
|
print '<meta http-equiv="refresh" content="0; URL='; |
|
print "http://$ENV{'SERVER_NAME'}/~$ENV{'user.name'}/$back_path"; print '" />'; |
|
print '</head></html>'; |
|