version 1.6, 2003/11/18 04:07:49
|
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 29
|
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; |
#Things still todo, |
|
#It has been tabinated |
|
#Now uses strict! with added feature of making everything very strict! |
|
#about 50% through rewriting things to use split and join |
|
#still have a lot of debugging statements that will go away after I get it to work ok(along with all the <br>'s) |
|
#still have to rewrite the refresh tag to work right, its broken |
|
#the whole thing is broken right now |
|
#will rename the variables and reorder most of the script to make it more sane |
|
#improve the general readability of the whole thing, because unlike C everyone gets to look at it, so it has to be readable |
|
#will get to it tommorrow night as I have a calc test to "pass" yea, or something like that :0) |
|
use lib '/home/httpd/lib/perl'; |
use lib '/home/httpd/lib/perl'; |
use LONCAPA::Configuration; |
use LONCAPA::loncgi; |
use LONCAPA::loncgi(); |
|
use Apache::lonnet; |
my %location_of; |
use strict; |
foreach my $program ('tar','gunzip','bunzip2','unzip') { |
|
foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/', |
|
'/usr/sbin/') { |
|
if (-x $dir.$program) { |
|
$location_of{$program} = $dir.$program; |
|
} |
|
} |
|
} |
|
|
if(! &LONCAPA::loncgi::check_cookie_and_load_env()){ |
if (!&LONCAPA::loncgi::check_cookie_and_load_env()) { |
|
print("Content-type: text/html\n\n"); |
|
print(<<END); |
|
<html><body>NO COOKIE!</body></html> |
|
END |
|
} else { |
print "Content-type: text/html\n\n"; |
print "Content-type: text/html\n\n"; |
print <<END; |
my $file=$Apache::lonnet::env{'cgi.file'}; |
<html><body>NO COOKIE!</body></html> |
my $dir=$Apache::lonnet::env{'cgi.dir'}; |
|
if(! $file || ! $dir) { |
|
print(<<END); |
|
<html><body>Bad Enviroment!</body></html> |
END |
END |
} else {my $username; |
} else { |
print "Content-type: text/html\n\n"; |
print(<<END); |
print "<html><head></head><body>"; |
<html><body><p><b>Output of decompress:</b></p> |
my $path = $ENV{'cgi.path'}; |
END |
$path =~ m|/{1}|; |
chdir($dir); |
$path = $'; #' stupid emacs |
my @cmd; |
$path =~ m|/{1}|; |
if ($file =~ m|\.zip$|) { |
$path = $'; |
@cmd = ($location_of{'unzip'},"-o"); |
my (@right) = split(/\./,$ENV{'request.role'}); |
} elsif ($file =~ m|\.tar\.gz$| |
my $role = shift(@right); |
|| $file =~ m|\.tgz$| ) { |
my $temp = shift(@right); |
@cmd = ($location_of{'tar'},"-zxpvf"); |
my (@left) = split(/\/+/,$temp);; |
} elsif ($file =~ m|\.tar\.bz2$|) { |
shift(@left); |
@cmd = ($location_of{'tar'},"-jxpvf"); |
shift(@left); |
} elsif ($file =~ m|\.bz2$|) { |
$temp = shift(@left); |
@cmd = ($location_of{'bunzip2'}); |
print "temp: $temp"; |
} elsif ($file =~ m|\.gz$|) { |
my $path2 = "/home/$username/public_html/"; |
@cmd = ($location_of{'gunzip'}); |
$path2 .=$path; |
} elsif ($file =~ m|\.tar$|) { |
my $back_path = ""; |
@cmd = ($location_of{'tar'},"-xpvf"); |
while($path =~ m|/|) { |
} else { |
$back_path .= $`; |
print("There has been an error in determining the file type of $file, please check name"); |
$back_path .= "/"; |
} |
$path = $'; #' stupid emacs |
if (@cmd) { |
} |
undef($!); |
$path .= '/'; |
undef($@); |
$path .= $back_path; |
open(OUTPUT,"-|", @cmd, $file); |
print "<br>path: $path<br>"; |
while (my $line = <OUTPUT>) { print("$line<br />"); } |
print "back_path: $back_path <br>"; |
close(OUTPUT); |
print "path2: $path2 <br>"; |
print("<p><b>Decompress complete.</b></p>"); |
print "$path2<br>"; |
if ($! || $@) { |
if ( -r $path2){ |
print("<p><b>An error occurred</b></p><p>$!</p><p>$@</p>"); |
print "Good read access is allowed"; |
} |
print "<br><br>"; |
print("</body></html>"); |
print "<br><br>right: $role"; |
|
my $filename = $ENV{'cgi.file'}; |
|
if($role eq "ca" || $role eq "au") { |
|
chdir $path; |
|
if ($filename =~ m|zip|) { |
|
system "unzip -qq $path2 &> /dev/null"; |
|
} elsif ($filename =~ m|tar.gz|) { |
|
system "tar -zxpvf $path2 &> /dev/null"; |
|
} elsif ($filename =~ m|tar.bz2|){ |
|
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'); |
|
} |
} |
|
|