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

version 1.6, 2003/11/18 04:07:49 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 29 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;
 #Things still todo,   
 #It has been tabinated  
 #Now uses strict! with added feature of making everything very strict!  
 #about 50% through rewriting things to use split and join  
 #still have a lot of debugging statements that will go away after I get it to work ok(along with all the <br>'s)  
 #still have to rewrite the refresh tag to work right, its broken  
 #the whole thing is broken right now  
 #will rename the variables and reorder most of the script to make it more sane  
 #improve the general readability of the whole thing, because unlike C everyone gets to look at it, so it has to be readable  
 #will get to it tommorrow night as I have a calc test to "pass" yea, or something like that :0)  
 use lib '/home/httpd/lib/perl';  use lib '/home/httpd/lib/perl';
 use LONCAPA::Configuration;  use LONCAPA::loncgi;
 use LONCAPA::loncgi();  
 use Apache::lonnet;  
 use strict;   
   
 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 {my $username;  } 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'};
  my $path = $ENV{'cgi.path'};      my $dir=$Apache::lonnet::env{'cgi.dir'}; 
  $path =~ m|/{1}|;      if(! $file || ! $dir) {
  $path = $'; #' stupid emacs          print(<<END);
  $path =~ m|/{1}|;          <html><body>Bad Enviroment!</body></html>
  $path = $';  END
  my (@right) = split(/\./,$ENV{'request.role'});      } else {
  my $role = shift(@right);          print(<<END);
  my $temp = shift(@right);   <html><body><p><b>Output of decompress:</b></p>
  my (@left) = split(/\/+/,$temp);;  END
  shift(@left);          chdir($dir);
  shift(@left);   my @cmd;
  $temp = shift(@left);          if ($file =~ m|\.zip$|) {
  print "temp: $temp";              @cmd = ("/usr/bin/unzip","-o");
  my $path2 = "/home/$username/public_html/";          } elsif ($file =~ m|\.tar\.gz$|) {
  $path2 .=$path;              @cmd = ("/usr/bin/tar","-zxpvf");
  my $back_path = "";          } elsif ($file =~ m|\.tar\.bz2$|) {
  while($path =~ m|/|) {              @cmd = ("/usr/bin/tar","-jxpvf");
     $back_path .= $`;          } elsif ($file =~ m|\.bz2$|) {
     $back_path .= "/";              @cmd = ("/usr/bin/bunzip2");
     $path = $'; #' stupid emacs          } elsif ($file =~ m|\.tgz$|) {
  }              @cmd = ("/usr/bin/tar","-zxpvf");
  $path .= '/';          } elsif ($file =~ m|\.gz$|) {
  $path .= $back_path;      @cmd = ("/usr/bin/gunzip");
  print "<br>path: $path<br>";          } elsif ($file =~ m|\.tar$|) {
  print "back_path: $back_path <br>";              @cmd = ("/usr/bin/tar","-xpvf");
  print "path2: $path2 <br>";          } else {
  print "$path2<br>";              print("There has been an error in determining the file type of $file, please check name");
  if ( -r $path2){          }
  print "Good read access is allowed";   if (@cmd) {
  print "<br><br>";      undef($!);
  print "<br><br>right: $role";      undef($@);
  my $filename = $ENV{'cgi.file'};      open(OUTPUT,"-|", @cmd, $file);
  if($role eq "ca" || $role eq "au") {      while (<OUTPUT>) { print "$_<br />"; }
  chdir $path;      close(OUTPUT);
  if      ($filename =~ m|zip|) {      print("<p><b>Decompress complete.</b></p>");
     system "unzip -qq $path2 &> /dev/null";      if ($! || $@) {
  } elsif ($filename =~ m|tar.gz|) {   print("<p><b>An error occurred</b></p><p>$!</p><p>$@</p>");
     system "tar -zxpvf $path2 &> /dev/null";      }
  } elsif ($filename =~ m|tar.bz2|){      print("</body></html>");
    system "tar -jxpvf $path2 &> /dev/null";  
  } 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.6  
changed lines
  Added in v.1.15


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