Diff for /loncom/cgi/decompress.pl between versions 1.5 and 1.15

version 1.5, 2003/11/17 23:12:12 version 1.15, 2005/11/03 20:36:58
Line 1 Line 1
 #!/usr/bin/perl  #!/usr/bin/perl
 #  #
 #   #
 # 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 28 Line 29
 # 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
 ####  ####
   use strict;
 use lib '/home/httpd/lib/perl';  use lib '/home/httpd/lib/perl';
 use LONCAPA::Configuration;  use LONCAPA::loncgi;
 use LONCAPA::loncgi();  
 use Apache::lonnet;  
   
 if(! &LONCAPA::loncgi::check_cookie_and_load_env()){  if(! &LONCAPA::loncgi::check_cookie_and_load_env()) {
     print "Content-type: text/html\n\n";      print "Content-type: text/html\n\n";
     print <<END;      print <<END;
  <html><body>NO COOKIE!</body></html>      <html><body>NO COOKIE!</body></html>
 END  END
 } else {  } else {
     print "Content-type: text/html\n\n";      print "Content-type: text/html\n\n";
 print "<html><head></head><body>";      my $file=$Apache::lonnet::env{'cgi.file'};
 print "$ENV{'cgi.path'}";      my $dir=$Apache::lonnet::env{'cgi.dir'}; 
 print "<br>$ENV{'cgi.file'}";      if(! $file || ! $dir) {
 print "<br>$ENV{'user.name'}<br>";          print(<<END);
 $path = $ENV{'cgi.path'};          <html><body>Bad Enviroment!</body></html>
 $path =~ m|/{1}|;  END
 $path = $'; #' stupid emacs      } else {
 $path =~ m|/{1}|;          print(<<END);
 $path = $';   <html><body><p><b>Output of decompress:</b></p>
 $username = $`; #Hmm, can't use the enviroment for this, if you are a co-author.. so we work around it.  END
 $path2 = "/home/$username/public_html/";          chdir($dir);
 $path2 .=$path;   my @cmd;
 $back_path = "";          if ($file =~ m|\.zip$|) {
  while($path =~ m|/|) {              @cmd = ("/usr/bin/unzip","-o");
     $back_path .= $`;          } elsif ($file =~ m|\.tar\.gz$|) {
     $back_path .= "/";              @cmd = ("/usr/bin/tar","-zxpvf");
     $path = $'; #' stupid emacs          } elsif ($file =~ m|\.tar\.bz2$|) {
  }              @cmd = ("/usr/bin/tar","-jxpvf");
 $path = "/home/$username/public_html";          } elsif ($file =~ m|\.bz2$|) {
 $path .= '/';              @cmd = ("/usr/bin/bunzip2");
 $path .= $back_path;          } elsif ($file =~ m|\.tgz$|) {
 print "<br>path: $path<br>";              @cmd = ("/usr/bin/tar","-zxpvf");
 print "back_path: $back_path <br>";          } elsif ($file =~ m|\.gz$|) {
 print "path2: $path2 <br>";      @cmd = ("/usr/bin/gunzip");
 print "$path2<br>";          } elsif ($file =~ m|\.tar$|) {
 if ( -r $path2){              @cmd = ("/usr/bin/tar","-xpvf");
 print "Good read access is allowed";          } else {
 print "<br><br>";              print("There has been an error in determining the file type of $file, please check name");
 $right = $ENV{'request.role'};          }
 $right =~ m|\.|;   if (@cmd) {
 $right = $`;      undef($!);
 $filename = $ENV{'cgi.file'};      undef($@);
 if($right eq "ca" || $right eq "au") {      open(OUTPUT,"-|", @cmd, $file);
 chdir $path;      while (<OUTPUT>) { print "$_<br />"; }
 if      ($filename =~ m|zip|) {      close(OUTPUT);
     system "unzip -qq $path2 &> /dev/null";      print("<p><b>Decompress complete.</b></p>");
  } elsif ($filename =~ m|tar.gz|) {      if ($! || $@) {
     system "tar -zxpvf $path2 &> /dev/null";   print("<p><b>An error occurred</b></p><p>$!</p><p>$@</p>");
  } elsif ($filename =~ m|tar.bz2|){      }
    system "tar -jxpvf $path2 &> /dev/null";      print("</body></html>");
  } elsif ($filename =~ m|bz2|){  
     system "bunzip2 $path2 &> /dev/null";  
  } elsif ($filename =~ m|tgz|){  
     system "tar -zxpvf $path2 &> /dev/null";  
  } elsif ($filename =~ m|gz|){  
     system "gunzip $path2 &> /dev/null";  
  } elsif ($filename =~ m|tar|){  
     system "tar -xpvf $path2 &> /dev/null";  
  }   }
 }       }
 else {print "You don't have proper privledges";}  
 }  
 else { print "Read access not allowed!"; }  
 print '<meta http-equiv="refresh" content="0; URL=';  
 print "http://$ENV{'SERVER_NAME'}/~$username'}/$back_path"; print '" />';  
 print '</body></html>';  
 &Apache::lonnet::delenv(cgi.file);  
 &Apache::lonnet::delenv(cgi.path);  
 }  }
   

Removed from v.1.5  
changed lines
  Added in v.1.15


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