--- loncom/lontrans.pm 2002/08/08 13:45:21 1.2 +++ loncom/lontrans.pm 2020/03/05 22:02:32 1.14.10.1 @@ -1,7 +1,7 @@ # The LearningOnline Network # URL translation for User Files # -# $Id: lontrans.pm,v 1.2 2002/08/08 13:45:21 www Exp $ +# $Id: lontrans.pm,v 1.14.10.1 2020/03/05 22:02:32 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -32,24 +32,33 @@ use strict; use Apache::Constants qw(:common :remotehost); use Apache::lonnet(); use Apache::File(); - -sub propath { - my ($udom,$uname)=@_; - $udom=~s/\W//g; - $uname=~s/\W//g; - my $subdir=$uname.'__'; - $subdir =~ s/(.)(.)(.).*/$1\/$2\/$3/; - my $proname="$Apache::lonnet::perlvar{'lonUsersDir'}/$udom/$subdir/$uname"; - return $proname; -} +use LONCAPA; sub handler { my $r = shift; - unless ($r->uri=~/^\/uploaded\//) { return DECLINED; } - my ($dum1,$dum2,$udom,$uname,$ufile)=split(/\//,$r->uri); - $ufile=~s/^[\~\.]+//; - $r->filename(&propath($udom,$uname).'/userfiles/'.$ufile); + # FIXME line remove when mod_perl fixes BUG#4948 + $r->notes->set('error-notes' => ''); + if ($r->uri=~m|^(/raw)?/uploaded/|) { + my $fn = $r->uri(); + $fn=~s/^\/raw//; + my (undef,undef,$udom,$uname,@ufile)=split(/\//,$fn); + if (@ufile) { $ufile[-1]=~s/^[\~\.]+//; } + my $chome=&Apache::lonnet::homeserver($uname,$udom); + my $allowed=0; + my @ids=&Apache::lonnet::current_machine_ids(); + foreach my $id (@ids) { if ($id eq $chome) { $allowed=1; } } + if ($allowed) { + $r->filename(&propath($udom,$uname). + '/userfiles/'.(join('/',@ufile))); + } + return OK; + } elsif ($r->uri =~ m{^\Q/adm/wrapper/ext/https:/\E[^/]}) { + my $uri = $r->uri; + $uri =~ s{^(\Q/adm/wrapper/ext/https:/\E)}{$1/}; + $r->uri($uri); + } + return DECLINED; } 1;