--- loncom/auth/lonauth.pm 2005/07/05 21:30:14 1.68 +++ loncom/auth/lonauth.pm 2005/07/07 06:18:37 1.69 @@ -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 @@ sub success { 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 @@ sub success { 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 @@ sub success { # ------------------------------------------------------------ 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);