--- loncom/publisher/loncfile.pm 2003/02/10 23:19:45 1.25 +++ loncom/publisher/loncfile.pm 2003/08/01 20:32:05 1.35 @@ -9,7 +9,7 @@ # and displays a page showing the results of the action. # # -# $Id: loncfile.pm,v 1.25 2003/02/10 23:19:45 albertel Exp $ +# $Id: loncfile.pm,v 1.35 2003/08/01 20:32:05 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -92,6 +92,7 @@ use Apache::Constants qw(:common :http : use Apache::loncacc; use Apache::Log (); use Apache::lonnet; +use Apache::loncommon(); my $DEBUG=0; my $r; # Needs to be global for some stuff RF. @@ -172,8 +173,9 @@ Global References sub URLToPath { my $Url = shift; &Debug($r, "UrlToPath got: $Url"); - $Url=~ s/^http\:\/\/[^\/]+\/\~(\w+)/\/home\/$1\/public_html/; $Url=~ s/^http\:\/\/[^\/]+//; + $Url=~ s/^\///; + $Url=~ s/(\~|priv\/)(\w+)\//\/home\/$2\/public_html\//; &Debug($r, "Returning $Url \n"); return $Url; } @@ -387,6 +389,17 @@ sub checksuffix { } return $result; } + +sub cleanDest { + my ($request,$dest)=@_; + #remove bad characters + if ($dest=~/[\#\?&]/) { + $request->print("
Invalid characters in requested name have been removed.
"); + $dest=~s/[\#\?&]//g; + } + return $dest; +} + =pod =item CloseForm1($request, $user, $file) @@ -412,7 +425,7 @@ sub CloseForm1 { &Debug($request, "Cancel url is: ".$cancelurl); $request->print(''); $request->print(''); + '" method="POST">'); } @@ -494,13 +507,19 @@ sub Rename1 { if(-e $conspace) { if($ENV{'form.newfilename'}) { my $newfilename = $ENV{'form.newfilename'}; - if ($newfilename =~ m|^[^\.]+$|) { + if ($newfilename =~ m|/[^\.]+$|) { #no extension add on orignal extension if ($filename =~ m|/[^\.]*\.([^\.]+)$|) { $newfilename.='.'.$1; } } $request->print(&checksuffix($filename, $newfilename)); + #renaming a dir, delete the trailing / + #remove last element for current dir + if ($filename =~ m|/$|) { + $filename =~ s|/$||; + $dir =~ s|/[^/]*$||; + } my $return=&exists($user, $domain, $dir, $newfilename); $request->print($return); if ($return =~/^Error:/) { @@ -764,6 +783,10 @@ sub NewFile1 { if ($ENV{'form.action'} =~ /new(.+)file/) { my $extension=$1; if ($newfilename !~ /\Q.$extension\E$/) { + if ($newfilename =~ m|^[^\.]*\.([^\.]+)$|) { + #already has an extension strip it and add in expected one + $newfilename =~ s|.([^\.]+)$||; + } $newfilename.=".$extension"; } } @@ -782,9 +805,9 @@ sub NewFile1 { &Debug($request, "Dest url is: ".$dest); $request->print(''); $request->print(''); + '" method="POST">'); $request->print(''); + '" method="POST">'); } } @@ -826,16 +849,19 @@ sub phaseone { # my $conspace=ConstructionPathFromRelative($uname, $fn); - + $ENV{'form.newfilename'}=&cleanDest($r,$ENV{'form.newfilename'}); + $r->print('