--- loncom/publisher/loncfile.pm 2003/08/04 20:34:19 1.39
+++ loncom/publisher/loncfile.pm 2003/12/13 19:54:16 1.46
@@ -9,7 +9,7 @@
# and displays a page showing the results of the action.
#
#
-# $Id: loncfile.pm,v 1.39 2003/08/04 20:34:19 www Exp $
+# $Id: loncfile.pm,v 1.46 2003/12/13 19:54:16 taceyjo1 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -110,7 +110,7 @@ sub Debug {
# Put out the indicated message butonly if DEBUG is true.
if ($DEBUG) {
- $log->debug($message);
+ $r->log_reason($message);
}
}
@@ -168,7 +168,7 @@ sub url {
sub display {
my $fn=shift;
- $fn=~s/^\/home\/(\w+)\/public\_html//;
+ $fn=~s-^/home/(\w+)/public_html-/priv/$1-;
return ''.$fn.'';
}
@@ -387,6 +387,10 @@ sub Rename1 {
if(-e $fn) {
if($newfilename) {
+ # is dest a dir
+ if (-d $newfilename) {
+ if ($fn =~ m|/([^/]*)$|) { $newfilename .= '/'.$1; }
+ }
if ($newfilename =~ m|/[^\.]+$|) {
#no extension add on original extension
if ($fn =~ m|/[^\.]*\.([^\.]+)$|) {
@@ -399,6 +403,10 @@ sub Rename1 {
if (-d $fn) {
$newfilename=~s/\/[^\/]+\/([^\/]+)$/\/$1/;
}
+ $newfilename=~s://+:/:g; # remove duplicate /
+ while ($newfilename=~m:/\.\./:) {
+ $newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/..
+ }
my $return=&exists($user, $domain, $newfilename);
$request->print($return);
if ($return =~/^Error:/) {
@@ -485,24 +493,36 @@ Parameters:
=cut
sub Copy1 {
- my ($request, $user, $domain, $fn, $newfilename) = @_;
+ my ($request, $user, $domain, $fn, $newfilename) = @_;
- if(-e $fn) {
- $request->print(&checksuffix($fn,$newfilename));
- my $return=&exists($user, $domain, $newfilename);
- $request->print($return);
- if ($return =~/^Error:/) {
- $request->print('
Cancel');
- return;
+ if(-e $fn) {
+ # is dest a dir
+ if (-d $newfilename) {
+ if ($fn =~ m|/([^/]*)$|) { $newfilename .= '/'.$1; }
+ }
+ if ($newfilename =~ m|/[^\.]+$|) {
+ #no extension add on original extension
+ if ($fn =~ m|/[^\.]*\.([^\.]+)$|) { $newfilename.='.'.$1; }
+ }
+ $newfilename=~s://+:/:g; # remove duplicate /
+ while ($newfilename=~m:/\.\./:) {
+ $newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/..
+ }
+ $request->print(&checksuffix($fn,$newfilename));
+ my $return=&exists($user, $domain, $newfilename);
+ $request->print($return);
+ if ($return =~/^Error:/) {
+ $request->print('
Cancel');
+ return;
+ }
+ $request->print('
Copy '.&display($fn).'
to '.
+ &display($newfilename).'?
No such file: '.&display($fn).'
'); } - $request->print('Copy '.&display($fn).'
to '.
- &display($newfilename).'?
No such file: '.&display($fn).'
'); - } } =pod @@ -559,6 +579,17 @@ sub NewDir1 } } + +sub Decompress1 { + my ($request, $user, $domain, $fn) = @_; + if( -e $fn) { + $request->print(''); + $request->print('Decompress '.&display($fn).'?
'); + &CloseForm1($request, $fn); + } else { + $request->print('No such file: '.&display($fn).'
'); + } +} =pod =item NewFile1 @@ -605,6 +636,14 @@ sub NewFile1 { if ($ENV{'form.action'} =~ /new(.+)file/) { my $extension=$1; + + ##Informs User (name).(number).(extension) not allowed + if($newfilename =~ /\.(\d+)\.(\w+)$/){ + $r->print(''.$newfilename. + ' - Bad FilenameNo such file.
print('Error: '.$!.''); + return 0; + } + } + else { + $request->print('No such file.
print('Error: '.$!.''); + return 0; + } + } + else { + $request->print('No such file.
$file); + &Apache::lonnet::appenv('cgi.dir' => $dir); + my $result=&Apache::lonnet::ssi_body('/cgi-bin/decompress.pl'); + $r->print($result); + &Apache::lonnet::delenv('cgi.file'); + &Apache::lonnet::delenv('cgi.dir'); + return 1; +} =pod =item phasetwo($r, $fn, $uname, $udom) @@ -916,13 +1023,14 @@ sub phasetwo { my $dir; # Directory path my $main; # Filename. my $suffix; # Extension. - - if ($fn=~m:(.*)/([^/]+)\.(\w+)$:) { + if ($fn=~m:(.*)/([^/]+):) { $dir=$1; # Directory path $main=$2; # Filename. - $suffix=$3; # Extension. - } - + } + if($main=~m:\.(\w+)$:){ # Fixes problems with filenames with no extensions + $main=$`; + $suffix=$1; + } my $dest; # On success this is where we'll go. &Debug($r, @@ -939,8 +1047,16 @@ sub phasetwo { "loncfie::phase2 action is $ENV{'form.action'}"); # Select the appropriate processing sub. - - if ($ENV{'form.action'} eq 'rename') { # Rename. + if ($ENV{'form.action'} eq 'decompress') { + $main .= '.'; + $main .= $suffix; + if(!&decompress2($r, $uname, $dir, $main)) { + return ; + } + $dest = $dir."/."; + + + } elsif ($ENV{'form.action'} eq 'rename') { # Rename. if($ENV{'form.newfilename'}) { if (!defined($dir)) { $fn=~m:^(.*)/:; @@ -962,7 +1078,7 @@ sub phasetwo { } elsif ($ENV{'form.action'} eq 'copy') { if($ENV{'form.newfilename'}) { if(!&Copy2($r, $uname, $dir, $fn, $ENV{'form.newfilename'})) { - return + return ; } $dest = $ENV{'form.newfilename'}; @@ -997,9 +1113,20 @@ sub handler { my $fn; if ($ENV{'form.filename'}) { + + &Debug($r, "test: $ENV{'form.filename'}"); $fn=&Apache::lonnet::unescape($ENV{'form.filename'}); $fn=&URLToPath($fn); - } elsif ($ENV{'form.qualifiedfilename'}) { + } + #Just hijack the script only the first time around to inject the correct information for further processing + elsif($ENV{'QUERY_STRING'} && $ENV{'form.phase'} ne 'two') { + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['decompress']); + $fn=&Apache::lonnet::unescape($ENV{'form.decompress'}); + $fn=&URLToPath($fn); + $ENV{'form.action'}="decompress"; + } + + elsif ($ENV{'form.qualifiedfilename'}) { $fn=$ENV{'form.qualifiedfilename'}; } else { &Debug($r, "loncfile::handler - no form.filename"); @@ -1056,6 +1183,8 @@ sub handler { $r->print('