version 1.5, 2003/11/17 23:12:12
|
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(); |
|
use Apache::lonnet; |
|
|
|
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 { |
print "Content-type: text/html\n\n"; |
print "Content-type: text/html\n\n"; |
print "<html><head></head><body>"; |
my $file=$Apache::lonnet::env{'cgi.file'}; |
print "$ENV{'cgi.path'}"; |
my $dir=$Apache::lonnet::env{'cgi.dir'}; |
print "<br>$ENV{'cgi.file'}"; |
if(! $file || ! $dir) { |
print "<br>$ENV{'user.name'}<br>"; |
print(<<END); |
$path = $ENV{'cgi.path'}; |
<html><body>Bad Enviroment!</body></html> |
$path =~ m|/{1}|; |
END |
$path = $'; #' stupid emacs |
} else { |
$path =~ m|/{1}|; |
print(<<END); |
$path = $'; |
<html><body><p><b>Output of decompress:</b></p> |
$username = $`; #Hmm, can't use the enviroment for this, if you are a co-author.. so we work around it. |
END |
$path2 = "/home/$username/public_html/"; |
chdir($dir); |
$path2 .=$path; |
my @cmd; |
$back_path = ""; |
if ($file =~ m|\.zip$|) { |
while($path =~ m|/|) { |
@cmd = ($location_of{'unzip'},"-o"); |
$back_path .= $`; |
} elsif ($file =~ m|\.tar\.gz$| |
$back_path .= "/"; |
|| $file =~ m|\.tgz$| ) { |
$path = $'; #' stupid emacs |
@cmd = ($location_of{'tar'},"-zxpvf"); |
} |
} elsif ($file =~ m|\.tar\.bz2$|) { |
$path = "/home/$username/public_html"; |
@cmd = ($location_of{'tar'},"-jxpvf"); |
$path .= '/'; |
} elsif ($file =~ m|\.bz2$|) { |
$path .= $back_path; |
@cmd = ($location_of{'bunzip2'}); |
print "<br>path: $path<br>"; |
} elsif ($file =~ m|\.gz$|) { |
print "back_path: $back_path <br>"; |
@cmd = ($location_of{'gunzip'}); |
print "path2: $path2 <br>"; |
} elsif ($file =~ m|\.tar$|) { |
print "$path2<br>"; |
@cmd = ($location_of{'tar'},"-xpvf"); |
if ( -r $path2){ |
} else { |
print "Good read access is allowed"; |
print("There has been an error in determining the file type of $file, please check name"); |
print "<br><br>"; |
} |
$right = $ENV{'request.role'}; |
if (@cmd) { |
$right =~ m|\.|; |
undef($!); |
$right = $`; |
undef($@); |
$filename = $ENV{'cgi.file'}; |
open(OUTPUT,"-|", @cmd, $file); |
if($right eq "ca" || $right eq "au") { |
while (my $line = <OUTPUT>) { print("$line<br />"); } |
chdir $path; |
close(OUTPUT); |
if ($filename =~ m|zip|) { |
print("<p><b>Decompress complete.</b></p>"); |
system "unzip -qq $path2 &> /dev/null"; |
if ($! || $@) { |
} elsif ($filename =~ m|tar.gz|) { |
print("<p><b>An error occurred</b></p><p>$!</p><p>$@</p>"); |
system "tar -zxpvf $path2 &> /dev/null"; |
} |
} elsif ($filename =~ m|tar.bz2|){ |
print("</body></html>"); |
system "tar -jxpvf $path2 &> /dev/null"; |
|
} elsif ($filename =~ m|bz2|){ |
|
system "bunzip2 $path2 &> /dev/null"; |
|
} elsif ($filename =~ m|tgz|){ |
|
system "tar -zxpvf $path2 &> /dev/null"; |
|
} elsif ($filename =~ m|gz|){ |
|
system "gunzip $path2 &> /dev/null"; |
|
} elsif ($filename =~ m|tar|){ |
|
system "tar -xpvf $path2 &> /dev/null"; |
|
} |
} |
} |
} |
else {print "You don't have proper privledges";} |
|
} |
|
else { print "Read access not allowed!"; } |
|
print '<meta http-equiv="refresh" content="0; URL='; |
|
print "http://$ENV{'SERVER_NAME'}/~$username'}/$back_path"; print '" />'; |
|
print '</body></html>'; |
|
&Apache::lonnet::delenv(cgi.file); |
|
&Apache::lonnet::delenv(cgi.path); |
|
} |
} |
|
|