Diff for /loncom/cgi/decompress.pl between versions 1.11 and 1.17

version 1.11, 2003/12/13 00:20:47 version 1.17, 2008/11/28 20:42:20
Line 31 Line 31
 ####  ####
 use strict;  use strict;
 use lib '/home/httpd/lib/perl';  use lib '/home/httpd/lib/perl';
 use LONCAPA::loncgi ();  use Apache::lonnet;
 if(! &LONCAPA::loncgi::check_cookie_and_load_env()) {  use Apache::lonlocal;
     print "Content-type: text/html\n\n";  use LONCAPA::loncgi;
     print <<END;  
     <html><body>NO COOKIE!</body></html>  my %location_of;
 END  foreach my $program ('tar','gunzip','bunzip2','unzip') {
       foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
        '/usr/sbin/') {
    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();
     if(! $ENV{'cgi.file'} || ! $ENV{'cgi.dir'}) {      my %lt = &Apache::lonlocal::texthash (
         print <<END;                                              bade => 'Bad Environment!',
         <html><body>Bad Enviroment!</body></html>                                              outo => 'Output of decompress:',
                                               comp => 'Decompress complete.', 
                                               erro => 'An error occurred',
                                            );
       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{'bade'}</span></body></html>
 END  END
     } else {      } else {
         print <<END;          print(<<END);
  <html><body><b>Output of decompress:</b><br /><br />   <html><body><p><b>$lt{'outo'}</b></p>
 END  END
         chdir $ENV{'cgi.dir'};          chdir($dir);
         if ($ENV{'cgi.file'} =~ m|\.zip$|i) {   my @cmd;
             open(OUTPUT, "unzip -o $ENV{'cgi.file'} 2> /dev/null |");          if ($file =~ m|\.zip$|) {
             while (<OUTPUT>) {              @cmd = ($location_of{'unzip'},"-o");
                 print "$_<br />";          } elsif ($file =~ m|\.tar\.gz$|
             }   || $file =~ m|\.tgz$| ) {
             close(OUTPUT);              @cmd = ($location_of{'tar'},"-zxpvf");
         } elsif ($ENV{'cgi.file'} =~ m|\.tar\.gz$|i) {          } elsif ($file =~ m|\.tar\.bz2$|) {
             open(OUTPUT, "tar -zxpvf $ENV{'cgi.file'} 2> /dev/null |");              @cmd = ($location_of{'tar'},"-jxpvf");
             while (<OUTPUT>) {          } elsif ($file =~ m|\.bz2$|) {
                 print "$_<br />";              @cmd = ($location_of{'bunzip2'});
             }          } elsif ($file =~ m|\.gz$|) {
             close(OUTPUT);      @cmd = ($location_of{'gunzip'});
         } elsif ($ENV{'cgi.file'} =~ m|\.tar\.bz2$|i) {          } elsif ($file =~ m|\.tar$|) {
             open(OUTPUT, "tar -jxpvf $ENV{'cgi.file'} 2> /dev/null |");              @cmd = ($location_of{'tar'},"-xpvf");
             while (<OUTPUT>) {  
                 print "$_<br />";  
             }  
             close(OUTPUT);  
         } elsif ($ENV{'cgi.file'} =~ m|\.bz2$|i) {  
             open(OUTPUT, "bunzip2 $ENV{'cgi.file'} 2> /dev/null |");  
             while (<OUTPUT>) {  
                 print "$_<br />";  
             }  
             close(OUTPUT);  
         } elsif ($ENV{'cgi.file'} =~ m|\.tgz$|i) {  
             open(OUTPUT, "tar -zxpvf $ENV{'cgi.file'} 2> /dev/null |");  
             while (<OUTPUT>) {  
                 print "$_<br />";  
             }  
             close(OUTPUT);  
         } elsif ($ENV{'cgi.file'} =~ m|\.gz$|i) {  
             open(OUTPUT, "gunzip $ENV{'cgi.file'} 2> /dev/null |");  
             while (<OUTPUT>) {  
                 print "$_<br />";  
             }  
             close(OUTPUT);  
         } elsif ($ENV{'cgi.file'} =~ m|\.tar$|i) {  
             open(OUTPUT, "tar -xpvf $ENV{'cgi.file'} 2> /dev/null |");  
             while (<OUTPUT>) {  
                 print "$_<br />";  
             }  
             close(OUTPUT);  
         } else {          } else {
             print "There has been an error in determining the file type of $ENV{'cgi.file'}, please check name";              print('<span class="LC_error">'.&Apache::lonlocal::mt('There has been an error in determining the file type of [_1], please check the name',$file).'</span>');
         }          }
         print "<br /><b>Decompress complete!</b><br /></body></html>";   if (@cmd) {
       undef($!);
       undef($@);
       open(OUTPUT,"-|", @cmd, $file);
       while (my $line = <OUTPUT>) { print("$line<br />"); }
       close(OUTPUT);
       print("<p><b>$lt{'comp'}</b></p>");
       if ($! || $@) {
    print('<p><span class="LC_error">'.$lt{'erro'}.'<br />'.$!.'<br />'.$@.'</span></p>');
       }
    }
           print('</body></html>');
     }      }
 }  }
   

Removed from v.1.11  
changed lines
  Added in v.1.17


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