version 1.4, 2003/10/20 22:38:28
|
version 1.15, 2005/11/03 20:36:58
|
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 LONCAPA::loncgi; |
use LONCAPA::loncgi(); |
|
|
|
if(! &LONCAPA::loncgi::check_cookie_and_load_env()){ |
if(! &LONCAPA::loncgi::check_cookie_and_load_env()) { |
print "Content-type: text/html\n\n"; |
print "Content-type: text/html\n\n"; |
print <<END; |
print <<END; |
<html><body>NO COOKIE!</body></html> |
<html><body>NO COOKIE!</body></html> |
END |
END |
} else { |
} else { |
$url = $ENV{'HTTP_REFERER'}; |
print "Content-type: text/html\n\n"; |
$url =~ m|/{2}|; |
my $file=$Apache::lonnet::env{'cgi.file'}; |
$url = $'; #' stupid emacs |
my $dir=$Apache::lonnet::env{'cgi.dir'}; |
$url =~ m|/{1}|; |
if(! $file || ! $dir) { |
$referer = $`; |
print(<<END); |
if($referer ne $ENV{'SERVER_NAME'}) { |
<html><body>Bad Enviroment!</body></html> |
print "Content-type: text/html\n\n"; |
END |
print "<html><body>You are trying something that is not allowed, go to the real homeserver and try again</body></html>"; |
|
} else { |
} else { |
$url = $'; #' stupid emacs |
print(<<END); |
$url =~ m|$ENV{'user.name'}/{1}|; |
<html><body><p><b>Output of decompress:</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 = ("/usr/bin/unzip","-o"); |
while($url =~ m|/|) { |
} elsif ($file =~ m|\.tar\.gz$|) { |
$path .= $`; |
@cmd = ("/usr/bin/tar","-zxpvf"); |
$back_path .= $`; |
} elsif ($file =~ m|\.tar\.bz2$|) { |
$path .= "/"; |
@cmd = ("/usr/bin/tar","-jxpvf"); |
$back_path .= "/"; |
} elsif ($file =~ m|\.bz2$|) { |
$url = $'; #' stupid emacs |
@cmd = ("/usr/bin/bunzip2"); |
} |
} elsif ($file =~ m|\.tgz$|) { |
chdir $path; |
@cmd = ("/usr/bin/tar","-zxpvf"); |
$filename=$url; |
} elsif ($file =~ m|\.gz$|) { |
if ($url =~ m|zip|) { |
@cmd = ("/usr/bin/gunzip"); |
system "unzip -qq $filename &> /dev/null"; |
} elsif ($file =~ m|\.tar$|) { |
} elsif ($url =~ m|tar.gz|) { |
@cmd = ("/usr/bin/tar","-xpvf"); |
system "tar -zxpvf $filename &> /dev/null"; |
} else { |
} elsif ($url =~ m|tar.bz2|){ |
print("There has been an error in determining the file type of $file, please check name"); |
system "tar -jxpvf $filename &> /dev/null"; |
} |
} elsif ($url =~ m|bz2|){ |
if (@cmd) { |
system "bunzip2 $filename &> /dev/null"; |
undef($!); |
} elsif ($url =~ m|tgz|){ |
undef($@); |
system "tar -zxpvf $filename &> /dev/null"; |
open(OUTPUT,"-|", @cmd, $file); |
} elsif ($url =~ m|gz|){ |
while (<OUTPUT>) { print "$_<br />"; } |
system "gunzip $filename &> /dev/null"; |
close(OUTPUT); |
} elsif ($url =~ m|tar|){ |
print("<p><b>Decompress complete.</b></p>"); |
system "tar -xpvf $filename &> /dev/null"; |
if ($! || $@) { |
|
print("<p><b>An error occurred</b></p><p>$!</p><p>$@</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>'; |
|