[LON-CAPA-cvs] cvs: loncom / loncapa_apache.conf lond lontrans.pm /auth lontokacc.pm lonuploadedacc.pm

www lon-capa-cvs@mail.lon-capa.org
Thu, 08 Aug 2002 13:45:21 -0000


This is a MIME encoded message

--www1028814321
Content-Type: text/plain

www		Thu Aug  8 09:45:21 2002 EDT

  Modified files:              
    /loncom	loncapa_apache.conf lond lontrans.pm 
    /loncom/auth	lontokacc.pm lonuploadedacc.pm 
  Log:
  Routines for file upload
  
  
--www1028814321
Content-Type: text/plain
Content-Disposition: attachment; filename="www-20020808094521.txt"

Index: loncom/loncapa_apache.conf
diff -u loncom/loncapa_apache.conf:1.12 loncom/loncapa_apache.conf:1.13
--- loncom/loncapa_apache.conf:1.12	Fri Aug  2 10:45:04 2002
+++ loncom/loncapa_apache.conf	Thu Aug  8 09:45:21 2002
@@ -1,7 +1,7 @@
 ##
 ## loncapa_apache.conf -- Apache HTTP LON-CAPA configuration file
 ##
-## $Id: loncapa_apache.conf,v 1.12 2002/08/02 14:45:04 www Exp $
+## $Id: loncapa_apache.conf,v 1.13 2002/08/08 13:45:21 www Exp $
 ##
 ## 1/11/2002 - Scott Harrison
 ## 2/19/2002 - Scott Harrison
@@ -56,11 +56,9 @@
 
 <LocationMatch "^/userfiles.*">
 PerlAccessHandler       Apache::lontokacc
-ErrorDocument     404 /adm/notfound.html
-ErrorDocument	  500 /adm/errorhandler
 </LocationMatch>
 
-<LocationMatch "/^uploaded.*">
+<LocationMatch "^/uploaded.*">
 PerlAccessHandler	Apache::lonuploadedacc
 ErrorDocument     404 /adm/notfound.html
 ErrorDocument	  500 /adm/errorhandler
@@ -413,7 +411,13 @@
 PerlAccessHandler       Apache::lonacc
 SetHandler perl-script
 PerlHandler Apache::lonchat
-ErrorDocument     403 /adm/login
+ErrorDocument	  500 /adm/errorhandler
+</Location>
+
+<Location /adm/chatfetch>
+PerlAccessHandler       Apache::lonacc
+SetHandler perl-script
+PerlHandler Apache::lonchatfetch
 ErrorDocument	  500 /adm/errorhandler
 </Location>
 
