File:  [LON-CAPA] / loncom / cgi / decompress.pl
Revision 1.11: download - view: text, annotated - select for diffs
Sat Dec 13 00:20:47 2003 UTC (20 years, 4 months ago) by albertel
Branches: MAIN
CVS tags: version_1_1_99_0, HEAD
- match the extension only (was mishandling zip.tar)
- match case insesitively

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

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