1: #!/usr/bin/perl
2: #
3: #
4: # Copyright Michigan State University Board of Trustees
5: # $Id:
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/cgi-bin/decompress.pl
24: #
25: # http://www.lon-capa.org/
26: #
27: # The LearningOnline Network with CAPA
28: #
29: # A CGI script that decompresses compressed files for mass uploading into
30: # construction space
31: ####
32:
33: #Things still todo,
34: #It has been tabinated
35: #Now uses strict! with added feature of making everything very strict!
36: #about 50% through rewriting things to use split and join
37: #still have a lot of debugging statements that will go away after I get it to work ok(along with all the <br>'s)
38: #still have to rewrite the refresh tag to work right, its broken
39: #the whole thing is broken right now
40: #will rename the variables and reorder most of the script to make it more sane
41: #improve the general readability of the whole thing, because unlike C everyone gets to look at it, so it has to be readable
42: #will get to it tommorrow night as I have a calc test to "pass" yea, or something like that :0)
43: use lib '/home/httpd/lib/perl';
44: use LONCAPA::Configuration;
45: use LONCAPA::loncgi();
46: use Apache::lonnet;
47: use strict;
48:
49: if(! &LONCAPA::loncgi::check_cookie_and_load_env()){
50: print "Content-type: text/html\n\n";
51: print <<END;
52: <html><body>NO COOKIE!</body></html>
53: END
54: } else {my $username;
55: print "Content-type: text/html\n\n";
56: print "<html><head></head><body>";
57: my $path = $ENV{'cgi.path'};
58: $path =~ m|/{1}|;
59: $path = $'; #' stupid emacs
60: $path =~ m|/{1}|;
61: $path = $';
62: my (@right) = split(/\./,$ENV{'request.role'});
63: my $role = shift(@right);
64: my $temp = shift(@right);
65: my (@left) = split(/\/+/,$temp);;
66: shift(@left);
67: shift(@left);
68: $temp = shift(@left);
69: print "temp: $temp";
70: my $path2 = "/home/$username/public_html/";
71: $path2 .=$path;
72: my $back_path = "";
73: while($path =~ m|/|) {
74: $back_path .= $`;
75: $back_path .= "/";
76: $path = $'; #' stupid emacs
77: }
78: $path .= '/';
79: $path .= $back_path;
80: print "<br>path: $path<br>";
81: print "back_path: $back_path <br>";
82: print "path2: $path2 <br>";
83: print "$path2<br>";
84: if ( -r $path2){
85: print "Good read access is allowed";
86: print "<br><br>";
87: print "<br><br>right: $role";
88: my $filename = $ENV{'cgi.file'};
89: if($role eq "ca" || $role eq "au") {
90: chdir $path;
91: if ($filename =~ m|zip|) {
92: system "unzip -qq $path2 &> /dev/null";
93: } elsif ($filename =~ m|tar.gz|) {
94: system "tar -zxpvf $path2 &> /dev/null";
95: } elsif ($filename =~ m|tar.bz2|){
96: system "tar -jxpvf $path2 &> /dev/null";
97: } elsif ($filename =~ m|bz2|){
98: system "bunzip2 $path2 &> /dev/null";
99: } elsif ($filename =~ m|tgz|){
100: system "tar -zxpvf $path2 &> /dev/null";
101: } elsif ($filename =~ m|gz|){
102: system "gunzip $path2 &> /dev/null";
103: } elsif ($filename =~ m|tar|){
104: system "tar -xpvf $path2 &> /dev/null";
105: }
106: }
107: else {print "You don't have proper privledges";}
108: }
109: else { print "Read access not allowed!"; }
110: #print '<meta http-equiv="refresh" content="0; URL=';
111: #print "http://$ENV{'SERVER_NAME'}/~$username'}/$back_path"; print '" />';
112: print '</body></html>';
113: &Apache::lonnet::delenv('cgi.file');
114: &Apache::lonnet::delenv('cgi.path');
115: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>