File:  [LON-CAPA] / loncom / cgi / decompress.pl
Revision 1.16: download - view: text, annotated - select for diffs
Fri May 5 21:07:19 2006 UTC (17 years, 11 months ago) by albertel
Branches: MAIN
CVS tags: version_2_7_X, version_2_7_1, version_2_7_0, version_2_6_X, version_2_6_99_1, version_2_6_99_0, version_2_6_3, version_2_6_2, version_2_6_1, version_2_6_0, version_2_5_X, version_2_5_99_1, version_2_5_99_0, version_2_5_2, version_2_5_1, version_2_5_0, version_2_4_X, version_2_4_99_0, version_2_4_2, version_2_4_1, version_2_4_0, version_2_3_X, version_2_3_99_0, version_2_3_2, version_2_3_1, version_2_3_0, version_2_2_X, version_2_2_99_1, version_2_2_99_0, version_2_2_2, version_2_2_1, version_2_2_0, version_2_1_99_3, version_2_1_99_2, version_2_1_99_1, version_2_1_99_0, HEAD
- look for the binaries instead of assuming we know where they are

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

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