Annotation of loncom/cgi/decompress.pl, revision 1.13

1.1       taceyjo1    1: #!/usr/bin/perl
                      2: #
1.7       taceyjo1    3: #
1.1       taceyjo1    4: # Copyright Michigan State University Board of Trustees
1.8       taceyjo1    5: # $Id
1.1       taceyjo1    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: ####
1.7       taceyjo1   32: use strict;
1.1       taceyjo1   33: use lib '/home/httpd/lib/perl';
1.13    ! albertel   34: use LONCAPA::loncgi;
        !            35: 
1.9       albertel   36: if(! &LONCAPA::loncgi::check_cookie_and_load_env()) {
1.3       albertel   37:     print "Content-type: text/html\n\n";
                     38:     print <<END;
1.7       taceyjo1   39:     <html><body>NO COOKIE!</body></html>
1.3       albertel   40: END
1.9       albertel   41: } else {
1.7       taceyjo1   42:     print "Content-type: text/html\n\n";
1.13    ! albertel   43:     my $file=$env{'cgi.file'};
        !            44:     my $dir=$env{'cgi.dir'}; 
1.12      albertel   45:     if(! $file || ! $dir) {
1.7       taceyjo1   46:         print <<END;
                     47:         <html><body>Bad Enviroment!</body></html>
                     48: END
1.9       albertel   49:     } else {
1.7       taceyjo1   50:         print <<END;
                     51: 	<html><body><b>Output of decompress:</b><br /><br />
                     52: END
1.12      albertel   53:         chdir $dir;
                     54:         if ($file =~ m|zip|) {
                     55:             open(OUTPUT, "unzip $file 2> /dev/null |");
1.9       albertel   56:             while (<OUTPUT>) {
1.7       taceyjo1   57:                 print "$_<br />";
                     58:             }
1.10      albertel   59:             close(OUTPUT);
1.12      albertel   60:         } elsif ($file =~ m|tar.gz|) {
                     61:             open(OUTPUT, "tar -zxpvf $file 2> /dev/null |");
1.9       albertel   62:             while (<OUTPUT>) {
1.7       taceyjo1   63:                 print "$_<br />";
                     64:             }
1.10      albertel   65:             close(OUTPUT);
1.12      albertel   66:         } elsif ($file =~ m|tar.bz2|) {
                     67:             open(OUTPUT, "tar -jxpvf $file 2> /dev/null |");
1.9       albertel   68:             while (<OUTPUT>) {
1.7       taceyjo1   69:                 print "$_<br />";
                     70:             }
1.10      albertel   71:             close(OUTPUT);
1.12      albertel   72:         } elsif ($file =~ m|bz2|) {
                     73:             open(OUTPUT, "bunzip2 $file 2> /dev/null |");
1.9       albertel   74:             while (<OUTPUT>) {
1.7       taceyjo1   75:                 print "$_<br />";
                     76:             }
1.10      albertel   77:             close(OUTPUT);
1.12      albertel   78:         } elsif ($file =~ m|tgz|) {
                     79:             open(OUTPUT, "tar -zxpvf $file 2> /dev/null |");
1.9       albertel   80:             while (<OUTPUT>) {
1.7       taceyjo1   81:                 print "$_<br />";
                     82:             }
1.10      albertel   83:             close(OUTPUT);
1.12      albertel   84:         } elsif ($file =~ m|gz|) {
                     85:             open(OUTPUT, "gunzip $file 2> /dev/null |");
1.9       albertel   86:             while (<OUTPUT>) {
1.7       taceyjo1   87:                 print "$_<br />";
                     88:             }
1.10      albertel   89:             close(OUTPUT);
1.12      albertel   90:         } elsif ($file =~ m|tar|) {
                     91:             open(OUTPUT, "tar -xpvf $file 2> /dev/null |");
1.9       albertel   92:             while (<OUTPUT>) {
1.7       taceyjo1   93:                 print "$_<br />";
                     94:             }
1.10      albertel   95:             close(OUTPUT);
1.9       albertel   96:         } else {
1.12      albertel   97:             print "There has been an error in determining the file type of $file, please check name";
1.7       taceyjo1   98:         }
                     99:         print "<br /><b>Decompress complete!</b><br /></body></html>";
                    100:     }
                    101: }
                    102: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>