--- loncom/interface/domainprefs.pm 2022/02/14 02:48:46 1.405
+++ loncom/interface/domainprefs.pm 2022/06/08 03:36:07 1.410
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.405 2022/02/14 02:48:46 raeburn Exp $
+# $Id: domainprefs.pm,v 1.410 2022/06/08 03:36:07 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -249,13 +249,16 @@ sub handler {
}
}
if (ref($domconfig{'ltisec'}) eq 'HASH') {
- if (ref($domconfig{'ltisec'}{'prot'}) eq 'HASH') {
+ if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
if (ref($encconfig{'linkprot'}) eq 'HASH') {
- foreach my $id (keys(%{$domconfig{'ltisec'}{'prot'}})) {
- if ((ref($domconfig{'ltisec'}{'prot'}{$id}) eq 'HASH') &&
+ foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
+ unless ($id =~ /^\d+$/) {
+ delete($domconfig{'ltisec'}{'linkprot'}{$id});
+ }
+ if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
(ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
foreach my $item ('key','secret') {
- $domconfig{'ltisec'}{'prot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
+ $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
}
}
}
@@ -324,7 +327,9 @@ sub handler {
header => [{col1 => 'Setting',
col2 => 'Value'},
{col1 => 'Institutional user types',
- col2 => 'Name displayed'}],
+ col2 => 'Name displayed'},
+ {col1 => 'Mapping for missing usernames via standard log-in',
+ col2 => 'Rules in use'}],
print => \&print_defaults,
modify => \&modify_defaults,
},
@@ -637,7 +642,7 @@ sub handler {
col2 => 'Settings'},
{col1 => 'Rules for shared secrets',
col2 => 'Settings'},
- {col1 => 'Link Protectors (domain)',
+ {col1 => 'Link Protectors',
col2 => 'Settings'},
{col1 => 'Consumers',
col2 => 'Settings'},],
@@ -980,7 +985,7 @@ sub print_config_box {
if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
($action eq 'usersessions') || ($action eq 'coursecategories') ||
- ($action eq 'trust') || ($action eq 'contacts') ||
+ ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
($action eq 'privacy') || ($action eq 'passwords') || ($action eq 'lti')) {
if ($action eq 'coursecategories') {
$output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
@@ -1068,8 +1073,8 @@ sub print_config_box {
}
$rowtotal ++;
} elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
- ($action eq 'defaults') || ($action eq 'directorysrch') ||
- ($action eq 'helpsettings') || ($action eq 'wafproxy')) {
+ ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
+ ($action eq 'wafproxy')) {
$output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
} elsif ($action eq 'scantron') {
$output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
@@ -3429,6 +3434,7 @@ sub lti_javascript {
push(@jsarray,$ordered{$item});
}
my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
+ my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
return <<"ENDSCRIPT";
@@ -6490,6 +6499,9 @@ sub print_lti {
if (exists($settings->{'linkprot'})) {
if (ref($settings->{'linkprot'}) eq 'HASH') {
%linkprot = %{$settings->{'linkprot'}};
+ if ($linkprot{'lock'}) {
+ delete($linkprot{'lock'});
+ }
}
}
} else {
@@ -6595,8 +6607,9 @@ sub print_lti {
$$rowtotal += $itemcount;
} elsif ($position eq 'middle') {
$datatable = &password_rules('secrets',\$itemcount,\%rules);
+ $$rowtotal += $itemcount;
} elsif ($position eq 'lower') {
- $datatable .= '
Not set yet | To be done |
';
+ $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
} else {
my $maxnum = 0;
my %ordered;
@@ -10456,7 +10469,7 @@ sub user_formats_row {
'username' => 'new usernames',
'id' => 'IDs',
);
- unless ($type eq 'email') {
+ unless (($type eq 'email') || ($type eq 'unamemap')) {
my $css_class = $rowcount%2?' class="LC_odd_row"':'';
$output = ''.
''.
@@ -10511,9 +10524,9 @@ sub user_formats_row {
} elsif ($colsleft == 1) {
$output .= ' | | ';
}
- $output .= '
';
- unless ($type eq 'email') {
- $output .= '';
+ $output .= '';
+ unless (($type eq 'email') || ($type eq 'unamemap')) {
+ $output .= '';
}
return $output;
}
@@ -10656,7 +10669,7 @@ sub print_defaults {
$datatable .= '';
$rownum ++;
}
- } else {
+ } elsif ($position eq 'middle') {
my %defaults;
if (ref($settings) eq 'HASH') {
if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
@@ -10706,6 +10719,22 @@ sub print_defaults {
$rownum ++;
}
}
+ } else {
+ my ($unamemaprules,$ruleorder) =
+ &Apache::lonnet::inst_userrules($dom,'unamemap');
+ $css_class = $rownum%2?' class="LC_odd_row"':'';
+ if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
+ my $numinrow = 2;
+ $datatable .= ''.&mt('Available conversions').' | '.
+ &user_formats_row('unamemap',$settings,$unamemaprules,
+ $ruleorder,$numinrow).
+ ' |
';
+ }
+ if ($datatable eq '') {
+ $datatable .= ''.
+ &mt('No rules set for domain in customized localenroll.pm').
+ ' |
';
+ }
}
$$rowtotal += $rownum;
return $datatable;
@@ -11557,7 +11586,7 @@ function warnInt$prefix(field) {
field.value.replace(/^\s+/,'');
field.value.replace(/\s+\$/,'');
var regexdigit=/^\\d+\$/;
- if (field.name == '$prefix\_min') {
+ if (field.name == '${prefix}_min') {
if (field.value == '') {
alert('$intalert{passmin}');
field.value = '$defmin';
@@ -11577,7 +11606,7 @@ function warnInt$prefix(field) {
field.value = '';
}
if (field.value != '') {
- if (field.name == '$prefix\_expire') {
+ if (field.name == '${prefix}_expire') {
var regexpposnum=/^\\d+(|\\.\\d*)\$/;
if (!regexpposnum.test(field.value)) {
alert('$intalert{passexp}');
@@ -11591,10 +11620,10 @@ function warnInt$prefix(field) {
}
} else {
if (!regexdigit.test(field.value)) {
- if (field.name == '$prefix\_max') {
+ if (field.name == '${prefix}_max') {
alert('$intalert{passmax}');
} else {
- if (field.name == '$prefix\_numsaved') {
+ if (field.name == '${prefix}_numsaved') {
alert('$intalert{passnum}');
}
}
@@ -15828,12 +15857,20 @@ sub modify_lti {
my %menutitles = <imenu_titles();
- my (%currltisec,%secchanges,%newltisec,%keyset,%newkeyset);
+ my (%currltisec,%secchanges,%newltisec,%newltienc,%keyset,%newkeyset);
$newltisec{'private'}{'keys'} = [];
$newltisec{'encrypt'} = {};
$newltisec{'rules'} = {};
+ $newltisec{'linkprot'} = {};
if (ref($domconfig{'ltisec'}) eq 'HASH') {
%currltisec = %{$domconfig{'ltisec'}};
+ if (ref($currltisec{'linkprot'}) eq 'HASH') {
+ foreach my $id (keys(%{$currltisec{'linkprot'}})) {
+ unless ($id =~ /^\d+$/) {
+ delete($currltisec{'linkprot'}{$id});
+ }
+ }
+ }
if (ref($currltisec{'private'}) eq 'HASH') {
if (ref($currltisec{'private'}{'keys'}) eq 'ARRAY') {
$newltisec{'private'}{'keys'} = $currltisec{'private'}{'keys'};
@@ -15895,6 +15932,62 @@ sub modify_lti {
}
}
+ my (%linkprotchg,$linkprotoutput,$is_home);
+ my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
+ \%linkprotchg,'domain');
+ my $home = &Apache::lonnet::domain($dom,'primary');
+ unless (($home eq 'no_host') || ($home eq '')) {
+ my @ids=&Apache::lonnet::current_machine_ids();
+ foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
+ }
+
+ if (keys(%linkprotchg)) {
+ $secchanges{'linkprot'} = 1;
+ my %oldlinkprot;
+ if (ref($currltisec{'linkprot'}) eq 'HASH') {
+ %oldlinkprot = %{$currltisec{'linkprot'}};
+ }
+ foreach my $id (keys(%linkprotchg)) {
+ if (ref($linkprotchg{$id}) eq 'HASH') {
+ foreach my $inner (keys(%{$linkprotchg{$id}})) {
+ if (($inner eq 'secret') || ($inner eq 'key')) {
+ if ($is_home) {
+ $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
+ }
+ }
+ }
+ } else {
+ $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
+ }
+ }
+ $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
+ if (keys(%linkprotchg)) {
+ %{$newltisec{'linkprot'}} = %linkprotchg;
+ }
+ }
+ if (ref($currltisec{'linkprot'}) eq 'HASH') {
+ foreach my $id (%{$currltisec{'linkprot'}}) {
+ next if ($id !~ /^\d+$/);
+ unless (exists($linkprotchg{$id})) {
+ if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
+ foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
+ if (($inner eq 'secret') || ($inner eq 'key')) {
+ if ($is_home) {
+ $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
+ }
+ } else {
+ $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
+ }
+ }
+ } else {
+ $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
+ }
+ }
+ }
+ }
+ if ($proterror) {
+ $errors .= ''.$proterror.'';
+ }
my (@items,%deletions,%itemids);
if ($env{'form.lti_add'}) {
my $consumer = $env{'form.lti_consumer_add'};
@@ -16200,8 +16293,16 @@ sub modify_lti {
my %ltihash = (
$action => { %confhash }
);
+ my %ltienchash = (
+ $action => { %encconfig }
+ );
if (keys(%secchanges)) {
$ltihash{'ltisec'} = \%newltisec;
+ if ($secchanges{'linkprot'}) {
+ if ($is_home) {
+ $ltienchash{'linkprot'} = \%newltienc;
+ }
+ }
}
my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
if ($putresult eq 'ok') {
@@ -16218,10 +16319,12 @@ sub modify_lti {
$dom,$hostid);
}
}
+ if (ref($lastactref) eq 'HASH') {
+ if (($secchanges{'encrypt'}) || ($secchanges{'private'})) {
+ $lastactref->{'domdefaults'} = 1;
+ }
+ }
}
- my %ltienchash = (
- $action => { %encconfig }
- );
&Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
return &mt('No changes made.');
@@ -16298,6 +16401,8 @@ sub modify_lti {
}
}
}
+ } elsif ($item eq 'linkprot') {
+ $resulttext .= $linkprotoutput;
}
}
}
@@ -19885,6 +19990,41 @@ sub modify_defaults {
$newvalues{$item} = $staticdefaults{$item};
}
}
+ my ($unamemaprules,$ruleorder);
+ my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
+ if (@possunamemaprules) {
+ ($unamemaprules,$ruleorder) =
+ &Apache::lonnet::inst_userrules($dom,'unamemap');
+ if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
+ if (@{$ruleorder} > 0) {
+ my %possrules;
+ map { $possrules{$_} = 1; } @possunamemaprules;
+ foreach my $rule (@{$ruleorder}) {
+ if ($possrules{$rule}) {
+ push(@{$newvalues{'unamemap_rule'}},$rule);
+ }
+ }
+ }
+ }
+ }
+ if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
+ if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
+ my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
+ $newvalues{'unamemap_rule'});
+ if (@rulediffs) {
+ $changes{'unamemap_rule'} = 1;
+ $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
+ }
+ } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
+ $changes{'unamemap_rule'} = 1;
+ delete($domdefaults{'unamemap_rule'});
+ }
+ } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
+ if (@{$newvalues{'unamemap_rule'}} > 0) {
+ $changes{'unamemap_rule'} = 1;
+ $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
+ }
+ }
my %defaults_hash = (
defaults => \%newvalues,
);
@@ -19999,6 +20139,26 @@ sub modify_defaults {
$resulttext .= ''.&mt('Institutional user status types deleted').'';
}
}
+ } elsif ($item eq 'unamemap_rule') {
+ if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
+ my @rulenames;
+ if (ref($unamemaprules) eq 'HASH') {
+ foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
+ if (ref($unamemaprules->{$rule}) eq 'HASH') {
+ push(@rulenames,$unamemaprules->{$rule}->{'name'});
+ }
+ }
+ }
+ if (@rulenames) {
+ $resulttext .= ''.&mt('Mapping for missing usernames includes: [_1]',
+ '').
+ '';
+ } else {
+ $resulttext .= ''.&mt('No mapping for missing usernames via standard log-in').'';
+ }
+ } else {
+ $resulttext .= ''.&mt('Mapping for missing usernames via standard log-in deleted').'';
+ }
} else {
my $value = $env{'form.'.$item};
if ($value eq '') {
@@ -22624,8 +22784,10 @@ sub modify_trust {
}
my $cachetime = 24*60*60;
&Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
+ &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
if (ref($lastactref) eq 'HASH') {
$lastactref->{'domdefaults'} = 1;
+ $lastactref->{'trust'} = 1;
}
if (keys(%changes) > 0) {
my %lt = &trust_titles();
@@ -23694,7 +23856,7 @@ sub devalidate_remote_domconfs {
map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
'directorysrch','passwdconf','cats','proxyalias','proxysaml',
- 'ipaccess');
+ 'ipaccess','trust');
my %cache_by_lonhost;
if (exists($cachekeys->{'samllanding'})) {
if (ref($cachekeys->{'samllanding'}) eq 'HASH') {