Index: loncom/lond
diff -u loncom/lond:1.85 loncom/lond:1.86
--- loncom/lond:1.85	Thu Aug  1 14:44:19 2002
+++ loncom/lond	Thu Aug  8 09:45:21 2002
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.85 2002/08/01 18:44:19 www Exp $
+# $Id: lond,v 1.86 2002/08/08 13:45:21 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -949,10 +949,48 @@
                        }
 # -------------------------------------- fetch a user file from a remote server
                    } elsif ($userinput =~ /^fetchuserfile/) {
-                       my ($cmd,$fname)=split(/:/,$userinput);
+                      my ($cmd,$fname)=split(/:/,$userinput);
+		      my ($udom,$uname,$ufile)=split(/\//,$fname);
+                      my $udir=propath($udom,$uname).'/userfiles';
+                      unless (-e $udir) { mkdir($udir); }
+                       if (-e $udir) {
+                       $ufile=~s/^[\.\~]+//;
+                       $ufile=~s/\///g;
+                       my $transname=$udir.'/'.$ufile;
+                       my $remoteurl='http://'.$clientip.'/userfiles/'.$fname;
+                             my $response;
+                              {
+                             my $ua=new LWP::UserAgent;
+                             my $request=new HTTP::Request('GET',"$remoteurl");
+                             $response=$ua->request($request,$transname);
+			      }
+                             if ($response->is_error()) {
+				 unlink($transname);
+                                 my $message=$response->status_line;
+                                 &logthis(
+                                  "LWP GET: $message for $fname ($remoteurl)");
+				 print $client "failed\n";
+                             } else {
+                                 print $client "ok\n";
+                             }
+                     } else {
+                       print $client "not_home\n";
+                     } 
 # ------------------------------------------ authenticate access to a user file
-                   } elsif ($userinput =~ /^authuserfile/) {
+                   } elsif ($userinput =~ /^tokenauthuserfile/) {
                        my ($cmd,$fname,$session)=split(/:/,$userinput);
+                       chomp($session);
+                       $reply='non_auth';
+                       if (open(ENVIN,$perlvar{'lonIDsDir'}.'/'.
+                                      $session.'.id')) {
+                        while ($line=<ENVIN>) {
+			   if ($line=~/userfile\.$fname\=/) { $reply='ok'; }
+                        }
+                        close(ENVIN);
+                        print $client $reply."\n";
+		       } else {
+			print $client "invalid_token\n";
+                       }
 # ----------------------------------------------------------------- unsubscribe
                    } elsif ($userinput =~ /^unsub/) {
                        my ($cmd,$fname)=split(/:/,$userinput);
@@ -1264,6 +1302,20 @@
                        } else {
                            print $client "error:$!\n";
                        }
+# -------------------------------------------------------------------- chatsend
+                   } elsif ($userinput =~ /^chatsend/) {
+                       my ($cmd,$cdom,$cnum,$newpost)=split(/\:/,$userinput);
+                       &chatadd($cdom,$cnum,$newpost);
+                       print $client "ok\n";
+# -------------------------------------------------------------------- chatretr
+                   } elsif ($userinput =~ /^chatretr/) {
+                       my ($cmd,$cdom,$cnum)=split(/\:/,$userinput);
+                       my $reply='';
+                       foreach (&getchat($cdom,$cnum)) {
+			   $reply.=&escape($_).':';
+                       }
+                       $reply=~s/\:$//;
+                       print $client $reply."\n";
 # ------------------------------------------------------------------- querysend
                    } elsif ($userinput =~ /^querysend/) {
                        my ($cmd,$query,
@@ -1514,6 +1566,42 @@
     if ($newline) { print $sh $newline; }
     $sh->close();
     return $found;
+}
+
+sub getchat {
+    my ($cdom,$cname)=@_;
+    my @entries;
+    if (open(CHATIN,&propath($cdom,$cname).'/chatroom.txt')) {
+	while ($line=<CHATIN>) { push(@entries,$line); }
+        close(CHATIN);
+        return @entries;
+    }
+    return ();
+}
+
+sub chatadd {
+    my ($cdom,$cname,$newchat)=@_;
+    my @entries=&getchat($cdom,$cname);
+    my $time=time;
+    my ($lastid)=($entries[$#entries]=~/^(\w+)\:/);
+    my ($thentime,$idnum)=split(/\_/,$lastid);
+    my $newid=$time.'_000000';
+    if ($thentime==$time) {
+	$idnum=~s/^0+//;
+        $idnum++;
+        $idnum=substr('000000'.$idnum,-6,6);
+        $newid=$time.'_'.$idnum;
+    }
+    push (@entries,$newid.':'.$newchat."\n");
+    my $expired=$time-3600;
+    open(CHATOUT,'>'.&propath($cdom,$cname).'/chatroom.txt');
+    foreach (@entries) {
+        my ($thistime)=($_=~/(\d+)\_/);
+        if ($thistime>$expired) {
+	    print CHATOUT $_;
+        }
+    }
+    close(CHATOUT);
 }
 
 sub unsub {
Index: loncom/lontrans.pm
diff -u loncom/lontrans.pm:1.1 loncom/lontrans.pm:1.2
--- loncom/lontrans.pm:1.1	Fri Aug  2 10:45:04 2002
+++ loncom/lontrans.pm	Thu Aug  8 09:45:21 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # URL translation for User Files
 #
-# $Id: lontrans.pm,v 1.1 2002/08/02 14:45:04 www Exp $
+# $Id: lontrans.pm,v 1.2 2002/08/08 13:45:21 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -33,9 +33,23 @@
 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;
+} 
+
+
 sub handler {
     my $r = shift;
-    return DECLINED;
+    unless ($r->uri=~/^\/uploaded\//) { return DECLINED; }
+    my ($dum1,$dum2,$udom,$uname,$ufile)=split(/\//,$r->uri);
+    $ufile=~s/^[\~\.]+//;
+    $r->filename(&propath($udom,$uname).'/userfiles/'.$ufile);
 }
 
 1;
Index: loncom/auth/lontokacc.pm
diff -u loncom/auth/lontokacc.pm:1.5 loncom/auth/lontokacc.pm:1.6
--- loncom/auth/lontokacc.pm:1.5	Fri Aug  2 10:45:04 2002
+++ loncom/auth/lontokacc.pm	Thu Aug  8 09:45:21 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Access Handler for User File Transfers
 #
-# $Id: lontokacc.pm,v 1.5 2002/08/02 14:45:04 www Exp $
+# $Id: lontokacc.pm,v 1.6 2002/08/08 13:45:21 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -40,6 +40,10 @@
        $r->log_reason("Spoof request ".$reqhost);
        return FORBIDDEN;
     }
+    if ($reqhost eq 'localhost.localdomain') {
+       $r->register_cleanup(\&removefile);
+       return OK;
+    }
     my $readline;
     my $lontabdir=$r->dir_config('lonTabDir');
     {
@@ -64,10 +68,11 @@
 
 sub removefile {
     my $r=shift;
-    if ($r->status==HTTP_OK) {
+    if ($r->status==200) {
+        unlink($r->filename);
 	&Apache::lonnet::logthis('Unlinking '.$r->filename);
     } else {
-        &Apache::lonnet::logthis("Failed to transfer ".$r->filename);
+        &Apache::lonnet::logthis('Failed to transfer '.$r->filename);
     }
 }
 1;
Index: loncom/auth/lonuploadedacc.pm
diff -u loncom/auth/lonuploadedacc.pm:1.1 loncom/auth/lonuploadedacc.pm:1.2
--- loncom/auth/lonuploadedacc.pm:1.1	Fri Aug  2 10:45:04 2002
+++ loncom/auth/lonuploadedacc.pm	Thu Aug  8 09:45:21 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Access Handler for User Files
 #
-# $Id: lonuploadedacc.pm,v 1.1 2002/08/02 14:45:04 www Exp $
+# $Id: lonuploadedacc.pm,v 1.2 2002/08/08 13:45:21 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -31,11 +31,25 @@
 use strict;
 use Apache::Constants qw(:common :remotehost);
 use Apache::lonnet();
-use Apache::File();
 
 sub handler {
     my $r = shift;
-    return OK;
+    my $args=$r->args;
+    &Apache::loncommon::get_unprocessed_cgi($args,['token']); 
+    my ($dum1,$dum2,$udom,$uname,$ufile)=split(/\//,$r->uri);
+    $ufile=~s/^[\~\.]+//;
+    my ($server)=($ENV{'form.token'}=~/\_([a-zA-Z0-9]+)$/);
+
+    my $reply=&Apache::lonnet::reply('tokenauthuserfile:'.
+                 $udom.'/'.$uname.'/'.$ufile.':'.$ENV{'form.token'},
+				     $server);
+    if ($reply eq 'ok') {
+       return OK;
+   } else {
+       &Apache::lonnet::logthis(
+"Refused userfile access $uname at $udom for $ufile from $server with $ENV{'form.token'}: $reply");
+       return FORBIDDEN;
+   }
 }
 
 1;

--www1028814321--