[LON-CAPA-cvs] cvs: loncom /interface londocs.pm /lonnet/perl lonnet.pm

www lon-capa-cvs@mail.lon-capa.org
Thu, 01 Aug 2002 15:26:23 -0000


www		Thu Aug  1 11:26:23 2002 EDT

  Modified files:              
    /loncom/interface	londocs.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  Following public outcry, the logic of user file uploads is being changed.
  This does currently not work anymore.
  Plan:
  When file is uploaded, the home server of course or user is notified to grep
  the file (lond command needed for that) - goes into user home dir
  When file is requested, home server checks session environment of user for
  access permission to file (lond command needed for that)
  Modification of lontokacc needed to be more like lonracc for inter-server
  transfer
  URL redirect needed for actual download on homeserver
  
  
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.5 loncom/interface/londocs.pm:1.6
--- loncom/interface/londocs.pm:1.5	Wed Jul 31 11:23:55 2002
+++ loncom/interface/londocs.pm	Thu Aug  1 11:26:23 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.5 2002/07/31 15:23:55 www Exp $
+# $Id: londocs.pm,v 1.6 2002/08/01 15:26:23 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -55,7 +55,9 @@
 # upload a file
     if (($ENV{'form.uploaddoc.filename'}) && ($allowed)) {
         my $id=time.'_'.$ENV{'user.name'}.'_'.$ENV{'user.domain'};
-	my $url=&Apache::lonnet::userfileupload('uploaddoc');
+# this is for a course, not a user, so set coursedoc flag
+# probably the only place in the system where this should be "1"
+	my $url=&Apache::lonnet::userfileupload('uploaddoc',1);
         if ($url=~/^error\:/) {
         } else {
 	    my $comment=$ENV{'form.comment'};
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.258 loncom/lonnet/perl/lonnet.pm:1.259
--- loncom/lonnet/perl/lonnet.pm:1.258	Wed Jul 31 09:50:38 2002
+++ loncom/lonnet/perl/lonnet.pm	Thu Aug  1 11:26:23 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.258 2002/07/31 13:50:38 www Exp $
+# $Id: lonnet.pm,v 1.259 2002/08/01 15:26:23 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -712,26 +712,46 @@
 
 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});
 # Create the directory if not present
-    my $path='/userfiles/'.$ENV{'user.domain'}.'/'.$ENV{'user.name'}.'/';
+    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.$path);
+    my @parts=split(/\//,$filepath.'/userfiles/'.$path);
     my $count;
     for ($count=4;$count<=$#parts;$count++) {
         $filepath.="/$parts[$count]";
@@ -744,8 +764,12 @@
        my $fh=Apache::File->new('>'.$filepath.'/'.$fname);
        print $fh $ENV{'form.'.$formname};
     }
+# Notify homeserver to grep it
+#
+# FIXME - this still needs to happen
+#
 # Return the URL to it
-    return 'http://'.$ENV{'SERVER_NAME'}.$path.$fname;    
+    return '/uploaded/'.$path.$fname;    
 }
 
 # ------------------------------------------------------------------------- Log