[LON-CAPA-cvs] cvs: loncom / lond /auth migrateuser.pm switchserver.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Thu Oct 22 15:23:23 EDT 2020


raeburn		Thu Oct 22 19:23:23 2020 EDT

  Modified files:              
    /loncom/auth	migrateuser.pm switchserver.pm 
    /loncom	lond 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - If $env{'request.balancercookie'} set for user's session, and switch made
    to a different node, update hostID in cookie on balancer node once migrated.
  
  
-------------- next part --------------
Index: loncom/auth/migrateuser.pm
diff -u loncom/auth/migrateuser.pm:1.47 loncom/auth/migrateuser.pm:1.48
--- loncom/auth/migrateuser.pm:1.47	Sun May 24 11:25:29 2020
+++ loncom/auth/migrateuser.pm	Thu Oct 22 19:23:22 2020
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Starts a user off based of an existing token.
 #
-# $Id: migrateuser.pm,v 1.47 2020/05/24 11:25:29 raeburn Exp $
+# $Id: migrateuser.pm,v 1.48 2020/10/22 19:23:22 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -659,6 +659,20 @@
         } else {
             $extra_env = { 'request.balancercookie' => $data{'server'}.':'.$data{'balcookie'} };
         }
+    } elsif (($data{'server'}) && ($data{'otherbalcookie'})) {
+        my ($balancer,$balcookie) = split(/:/,$data{'otherbalcookie'});
+        if (defined(&Apache::lonnet::hostname($balancer)) && $balcookie =~ /^[a-f0-9]{32}$/) {
+            my $baldom = &Apache::lonnet::host_domain($balancer);
+            if (&Apache::lonnet::shared_institution($baldom)) {
+                my $cookieid = join('_',$udom,$data{'username'},$balcookie);
+                &Apache::lonnet::updatebalcookie($cookieid,$balancer,$data{'server'});
+                if (ref($extra_env) eq 'HASH') {
+                    $extra_env->{'request.balancercookie'} = $data{'otherbalcookie'};
+                } else {
+                    $extra_env = { 'request.balancercookie' => $data{'otherbalcookie'} };
+                }
+            }
+        }
     }
 
     if (($data{'conlost'}) && ($data{'server'})) {
Index: loncom/auth/switchserver.pm
diff -u loncom/auth/switchserver.pm:1.50 loncom/auth/switchserver.pm:1.51
--- loncom/auth/switchserver.pm:1.50	Tue Oct 20 01:38:12 2020
+++ loncom/auth/switchserver.pm	Thu Oct 22 19:23:22 2020
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Switch Servers Handler
 #
-# $Id: switchserver.pm,v 1.50 2020/10/20 01:38:12 raeburn Exp $
+# $Id: switchserver.pm,v 1.51 2020/10/22 19:23:22 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -231,10 +231,10 @@
 	return OK;
     }
 # -------------------------------------------------------- Menu script and info
-	   
+
 # ---------------------------------------------------------------- Get handover
 
-    my ($is_balancer,$setcookie,$newcookieid,$offloadto,$dom_balancers);
+    my ($is_balancer,$setcookie,$newcookieid,$otherbalcookie,$offloadto,$dom_balancers);
     my $only_body = 0;
     ($is_balancer,undef,$setcookie,$offloadto,$dom_balancers) =
         &Apache::lonnet::check_loadbalancing($env{'user.name'},$env{'user.domain'},'switchserver');
@@ -252,6 +252,9 @@
                                               $env{'user.name'},$env{'user.domain'});
         }
     }
