version 1.4, 2003/10/20 22:38:28
|
version 1.12, 2004/06/09 19:04:47
|
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(); |
my %origENV=%ENV; |
|
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=$ENV{'cgi.file'}; |
$url = $'; #' stupid emacs |
my $dir=$ENV{'cgi.dir'}; |
$url =~ m|/{1}|; |
%ENV=%origENV; |
$referer = $`; |
if(! $file || ! $dir) { |
if($referer ne $ENV{'SERVER_NAME'}) { |
print <<END; |
print "Content-type: text/html\n\n"; |
<html><body>Bad Enviroment!</body></html> |
print "<html><body>You are trying something that is not allowed, go to the real homeserver and try again</body></html>"; |
END |
} else { |
} else { |
$url = $'; #' stupid emacs |
print <<END; |
$url =~ m|$ENV{'user.name'}/{1}|; |
<html><body><b>Output of decompress:</b><br /><br /> |
$url = $'; #' stupid emacs |
END |
$url =~ m|\?{1}|; |
chdir $dir; |
$url = $`; |
if ($file =~ m|zip|) { |
$path ="/home/$ENV{'user.name'}/public_html/"; |
open(OUTPUT, "unzip $file 2> /dev/null |"); |
$back_path = ""; |
while (<OUTPUT>) { |
while($url =~ m|/|) { |
print "$_<br />"; |
$path .= $`; |
} |
$back_path .= $`; |
close(OUTPUT); |
$path .= "/"; |
} elsif ($file =~ m|tar.gz|) { |
$back_path .= "/"; |
open(OUTPUT, "tar -zxpvf $file 2> /dev/null |"); |
$url = $'; #' stupid emacs |
while (<OUTPUT>) { |
} |
print "$_<br />"; |
chdir $path; |
} |
$filename=$url; |
close(OUTPUT); |
if ($url =~ m|zip|) { |
} elsif ($file =~ m|tar.bz2|) { |
system "unzip -qq $filename &> /dev/null"; |
open(OUTPUT, "tar -jxpvf $file 2> /dev/null |"); |
} elsif ($url =~ m|tar.gz|) { |
while (<OUTPUT>) { |
system "tar -zxpvf $filename &> /dev/null"; |
print "$_<br />"; |
} elsif ($url =~ m|tar.bz2|){ |
} |
system "tar -jxpvf $filename &> /dev/null"; |
close(OUTPUT); |
} elsif ($url =~ m|bz2|){ |
} elsif ($file =~ m|bz2|) { |
system "bunzip2 $filename &> /dev/null"; |
open(OUTPUT, "bunzip2 $file 2> /dev/null |"); |
} elsif ($url =~ m|tgz|){ |
while (<OUTPUT>) { |
system "tar -zxpvf $filename &> /dev/null"; |
print "$_<br />"; |
} elsif ($url =~ m|gz|){ |
} |
system "gunzip $filename &> /dev/null"; |
close(OUTPUT); |
} elsif ($url =~ m|tar|){ |
} elsif ($file =~ m|tgz|) { |
system "tar -xpvf $filename &> /dev/null"; |
open(OUTPUT, "tar -zxpvf $file 2> /dev/null |"); |
} |
while (<OUTPUT>) { |
|
print "$_<br />"; |
|
} |
|
close(OUTPUT); |
|
} elsif ($file =~ m|gz|) { |
|
open(OUTPUT, "gunzip $file 2> /dev/null |"); |
|
while (<OUTPUT>) { |
|
print "$_<br />"; |
|
} |
|
close(OUTPUT); |
|
} elsif ($file =~ m|tar|) { |
|
open(OUTPUT, "tar -xpvf $file 2> /dev/null |"); |
|
while (<OUTPUT>) { |
|
print "$_<br />"; |
|
} |
|
close(OUTPUT); |
|
} else { |
|
print "There has been an error in determining the file type of $file, please check name"; |
|
} |
|
print "<br /><b>Decompress complete!</b><br /></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>'; |
|