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