version 1.3, 2003/10/20 15:51:51
|
version 1.16, 2006/05/05 21:07:19
|
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()){ |
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/') { |
|
if (-x $dir.$program) { |
|
$location_of{$program} = $dir.$program; |
|
} |
|
} |
|
} |
|
|
|
if (!&LONCAPA::loncgi::check_cookie_and_load_env()) { |
|
print("Content-type: text/html\n\n"); |
|
print(<<END); |
|
<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 = ($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("There has been an error in determining the file type of $file, please check name"); |
} 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>Decompress complete.</b></p>"); |
} elsif ($url =~ m|tar|){ |
if ($! || $@) { |
system "tar -xpvf $filename &> /dev/null"; |
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>'; |
|