version 1.6, 2003/11/18 04:07:49
|
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 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(); |
my %origENV=%ENV; |
use Apache::lonnet; |
if(! &LONCAPA::loncgi::check_cookie_and_load_env()) { |
use strict; |
|
|
|
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 {my $username; |
} else { |
print "Content-type: text/html\n\n"; |
print "Content-type: text/html\n\n"; |
print "<html><head></head><body>"; |
my $file=$ENV{'cgi.file'}; |
my $path = $ENV{'cgi.path'}; |
my $dir=$ENV{'cgi.dir'}; |
$path =~ m|/{1}|; |
%ENV=%origENV; |
$path = $'; #' stupid emacs |
if(! $file || ! $dir) { |
$path =~ m|/{1}|; |
print <<END; |
$path = $'; |
<html><body>Bad Enviroment!</body></html> |
my (@right) = split(/\./,$ENV{'request.role'}); |
END |
my $role = shift(@right); |
} else { |
my $temp = shift(@right); |
print <<END; |
my (@left) = split(/\/+/,$temp);; |
<html><body><b>Output of decompress:</b><br /><br /> |
shift(@left); |
END |
shift(@left); |
chdir $dir; |
$temp = shift(@left); |
if ($file =~ m|zip|) { |
print "temp: $temp"; |
open(OUTPUT, "unzip $file 2> /dev/null |"); |
my $path2 = "/home/$username/public_html/"; |
while (<OUTPUT>) { |
$path2 .=$path; |
print "$_<br />"; |
my $back_path = ""; |
} |
while($path =~ m|/|) { |
close(OUTPUT); |
$back_path .= $`; |
} elsif ($file =~ m|tar.gz|) { |
$back_path .= "/"; |
open(OUTPUT, "tar -zxpvf $file 2> /dev/null |"); |
$path = $'; #' stupid emacs |
while (<OUTPUT>) { |
} |
print "$_<br />"; |
$path .= '/'; |
} |
$path .= $back_path; |
close(OUTPUT); |
print "<br>path: $path<br>"; |
} elsif ($file =~ m|tar.bz2|) { |
print "back_path: $back_path <br>"; |
open(OUTPUT, "tar -jxpvf $file 2> /dev/null |"); |
print "path2: $path2 <br>"; |
while (<OUTPUT>) { |
print "$path2<br>"; |
print "$_<br />"; |
if ( -r $path2){ |
} |
print "Good read access is allowed"; |
close(OUTPUT); |
print "<br><br>"; |
} elsif ($file =~ m|bz2|) { |
print "<br><br>right: $role"; |
open(OUTPUT, "bunzip2 $file 2> /dev/null |"); |
my $filename = $ENV{'cgi.file'}; |
while (<OUTPUT>) { |
if($role eq "ca" || $role eq "au") { |
print "$_<br />"; |
chdir $path; |
} |
if ($filename =~ m|zip|) { |
close(OUTPUT); |
system "unzip -qq $path2 &> /dev/null"; |
} elsif ($file =~ m|tgz|) { |
} elsif ($filename =~ m|tar.gz|) { |
open(OUTPUT, "tar -zxpvf $file 2> /dev/null |"); |
system "tar -zxpvf $path2 &> /dev/null"; |
while (<OUTPUT>) { |
} elsif ($filename =~ m|tar.bz2|){ |
print "$_<br />"; |
system "tar -jxpvf $path2 &> /dev/null"; |
} |
} elsif ($filename =~ m|bz2|){ |
close(OUTPUT); |
system "bunzip2 $path2 &> /dev/null"; |
} elsif ($file =~ m|gz|) { |
} elsif ($filename =~ m|tgz|){ |
open(OUTPUT, "gunzip $file 2> /dev/null |"); |
system "tar -zxpvf $path2 &> /dev/null"; |
while (<OUTPUT>) { |
} elsif ($filename =~ m|gz|){ |
print "$_<br />"; |
system "gunzip $path2 &> /dev/null"; |
} |
} elsif ($filename =~ m|tar|){ |
close(OUTPUT); |
system "tar -xpvf $path2 &> /dev/null"; |
} elsif ($file =~ m|tar|) { |
} |
open(OUTPUT, "tar -xpvf $file 2> /dev/null |"); |
} |
while (<OUTPUT>) { |
else {print "You don't have proper privledges";} |
print "$_<br />"; |
} |
} |
else { print "Read access not allowed!"; } |
close(OUTPUT); |
#print '<meta http-equiv="refresh" content="0; URL='; |
} else { |
#print "http://$ENV{'SERVER_NAME'}/~$username'}/$back_path"; print '" />'; |
print "There has been an error in determining the file type of $file, please check name"; |
print '</body></html>'; |
} |
&Apache::lonnet::delenv('cgi.file'); |
print "<br /><b>Decompress complete!</b><br /></body></html>"; |
&Apache::lonnet::delenv('cgi.path'); |
} |
} |
} |
|
|