+    if ((!$is_balancer) && ($env{'request.balancercookie'})) {
+        $otherbalcookie = $env{'request.balancercookie'};
+    }
 
     my %info=('ip'            => $ENV{'REMOTE_ADDR'},
               'domain'        => $env{'user.domain'},
@@ -274,6 +277,8 @@
     }
     if ($newcookieid) {
         $info{'balcookie'} = $newcookieid;
+    } elsif ($otherbalcookie) {
+        $info{'otherbalcookie'} = $otherbalcookie;
     }
     if ($env{'form.origurl'}) {
         $info{'origurl'} = $env{'form.origurl'};
Index: loncom/lond
diff -u loncom/lond:1.563 loncom/lond:1.564
--- loncom/lond:1.563	Tue May  5 20:24:41 2020
+++ loncom/lond	Thu Oct 22 19:23:22 2020
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.563 2020/05/05 20:24:41 raeburn Exp $
+# $Id: lond,v 1.564 2020/10/22 19:23:22 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -65,7 +65,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.563 $'; #' stupid emacs
+my $VERSION='$Revision: 1.564 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -310,6 +310,7 @@
                tokenauthuserfile => {anywhere => 1},
                unsub => {content => 1,},
                update => {shared => 1},
+               updatebalcookie => {institutiononly => 1},
                updateclickers => {remote => 1},
                userhassession => {anywhere => 1},
                userload => {anywhere => 1},
@@ -5683,8 +5684,65 @@
 &register_handler("tmpdel", \&tmp_del_handler, 0, 1, 0);
 
 #
+#  Process the updatebalcookie command.  This command updates a
+#  cookie in the lonBalancedir directory on a load balancer node.
+#
+# Parameters:
+#   $cmd      - Command that got us here.
+#   $tail     - Tail of the request (escaped cookie: escaped current entry)
+#
+#   $client   - socket open on the client process.
+#
+# Returns:
+#   1     - Indicating processing should continue.
+# Side Effects:
+#   A cookie file is updated from the lonBalancedir directory
+#   A reply is sent to the client.
+#
+sub update_balcookie_handler {
+    my ($cmd, $tail, $client) = @_;
+
+    my $userinput= "$cmd:$tail";
+    chomp($tail);
+    my ($cookie,$lastentry) = map { &unescape($_) } (split(/:/,$tail));
+
+    my $updatedone;
+    if ($cookie =~ /^$LONCAPA::match_domain\_$LONCAPA::match_username\_[a-f0-9]{32}$/) {
+        my $execdir=$perlvar{'lonBalanceDir'};
+        if (-e "$execdir/$cookie.id") {
+            my $doupdate;
+            if (open(my $fh,'<',"$execdir/$cookie.id")) {
+                while (my $line = <$fh>) {
+                    chomp($line);
+                    if ($line eq $lastentry) {
+                        $doupdate = 1;
+                        last;
+                    }
+                }
+                close($fh);
+            }
+            if ($doupdate) {
+                if (open(my $fh,'>',"$execdir/$cookie.id")) {
+                    print $fh $clientname;
+                    close($fh);
+                    $updatedone = 1;
+                }
+            }
+        }
+    }
+    if ($updatedone) {
+        &Reply($client, "ok\n", $userinput);
+    } else {
+        &Failure( $client, "error: ".($!+0)."file update failed ".
+                  "while attempting updatebalcookie\n", $userinput);
+    }
+    return 1;
+}
+&register_handler("updatebalcookie", \&update_balcookie_handler, 0, 1, 0);
+
+#
 #  Process the delbalcookie command. This command deletes a balancer
-#  cookie in the lonBalancedir directory created by switchserver
+#  cookie in the lonBalancedir directory on a load balancer node.
 #
 # Parameters:
 #   $cmd      - Command that got us here.
@@ -5702,6 +5760,7 @@
     my $userinput= "$cmd:$cookie";
 
     chomp($cookie);
+    $cookie = &unescape($cookie);
     my $deleted = '';
     if ($cookie =~ /^$LONCAPA::match_domain\_$LONCAPA::match_username\_[a-f0-9]{32}$/) {
         my $execdir=$perlvar{'lonBalanceDir'};
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1430 loncom/lonnet/perl/lonnet.pm:1.1431
--- loncom/lonnet/perl/lonnet.pm:1.1430	Tue Oct 20 01:38:12 2020
+++ loncom/lonnet/perl/lonnet.pm	Thu Oct 22 19:23:23 2020
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1430 2020/10/20 01:38:12 raeburn Exp $
+# $Id: lonnet.pm,v 1.1431 2020/10/22 19:23:23 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1150,6 +1150,21 @@
     return ($otherserver,$cookie);
 }
 
+sub updatebalcookie {
+    my ($cookie,$balancer,$lastentry)=@_;
+    if ($cookie =~ /^($match_domain)\_($match_username)\_[a-f0-9]{32}$/) {
+        my ($udom,$uname) = ($1,$2);
+        my $uprimary_id = &domain($udom,'primary');
+        my $uintdom = &internet_dom($uprimary_id);
+        my $intdom = &internet_dom($balancer);
+        my $serverhomedom = &host_domain($balancer);
+        if (($uintdom ne '') && ($uintdom eq $intdom)) {
+            return &reply('updatebalcookie:'.&escape($cookie).':'.&escape($lastentry),$balancer);
+        }
+    }
+    return;
+}
+
 sub delbalcookie {
     my ($cookie,$balancer) =@_;
     if ($cookie =~ /^($match_domain)\_($match_username)\_[a-f0-9]{32}$/) {
@@ -1159,7 +1174,7 @@
         my $intdom = &internet_dom($balancer);
         my $serverhomedom = &host_domain($balancer);
         if (($uintdom ne '') && ($uintdom eq $intdom)) {
-            return &reply("delbalcookie:$cookie",$balancer);
+            return &reply('delbalcookie:'.&escape($cookie),$balancer);
         }
     }
 }


More information about the LON-CAPA-cvs mailing list