--- loncom/interface/domainprefs.pm 2022/02/14 02:48:46 1.405 +++ loncom/interface/domainprefs.pm 2022/02/15 04:28:01 1.406 @@ -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.406 2022/02/15 04:28:01 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}; } } } @@ -637,7 +640,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'},], @@ -3429,6 +3432,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 +6497,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 +6605,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 yetTo be done'; + $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain'); } else { my $maxnum = 0; my %ordered; @@ -15828,12 +15839,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 +15914,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 +16275,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') { @@ -16219,9 +16302,6 @@ sub modify_lti { } } } - 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 +16378,8 @@ sub modify_lti { } } } + } elsif ($item eq 'linkprot') { + $resulttext .= $linkprotoutput; } } }