Annotation of loncom/cgi/decompress.pl, revision 1.5
1.1 taceyjo1 1: #!/usr/bin/perl
2: #
3: #
4: # Copyright Michigan State University Board of Trustees
5: #
6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
7: #
8: # LON-CAPA is free software; you can redistribute it and/or modify
9: # it under the terms of the GNU General Public License as published by
10: # the Free Software Foundation; either version 2 of the License, or
11: # (at your option) any later version.
12: #
13: # LON-CAPA is distributed in the hope that it will be useful,
14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: # GNU General Public License for more details.
17: #
18: # You should have received a copy of the GNU General Public License
19: # along with LON-CAPA; if not, write to the Free Software
20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21: #
22: # /home/httpd/cgi-bin/decompress.pl
23: #
24: # http://www.lon-capa.org/
25: #
26: # The LearningOnline Network with CAPA
27: #
28: # A CGI script that decompresses compressed files for mass uploading into
29: # construction space
30: ####
31: use lib '/home/httpd/lib/perl';
32: use LONCAPA::Configuration;
33: use LONCAPA::loncgi();
1.5 ! taceyjo1 34: use Apache::lonnet;
1.1 taceyjo1 35:
36: if(! &LONCAPA::loncgi::check_cookie_and_load_env()){
1.3 albertel 37: print "Content-type: text/html\n\n";
38: print <<END;
39: <html><body>NO COOKIE!</body></html>
40: END
41: } else {
1.5 ! taceyjo1 42: print "Content-type: text/html\n\n";
! 43: print "<html><head></head><body>";
! 44: print "$ENV{'cgi.path'}";
! 45: print "<br>$ENV{'cgi.file'}";
! 46: print "<br>$ENV{'user.name'}<br>";
! 47: $path = $ENV{'cgi.path'};
! 48: $path =~ m|/{1}|;
! 49: $path = $'; #' stupid emacs
! 50: $path =~ m|/{1}|;
! 51: $path = $';
! 52: $username = $`; #Hmm, can't use the enviroment for this, if you are a co-author.. so we work around it.
! 53: $path2 = "/home/$username/public_html/";
! 54: $path2 .=$path;
! 55: $back_path = "";
! 56: while($path =~ m|/|) {
1.3 albertel 57: $back_path .= $`;
58: $back_path .= "/";
1.5 ! taceyjo1 59: $path = $'; #' stupid emacs
1.1 taceyjo1 60: }
1.5 ! taceyjo1 61: $path = "/home/$username/public_html";
! 62: $path .= '/';
! 63: $path .= $back_path;
! 64: print "<br>path: $path<br>";
! 65: print "back_path: $back_path <br>";
! 66: print "path2: $path2 <br>";
! 67: print "$path2<br>";
! 68: if ( -r $path2){
! 69: print "Good read access is allowed";
! 70: print "<br><br>";
! 71: $right = $ENV{'request.role'};
! 72: $right =~ m|\.|;
! 73: $right = $`;
! 74: $filename = $ENV{'cgi.file'};
! 75: if($right eq "ca" || $right eq "au") {
! 76: chdir $path;
! 77: if ($filename =~ m|zip|) {
! 78: system "unzip -qq $path2 &> /dev/null";
! 79: } elsif ($filename =~ m|tar.gz|) {
! 80: system "tar -zxpvf $path2 &> /dev/null";
! 81: } elsif ($filename =~ m|tar.bz2|){
! 82: system "tar -jxpvf $path2 &> /dev/null";
! 83: } elsif ($filename =~ m|bz2|){
! 84: system "bunzip2 $path2 &> /dev/null";
! 85: } elsif ($filename =~ m|tgz|){
! 86: system "tar -zxpvf $path2 &> /dev/null";
! 87: } elsif ($filename =~ m|gz|){
! 88: system "gunzip $path2 &> /dev/null";
! 89: } elsif ($filename =~ m|tar|){
! 90: system "tar -xpvf $path2 &> /dev/null";
1.1 taceyjo1 91: }
1.5 ! taceyjo1 92: }
! 93: else {print "You don't have proper privledges";}
1.1 taceyjo1 94: }
1.5 ! taceyjo1 95: else { print "Read access not allowed!"; }
1.3 albertel 96: print '<meta http-equiv="refresh" content="0; URL=';
1.5 ! taceyjo1 97: print "http://$ENV{'SERVER_NAME'}/~$username'}/$back_path"; print '" />';
! 98: print '</body></html>';
! 99: &Apache::lonnet::delenv(cgi.file);
! 100: &Apache::lonnet::delenv(cgi.path);
! 101: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>