[LON-CAPA-cvs] cvs: loncom /auth lonauth.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 07 Jul 2005 06:18:39 -0000


albertel		Thu Jul  7 02:18:39 2005 EDT

  Modified files:              
    /loncom/auth	lonauth.pm 
  Log:
  - support multiple public users at a time (100) BUG#2573
  
  
Index: loncom/auth/lonauth.pm
diff -u loncom/auth/lonauth.pm:1.68 loncom/auth/lonauth.pm:1.69
--- loncom/auth/lonauth.pm:1.68	Tue Jul  5 17:30:14 2005
+++ loncom/auth/lonauth.pm	Thu Jul  7 02:18:37 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # User Authentication Module
 #
-# $Id: lonauth.pm,v 1.68 2005/07/05 21:30:14 albertel Exp $
+# $Id: lonauth.pm,v 1.69 2005/07/07 06:18:37 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -49,27 +49,47 @@
     my ($r, $username, $domain, $authhost,$lowerurl) = @_;
     my $lonids=$r->dir_config('lonIDsDir');
 
+    my $public=($username eq 'public' && $domain eq 'public');
+
 # See if old ID present, if so, remove
 
-    my $filename;
-    opendir(DIR,$lonids);
-    while ($filename=readdir(DIR)) {
-       if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
-	  unlink($lonids.'/'.$filename);
-       }
-    }
-    closedir(DIR);
+    my ($filename,$cookie,$userroles);
+    my $now=time;
 
-# Give them a new cookie
+    if ($public) {
+	my $max_public=100;
+	my $oldest;
+	my $oldest_time=0;
+	for(my $next=1;$next<=$max_public;$next++) {
+	    if (-e $lonids."/publicuser_$next.id") {
+		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
+		if ($mtime<$oldest_time || !$oldest_time) {
+		    $oldest_time=$mtime;
+		    $oldest=$next;
+		}
+	    } else {
+		$cookie="publicuser_$next";
+		last;
+	    }
+	}
+	if (!$cookie) { $cookie="publicuser_$oldest"; }
+    } else {
+	opendir(DIR,$lonids);
+	while ($filename=readdir(DIR)) {
+	    if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
+		unlink($lonids.'/'.$filename);
+	    }
+	}
+	closedir(DIR);
 
-    my $cookie;
-    my $now=time;
-    $cookie="$username\_$now\_$domain\_$authhost";
+# Give them a new cookie
 
+	$cookie="$username\_$now\_$domain\_$authhost";
+    
 # Initialize roles
 
-    my $userroles=Apache::lonnet::rolesinit($domain,$username,$authhost);
-
+	$userroles=Apache::lonnet::rolesinit($domain,$username,$authhost);
+    }
 # ------------------------------------ Check browser type and MathML capability
 
     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
@@ -138,7 +158,7 @@
 	print $idf "request.role=cm\n";
         print $idf "request.role.adv=$env{'user.adv'}\n";
 	print $idf "request.host=$ENV{'REMOTE_ADDR'}\n";
-	if ($username eq 'public' && $domain eq 'public') { 
+	if ($public) {
 	    print $idf "environment.remote=off\n";
 	}
 	if ($FORM{'interface'}) {
@@ -175,9 +195,7 @@
 
 # ------------------------------------------------------------ Get cookie ready
 
-    if ($username eq 'public' && $domain eq 'public') {
-	return $cookie;
-    }
+    if ($public) { return $cookie; }
     $cookie="lonID=$cookie; path=/";
 # -------------------------------------------------------- Menu script and info
     my $windowinfo=&Apache::lonmenu::open($clientos);