[LON-CAPA-cvs] cvs: loncom / lonenc.pm /auth lonauth.pm migrateuser.pm /interface domainprefs.pm loncommon.pm
raeburn
raeburn at source.lon-capa.org
Sun Mar 15 19:04:16 EDT 2020
raeburn Sun Mar 15 23:04:16 2020 EDT
Modified files:
/loncom lonenc.pm
/loncom/auth lonauth.pm migrateuser.pm
/loncom/interface loncommon.pm domainprefs.pm
Log:
- Add domain configuration to offload users from other institutions, on next
access (after recording any submission to a problem).
- Switching user session to a different server can jump to the same resource
currently being viewed when encrypturl is in effect.
-------------- next part --------------
Index: loncom/lonenc.pm
diff -u loncom/lonenc.pm:1.25 loncom/lonenc.pm:1.26
--- loncom/lonenc.pm:1.25 Fri Sep 30 15:58:05 2011
+++ loncom/lonenc.pm Sun Mar 15 23:04:05 2020
@@ -1,7 +1,7 @@
# The LearningOnline Network
# URL translation for encrypted filenames
#
-# $Id: lonenc.pm,v 1.25 2011/09/30 15:58:05 raeburn Exp $
+# $Id: lonenc.pm,v 1.26 2020/03/15 23:04:05 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -116,9 +116,9 @@
}
sub encrypted {
- my ($uri,$force_enc) = @_;
+ my ($uri,$force_enc,$cid) = @_;
if (!$force_enc && $env{'request.role.adv'}) { return($uri); }
- my $seed=&encryptseed();
+ my $seed=&encryptseed($cid);
unless ($seed) {
return $uri;
}
Index: loncom/auth/lonauth.pm
diff -u loncom/auth/lonauth.pm:1.158 loncom/auth/lonauth.pm:1.159
--- loncom/auth/lonauth.pm:1.158 Sun Jun 16 22:32:04 2019
+++ loncom/auth/lonauth.pm Sun Mar 15 23:04:10 2020
@@ -1,7 +1,7 @@
# The LearningOnline Network
# User Authentication Module
#
-# $Id: lonauth.pm,v 1.158 2019/06/16 22:32:04 raeburn Exp $
+# $Id: lonauth.pm,v 1.159 2020/03/15 23:04:10 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -46,7 +46,7 @@
# ------------------------------------------------------------ Successful login
sub success {
my ($r, $username, $domain, $authhost, $lowerurl, $extra_env,
- $form,$skipcritical) = @_;
+ $form,$skipcritical,$cid) = @_;
# ------------------------------------------------------------ Get cookie ready
my $cookie =
@@ -148,16 +148,26 @@
}
if (defined($form->{symb})) {
my $destsymb = $form->{symb};
+ my $encrypted;
+ if ($destsymb =~ m{^/enc/}) {
+ $encrypted = 1;
+ if ($cid) {
+ $destsymb = &Apache::lonenc::unencrypted($destsymb,$cid);
+ }
+ }
$destination .= ($destination =~ /\?/) ? '&' : '?';
if ($destsymb =~ /___/) {
- # FIXME Need to deal with encrypted symbs and urls as needed.
my ($map,$resid,$desturl)=split(/___/,$destsymb);
$desturl = &Apache::lonnet::clutter($desturl);
+ if ($encrypted) {
+ $desturl = &Apache::lonenc::encrypted($desturl,1,$cid);
+ $destsymb = $form->{symb};
+ }
$desturl = &HTML::Entities::encode($desturl,'"<>&');
$destsymb = &HTML::Entities::encode($destsymb,'"<>&');
$destination .= 'destinationurl='.$desturl.
'&destsymb='.$destsymb;
- } else {
+ } elsif (!$encrypted) {
$destsymb = &HTML::Entities::encode($destsymb,'"<>&');
$destination .= 'destinationurl='.$destsymb;
}
Index: loncom/auth/migrateuser.pm
diff -u loncom/auth/migrateuser.pm:1.45 loncom/auth/migrateuser.pm:1.46
--- loncom/auth/migrateuser.pm:1.45 Sun Jun 16 22:27:06 2019
+++ loncom/auth/migrateuser.pm Sun Mar 15 23:04:11 2020
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Starts a user off based of an existing token.
#
-# $Id: migrateuser.pm,v 1.45 2019/06/16 22:27:06 raeburn Exp $
+# $Id: migrateuser.pm,v 1.46 2020/03/15 23:04:11 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -671,7 +671,7 @@
}
}
- my %form;
+ my (%form,$cid);
if ($data{'symb'} ne '') {
$form{'symb'} = $data{'symb'};
}
@@ -681,8 +681,13 @@
if ($data{'noloadbalance'} ne '') {
$form{'noloadbalance'} = $data{'noloadbalance'};
}
-
- if (!$data{'role'}) {
+ if ($data{'role'}) {
+ if ($data{'role'} =~ m{\./($match_domain)/($match_courseid)(?:/\w+|$)}) {
+ unless (&Apache::lonnet::homeserver($2,$1) eq 'no_host') {
+ $cid = $1.'_'.$2;
+ }
+ }
+ } else {
my $handle = &Apache::lonnet::check_for_valid_session($r);
if ($handle) {
&Apache::lonnet::transfer_profile_to_env($r->dir_config('lonIDsDir'),
@@ -915,7 +920,7 @@
$r->internal_redirect($next_url);
} else {
&Apache::lonauth::success($r,$data{'username'},$data{'domain'},$home,
- $next_url,$extra_env,\%form);
+ $next_url,$extra_env,\%form,'',$cid);
}
return OK;
}
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1339 loncom/interface/loncommon.pm:1.1340
--- loncom/interface/loncommon.pm:1.1339 Wed Feb 19 23:19:52 2020
+++ loncom/interface/loncommon.pm Sun Mar 15 23:04:15 2020
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1339 2020/02/19 23:19:52 raeburn Exp $
+# $Id: loncommon.pm,v 1.1340 2020/03/15 23:04:15 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -8526,43 +8526,85 @@
my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
+ my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
+ my $offload;
if (ref($domdefs{'offloadnow'}) eq 'HASH') {
- my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
if ($domdefs{'offloadnow'}{$lonhost}) {
- my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
- if (($newserver) && ($newserver ne $lonhost)) {
- my $numsec = 5;
- my $timeout = $numsec * 1000;
- my ($newurl,$locknum,%locks,$msg);
- if ($env{'request.role.adv'}) {
- ($locknum,%locks) = &Apache::lonnet::get_locks();
- }
- my $disable_submit = 0;
- if ($requrl =~ /$LONCAPA::assess_re/) {
- $disable_submit = 1;
+ $offload = 1;
+ }
+ }
+ unless ($offload) {
+ if (ref($domdefs{'offloadoth'}) eq 'HASH') {
+ if ($domdefs{'offloadoth'}{$lonhost}) {
+ if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
+ (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
+ unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
+ $offload = 1;
+ $dom_in_use = $env{'user.domain'};
+ }
}
- if ($locknum) {
- my @lockinfo = sort(values(%locks));
- $msg = &mt('Once the following tasks are complete: ')."\\n".
- join(", ",sort(values(%locks)))."\\n".
- &mt('your session will be transferred to a different server, after you click "Roles".');
+ }
+ }
+ }
+ if ($offload) {
+ my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
+ if (($newserver) && ($newserver ne $lonhost)) {
+ my $numsec = 5;
+ my $timeout = $numsec * 1000;
+ my ($newurl,$locknum,%locks,$msg);
+ if ($env{'request.role.adv'}) {
+ ($locknum,%locks) = &Apache::lonnet::get_locks();
+ }
+ my $disable_submit = 0;
+ if ($requrl =~ /$LONCAPA::assess_re/) {
+ $disable_submit = 1;
+ }
+ if ($locknum) {
+ my @lockinfo = sort(values(%locks));
+ $msg = &mt('Once the following tasks are complete: ')."\n".
+ join(", ",sort(values(%locks)))."\n";
+ if (&show_course()) {
+ $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
} else {
- if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
- $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
- }
- $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
- $newurl = '/adm/switchserver?otherserver='.$newserver;
- if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
- $newurl .= '&role='.$env{'request.role'};
+ $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
+ }
+ } else {
+ if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
+ $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
+ }
+ $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
+ $newurl = '/adm/switchserver?otherserver='.$newserver;
+ if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
+ $newurl .= '&role='.$env{'request.role'};
+ }
+ if ($env{'request.symb'}) {
+ my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
+ if ($shownsymb =~ m{^/enc/}) {
+ my $reqdmajor = 2;
+ my $reqdminor = 11;
+ my $reqdsubminor = 3;
+ my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
+ my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
+ my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
+ if (($major eq '' && $minor eq '') ||
+ (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
+ (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
+ ($reqdsubminor > $subminor))))) {
+ undef($shownsymb);
+ }
}
- if ($env{'request.symb'}) {
- $newurl .= '&symb='.$env{'request.symb'};
- } else {
- $newurl .= '&origurl='.$requrl;
+ if ($shownsymb) {
+ &js_escape(\$shownsymb);
+ $newurl .= '&symb='.$shownsymb;
}
+ } else {
+ my $shownurl = &Apache::lonenc::check_encrypt($requrl);
+ &js_escape(\$shownurl);
+ $newurl .= '&origurl='.$shownurl;
}
- &js_escape(\$msg);
- $result.=<<OFFLOAD
+ }
+ &js_escape(\$msg);
+ $result.=<<OFFLOAD
<meta http-equiv="pragma" content="no-cache" />
<script type="text/javascript">
// <![CDATA[
@@ -8583,7 +8625,6 @@
// ]]>
</script>
OFFLOAD
- }
}
}
}
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.370 loncom/interface/domainprefs.pm:1.371
--- loncom/interface/domainprefs.pm:1.370 Fri Feb 7 20:42:50 2020
+++ loncom/interface/domainprefs.pm Sun Mar 15 23:04:15 2020
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.370 2020/02/07 20:42:50 raeburn Exp $
+# $Id: domainprefs.pm,v 1.371 2020/03/15 23:04:15 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -893,7 +893,6 @@
($action eq 'usersessions') || ($action eq 'coursecategories') ||
($action eq 'trust') || ($action eq 'contacts') ||
($action eq 'privacy') || ($action eq 'passwords')) {
- my $leftnobr = ' LC_nobreak';
if ($action eq 'coursecategories') {
$output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
$colspan = ' colspan="2"';
@@ -6421,13 +6420,18 @@
if ($position eq 'top') {
if (keys(%serverhomes) > 1) {
my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
- my $curroffloadnow;
+ my ($curroffloadnow,$curroffloadoth);
if (ref($settings) eq 'HASH') {
if (ref($settings->{'offloadnow'}) eq 'HASH') {
$curroffloadnow = $settings->{'offloadnow'};
}
+ if (ref($settings->{'offloadoth'}) eq 'HASH') {
+ $curroffloadoth = $settings->{'offloadoth'};
+ }
}
- $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
+ my $other_insts = scalar(keys(%by_location));
+ $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
+ $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
} else {
$datatable .= '<tr'.$css_class.'><td colspan="2">'.
&mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
@@ -6871,7 +6875,8 @@
}
sub spares_row {
- my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
+ my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
+ $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
my $css_class;
my $numinrow = 4;
my $itemcount = 1;
@@ -6891,12 +6896,17 @@
}
}
next unless (ref($spareid->{$server}) eq 'HASH');
- my $checkednow;
+ my ($checkednow,$checkedoth);
if (ref($curroffloadnow) eq 'HASH') {
if ($curroffloadnow->{$server}) {
$checkednow = ' checked="checked"';
}
}
+ if (ref($curroffloadoth) eq 'HASH') {
+ if ($curroffloadoth->{$server}) {
+ $checkedoth = ' checked="checked"';
+ }
+ }
$css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
$datatable .= '<tr'.$css_class.'>
<td rowspan="2">
@@ -6905,8 +6915,15 @@
,'<b>'.$server.'</b>').'</span><br />'.
'<span class="LC_nobreak">'."\n".
'<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
- ' '.&mt('Switch active users on next access').'</label></span>'.
+ ' '.&mt('Switch any active user on next access').'</label></span>'.
"\n";
+ if ($other_insts) {
+ $datatable .= '<br />'.
+ '<span class="LC_nobreak">'."\n".
+ '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
+ ' '.&mt('Switch other institutions on next access').'</label></span>'.
+ "\n";
+ }
my (%current,%canselect);
my @choices =
&possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
@@ -18289,6 +18306,7 @@
}
}
$defaultshash{'usersessions'}{'offloadnow'} = {};
+ $defaultshash{'usersessions'}{'offloadoth'} = {};
my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
my @okoffload;
if (@offloadnow) {
@@ -18305,6 +18323,22 @@
}
}
}
+ my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
+ my @okoffloadoth;
+ if (@offloadoth) {
+ foreach my $server (@offloadoth) {
+ if (&Apache::lonnet::hostname($server) ne '') {
+ unless (grep(/^\Q$server\E$/, at okoffloadoth)) {
+ push(@okoffloadoth,$server);
+ }
+ }
+ }
+ if (@okoffloadoth) {
+ foreach my $lonhost (@okoffloadoth) {
+ $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
+ }
+ }
+ }
if (ref($domconfig{'usersessions'}) eq 'HASH') {
if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
if (ref($changes{'spares'}) eq 'HASH') {
@@ -18315,26 +18349,38 @@
} else {
$savespares = 1;
}
- if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
- foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
- unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
- $changes{'offloadnow'} = 1;
- last;
- }
- }
- unless ($changes{'offloadnow'}) {
- foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
- unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
- $changes{'offloadnow'} = 1;
+ foreach my $offload ('offloadnow','offloadoth') {
+ if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
+ foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
+ unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
+ $changes{$offload} = 1;
last;
}
}
- }
- } elsif (@okoffload) {
+ unless ($changes{$offload}) {
+ foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
+ unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
+ $changes{$offload} = 1;
+ last;
+ }
+ }
+ }
+ } else {
+ if (($offload eq 'offloadnow') && (@okoffload)) {
+ $changes{'offloadnow'} = 1;
+ }
+ if (($offload eq 'offloadoth') && (@okoffloadoth)) {
+ $changes{'offloadoth'} = 1;
+ }
+ }
+ }
+ } else {
+ if (@okoffload) {
$changes{'offloadnow'} = 1;
}
- } elsif (@okoffload) {
- $changes{'offloadnow'} = 1;
+ if (@okoffloadoth) {
+ $changes{'offloadoth'} = 1;
+ }
}
my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
if ((keys(%changes) > 0) || ($savespares)) {
@@ -18351,6 +18397,9 @@
if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
$domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
}
+ if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
+ $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
+ }
}
my $cachetime = 24*60*60;
&Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
@@ -18430,16 +18479,31 @@
if ($changes{'offloadnow'}) {
if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
- $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
+ $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
$resulttext .= '<li>'.$lonhost.'</li>';
}
$resulttext .= '</ul>';
} else {
- $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
+ $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
+ }
+ } else {
+ $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
+ }
+ }
+ if ($changes{'offloadoth'}) {
+ if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
+ if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
+ $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
+ foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
+ $resulttext .= '<li>'.$lonhost.'</li>';
+ }
+ $resulttext .= '</ul>';
+ } else {
+ $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
}
} else {
- $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
+ $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
}
}
$resulttext .= '</ul>';
More information about the LON-CAPA-cvs
mailing list