[LON-CAPA-cvs] cvs: loncom / lond /auth switchserver.pm /lonnet/perl lonnet.pm
albertel
lon-capa-cvs-allow@mail.lon-capa.org
Sat, 29 Sep 2007 04:03:52 -0000
albertel Sat Sep 29 00:03:52 2007 EDT
Modified files:
/loncom lond
/loncom/auth switchserver.pm
/loncom/lonnet/perl lonnet.pm
Log:
- when offloading a user session to a different server, check the remote
servers for an existing session and pick one of those first
- new lond command that checks if a session file exists for a specific user
- new lonnet routines to probe servers for one
Index: loncom/lond
diff -u loncom/lond:1.381 loncom/lond:1.382
--- loncom/lond:1.381 Wed Sep 12 16:29:13 2007
+++ loncom/lond Sat Sep 29 00:03:39 2007
@@ -2,7 +2,7 @@
# The LearningOnline Network
# lond "LON Daemon" Server (port "LOND" 5663)
#
-# $Id: lond,v 1.381 2007/09/12 20:29:13 raeburn Exp $
+# $Id: lond,v 1.382 2007/09/29 04:03:39 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -59,7 +59,7 @@
my $status='';
my $lastlog='';
-my $VERSION='$Revision: 1.381 $'; #' stupid emacs
+my $VERSION='$Revision: 1.382 $'; #' stupid emacs
my $remoteVERSION;
my $currenthostid="default";
my $currentdomainid;
@@ -2095,6 +2095,37 @@
®ister_handler("renameuserfile", \&rename_user_file_handler, 0,1,0);
#
+# Checks if the specified user has an active session on the server
+# return ok if so, not_found if not
+#
+# Parameters:
+# cmd - The request keyword that dispatched to tus.
+# tail - The tail of the request (colon separated parameters).
+# client - Filehandle open on the client.
+# Return:
+# 1.
+sub user_has_session_handler {
+ my ($cmd, $tail, $client) = @_;
+
+ my ($udom, $uname) = map { &unescape($_) } (split(/:/, $tail));
+
+ &logthis("Looking for $udom $uname");
+ opendir(DIR,$perlvar{'lonIDsDir'});
+ my $filename;
+ while ($filename=readdir(DIR)) {
+ last if ($filename=~/^\Q$uname\E_\d+_\Q$udom\E_/);
+ }
+ if ($filename) {
+ &Reply($client, "ok\n", "$cmd:$tail");
+ } else {
+ &Failure($client, "not_found\n", "$cmd:$tail");
+ }
+ return 1;
+
+}
+®ister_handler("userhassession", \&user_has_session_handler, 0,1,0);
+
+#
# Authenticate access to a user file by checking that the token the user's
# passed also exists in their session file
#
Index: loncom/auth/switchserver.pm
diff -u loncom/auth/switchserver.pm:1.16 loncom/auth/switchserver.pm:1.17
--- loncom/auth/switchserver.pm:1.16 Fri Sep 7 22:43:33 2007
+++ loncom/auth/switchserver.pm Sat Sep 29 00:03:46 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Switch Servers Handler
#
-# $Id: switchserver.pm,v 1.16 2007/09/08 02:43:33 raeburn Exp $
+# $Id: switchserver.pm,v 1.17 2007/09/29 04:03:46 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -83,8 +83,15 @@
['otherserver','role']);
my $switch_to=&Apache::lonnet::hostname($env{'form.otherserver'});
- if (!$env{'form.otherserver'}) {
- $env{'form.otherserver'}=&Apache::lonnet::spareserver(30000,undef,1);
+ if (! $env{'form.otherserver'}) {
+ $env{'form.otherserver'} =
+ &Apache::lonnet::find_existing_session($env{'user.domain'},
+ $env{'user.name'});
+ if (! $env{'form.otherserver'}) {
+ $env{'form.otherserver'} =
+ &Apache::lonnet::spareserver(30000,undef,1);
+ }
+
$switch_to=&Apache::lonnet::hostname($env{'form.otherserver'});
}
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.913 loncom/lonnet/perl/lonnet.pm:1.914
--- loncom/lonnet/perl/lonnet.pm:1.913 Mon Sep 24 20:21:12 2007
+++ loncom/lonnet/perl/lonnet.pm Sat Sep 29 00:03:51 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.913 2007/09/25 00:21:12 albertel Exp $
+# $Id: lonnet.pm,v 1.914 2007/09/29 04:03:51 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -582,6 +582,27 @@
}
return ($spare_server,$lowest_load);
}
+
+# --------------------------- ask offload servers if user already has a session
+sub find_existing_session {
+ my ($udom,$uname) = @_;
+ foreach my $try_server (@{ $spareid{'primary'} },
+ @{ $spareid{'default'} }) {
+ return $try_server if (&has_user_session($try_server, $udom, $uname));
+ }
+ return;
+}
+
+# -------------------------------- ask if server already has a session for user
+sub has_user_session {
+ my ($lonid,$udom,$uname) = @_;
+ my $result = &reply(join(':','userhassession',
+ map {&escape($_)} ($udom,$uname)),$lonid);
+ return 1 if ($result eq 'ok');
+
+ return 0;
+}
+
# --------------------------------------------- Try to change a user's password
sub changepass {