version 1.144, 2011/07/29 14:25:36
|
version 1.154, 2011/08/17 11:16:59
|
Line 197 sub handler {
|
Line 197 sub handler {
|
if ( exists($env{'form.phase'}) ) { |
if ( exists($env{'form.phase'}) ) { |
$phase = $env{'form.phase'}; |
$phase = $env{'form.phase'}; |
} |
} |
|
my %servers = &Apache::lonnet::internet_dom_servers($dom); |
my %domconfig = |
my %domconfig = |
&Apache::lonnet::get_dom('configuration',['login','rolecolors', |
&Apache::lonnet::get_dom('configuration',['login','rolecolors', |
'quotas','autoenroll','autoupdate','autocreate', |
'quotas','autoenroll','autoupdate','autocreate', |
'directorysrch','usercreation','usermodification', |
'directorysrch','usercreation','usermodification', |
'contacts','defaults','scantron','coursecategories', |
'contacts','defaults','scantron','coursecategories', |
'serverstatuses','requestcourses','helpsettings', |
'serverstatuses','requestcourses','helpsettings', |
'coursedefaults','usersessions'],$dom); |
'coursedefaults','usersessions','loadbalancing'],$dom); |
my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll', |
my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll', |
'autoupdate','autocreate','directorysrch','contacts', |
'autoupdate','autocreate','directorysrch','contacts', |
'usercreation','usermodification','scantron', |
'usercreation','usermodification','scantron', |
'requestcourses','coursecategories','serverstatuses','helpsettings', |
'requestcourses','coursecategories','serverstatuses','helpsettings', |
'coursedefaults','usersessions'); |
'coursedefaults','usersessions'); |
|
if (keys(%servers) > 1) { |
|
push(@prefs_order,'loadbalancing'); |
|
} |
my %prefs = ( |
my %prefs = ( |
'rolecolors' => |
'rolecolors' => |
{ text => 'Default color schemes', |
{ text => 'Default color schemes', |
Line 352 sub handler {
|
Line 356 sub handler {
|
col2 => 'Value',}], |
col2 => 'Value',}], |
}, |
}, |
'usersessions' => |
'usersessions' => |
{text => 'User session hosting', |
{text => 'User session hosting/offloading', |
help => 'Domain_Configuration_User_Sessions', |
help => 'Domain_Configuration_User_Sessions', |
header => [{col1 => 'Hosting of users from other domains', |
header => [{col1 => 'Domain server', |
|
col2 => 'Servers to offload sessions to when busy'}, |
|
{col1 => 'Hosting of users from other domains', |
col2 => 'Rules'}, |
col2 => 'Rules'}, |
{col1 => "Hosting domain's own users elsewhere", |
{col1 => "Hosting domain's own users elsewhere", |
col2 => 'Rules'}], |
col2 => 'Rules'}], |
}, |
}, |
|
'loadbalancing' => |
|
{text => 'Dedicated Load Balancer', |
|
help => 'Domain_Configuration_Load_Balancing', |
|
header => [{col1 => 'Server', |
|
col2 => 'Default destinations', |
|
col3 => 'User affliation', |
|
col4 => 'Overrides'}, |
|
], |
|
}, |
); |
); |
my %servers = &dom_servers($dom); |
|
if (keys(%servers) > 1) { |
if (keys(%servers) > 1) { |
$prefs{'login'} = { text => 'Log-in page options', |
$prefs{'login'} = { text => 'Log-in page options', |
help => 'Domain_Configuration_Login_Page', |
help => 'Domain_Configuration_Login_Page', |
Line 379 sub handler {
|
Line 393 sub handler {
|
if ($phase eq 'process') { |
if ($phase eq 'process') { |
&Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles); |
&Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles); |
} elsif ($phase eq 'display') { |
} elsif ($phase eq 'display') { |
&Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname); |
my $js; |
|
if (keys(%servers) > 1) { |
|
my ($othertitle,$usertypes,$types) = |
|
&Apache::loncommon::sorted_inst_types($dom); |
|
$js = &lonbalance_targets_js($dom,$types,\%servers). |
|
&new_spares_js(). |
|
&common_domprefs_js(). |
|
&Apache::loncommon::javascript_array_indexof(); |
|
} |
|
&Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js); |
} else { |
} else { |
if (keys(%domconfig) == 0) { |
if (keys(%domconfig) == 0) { |
my $primarylibserv = &Apache::lonnet::domain($dom,'primary'); |
my $primarylibserv = &Apache::lonnet::domain($dom,'primary'); |
Line 463 sub process_changes {
|
Line 486 sub process_changes {
|
$output = &modify_coursedefaults($dom,%domconfig); |
$output = &modify_coursedefaults($dom,%domconfig); |
} elsif ($action eq 'usersessions') { |
} elsif ($action eq 'usersessions') { |
$output = &modify_usersessions($dom,%domconfig); |
$output = &modify_usersessions($dom,%domconfig); |
|
} elsif ($action eq 'loadbalancing') { |
|
$output = &modify_loadbalancing($dom,%domconfig); |
} |
} |
return $output; |
return $output; |
} |
} |
Line 488 sub print_config_box {
|
Line 513 sub print_config_box {
|
} |
} |
if ($numheaders > 1) { |
if ($numheaders > 1) { |
my $colspan = ''; |
my $colspan = ''; |
|
my $rightcolspan = ''; |
if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) { |
if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) { |
$colspan = ' colspan="2"'; |
$colspan = ' colspan="2"'; |
} |
} |
|
if ($action eq 'usersessions') { |
|
$rightcolspan = ' colspan="3"'; |
|
} |
$output .= ' |
$output .= ' |
<tr> |
<tr> |
<td> |
<td> |
<table class="LC_nested"> |
<table class="LC_nested"> |
<tr class="LC_info_row"> |
<tr class="LC_info_row"> |
<td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td> |
<td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td> |
<td class="LC_right_item">'.&mt($item->{'header'}->[0]->{'col2'}).'</td> |
<td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td> |
</tr>'; |
</tr>'; |
$rowtotal ++; |
$rowtotal ++; |
if ($action eq 'autoupdate') { |
if ($action eq 'autoupdate') { |
Line 583 sub print_config_box {
|
Line 612 sub print_config_box {
|
} elsif ($action eq 'helpsettings') { |
} elsif ($action eq 'helpsettings') { |
$output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal); |
$output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal); |
} elsif ($action eq 'usersessions') { |
} elsif ($action eq 'usersessions') { |
$output .= &print_usersessions('bottom',$dom,$settings,\$rowtotal); |
$output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).' |
|
</table> |
|
</td> |
|
</tr> |
|
<tr> |
|
<td> |
|
<table class="LC_nested"> |
|
<tr class="LC_info_row"> |
|
<td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td> |
|
<td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'. |
|
&print_usersessions('bottom',$dom,$settings,\$rowtotal); |
|
$rowtotal ++; |
} elsif ($action eq 'coursedefaults') { |
} elsif ($action eq 'coursedefaults') { |
$output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal); |
$output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal); |
} elsif ($action eq 'rolecolors') { |
} elsif ($action eq 'rolecolors') { |
Line 644 sub print_config_box {
|
Line 684 sub print_config_box {
|
} |
} |
$output .= '</td>'; |
$output .= '</td>'; |
if ($item->{'header'}->[0]->{'col3'}) { |
if ($item->{'header'}->[0]->{'col3'}) { |
$output .= '<td class="LC_right_item" valign="top">'. |
if (defined($item->{'header'}->[0]->{'col4'})) { |
&mt($item->{'header'}->[0]->{'col3'}); |
$output .= '<td class="LC_left_item" valign="top">'. |
|
&mt($item->{'header'}->[0]->{'col3'}); |
|
} else { |
|
$output .= '<td class="LC_right_item" valign="top">'. |
|
&mt($item->{'header'}->[0]->{'col3'}); |
|
} |
if ($action eq 'serverstatuses') { |
if ($action eq 'serverstatuses') { |
$output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)'; |
$output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)'; |
} |
} |
$output .= '</td>'; |
$output .= '</td>'; |
} |
} |
|
if ($item->{'header'}->[0]->{'col4'}) { |
|
$output .= '<td class="LC_right_item" valign="top">'. |
|
&mt($item->{'header'}->[0]->{'col4'}); |
|
} |
$output .= '</tr>'; |
$output .= '</tr>'; |
$rowtotal ++; |
$rowtotal ++; |
if ($action eq 'login') { |
if ($action eq 'login') { |
Line 674 sub print_config_box {
|
Line 723 sub print_config_box {
|
$output .= &print_serverstatuses($dom,$settings,\$rowtotal); |
$output .= &print_serverstatuses($dom,$settings,\$rowtotal); |
} elsif ($action eq 'helpsettings') { |
} elsif ($action eq 'helpsettings') { |
$output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal); |
$output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal); |
|
} elsif ($action eq 'loadbalancing') { |
|
$output .= &print_loadbalancing($dom,$settings,\$rowtotal); |
} |
} |
} |
} |
$output .= ' |
$output .= ' |
Line 690 sub print_login {
|
Line 741 sub print_login {
|
my %choices = &login_choices(); |
my %choices = &login_choices(); |
|
|
if ($position eq 'top') { |
if ($position eq 'top') { |
my %servers = &dom_servers($dom); |
my %servers = &Apache::lonnet::internet_dom_servers($dom); |
my $choice = $choices{'disallowlogin'}; |
my $choice = $choices{'disallowlogin'}; |
$css_class = ' class="LC_odd_row"'; |
$css_class = ' class="LC_odd_row"'; |
$datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'. |
$datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'. |
Line 2287 sub print_usersessions {
|
Line 2338 sub print_usersessions {
|
my ($css_class,$datatable,%checked,%choices); |
my ($css_class,$datatable,%checked,%choices); |
my (%by_ip,%by_location,@intdoms); |
my (%by_ip,%by_location,@intdoms); |
&build_location_hashes(\@intdoms,\%by_ip,\%by_location); |
&build_location_hashes(\@intdoms,\%by_ip,\%by_location); |
if (keys(%by_location) == 0) { |
|
if ($position eq 'top') { |
my @alldoms = &Apache::lonnet::all_domains(); |
$datatable .= '<tr'.$css_class.'><td colspan="2">'. |
my %serverhomes = %Apache::lonnet::serverhomeIDs; |
&mt('Nothing to set here, as the cluster to which this domain belongs only contains this institution.'); |
my %servers = &Apache::lonnet::internet_dom_servers($dom); |
} |
my %altids = &id_for_thisdom(%servers); |
} |
|
my %lt = &usersession_titles(); |
|
my $itemcount = 1; |
my $itemcount = 1; |
my $numinrow = 5; |
|
my $prefix; |
|
my @types; |
|
if ($position eq 'top') { |
if ($position eq 'top') { |
$prefix = 'hosted'; |
if (keys(%serverhomes) > 1) { |
@types = ('excludedomain','includedomain'); |
my %spareid = ¤t_offloads_to($dom,$settings,\%servers); |
|
$datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$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.'); |
|
} |
} else { |
} else { |
$prefix = 'remote'; |
if (keys(%by_location) == 0) { |
@types = ('version','excludedomain','includedomain'); |
$datatable .= '<tr'.$css_class.'><td colspan="2">'. |
} |
&mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.'); |
my (%current,%checkedon,%checkedoff); |
} else { |
my @lcversions = &Apache::lonnet::all_loncaparevs(); |
my %lt = &usersession_titles(); |
my @locations = sort(keys(%by_location)); |
my $numinrow = 5; |
foreach my $type (@types) { |
my $prefix; |
$checkedon{$type} = ''; |
my @types; |
$checkedoff{$type} = ' checked="checked"'; |
if ($position eq 'bottom') { |
} |
$prefix = 'remote'; |
if (ref($settings) eq 'HASH') { |
@types = ('version','excludedomain','includedomain'); |
if (ref($settings->{$prefix}) eq 'HASH') { |
} else { |
foreach my $key (keys(%{$settings->{$prefix}})) { |
$prefix = 'hosted'; |
$current{$key} = $settings->{$prefix}{$key}; |
@types = ('excludedomain','includedomain'); |
if ($key eq 'version') { |
|
if ($current{$key} ne '') { |
|
$checkedon{$key} = ' checked="checked"'; |
|
$checkedoff{$key} = ''; |
|
} |
|
} elsif (ref($current{$key}) eq 'ARRAY') { |
|
$checkedon{$key} = ' checked="checked"'; |
|
$checkedoff{$key} = ''; |
|
} |
|
} |
} |
} |
my (%current,%checkedon,%checkedoff); |
} |
my @lcversions = &Apache::lonnet::all_loncaparevs(); |
foreach my $type (@types) { |
my @locations = sort(keys(%by_location)); |
next if ($type ne 'version' && !@locations); |
foreach my $type (@types) { |
$css_class = $itemcount%2 ? ' class="LC_odd_row"' : ''; |
$checkedon{$type} = ''; |
$datatable .= '<tr'.$css_class.'> |
$checkedoff{$type} = ' checked="checked"'; |
<td><span class="LC_nobreak">'.$lt{$type}.'</span><br /> |
} |
<span class="LC_nobreak"> |
if (ref($settings) eq 'HASH') { |
<label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label> |
if (ref($settings->{$prefix}) eq 'HASH') { |
<label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>'; |
foreach my $key (keys(%{$settings->{$prefix}})) { |
if ($type eq 'version') { |
$current{$key} = $settings->{$prefix}{$key}; |
my $selector = '<select name="'.$prefix.'_version">'; |
if ($key eq 'version') { |
foreach my $version (@lcversions) { |
if ($current{$key} ne '') { |
my $selected = ''; |
$checkedon{$key} = ' checked="checked"'; |
if ($current{'version'} eq $version) { |
$checkedoff{$key} = ''; |
$selected = ' selected="selected"'; |
} |
|
} elsif (ref($current{$key}) eq 'ARRAY') { |
|
$checkedon{$key} = ' checked="checked"'; |
|
$checkedoff{$key} = ''; |
|
} |
|
} |
} |
} |
$selector .= ' <option value="'.$version.'"'. |
|
$selected.'>'.$version.'</option>'; |
|
} |
} |
$selector .= '</select> '; |
foreach my $type (@types) { |
$datatable .= &mt('remote server must be version: [_1] or later',$selector); |
next if ($type ne 'version' && !@locations); |
} else { |
$css_class = $itemcount%2 ? ' class="LC_odd_row"' : ''; |
$datatable.= '<div><input type="button" value="'.&mt('check all').'" '. |
$datatable .= '<tr'.$css_class.'> |
'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'. |
<td><span class="LC_nobreak">'.$lt{$type}.'</span><br /> |
' />'.(' 'x2). |
<span class="LC_nobreak"> |
'<input type="button" value="'.&mt('uncheck all').'" '. |
<label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label> |
'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'. |
<label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>'; |
"\n". |
if ($type eq 'version') { |
'</div><div><table>'; |
my $selector = '<select name="'.$prefix.'_version">'; |
my $rem; |
foreach my $version (@lcversions) { |
for (my $i=0; $i<@locations; $i++) { |
my $selected = ''; |
my ($showloc,$value,$checkedtype); |
if ($current{'version'} eq $version) { |
if (ref($by_location{$locations[$i]}) eq 'ARRAY') { |
$selected = ' selected="selected"'; |
my $ip = $by_location{$locations[$i]}->[0]; |
} |
if (ref($by_ip{$ip}) eq 'ARRAY') { |
$selector .= ' <option value="'.$version.'"'. |
$value = join(':',@{$by_ip{$ip}}); |
$selected.'>'.$version.'</option>'; |
$showloc = join(', ',@{$by_ip{$ip}}); |
} |
if (ref($current{$type}) eq 'ARRAY') { |
$selector .= '</select> '; |
foreach my $loc (@{$by_ip{$ip}}) { |
$datatable .= &mt('remote server must be version: [_1] or later',$selector); |
if (grep(/^\Q$loc\E$/,@{$current{$type}})) { |
} else { |
$checkedtype = ' checked="checked"'; |
$datatable.= '<div><input type="button" value="'.&mt('check all').'" '. |
last; |
'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'. |
|
' />'.(' 'x2). |
|
'<input type="button" value="'.&mt('uncheck all').'" '. |
|
'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'. |
|
"\n". |
|
'</div><div><table>'; |
|
my $rem; |
|
for (my $i=0; $i<@locations; $i++) { |
|
my ($showloc,$value,$checkedtype); |
|
if (ref($by_location{$locations[$i]}) eq 'ARRAY') { |
|
my $ip = $by_location{$locations[$i]}->[0]; |
|
if (ref($by_ip{$ip}) eq 'ARRAY') { |
|
$value = join(':',@{$by_ip{$ip}}); |
|
$showloc = join(', ',@{$by_ip{$ip}}); |
|
if (ref($current{$type}) eq 'ARRAY') { |
|
foreach my $loc (@{$by_ip{$ip}}) { |
|
if (grep(/^\Q$loc\E$/,@{$current{$type}})) { |
|
$checkedtype = ' checked="checked"'; |
|
last; |
|
} |
|
} |
} |
} |
} |
} |
} |
} |
|
$rem = $i%($numinrow); |
|
if ($rem == 0) { |
|
if ($i > 0) { |
|
$datatable .= '</tr>'; |
|
} |
|
$datatable .= '<tr>'; |
|
} |
|
$datatable .= '<td class="LC_left_item">'. |
|
'<span class="LC_nobreak"><label>'. |
|
'<input type="checkbox" name="'.$prefix.'_'.$type. |
|
'" value="'.$value.'"'.$checkedtype.' />'.$showloc. |
|
'</label></span></td>'; |
} |
} |
} |
$rem = @locations%($numinrow); |
$rem = $i%($numinrow); |
my $colsleft = $numinrow - $rem; |
if ($rem == 0) { |
if ($colsleft > 1 ) { |
if ($i > 0) { |
$datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'. |
$datatable .= '</tr>'; |
' </td>'; |
|
} elsif ($colsleft == 1) { |
|
$datatable .= '<td class="LC_left_item"> </td>'; |
} |
} |
$datatable .= '<tr>'; |
$datatable .= '</tr></table>'; |
} |
} |
$datatable .= '<td class="LC_left_item">'. |
$datatable .= '</td></tr>'; |
'<span class="LC_nobreak"><label>'. |
$itemcount ++; |
'<input type="checkbox" name="'.$prefix.'_'.$type. |
|
'" value="'.$value.'"'.$checkedtype.' />'.$showloc. |
|
'</label></span></td>'; |
|
} |
} |
$rem = @locations%($numinrow); |
|
my $colsleft = $numinrow - $rem; |
|
if ($colsleft > 1 ) { |
|
$datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'. |
|
' </td>'; |
|
} elsif ($colsleft == 1) { |
|
$datatable .= '<td class="LC_left_item"> </td>'; |
|
} |
|
$datatable .= '</tr></table>'; |
|
} |
} |
$datatable .= '</td></tr>'; |
|
$itemcount ++; |
|
} |
} |
$$rowtotal += $itemcount; |
$$rowtotal += $itemcount; |
return $datatable; |
return $datatable; |
Line 2452 sub build_location_hashes {
|
Line 2517 sub build_location_hashes {
|
return; |
return; |
} |
} |
|
|
|
sub current_offloads_to { |
|
my ($dom,$settings,$servers) = @_; |
|
my (%spareid,%otherdomconfigs); |
|
if (ref($servers) eq 'HASH') { |
|
foreach my $lonhost (sort(keys(%{$servers}))) { |
|
my $gotspares; |
|
if (ref($settings) eq 'HASH') { |
|
if (ref($settings->{'spares'}) eq 'HASH') { |
|
if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') { |
|
$spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'}; |
|
$spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'}; |
|
$gotspares = 1; |
|
} |
|
} |
|
} |
|
unless ($gotspares) { |
|
my $gotspares; |
|
my $serverhomeID = |
|
&Apache::lonnet::get_server_homeID($servers->{$lonhost}); |
|
my $serverhomedom = |
|
&Apache::lonnet::host_domain($serverhomeID); |
|
if ($serverhomedom ne $dom) { |
|
if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) { |
|
if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') { |
|
if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') { |
|
$spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'}; |
|
$spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'}; |
|
$gotspares = 1; |
|
} |
|
} |
|
} else { |
|
$otherdomconfigs{$serverhomedom} = |
|
&Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom); |
|
if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') { |
|
if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') { |
|
if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') { |
|
if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') { |
|
$spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'}; |
|
$spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'}; |
|
$gotspares = 1; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
unless ($gotspares) { |
|
if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) { |
|
$spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'}; |
|
$spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'}; |
|
} else { |
|
my $server_hostname = &Apache::lonnet::hostname($lonhost); |
|
my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname); |
|
if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) { |
|
$spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'}; |
|
$spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'}; |
|
} else { |
|
my %what = ( |
|
spareid => 1, |
|
); |
|
my ($result,$returnhash) = |
|
&Apache::lonnet::get_remote_globals($lonhost,\%what); |
|
if ($result eq 'ok') { |
|
if (ref($returnhash) eq 'HASH') { |
|
if (ref($returnhash->{'spareid'}) eq 'HASH') { |
|
$spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'}; |
|
$spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'}; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
return %spareid; |
|
} |
|
|
|
sub spares_row { |
|
my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_; |
|
my $css_class; |
|
my $numinrow = 4; |
|
my $itemcount = 1; |
|
my $datatable; |
|
my %typetitles = &sparestype_titles(); |
|
if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) { |
|
foreach my $server (sort(keys(%{$servers}))) { |
|
my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server}); |
|
my ($othercontrol,$serverdom); |
|
if ($serverhome ne $server) { |
|
$serverdom = &Apache::lonnet::host_domain($serverhome); |
|
$othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>'); |
|
} else { |
|
$serverdom = &Apache::lonnet::host_domain($server); |
|
if ($serverdom ne $dom) { |
|
$othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>'); |
|
} |
|
} |
|
next unless (ref($spareid->{$server}) eq 'HASH'); |
|
$css_class = $itemcount%2 ? ' class="LC_odd_row"' : ''; |
|
$datatable .= '<tr'.$css_class.'> |
|
<td rowspan="2"> |
|
<span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n"; |
|
my (%current,%canselect); |
|
my @choices = |
|
&possible_newspares($server,$spareid->{$server},$serverhomes,$altids); |
|
foreach my $type ('primary','default') { |
|
if (ref($spareid->{$server}) eq 'HASH') { |
|
if (ref($spareid->{$server}{$type}) eq 'ARRAY') { |
|
my @spares = @{$spareid->{$server}{$type}}; |
|
if (@spares > 0) { |
|
if ($othercontrol) { |
|
$current{$type} = join(', ',@spares); |
|
} else { |
|
$current{$type} .= '<table>'; |
|
my $numspares = scalar(@spares); |
|
for (my $i=0; $i<@spares; $i++) { |
|
my $rem = $i%($numinrow); |
|
if ($rem == 0) { |
|
if ($i > 0) { |
|
$current{$type} .= '</tr>'; |
|
} |
|
$current{$type} .= '<tr>'; |
|
} |
|
$current{$type} .= '<td><label><input type="checkbox" name="spare_'.$type.'_'.$server.'" id="spare_'.$type.'_'.$server.'_'.$i.'" checked="checked" value="'.$spareid->{$server}{$type}[$i].'" onclick="updateNewSpares(this.form,'."'$server'".');" /> '. |
|
$spareid->{$server}{$type}[$i]. |
|
'</label></td>'."\n"; |
|
} |
|
my $rem = @spares%($numinrow); |
|
my $colsleft = $numinrow - $rem; |
|
if ($colsleft > 1 ) { |
|
$current{$type} .= '<td colspan="'.$colsleft. |
|
'" class="LC_left_item">'. |
|
' </td>'; |
|
} elsif ($colsleft == 1) { |
|
$current{$type} .= '<td class="LC_left_item"> </td>'."\n"; |
|
} |
|
$current{$type} .= '</tr></table>'; |
|
} |
|
} |
|
} |
|
if ($current{$type} eq '') { |
|
$current{$type} = &mt('None specified'); |
|
} |
|
if ($othercontrol) { |
|
if ($type eq 'primary') { |
|
$canselect{$type} = $othercontrol; |
|
} |
|
} else { |
|
$canselect{$type} = |
|
&mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '. |
|
'<select name="newspare_'.$type.'_'.$server.'" '. |
|
'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n". |
|
'<option value="" selected ="selected">'.&mt('Select').'</option>'."\n"; |
|
if (@choices > 0) { |
|
foreach my $lonhost (@choices) { |
|
$canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n"; |
|
} |
|
} |
|
$canselect{$type} .= '</select>'."\n"; |
|
} |
|
} else { |
|
$current{$type} = &mt('Could not be determined'); |
|
if ($type eq 'primary') { |
|
$canselect{$type} = $othercontrol; |
|
} |
|
} |
|
if ($type eq 'default') { |
|
$datatable .= '<tr'.$css_class.'>'; |
|
} |
|
$datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n". |
|
'<td>'.$current{$type}.'</td>'."\n". |
|
'<td>'.$canselect{$type}.'</td></tr>'."\n"; |
|
} |
|
$itemcount ++; |
|
} |
|
} |
|
$$rowtotal += $itemcount; |
|
return $datatable; |
|
} |
|
|
|
sub possible_newspares { |
|
my ($server,$currspares,$serverhomes,$altids) = @_; |
|
my $serverhostname = &Apache::lonnet::hostname($server); |
|
my %excluded; |
|
if ($serverhostname ne '') { |
|
%excluded = ( |
|
$serverhostname => 1, |
|
); |
|
} |
|
if (ref($currspares) eq 'HASH') { |
|
foreach my $type (keys(%{$currspares})) { |
|
if (ref($currspares->{$type}) eq 'ARRAY') { |
|
if (@{$currspares->{$type}} > 0) { |
|
foreach my $curr (@{$currspares->{$type}}) { |
|
my $hostname = &Apache::lonnet::hostname($curr); |
|
$excluded{$hostname} = 1; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
my @choices; |
|
if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) { |
|
if (keys(%{$serverhomes}) > 1) { |
|
foreach my $name (sort(keys(%{$serverhomes}))) { |
|
unless ($excluded{$name}) { |
|
if (exists($altids->{$serverhomes->{$name}})) { |
|
push(@choices,$altids->{$serverhomes->{$name}}); |
|
} else { |
|
push(@choices,$serverhomes->{$name}); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
return sort(@choices); |
|
} |
|
|
|
sub print_loadbalancing { |
|
my ($dom,$settings,$rowtotal) = @_; |
|
my $primary_id = &Apache::lonnet::domain($dom,'primary'); |
|
my $intdom = &Apache::lonnet::internet_dom($primary_id); |
|
my $numinrow = 1; |
|
my $datatable; |
|
my %servers = &Apache::lonnet::internet_dom_servers($dom); |
|
my ($currbalancer,$currtargets,$currrules); |
|
if (keys(%servers) > 1) { |
|
if (ref($settings) eq 'HASH') { |
|
$currbalancer = $settings->{'lonhost'}; |
|
$currtargets = $settings->{'targets'}; |
|
$currrules = $settings->{'rules'}; |
|
} else { |
|
($currbalancer,$currtargets) = |
|
&Apache::lonnet::get_lonbalancer_config(\%servers); |
|
} |
|
} else { |
|
return; |
|
} |
|
my ($othertitle,$usertypes,$types) = |
|
&Apache::loncommon::sorted_inst_types($dom); |
|
my $rownum = 6; |
|
if (ref($types) eq 'ARRAY') { |
|
$rownum += scalar(@{$types}); |
|
} |
|
my $css_class = ' class="LC_odd_row"'; |
|
my $targets_div_style = 'display: none'; |
|
my $disabled_div_style = 'display: block'; |
|
my $homedom_div_style = 'display: none'; |
|
$datatable = '<tr'.$css_class.'>'. |
|
'<td rowspan="'.$rownum.'" valign="top">'. |
|
'<p><select name="loadbalancing_lonhost" onchange="toggleTargets();">'."\n". |
|
'<option value=""'; |
|
if (($currbalancer eq '') || (!grep(/^\Q$currbalancer\E$/,keys(%servers)))) { |
|
$datatable .= ' selected="selected"'; |
|
} else { |
|
$targets_div_style = 'display: block'; |
|
$disabled_div_style = 'display: none'; |
|
if ($dom eq &Apache::lonnet::host_domain($currbalancer)) { |
|
$homedom_div_style = 'display: block'; |
|
} |
|
} |
|
$datatable .= '>'.&mt('None').'</option>'."\n"; |
|
foreach my $lonhost (sort(keys(%servers))) { |
|
my $selected; |
|
if ($lonhost eq $currbalancer) { |
|
$selected .= ' selected="selected"'; |
|
} |
|
$datatable .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>'."\n"; |
|
} |
|
$datatable .= '</select></p></td><td rowspan="'.$rownum.'" valign="top">'. |
|
'<div id="loadbalancing_disabled" style="'.$disabled_div_style.'">'.&mt('No dedicated Load Balancer').'</div>'."\n". |
|
'<div id="loadbalancing_targets" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />'; |
|
my ($numspares,@spares) = &count_servers($currbalancer,%servers); |
|
my @sparestypes = ('primary','default'); |
|
my %typetitles = &sparestype_titles(); |
|
foreach my $sparetype (@sparestypes) { |
|
my $targettable; |
|
for (my $i=0; $i<$numspares; $i++) { |
|
my $checked; |
|
if (ref($currtargets) eq 'HASH') { |
|
if (ref($currtargets->{$sparetype}) eq 'ARRAY') { |
|
if (grep(/^\Q$spares[$i]\E$/,@{$currtargets->{$sparetype}})) { |
|
$checked = ' checked="checked"'; |
|
} |
|
} |
|
} |
|
my $chkboxval; |
|
if (($currbalancer ne '') && (grep((/^\Q$currbalancer\E$/,keys(%servers))))) { |
|
$chkboxval = $spares[$i]; |
|
} |
|
$targettable .= '<td><label><input type="checkbox" name="loadbalancing_target_'.$sparetype.'"'. |
|
$checked.' value="'.$chkboxval.'" id="loadbalancing_target_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$sparetype'".');" /><span id="loadbalancing_targettxt_'.$sparetype.'_'.$i.'"> '.$chkboxval. |
|
'</span></label></td>'; |
|
my $rem = $i%($numinrow); |
|
if ($rem == 0) { |
|
if ($i > 0) { |
|
$targettable .= '</tr>'; |
|
} |
|
$targettable .= '<tr>'; |
|
} |
|
} |
|
if ($targettable ne '') { |
|
my $rem = $numspares%($numinrow); |
|
my $colsleft = $numinrow - $rem; |
|
if ($colsleft > 1 ) { |
|
$targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'. |
|
' </td>'; |
|
} elsif ($colsleft == 1) { |
|
$targettable .= '<td class="LC_left_item"> </td>'; |
|
} |
|
$datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'. |
|
'<table><tr>'.$targettable.'</table><br />'; |
|
} |
|
} |
|
$datatable .= '</div></td></tr>'. |
|
&loadbalancing_rules($dom,$intdom,$currrules,$othertitle, |
|
$usertypes,$types,\%servers,$currbalancer, |
|
$targets_div_style,$homedom_div_style,$css_class); |
|
$$rowtotal += $rownum; |
|
return $datatable; |
|
} |
|
|
|
sub loadbalancing_rules { |
|
my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers, |
|
$currbalancer,$targets_div_style,$homedom_div_style,$css_class) = @_; |
|
my $output; |
|
my ($alltypes,$othertypes,$titles) = |
|
&loadbalancing_titles($dom,$intdom,$usertypes,$types); |
|
if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) { |
|
foreach my $type (@{$alltypes}) { |
|
my $current; |
|
if (ref($currrules) eq 'HASH') { |
|
$current = $currrules->{$type}; |
|
} |
|
if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) { |
|
if ($dom ne &Apache::lonnet::host_domain($currbalancer)) { |
|
$current = ''; |
|
} |
|
} |
|
$output .= &loadbalance_rule_row($type,$titles->{$type},$current, |
|
$servers,$currbalancer,$dom, |
|
$targets_div_style,$homedom_div_style,$css_class); |
|
} |
|
} |
|
return $output; |
|
} |
|
|
|
sub loadbalancing_titles { |
|
my ($dom,$intdom,$usertypes,$types) = @_; |
|
my %othertypes = ( |
|
'_LC_adv' => &mt('Advanced users from [_1]',$dom), |
|
'_LC_author' => &mt('Users from [_1] with author role',$dom), |
|
'_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom), |
|
'_LC_external' => &mt('Users not from [_1]',$intdom), |
|
); |
|
my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external'); |
|
if (ref($types) eq 'ARRAY') { |
|
unshift(@alltypes,@{$types},'default'); |
|
} |
|
my %titles; |
|
foreach my $type (@alltypes) { |
|
if ($type =~ /^_LC_/) { |
|
$titles{$type} = $othertypes{$type}; |
|
} elsif ($type eq 'default') { |
|
$titles{$type} = &mt('All users from [_1]',$dom); |
|
if (ref($types) eq 'ARRAY') { |
|
if (@{$types} > 0) { |
|
$titles{$type} = &mt('Other users from [_1]',$dom); |
|
} |
|
} |
|
} elsif (ref($usertypes) eq 'HASH') { |
|
$titles{$type} = $usertypes->{$type}; |
|
} |
|
} |
|
return (\@alltypes,\%othertypes,\%titles); |
|
} |
|
|
|
sub loadbalance_rule_row { |
|
my ($type,$title,$current,$servers,$currbalancer,$dom,$targets_div_style, |
|
$homedom_div_style,$css_class) = @_; |
|
my @rulenames = ('default','homeserver'); |
|
my %ruletitles = &offloadtype_text(); |
|
if ($type eq '_LC_external') { |
|
push(@rulenames,'externalbalancer'); |
|
} else { |
|
push(@rulenames,'specific'); |
|
} |
|
my $style = $targets_div_style; |
|
if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) { |
|
$style = $homedom_div_style; |
|
} |
|
my $output = |
|
'<tr'.$css_class.'><td valign="top"><div id="balanceruletitle_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n". |
|
'<td><div id="balancerule_'.$type.'" style="'.$style.'">'."\n"; |
|
for (my $i=0; $i<@rulenames; $i++) { |
|
my $rule = $rulenames[$i]; |
|
my ($checked,$extra); |
|
if ($rulenames[$i] eq 'default') { |
|
$rule = ''; |
|
} |
|
if ($rulenames[$i] eq 'specific') { |
|
if (ref($servers) eq 'HASH') { |
|
my $default; |
|
if (($current ne '') && (exists($servers->{$current}))) { |
|
$checked = ' checked="checked"'; |
|
} |
|
unless ($checked) { |
|
$default = ' selected="selected"'; |
|
} |
|
$extra = ': <select name="loadbalancing_singleserver_'.$type. |
|
'" id="loadbalancing_singleserver_'.$type. |
|
'" onchange="singleServerToggle('."'$type'".')">'."\n". |
|
'<option value=""'.$default.'></option>'."\n"; |
|
foreach my $lonhost (sort(keys(%{$servers}))) { |
|
next if ($lonhost eq $currbalancer); |
|
my $selected; |
|
if ($lonhost eq $current) { |
|
$selected = ' selected="selected"'; |
|
} |
|
$extra .= '<option value="'.$lonhost.'"'.$selected.'>'.$lonhost.'</option>'; |
|
} |
|
$extra .= '</select>'; |
|
} |
|
} elsif ($rule eq $current) { |
|
$checked = ' checked="checked"'; |
|
} |
|
$output .= '<span class="LC_nobreak"><label>'. |
|
'<input type="radio" name="loadbalancing_rules_'.$type. |
|
'" id="loadbalancing_rules_'.$type.'_'.$i.'" value="'. |
|
$rule.'" onclick="balanceruleChange('."this.form,'$type'". |
|
')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}. |
|
'</label>'.$extra.'</span><br />'."\n"; |
|
} |
|
$output .= '</div></td></tr>'."\n"; |
|
return $output; |
|
} |
|
|
|
sub offloadtype_text { |
|
my %ruletitles = &Apache::lonlocal::texthash ( |
|
'default' => 'Offloads to default destinations', |
|
'homeserver' => "Offloads to user's home server", |
|
'externalbalancer' => "Offloads to Load Balancer in user's domain", |
|
'specific' => 'Offloads to specific server', |
|
); |
|
return %ruletitles; |
|
} |
|
|
|
sub sparestype_titles { |
|
my %typestitles = &Apache::lonlocal::texthash ( |
|
'primary' => 'primary', |
|
'default' => 'default', |
|
); |
|
return %typestitles; |
|
} |
|
|
sub contact_titles { |
sub contact_titles { |
my %titles = &Apache::lonlocal::texthash ( |
my %titles = &Apache::lonlocal::texthash ( |
'supportemail' => 'Support E-mail address', |
'supportemail' => 'Support E-mail address', |
Line 3810 sub modify_login {
|
Line 4332 sub modify_login {
|
\%loginhash); |
\%loginhash); |
} |
} |
|
|
my %servers = &dom_servers($dom); |
my %servers = &Apache::lonnet::internet_dom_servers($dom); |
my @loginvia_attribs = ('serverpath','custompath','exempt'); |
my @loginvia_attribs = ('serverpath','custompath','exempt'); |
if (keys(%servers) > 1) { |
if (keys(%servers) > 1) { |
foreach my $lonhost (keys(%servers)) { |
foreach my $lonhost (keys(%servers)) { |
Line 6766 sub modify_coursedefaults {
|
Line 7288 sub modify_coursedefaults {
|
|
|
sub modify_usersessions { |
sub modify_usersessions { |
my ($dom,%domconfig) = @_; |
my ($dom,%domconfig) = @_; |
my @types = ('version','excludedomain','includedomain'); |
my @hostingtypes = ('version','excludedomain','includedomain'); |
my @prefixes = ('remote','hosted'); |
my @offloadtypes = ('primary','default'); |
|
my %types = ( |
|
remote => \@hostingtypes, |
|
hosted => \@hostingtypes, |
|
spares => \@offloadtypes, |
|
); |
|
my @prefixes = ('remote','hosted','spares'); |
my @lcversions = &Apache::lonnet::all_loncaparevs(); |
my @lcversions = &Apache::lonnet::all_loncaparevs(); |
my (%by_ip,%by_location,@intdoms); |
my (%by_ip,%by_location,@intdoms); |
&build_location_hashes(\@intdoms,\%by_ip,\%by_location); |
&build_location_hashes(\@intdoms,\%by_ip,\%by_location); |
Line 6780 sub modify_usersessions {
|
Line 7308 sub modify_usersessions {
|
my $resulttext; |
my $resulttext; |
my %iphost = &Apache::lonnet::get_iphost(); |
my %iphost = &Apache::lonnet::get_iphost(); |
foreach my $prefix (@prefixes) { |
foreach my $prefix (@prefixes) { |
foreach my $type (@types) { |
next if ($prefix eq 'spares'); |
|
foreach my $type (@{$types{$prefix}}) { |
my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'}; |
my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'}; |
if ($type eq 'version') { |
if ($type eq 'version') { |
my $value = $env{'form.'.$prefix.'_'.$type}; |
my $value = $env{'form.'.$prefix.'_'.$type}; |
Line 6872 sub modify_usersessions {
|
Line 7401 sub modify_usersessions {
|
} |
} |
} |
} |
} |
} |
if (keys(%changes) > 0) { |
|
|
my @alldoms = &Apache::lonnet::all_domains(); |
|
my %servers = &Apache::lonnet::internet_dom_servers($dom); |
|
my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers); |
|
my $savespares; |
|
|
|
foreach my $lonhost (sort(keys(%servers))) { |
|
my $serverhomeID = |
|
&Apache::lonnet::get_server_homeID($servers{$lonhost}); |
|
my $serverhostname = &Apache::lonnet::hostname($lonhost); |
|
$defaultshash{'usersessions'}{'spares'}{$lonhost} = {}; |
|
my %spareschg; |
|
foreach my $type (@{$types{'spares'}}) { |
|
my @okspares; |
|
my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost); |
|
foreach my $server (@checked) { |
|
if (&Apache::lonnet::hostname($server) ne '') { |
|
unless (&Apache::lonnet::hostname($server) eq $serverhostname) { |
|
unless (grep(/^\Q$server\E$/,@okspares)) { |
|
push(@okspares,$server); |
|
} |
|
} |
|
} |
|
} |
|
my $new = $env{'form.newspare_'.$type.'_'.$lonhost}; |
|
my $newspare; |
|
if (($new ne '') && (&Apache::lonnet::hostname($new))) { |
|
unless (&Apache::lonnet::hostname($new) eq $serverhostname) { |
|
$newspare = $new; |
|
} |
|
} |
|
my @spares; |
|
if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) { |
|
@spares = sort(@okspares,$newspare); |
|
} else { |
|
@spares = sort(@okspares); |
|
} |
|
$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares; |
|
if (ref($spareid{$lonhost}) eq 'HASH') { |
|
if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') { |
|
my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares); |
|
if (@diffs > 0) { |
|
$spareschg{$type} = 1; |
|
} |
|
} |
|
} |
|
} |
|
if (keys(%spareschg) > 0) { |
|
$changes{'spares'}{$lonhost} = \%spareschg; |
|
} |
|
} |
|
|
|
if (ref($domconfig{'usersessions'}) eq 'HASH') { |
|
if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') { |
|
if (ref($changes{'spares'}) eq 'HASH') { |
|
if (keys(%{$changes{'spares'}}) > 0) { |
|
$savespares = 1; |
|
} |
|
} |
|
} else { |
|
$savespares = 1; |
|
} |
|
} |
|
|
|
my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.'); |
|
if ((keys(%changes) > 0) || ($savespares)) { |
my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash, |
my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash, |
$dom); |
$dom); |
if ($putresult eq 'ok') { |
if ($putresult eq 'ok') { |
Line 6886 sub modify_usersessions {
|
Line 7480 sub modify_usersessions {
|
} |
} |
my $cachetime = 24*60*60; |
my $cachetime = 24*60*60; |
&Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime); |
&Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime); |
my %lt = &usersession_titles(); |
if (keys(%changes) > 0) { |
$resulttext = &mt('Changes made:').'<ul>'; |
my %lt = &usersession_titles(); |
foreach my $prefix (@prefixes) { |
$resulttext = &mt('Changes made:').'<ul>'; |
if (ref($changes{$prefix}) eq 'HASH') { |
foreach my $prefix (@prefixes) { |
$resulttext .= '<li>'.$lt{$prefix}.'<ul>'; |
if (ref($changes{$prefix}) eq 'HASH') { |
foreach my $type (@types) { |
$resulttext .= '<li>'.$lt{$prefix}.'<ul>'; |
if (defined($changes{$prefix}{$type})) { |
if ($prefix eq 'spares') { |
my $newvalue; |
if (ref($changes{$prefix}) eq 'HASH') { |
if (ref($defaultshash{'usersessions'}) eq 'HASH') { |
foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) { |
if (ref($defaultshash{'usersessions'}{$prefix})) { |
$resulttext .= '<li><b>'.$lonhost.'</b> '; |
if ($type eq 'version') { |
my $lonhostdom = &Apache::lonnet::host_domain($lonhost); |
$newvalue = $defaultshash{'usersessions'}{$prefix}{$type}; |
&Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom); |
} elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') { |
if (ref($changes{$prefix}{$lonhost}) eq 'HASH') { |
if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) { |
foreach my $type (@{$types{$prefix}}) { |
$newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}}); |
if ($changes{$prefix}{$lonhost}{$type}) { |
|
my $offloadto = &mt('None'); |
|
if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') { |
|
if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) { |
|
$offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}}); |
|
} |
|
} |
|
$resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3); |
|
} |
} |
} |
} |
} |
|
$resulttext .= '</li>'; |
} |
} |
} |
} |
if ($newvalue eq '') { |
} else { |
if ($type eq 'version') { |
foreach my $type (@{$types{$prefix}}) { |
$resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>'; |
if (defined($changes{$prefix}{$type})) { |
} else { |
my $newvalue; |
$resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>'; |
if (ref($defaultshash{'usersessions'}) eq 'HASH') { |
|
if (ref($defaultshash{'usersessions'}{$prefix})) { |
|
if ($type eq 'version') { |
|
$newvalue = $defaultshash{'usersessions'}{$prefix}{$type}; |
|
} elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') { |
|
if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) { |
|
$newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}}); |
|
} |
|
} |
|
} |
|
} |
|
if ($newvalue eq '') { |
|
if ($type eq 'version') { |
|
$resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>'; |
|
} else { |
|
$resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>'; |
|
} |
|
} else { |
|
if ($type eq 'version') { |
|
$newvalue .= ' '.&mt('(or later)'); |
|
} |
|
$resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>'; |
|
} |
} |
} |
} else { |
|
if ($type eq 'version') { |
|
$newvalue .= ' '.&mt('(or later)'); |
|
} |
|
$resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>'; |
|
} |
} |
} |
} |
|
$resulttext .= '</ul>'; |
} |
} |
$resulttext .= '</ul>'; |
|
} |
} |
|
$resulttext .= '</ul>'; |
|
} else { |
|
$resulttext = $nochgmsg; |
} |
} |
$resulttext .= '</ul>'; |
|
} else { |
} else { |
$resulttext = '<span class="LC_error">'. |
$resulttext = '<span class="LC_error">'. |
&mt('An error occurred: [_1]',$putresult).'</span>'; |
&mt('An error occurred: [_1]',$putresult).'</span>'; |
} |
} |
} else { |
} else { |
$resulttext = &mt('No changes made to settings for user session hosting.'); |
$resulttext = $nochgmsg; |
|
} |
|
return $resulttext; |
|
} |
|
|
|
sub modify_loadbalancing { |
|
my ($dom,%domconfig) = @_; |
|
my $primary_id = &Apache::lonnet::domain($dom,'primary'); |
|
my $intdom = &Apache::lonnet::internet_dom($primary_id); |
|
my ($othertitle,$usertypes,$types) = |
|
&Apache::loncommon::sorted_inst_types($dom); |
|
my %servers = &Apache::lonnet::internet_dom_servers($dom); |
|
my @sparestypes = ('primary','default'); |
|
my %typetitles = &sparestype_titles(); |
|
my $resulttext; |
|
if (keys(%servers) > 1) { |
|
my ($currbalancer,$currtargets,$currrules); |
|
if (ref($domconfig{'loadbalancing'}) eq 'HASH') { |
|
$currbalancer = $domconfig{'loadbalancing'}{'lonhost'}; |
|
$currtargets = $domconfig{'loadbalancing'}{'targets'}; |
|
$currrules = $domconfig{'loadbalancing'}{'rules'}; |
|
} else { |
|
($currbalancer,$currtargets) = |
|
&Apache::lonnet::get_lonbalancer_config(\%servers); |
|
} |
|
my ($saveloadbalancing,%defaultshash,%changes); |
|
my ($alltypes,$othertypes,$titles) = |
|
&loadbalancing_titles($dom,$intdom,$usertypes,$types); |
|
my %ruletitles = &offloadtype_text(); |
|
my $balancer = $env{'form.loadbalancing_lonhost'}; |
|
if (!$servers{$balancer}) { |
|
undef($balancer); |
|
} |
|
if ($currbalancer ne $balancer) { |
|
$changes{'lonhost'} = 1; |
|
} |
|
$defaultshash{'loadbalancing'}{'lonhost'} = $balancer; |
|
if ($balancer ne '') { |
|
unless (ref($domconfig{'loadbalancing'}) eq 'HASH') { |
|
$saveloadbalancing = 1; |
|
} |
|
foreach my $sparetype (@sparestypes) { |
|
my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$sparetype); |
|
my @offloadto; |
|
foreach my $target (@targets) { |
|
if (($servers{$target}) && ($target ne $balancer)) { |
|
if ($sparetype eq 'default') { |
|
if (ref($defaultshash{'loadbalancing'}{'targets'}{'primary'}) eq 'ARRAY') { |
|
next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{'targets'}{'primary'}})); |
|
} |
|
} |
|
unless(grep(/^\Q$target\E$/,@offloadto)) { |
|
push(@offloadto,$target); |
|
} |
|
} |
|
$defaultshash{'loadbalancing'}{'targets'}{$sparetype} = \@offloadto; |
|
} |
|
} |
|
} else { |
|
foreach my $sparetype (@sparestypes) { |
|
$defaultshash{'loadbalancing'}{'targets'}{$sparetype} = []; |
|
} |
|
} |
|
if (ref($currtargets) eq 'HASH') { |
|
foreach my $sparetype (@sparestypes) { |
|
if (ref($currtargets->{$sparetype}) eq 'ARRAY') { |
|
my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets->{$sparetype},$defaultshash{'loadbalancing'}{'targets'}{$sparetype}); |
|
if (@targetdiffs > 0) { |
|
$changes{'targets'} = 1; |
|
} |
|
} elsif (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') { |
|
if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) { |
|
$changes{'targets'} = 1; |
|
} |
|
} |
|
} |
|
} else { |
|
foreach my $sparetype (@sparestypes) { |
|
if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') { |
|
if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) { |
|
$changes{'targets'} = 1; |
|
} |
|
} |
|
} |
|
} |
|
my $ishomedom; |
|
if ($balancer ne '') { |
|
if (&Apache::lonnet::host_domain($balancer) eq $dom) { |
|
$ishomedom = 1; |
|
} |
|
} |
|
if (ref($alltypes) eq 'ARRAY') { |
|
foreach my $type (@{$alltypes}) { |
|
my $rule; |
|
if ($balancer ne '') { |
|
unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) && |
|
(!$ishomedom)) { |
|
$rule = $env{'form.loadbalancing_rules_'.$type}; |
|
} |
|
if ($rule eq 'specific') { |
|
$rule = $env{'form.loadbalancing_singleserver_'.$type}; |
|
} |
|
} |
|
$defaultshash{'loadbalancing'}{'rules'}{$type} = $rule; |
|
if (ref($currrules) eq 'HASH') { |
|
if ($rule ne $currrules->{$type}) { |
|
$changes{'rules'}{$type} = 1; |
|
} |
|
} elsif ($rule ne '') { |
|
$changes{'rules'}{$type} = 1; |
|
} |
|
} |
|
} |
|
my $nochgmsg = &mt('No changes made to Load Balancer settings.'); |
|
if ((keys(%changes) > 0) || ($saveloadbalancing)) { |
|
my $putresult = &Apache::lonnet::put_dom('configuration', |
|
\%defaultshash,$dom); |
|
if ($putresult eq 'ok') { |
|
if (keys(%changes) > 0) { |
|
if ($changes{'lonhost'}) { |
|
if ($currbalancer ne '') { |
|
&Apache::lonnet::remote_devalidate_cache($currbalancer,'loadbalancing',$dom); |
|
} |
|
if ($balancer eq '') { |
|
$resulttext .= '<li>'.&mt('Load Balancing with dedicated server discontinued').'</li>'; |
|
} else { |
|
&Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom); |
|
$resulttext .= '<li>'.&mt('Dedicated Load Balancer server set to [_1]',$balancer); |
|
} |
|
} else { |
|
&Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom); |
|
} |
|
if (($changes{'targets'}) && ($balancer ne '')) { |
|
my %offloadstr; |
|
foreach my $sparetype (@sparestypes) { |
|
if (ref($defaultshash{'loadbalancing'}{'targets'}{$sparetype}) eq 'ARRAY') { |
|
if (@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}} > 0) { |
|
$offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{'targets'}{$sparetype}}); |
|
} |
|
} |
|
} |
|
if (keys(%offloadstr) == 0) { |
|
$resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>'; |
|
} else { |
|
my $showoffload; |
|
foreach my $sparetype (@sparestypes) { |
|
$showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: '; |
|
if (defined($offloadstr{$sparetype})) { |
|
$showoffload .= $offloadstr{$sparetype}; |
|
} else { |
|
$showoffload .= &mt('None'); |
|
} |
|
$showoffload .= (' 'x3); |
|
} |
|
$resulttext .= '<li>'.&mt('By default, Load Balancer server set to offload to: [_1]',$showoffload).'</li>'; |
|
} |
|
} |
|
if ((ref($changes{'rules'}) eq 'HASH') && ($balancer ne '')) { |
|
if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) { |
|
foreach my $type (@{$alltypes}) { |
|
if ($changes{'rules'}{$type}) { |
|
my $rule = $defaultshash{'loadbalancing'}{'rules'}{$type}; |
|
my $balancetext; |
|
if ($rule eq '') { |
|
$balancetext = $ruletitles{'default'}; |
|
} elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) { |
|
$balancetext = $ruletitles{$rule}; |
|
} else { |
|
$balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{'rules'}{$type}); |
|
} |
|
$resulttext .= '<li>'.&mt('Load Balancing for [_1] set to: [_2]',$titles->{$type},$balancetext).'</li>'; |
|
} |
|
} |
|
} |
|
} |
|
if ($resulttext ne '') { |
|
$resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>'; |
|
} else { |
|
$resulttext = $nochgmsg; |
|
} |
|
} else { |
|
$resulttext = $nochgmsg; |
|
if ($balancer ne '') { |
|
&Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom); |
|
} |
|
} |
|
} else { |
|
$resulttext = '<span class="LC_error">'. |
|
&mt('An error occurred: [_1]',$putresult).'</span>'; |
|
} |
|
} else { |
|
$resulttext = $nochgmsg; |
|
} |
|
} else { |
|
$resulttext = &mt('Load Balancing unavailable as this domain only has one server.'); |
} |
} |
return $resulttext; |
return $resulttext; |
} |
} |
Line 6973 sub recurse_cat_deletes {
|
Line 7789 sub recurse_cat_deletes {
|
return; |
return; |
} |
} |
|
|
sub dom_servers { |
|
my ($dom) = @_; |
|
my (%uniqservers,%servers); |
|
my $primaryserver = &Apache::lonnet::hostname(&Apache::lonnet::domain($dom,'primary')); |
|
my @machinedoms = &Apache::lonnet::machine_domains($primaryserver); |
|
foreach my $mdom (@machinedoms) { |
|
my %currservers = %servers; |
|
my %server = &Apache::lonnet::get_servers($mdom); |
|
%servers = (%currservers,%server); |
|
} |
|
my %by_hostname; |
|
foreach my $id (keys(%servers)) { |
|
push(@{$by_hostname{$servers{$id}}},$id); |
|
} |
|
foreach my $hostname (sort(keys(%by_hostname))) { |
|
if (@{$by_hostname{$hostname}} > 1) { |
|
my $match = 0; |
|
foreach my $id (@{$by_hostname{$hostname}}) { |
|
if (&Apache::lonnet::host_domain($id) eq $dom) { |
|
$uniqservers{$id} = $hostname; |
|
$match = 1; |
|
} |
|
} |
|
unless ($match) { |
|
$uniqservers{$by_hostname{$hostname}[0]} = $hostname; |
|
} |
|
} else { |
|
$uniqservers{$by_hostname{$hostname}[0]} = $hostname; |
|
} |
|
} |
|
return %uniqservers; |
|
} |
|
|
|
sub get_active_dcs { |
sub get_active_dcs { |
my ($dom) = @_; |
my ($dom) = @_; |
my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']); |
my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']); |
Line 7079 sub active_dc_picker {
|
Line 7862 sub active_dc_picker {
|
sub usersession_titles { |
sub usersession_titles { |
return &Apache::lonlocal::texthash( |
return &Apache::lonlocal::texthash( |
hosted => 'Hosting of sessions for users from other domains on servers in this domain', |
hosted => 'Hosting of sessions for users from other domains on servers in this domain', |
|
|
remote => 'Hosting of sessions for users in this domain on servers in other domains', |
remote => 'Hosting of sessions for users in this domain on servers in other domains', |
|
spares => 'Servers offloaded to, when busy', |
version => 'LON-CAPA version requirement', |
version => 'LON-CAPA version requirement', |
excludedomain => 'Allow all, but exclude specific domains', |
excludedomain => 'Allow all, but exclude specific domains', |
includedomain => 'Deny all, but include specific domains', |
includedomain => 'Deny all, but include specific domains', |
|
primary => 'Primary (checked first)', |
|
default => 'Default', |
); |
); |
} |
} |
|
|
|
sub id_for_thisdom { |
|
my (%servers) = @_; |
|
my %altids; |
|
foreach my $server (keys(%servers)) { |
|
my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server}); |
|
if ($serverhome ne $server) { |
|
$altids{$serverhome} = $server; |
|
} |
|
} |
|
return %altids; |
|
} |
|
|
|
sub count_servers { |
|
my ($currbalancer,%servers) = @_; |
|
my (@spares,$numspares); |
|
foreach my $lonhost (sort(keys(%servers))) { |
|
next if ($currbalancer eq $lonhost); |
|
push(@spares,$lonhost); |
|
} |
|
if ($currbalancer) { |
|
$numspares = scalar(@spares); |
|
} else { |
|
$numspares = scalar(@spares) - 1; |
|
} |
|
return ($numspares,@spares); |
|
} |
|
|
|
sub lonbalance_targets_js { |
|
my ($dom,$types,$servers) = @_; |
|
my $select = &mt('Select'); |
|
my ($alltargets,$allishome,$allinsttypes,@alltypes); |
|
if (ref($servers) eq 'HASH') { |
|
$alltargets = join("','",sort(keys(%{$servers}))); |
|
my @homedoms; |
|
foreach my $server (sort(keys(%{$servers}))) { |
|
if (&Apache::lonnet::host_domain($server) eq $dom) { |
|
push(@homedoms,'1'); |
|
} else { |
|
push(@homedoms,'0'); |
|
} |
|
} |
|
$allishome = join("','",@homedoms); |
|
} |
|
if (ref($types) eq 'ARRAY') { |
|
if (@{$types} > 0) { |
|
@alltypes = @{$types}; |
|
} |
|
} |
|
push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external'); |
|
$allinsttypes = join("','",@alltypes); |
|
return <<"END"; |
|
|
|
<script type="text/javascript"> |
|
// <![CDATA[ |
|
|
|
function toggleTargets() { |
|
var balancer = document.display.loadbalancing_lonhost.options[document.display.loadbalancing_lonhost.selectedIndex].value; |
|
if (balancer == '') { |
|
hideSpares(); |
|
} else { |
|
var homedoms = new Array('$allishome'); |
|
var ishomedom = homedoms[document.display.loadbalancing_lonhost.selectedIndex]; |
|
showSpares(balancer,ishomedom); |
|
} |
|
return; |
|
} |
|
|
|
function showSpares(balancer,ishomedom) { |
|
var alltargets = new Array('$alltargets'); |
|
var insttypes = new Array('$allinsttypes'); |
|
var offloadtypes = new Array('primary','default'); |
|
|
|
document.getElementById('loadbalancing_targets').style.display='block'; |
|
document.getElementById('loadbalancing_disabled').style.display='none'; |
|
|
|
for (var i=0; i<offloadtypes.length; i++) { |
|
var count = 0; |
|
for (var j=0; j<alltargets.length; j++) { |
|
if (alltargets[j] != balancer) { |
|
document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+count).value = alltargets[j]; |
|
document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textAlign='left'; |
|
document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).style.textFace='normal'; |
|
document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j]; |
|
count ++; |
|
} |
|
} |
|
} |
|
for (var k=0; k<insttypes.length; k++) { |
|
if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) { |
|
if (ishomedom == 1) { |
|
document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block'; |
|
document.getElementById('balancerule_'+insttypes[k]).style.display='block'; |
|
} else { |
|
document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none'; |
|
document.getElementById('balancerule_'+insttypes[k]).style.display='none'; |
|
|
|
} |
|
} else { |
|
document.getElementById('balanceruletitle_'+insttypes[k]).style.display='block'; |
|
document.getElementById('balancerule_'+insttypes[k]).style.display='block'; |
|
} |
|
if ((insttypes[k] != '_LC_external') && |
|
((insttypes[k] != '_LC_internetdom') || |
|
((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) { |
|
document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true); |
|
for (var m=0; m<alltargets.length; m++) { |
|
var idx = m+1; |
|
if (alltargets[m] != balancer) { |
|
document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[idx] = new Option(alltargets[m],alltargets[m],false,false); |
|
} |
|
} |
|
} |
|
} |
|
return; |
|
} |
|
|
|
function hideSpares() { |
|
var alltargets = new Array('$alltargets'); |
|
var insttypes = new Array('$allinsttypes'); |
|
var offloadtypes = new Array('primary','default'); |
|
|
|
document.getElementById('loadbalancing_targets').style.display='none'; |
|
document.getElementById('loadbalancing_disabled').style.display='block'; |
|
|
|
var total = alltargets.length - 1; |
|
for (var i=0; i<offloadtypes; i++) { |
|
for (var j=0; j<total; j++) { |
|
document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).checked = false; |
|
document.getElementById('loadbalancing_target_'+offloadtypes[i]+'_'+j).value = ''; |
|
document.getElementById('loadbalancing_targettxt_'+offloadtypes[i]+'_'+j).innerHTML = ''; |
|
} |
|
} |
|
for (var k=0; k<insttypes.length; k++) { |
|
document.getElementById('balanceruletitle_'+insttypes[k]).style.display='none'; |
|
document.getElementById('balancerule_'+insttypes[k]).style.display='none'; |
|
if (insttypes[k] != '_LC_external') { |
|
document.getElementById('loadbalancing_singleserver_'+insttypes[k]).length = 0; |
|
document.getElementById('loadbalancing_singleserver_'+insttypes[k]).options[0] = new Option("","",true,true); |
|
} |
|
} |
|
return; |
|
} |
|
|
|
function checkOffloads(item,type) { |
|
var alltargets = new Array('$alltargets'); |
|
var offloadtypes = new Array('primary','default'); |
|
if (item.checked) { |
|
var total = alltargets.length - 1; |
|
var other; |
|
if (type == offloadtypes[0]) { |
|
other = offloadtypes[1]; |
|
} else { |
|
other = offloadtypes[0]; |
|
} |
|
for (var i=0; i<total; i++) { |
|
var server = document.getElementById('loadbalancing_target_'+other+'_'+i).value; |
|
if (server == item.value) { |
|
if (document.getElementById('loadbalancing_target_'+other+'_'+i).checked) { |
|
document.getElementById('loadbalancing_target_'+other+'_'+i).checked = false; |
|
} |
|
} |
|
} |
|
} |
|
return; |
|
} |
|
|
|
function singleServerToggle(type) { |
|
var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+type).selectedIndex; |
|
if (offloadtoSelIdx == 0) { |
|
document.getElementById('loadbalancing_rules_'+type+'_0').checked = true; |
|
document.getElementById('loadbalancing_singleserver_'+type).options[0].text = ''; |
|
|
|
} else { |
|
document.getElementById('loadbalancing_rules_'+type+'_2').checked = true; |
|
document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select'; |
|
} |
|
return; |
|
} |
|
|
|
function balanceruleChange(formname,type) { |
|
if (type == '_LC_external') { |
|
return; |
|
} |
|
var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+type); |
|
for (var i=0; i<typesRules.length; i++) { |
|
if (formname.elements[typesRules[i]].checked) { |
|
if (formname.elements[typesRules[i]].value != 'specific') { |
|
document.getElementById('loadbalancing_singleserver_'+type).selectedIndex = 0; |
|
document.getElementById('loadbalancing_singleserver_'+type).options[0].text = ''; |
|
} else { |
|
document.getElementById('loadbalancing_singleserver_'+type).options[0].text = '$select'; |
|
} |
|
} |
|
} |
|
return; |
|
} |
|
|
|
// ]]> |
|
</script> |
|
|
|
END |
|
} |
|
|
|
sub new_spares_js { |
|
my @sparestypes = ('primary','default'); |
|
my $types = join("','",@sparestypes); |
|
my $select = &mt('Select'); |
|
return <<"END"; |
|
|
|
<script type="text/javascript"> |
|
// <![CDATA[ |
|
|
|
function updateNewSpares(formname,lonhost) { |
|
var types = new Array('$types'); |
|
var include = new Array(); |
|
var exclude = new Array(); |
|
for (var i=0; i<types.length; i++) { |
|
var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost); |
|
for (var j=0; j<spareboxes.length; j++) { |
|
if (formname.elements[spareboxes[j]].checked) { |
|
exclude.push(formname.elements[spareboxes[j]].value); |
|
} else { |
|
include.push(formname.elements[spareboxes[j]].value); |
|
} |
|
} |
|
} |
|
for (var i=0; i<types.length; i++) { |
|
var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost); |
|
var selIdx = newSpare.selectedIndex; |
|
var currnew = newSpare.options[selIdx].value; |
|
var okSpares = new Array(); |
|
for (var j=0; j<newSpare.options.length; j++) { |
|
var possible = newSpare.options[j].value; |
|
if (possible != '') { |
|
if (exclude.indexOf(possible) == -1) { |
|
okSpares.push(possible); |
|
} else { |
|
if (currnew == possible) { |
|
selIdx = 0; |
|
} |
|
} |
|
} |
|
} |
|
for (var k=0; k<include.length; k++) { |
|
if (okSpares.indexOf(include[k]) == -1) { |
|
okSpares.push(include[k]); |
|
} |
|
} |
|
okSpares.sort(); |
|
newSpare.options.length = 0; |
|
if (selIdx == 0) { |
|
newSpare.options[0] = new Option("$select","",true,true); |
|
} else { |
|
newSpare.options[0] = new Option("$select","",false,false); |
|
} |
|
for (var m=0; m<okSpares.length; m++) { |
|
var idx = m+1; |
|
var selThis = 0; |
|
if (selIdx != 0) { |
|
if (okSpares[m] == currnew) { |
|
selThis = 1; |
|
} |
|
} |
|
if (selThis == 1) { |
|
newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true); |
|
} else { |
|
newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false); |
|
} |
|
} |
|
} |
|
return; |
|
} |
|
|
|
function checkNewSpares(lonhost,type) { |
|
var newSpare = document.getElementById('newspare_'+type+'_'+lonhost); |
|
var chosen = newSpare.options[newSpare.selectedIndex].value; |
|
if (chosen != '') { |
|
var othertype; |
|
var othernewSpare; |
|
if (type == 'primary') { |
|
othernewSpare = document.getElementById('newspare_default_'+lonhost); |
|
} |
|
if (type == 'default') { |
|
othernewSpare = document.getElementById('newspare_primary_'+lonhost); |
|
} |
|
if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) { |
|
othernewSpare.selectedIndex = 0; |
|
} |
|
} |
|
return; |
|
} |
|
|
|
// ]]> |
|
</script> |
|
|
|
END |
|
|
|
} |
|
|
|
sub common_domprefs_js { |
|
return <<"END"; |
|
|
|
<script type="text/javascript"> |
|
// <![CDATA[ |
|
|
|
function getIndicesByName(formname,item) { |
|
var group = new Array(); |
|
for (var i=0;i<formname.elements.length;i++) { |
|
if (formname.elements[i].name == item) { |
|
group.push(formname.elements[i].id); |
|
} |
|
} |
|
return group; |
|
} |
|
|
|
// ]]> |
|
</script> |
|
|
|
END |
|
|
|
} |
|
|
1; |
1; |