--- loncom/lonnet/perl/lonnet.pm 2002/07/30 21:20:27 1.257 +++ loncom/lonnet/perl/lonnet.pm 2002/08/01 15:26:23 1.259 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.257 2002/07/30 21:20:27 www Exp $ +# $Id: lonnet.pm,v 1.259 2002/08/01 15:26:23 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -712,27 +712,64 @@ sub ssi { sub tokenwrapper { my $uri=shift; - my $token=&reply('tmpput:'.&escape($uri),$perlvar{'lonHostID'}); - return $uri.(($uri=~/\?/)?'&':'?'). - 'token='.$token.'&server='.$perlvar{'lonHostID'}; + $uri=~s/^http\:\/\/([^\/]+)//; + $uri=~s/^\///; + $ENV{'user.environment'}=~/\/([^\/]+)\.id/; + my $token=$1; + if ($uri=~/^uploaded\/([^\/]+)\/([^\/]+)\/([^\/]+)(\?\.*)*$/) { + &appenv('userfile.'.$1.'/'.$2.'/'.$3 => $ENV{'request.course.id'}); + return 'http://'.$hostname{ &homeserver($2,$1)}.'/'.$uri. + (($uri=~/\?/)?'&':'?').'token='.$token; + } else { + return '/adm/notfound.html'; + } } # --------------- Take an uploaded file and put it into the userfiles directory -# input: name of form element +# input: name of form element, coursedoc=1 means this is for the course # output: url of file in userspace sub userfileupload { - my $formname=shift; + my ($formname,$coursedoc)=@_; my $fname=$ENV{'form.'.$formname.'.filename'}; $fname=~s/\\/\//g; $fname=~s/^.*\/([^\/]+)$/$1/; unless ($fname) { return 'error: no uploaded file'; } chop($ENV{'form.'.$formname}); - my $path='/userfiles/'.$ENV{'user.domain'}.'/'.$ENV{'user.name'}.'/'; +# Create the directory if not present + my $docuname=''; + my $docudom=''; + my $docuhome=''; + if ($coursedoc) { + $docuname=$ENV{'course.'.$ENV{'request.course.id'}.'.num'}; + $docudom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}; + $docuhome=$ENV{'course.'.$ENV{'request.course.id'}.'.home'}; + } else { + $docuname=$ENV{'user.name'}; + $docudom=$ENV{'user.domain'}; + $docuhome=$ENV{'user.home'}; + } + my $path=$docudom.'/'.$docuname.'/'; + my $filepath=$perlvar{'lonDocRoot'}; + my @parts=split(/\//,$filepath.'/userfiles/'.$path); + my $count; + for ($count=4;$count<=$#parts;$count++) { + $filepath.="/$parts[$count]"; + if ((-e $filepath)!=1) { + mkdir($filepath,0777); + } + } +# Save the file + { + my $fh=Apache::File->new('>'.$filepath.'/'.$fname); + print $fh $ENV{'form.'.$formname}; + } +# Notify homeserver to grep it # -# FIXME: actually save file +# FIXME - this still needs to happen # - return 'http;//'.$ENV{'SERVER_NAME'}.$path.$fname; +# Return the URL to it + return '/uploaded/'.$path.$fname; } # ------------------------------------------------------------------------- Log