--- loncom/interface/domainprefs.pm 2014/07/15 21:52:16 1.160.6.51 +++ loncom/interface/domainprefs.pm 2014/10/07 03:16:05 1.160.6.55 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.160.6.51 2014/07/15 21:52:16 raeburn Exp $ +# $Id: domainprefs.pm,v 1.160.6.55 2014/10/07 03:16:05 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -3642,9 +3642,10 @@ sub print_loadbalancing { $disabled = ' disabled="disabled"'; } $targettable .= - ''; my $rem = $i%($numinrow); if ($rem == 0) { if (($i > 0) && ($i < $numspares-1)) { @@ -3734,7 +3735,7 @@ sub loadbalancing_rules { if (ref($currrules) eq 'HASH') { $current = $currrules->{$type}; } - if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) { + if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) { if ($dom ne &Apache::lonnet::host_domain($lonhost)) { $current = ''; } @@ -3786,7 +3787,7 @@ sub loadbalance_rule_row { my @rulenames; my %ruletitles = &offloadtype_text(); if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) { - @rulenames = ('balancer','offloadedto'); + @rulenames = ('balancer','offloadedto','specific'); } else { @rulenames = ('default','homeserver'); if ($type eq '_LC_external') { @@ -3797,7 +3798,7 @@ sub loadbalance_rule_row { push(@rulenames,'none'); } my $style = $targets_div_style; - if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) { + if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) { $style = $homedom_div_style; } my $space; @@ -3848,8 +3849,13 @@ sub loadbalance_rule_row { ' '.$ruletitles{$rulenames[$i]}. - ''.$extra.'
'."\n"; + ')"'.$checked.' /> '; + if (($rulenames[$i] eq 'specific') && ($type =~ /_LC_ipchange/)) { + $output .= $ruletitles{'particular'}; + } else { + $output .= $ruletitles{$rulenames[$i]}; + } + $output .= ''.$extra.'
'."\n"; } $output .= ''."\n"; return $output; @@ -3864,6 +3870,7 @@ sub offloadtype_text { 'none' => 'No offload', 'balancer' => 'Session hosted on Load Balancer, after re-authentication', 'offloadedto' => 'Session hosted on offload server, after re-authentication', + 'particular' => 'Session hosted (after re-auth) on server:', ); return %ruletitles; } @@ -6053,7 +6060,7 @@ sub modify_login { if (!$privkey) { $chgtxt .= '
  • '.&mt('Private key deleted').'
  • '; } else { - $chgtxt .= '
  • '.&mt('Private key set to [_1]',$pubkey).'
  • '; + $chgtxt .= '
  • '.&mt('Private key set to [_1]',$privkey).'
  • '; } $chgtxt .= ''; $resulttext .= '
  • '.$chgtxt.'
  • '; @@ -9057,8 +9064,8 @@ sub process_captcha { if ($newsettings->{'captcha'} eq 'recaptcha') { $newpub = $env{'form.'.$container.'_recaptchapub'}; $newpriv = $env{'form.'.$container.'_recaptchapriv'}; - $newpub =~ s/\W//g; - $newpriv =~ s/\W//g; + $newpub =~ s/[^\w\-]//g; + $newpriv =~ s/[^\w\-]//g; $newsettings->{'recaptchakeys'} = { public => $newpub, private => $newpriv, @@ -10661,6 +10668,7 @@ sub modify_loadbalancing { my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom); my %servers = &Apache::lonnet::internet_dom_servers($dom); + my %libraryservers = &Apache::lonnet::get_servers($dom,'library'); my @sparestypes = ('primary','default'); my %typetitles = &sparestype_titles(); my $resulttext; @@ -10752,7 +10760,10 @@ sub modify_loadbalancing { $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type}; } if ($rule eq 'specific') { - $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type}; + my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type}; + if (exists($servers{$specifiedhost})) { + $rule = $specifiedhost; + } } $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule; if (ref($currrules{$balancer}) eq 'HASH') { @@ -10774,20 +10785,22 @@ sub modify_loadbalancing { \%defaultshash,$dom); if ($putresult eq 'ok') { if (keys(%changes) > 0) { + my %toupdate; if (ref($changes{'delete'}) eq 'ARRAY') { foreach my $balancer (sort(@{$changes{'delete'}})) { $resulttext .= '
  • '.&mt('Load Balancing discontinued for: [_1]',$balancer).'
  • '; - my $cachekey = &escape('loadbalancing').':'.&escape($dom); - &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]); + $toupdate{$balancer} = 1; } } if (ref($changes{'add'}) eq 'ARRAY') { foreach my $balancer (sort(@{$changes{'add'}})) { $resulttext .= '
  • '.&mt('Load Balancing enabled for: [_1]',$balancer); + $toupdate{$balancer} = 1; } } if (ref($changes{'curr'}) eq 'HASH') { foreach my $balancer (sort(keys(%{$changes{'curr'}}))) { + $toupdate{$balancer} = 1; if (ref($changes{'curr'}{$balancer}) eq 'HASH') { if ($changes{'curr'}{$balancer}{'targets'}) { my %offloadstr; @@ -10824,8 +10837,38 @@ sub modify_loadbalancing { if ($rule eq '') { $balancetext = $ruletitles{'default'}; } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') || - ($rule eq 'balancer') || ($rule eq 'offloadedto')) { - $balancetext = $ruletitles{$rule}; + ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) { + if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) { + foreach my $sparetype (@sparestypes) { + if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') { + map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}}); + } + } + foreach my $item (@{$alltypes}) { + next if ($item =~ /^_LC_ipchange/); + my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item}; + if ($hasrule eq 'homeserver') { + map { $toupdate{$_} = 1; } (keys(%libraryservers)); + } else { + unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) { + if ($servers{$hasrule}) { + $toupdate{$hasrule} = 1; + } + } + } + } + if (($rule eq 'balancer') || ($rule eq 'offloadedto')) { + $balancetext = $ruletitles{$rule}; + } else { + my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type}; + $balancetext = $ruletitles{'particular'}.' '.$receiver; + if ($receiver) { + $toupdate{$receiver}; + } + } + } else { + $balancetext = $ruletitles{$rule}; + } } else { $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type}); } @@ -10834,8 +10877,25 @@ sub modify_loadbalancing { } } } - my $cachekey = &escape('loadbalancing').':'.&escape($dom); - &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]); + if (keys(%toupdate)) { + my %thismachine; + my $updatedhere; + my $cachetime = 60*60*24; + map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids(); + foreach my $lonhost (keys(%toupdate)) { + if ($thismachine{$lonhost}) { + unless ($updatedhere) { + &Apache::lonnet::do_cache_new('loadbalancing',$dom, + $defaultshash{'loadbalancing'}, + $cachetime); + $updatedhere = 1; + } + } else { + my $cachekey = &escape('loadbalancing').':'.&escape($dom); + &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]); + } + } + } } } if ($resulttext ne '') {