--- loncom/publisher/loncfile.pm 2011/10/30 19:27:27 1.112 +++ loncom/publisher/loncfile.pm 2011/11/02 19:12:40 1.113 @@ -9,7 +9,7 @@ # and displays a page showing the results of the action. # # -# $Id: loncfile.pm,v 1.112 2011/10/30 19:27:27 raeburn Exp $ +# $Id: loncfile.pm,v 1.113 2011/11/02 19:12:40 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -158,26 +158,28 @@ Global References sub URLToPath { my $Url = shift; &Debug($r, "UrlToPath got: $Url"); - $Url=~ s/\/+/\//g; - $Url=~ s/^https?\:\/\/[^\/]+//; - $Url=~ s/^\///; - $Url='/home/httpd/html/'.$Url; + $Url=~ s{^https?\://[^/]+}{}; + $Url=~ s{//+}{/}g; + $Url=~ s{^/}{}; + $Url=$Apache::lonnet::perlvar{'lonDocRoot'}."/$Url"; &Debug($r, "Returning $Url \n"); return $Url; } sub url { my $fn=shift; - $fn=~s/^\/home\/httpd\/html//; - $fn=~s/\/\.\//\//g; + my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'}; + $fn=~ s/^\Q$londocroot\E//; + $fn=~s{/\./}{/}g; $fn=&HTML::Entities::encode($fn,'<>"&'); return $fn; } sub display { my $fn=shift; - $fn=~s/^\/home\/httpd\/html//; - $fn=~s/\/\.\//\//g; + my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'}; + $fn=~s/^\Q$londocroot\E//; + $fn=~s{/\./}{/}g; return ''.$fn.''; } @@ -395,15 +397,16 @@ sub relativeDest { my $error = ''; if ($newfilename=~/^\//) { # absolute, simply add path - $newfilename='/home/httpd/html/res/'.$udom.'/'.$uname.'/'; + my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'}; + $newfilename="$londocroot/res/$udom/$uname/"; } else { my $dir=$fn; - $dir=~s/\/[^\/]+$//; + $dir=~s{/[^/]+$}{}; $newfilename=$dir.'/'.$newfilename; } - $newfilename=~s://+:/:g; # remove duplicate / - while ($newfilename=~m:/\.\./:) { - $newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/.. + $newfilename=~s{//+}{/}g; # remove duplicate / + while ($newfilename=~m{/\.\./}) { + $newfilename=~ s{/[^/]+/\.\./}{/}g; #remove dir/.. } my ($authorname,$authordom)=&Apache::loncacc::constructaccess($newfilename); unless (($authorname) && ($authordom)) { @@ -1437,13 +1440,11 @@ sub handler { } # ----------------------------------------------------------- Start page output - my $uname; - my $udom; - ($uname,$udom)=&Apache::loncacc::constructaccess($fn); + my ($uname,$udom) = &Apache::loncacc::constructaccess($fn); &Debug($r, "loncfile::handler constructaccess uname = $uname domain = $udom"); - unless (($uname) && ($udom)) { + if (($uname eq '') || ($udom eq '')) { $r->log_reason($uname.' at '.$udom. ' trying to manipulate file '.$env{'form.filename'}. ' ('.$fn.') - not authorized', @@ -1470,6 +1471,10 @@ function writeDone() { |; $loaditem{'onload'} = "writeDone()"; } + + my $londocroot = $r->dir_config('lonDocRoot'); + my $trailfile = $fn; + $trailfile =~ s{^/(priv/)}{$londocroot/$1}; # Breadcrumbs &Apache::lonhtmlcommon::clear_breadcrumbs(); @@ -1488,7 +1493,7 @@ function writeDone() { {'add_entries' => \%loaditem,}) .&Apache::lonhtmlcommon::breadcrumbs() .&Apache::loncommon::head_subbox( - &Apache::loncommon::CSTR_pageheader()) + &Apache::loncommon::CSTR_pageheader($trailfile)) ); $r->print('

'.&mt('Location').': '.&display($fn).'

');