File:  [LON-CAPA] / loncom / cgi / decompress.pl
Revision 1.15: download - view: text, annotated - select for diffs
Thu Nov 3 20:36:58 2005 UTC (18 years, 6 months ago) by albertel
Branches: MAIN
CVS tags: version_2_1_X, version_2_1_3, version_2_1_2, version_2_1_1, version_2_1_0, version_2_0_99_1, HEAD
- shorter and safer
- BUG#4439, filneams with spaces weren't working

    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: 
   36: if(! &LONCAPA::loncgi::check_cookie_and_load_env()) {
   37:     print "Content-type: text/html\n\n";
   38:     print <<END;
   39:     <html><body>NO COOKIE!</body></html>
   40: END
   41: } else {
   42:     print "Content-type: text/html\n\n";
   43:     my $file=$Apache::lonnet::env{'cgi.file'};
   44:     my $dir=$Apache::lonnet::env{'cgi.dir'}; 
   45:     if(! $file || ! $dir) {
   46:         print(<<END);
   47:         <html><body>Bad Enviroment!</body></html>
   48: END
   49:     } else {
   50:         print(<<END);
   51: 	<html><body><p><b>Output of decompress:</b></p>
   52: END
   53:         chdir($dir);
   54: 	my @cmd;
   55:         if ($file =~ m|\.zip$|) {
   56:             @cmd = ("/usr/bin/unzip","-o");
   57:         } elsif ($file =~ m|\.tar\.gz$|) {
   58:             @cmd = ("/usr/bin/tar","-zxpvf");
   59:         } elsif ($file =~ m|\.tar\.bz2$|) {
   60:             @cmd = ("/usr/bin/tar","-jxpvf");
   61:         } elsif ($file =~ m|\.bz2$|) {
   62:             @cmd = ("/usr/bin/bunzip2");
   63:         } elsif ($file =~ m|\.tgz$|) {
   64:             @cmd = ("/usr/bin/tar","-zxpvf");
   65:         } elsif ($file =~ m|\.gz$|) {
   66: 	    @cmd = ("/usr/bin/gunzip");
   67:         } elsif ($file =~ m|\.tar$|) {
   68:             @cmd = ("/usr/bin/tar","-xpvf");
   69:         } else {
   70:             print("There has been an error in determining the file type of $file, please check name");
   71:         }
   72: 	if (@cmd) {
   73: 	    undef($!);
   74: 	    undef($@);
   75: 	    open(OUTPUT,"-|", @cmd, $file);
   76: 	    while (<OUTPUT>) { print "$_<br />"; }
   77: 	    close(OUTPUT);
   78: 	    print("<p><b>Decompress complete.</b></p>");
   79: 	    if ($! || $@) {
   80: 		print("<p><b>An error occurred</b></p><p>$!</p><p>$@</p>");
   81: 	    }
   82: 	    print("</body></html>");
   83: 	}
   84:     }
   85: }
   86: 

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