Diff for /loncom/cgi/decompress.pl between versions 1.13 and 1.18

version 1.13, 2005/04/07 06:56:21 version 1.18, 2012/04/19 02:13:00
Line 1 Line 1
 #!/usr/bin/perl  #!/usr/bin/perl
 #  #
   # $Id$
 #  #
 # Copyright Michigan State University Board of Trustees  # Copyright Michigan State University Board of Trustees
 # $Id  
 #  #
 # This file is part of the LearningOnline Network with CAPA (LON-CAPA).  # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
 #  #
Line 27 Line 27
 # The LearningOnline Network with CAPA  # The LearningOnline Network with CAPA
 #  #
 # A CGI script that decompresses compressed files for mass uploading into  # A CGI script that decompresses compressed files for mass uploading into
 # construction space  # construction space or into a course.
 ####  ####
 use strict;  use strict;
 use lib '/home/httpd/lib/perl';  use lib '/home/httpd/lib/perl';
   use Apache::lonnet;
   use Apache::lonlocal;
 use LONCAPA::loncgi;  use LONCAPA::loncgi;
   
 if(! &LONCAPA::loncgi::check_cookie_and_load_env()) {  my %location_of;
     print "Content-type: text/html\n\n";  foreach my $program ('tar','gunzip','bunzip2','unzip') {
     print <<END;      foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
     <html><body>NO COOKIE!</body></html>       '/usr/sbin/') {
 END   if (-x $dir.$program) {
       $location_of{$program} = $dir.$program;
    }
       }
   }
   
   print("Content-type: text/html\n\n");
   
   if (!&LONCAPA::loncgi::check_cookie_and_load_env()) {
       &Apache::lonlocal::get_language_handle();
       print(&LONCAPA::loncgi::missing_cookie_msg());
 } else {  } else {
     print "Content-type: text/html\n\n";      &Apache::lonlocal::get_language_handle();
     my $file=$env{'cgi.file'};      my %lt = &Apache::lonlocal::texthash (
     my $dir=$env{'cgi.dir'};                                               bade => 'Invalid file or directory name',
     if(! $file || ! $dir) {                                              outo => 'Output of decompress:',
         print <<END;                                              comp => 'Decompress complete.', 
         <html><body>Bad Enviroment!</body></html>                                              erro => 'An error occurred.',
                                               extf => 'Extraction failed.',
                                            );
       my $file=$Apache::lonnet::env{'cgi.file'};
       my $dir=$Apache::lonnet::env{'cgi.dir'};
       if (!$file || !$dir) {
           print(<<END);
           <html><body><span class="LC_error">$lt{'extf'} $lt{'bade'}</span></body></html>
 END  END
       } elsif (!-d $dir) {
           print('<html><body><span class="LC_error">'.$lt{'extf'}.' '."\n".
                 &Apache::lonlocal::mt('The specified directory "[_1]" is invalid.',$dir).
                 '</span></body></html>');
     } else {      } else {
         print <<END;          my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
  <html><body><b>Output of decompress:</b><br /><br />          my $lonuserroot = $Apache::lonnet::perlvar{'lonUsersDir'};
           if (($dir !~ /^\Qlondocroot\E/) && ($dir !~ /^\Q$lonuserroot\E/)) {
               print('<html><body><span class="LC_error">'.$lt{'extf'}.'<br />'."\n".
                     &Apache::lonlocal::mt('The specified directory "[_1]" is invalid',$dir).
                     '</span></body></html>');
           } elsif (chdir($dir)) {
               if (-e $file) {
                   print(<<END);
           <html><body><p><b>$lt{'outo'}</b></p>
 END  END
         chdir $dir;                  my @cmd;
         if ($file =~ m|zip|) {                  if ($file =~ m|\.zip$|) {
             open(OUTPUT, "unzip $file 2> /dev/null |");                      @cmd = ($location_of{'unzip'},"-o");
             while (<OUTPUT>) {                  } elsif ($file =~ m|\.tar\.gz$|
                 print "$_<br />";              || $file =~ m|\.tgz$| ) {
             }                      @cmd = ($location_of{'tar'},"-zxpvf");
             close(OUTPUT);                  } elsif ($file =~ m|\.tar\.bz2$|) {
         } elsif ($file =~ m|tar.gz|) {                      @cmd = ($location_of{'tar'},"-jxpvf");
             open(OUTPUT, "tar -zxpvf $file 2> /dev/null |");                  } elsif ($file =~ m|\.bz2$|) {
             while (<OUTPUT>) {                      @cmd = ($location_of{'bunzip2'});
                 print "$_<br />";                  } elsif ($file =~ m|\.gz$|) {
             }              @cmd = ($location_of{'gunzip'});
             close(OUTPUT);                  } elsif ($file =~ m|\.tar$|) {
         } elsif ($file =~ m|tar.bz2|) {                      @cmd = ($location_of{'tar'},"-xpvf");
             open(OUTPUT, "tar -jxpvf $file 2> /dev/null |");                  }
             while (<OUTPUT>) {          if (@cmd) {
                 print "$_<br />";              undef($!);
             }              undef($@);
             close(OUTPUT);              open(OUTPUT,"-|", @cmd, $file);
         } elsif ($file =~ m|bz2|) {              while (my $line = <OUTPUT>) { print("$line<br />"); }
             open(OUTPUT, "bunzip2 $file 2> /dev/null |");              close(OUTPUT);
             while (<OUTPUT>) {              print("<p><b>$lt{'comp'}</b></p>");
                 print "$_<br />";              if ($! || $@) {
             }          print('<p><span class="LC_error">'.$lt{'erro'}.'<br />'.$!."\n".
             close(OUTPUT);                                '<br />'.$@.'</span></p>');
         } elsif ($file =~ m|tgz|) {              } else {
             open(OUTPUT, "tar -zxpvf $file 2> /dev/null |");                          &Apache::lonnet::appenv({'cgi.decompressed' => 'ok'});
             while (<OUTPUT>) {                      }
                 print "$_<br />";                  } else {
             }                      print('<span class="LC_error">'.
             close(OUTPUT);                            &Apache::lonlocal::mt('There has been an error in determining the file type of [_1], please check the name.',$file).'</span>');
         } elsif ($file =~ m|gz|) {                  }
             open(OUTPUT, "gunzip $file 2> /dev/null |");                  print('</body></html>');
             while (<OUTPUT>) {              } else {
                 print "$_<br />";                  print('<html><body><span class="LC_error">'.$lt{'extf'}.'<br />'."\n".
             }                        &Apache::lonlocal::mt('The specified file "[_1]" does not exist.',$file).
             close(OUTPUT);                        '</span></body></html>');
         } elsif ($file =~ m|tar|) {  
             open(OUTPUT, "tar -xpvf $file 2> /dev/null |");  
             while (<OUTPUT>) {  
                 print "$_<br />";  
             }              }
             close(OUTPUT);  
         } else {          } else {
             print "There has been an error in determining the file type of $file, please check name";              print('<html><body><span class="LC_error">'.$lt{'extf'}.'<br />'."\n".
                     &Apache::lonlocal::mt('Could not change working directory to "[_1]".',$dir).
                     '</span></body></html>');
         }          }
         print "<br /><b>Decompress complete!</b><br /></body></html>";  
     }      }
 }  }
   

Removed from v.1.13  
changed lines
  Added in v.1.18


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.