[LON-CAPA-cvs] cvs: loncom /interface domainprefs.pm
raeburn
raeburn@source.lon-capa.org
Wed, 03 Mar 2010 16:43:42 -0000
This is a MIME encoded message
--raeburn1267634622
Content-Type: text/plain
raeburn Wed Mar 3 16:43:42 2010 EDT
Modified files:
/loncom/interface domainprefs.pm
Log:
- More customization of redirection of log-in pages for individual servers in a domain to a load balancer server.
- can specify path on load balancer server
- can specify IPs to be exempt from redirection (e.g., to allow
continued access for robotic monotoring).
--raeburn1267634622
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100303164342.txt"
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.127 loncom/interface/domainprefs.pm:1.128
--- loncom/interface/domainprefs.pm:1.127 Mon Feb 22 18:28:13 2010
+++ loncom/interface/domainprefs.pm Wed Mar 3 16:43:41 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.127 2010/02/22 18:28:13 raeburn Exp $
+# $Id: domainprefs.pm,v 1.128 2010/03/03 16:43:41 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -664,9 +664,12 @@
my %servers = &dom_servers($dom);
my $choice = $choices{'disallowlogin'};
$css_class = ' class="LC_odd_row"';
- $datatable .= '<tr'.$css_class.'><td>'.$choices{'disallowlogin'}.'</td>'.
+ $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
'<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
- '<th>'.$choices{'serverurl'}.'</th></tr>'."\n";
+ '<th>'.$choices{'server'}.'</th>'.
+ '<th>'.$choices{'serverpath'}.'</th>'.
+ '<th>'.$choices{'custompath'}.'</th>'.
+ '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
my %disallowed;
if (ref($settings) eq 'HASH') {
if (ref($settings->{'loginvia'}) eq 'HASH') {
@@ -675,23 +678,52 @@
}
foreach my $lonhost (sort(keys(%servers))) {
my $direct = 'selected="selected"';
- if ($disallowed{$lonhost} eq '') {
- $direct = '';
+ if (ref($disallowed{$lonhost}) eq 'HASH') {
+ if ($disallowed{$lonhost}{'server'} ne '') {
+ $direct = '';
+ }
}
$datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
- '<td><select name="'.$lonhost.'_serverurl">'.
+ '<td><select name="'.$lonhost.'_server">'.
'<option value=""'.$direct.'>'.$choices{'directlogin'}.
'</option>';
foreach my $hostid (keys(%servers)) {
next if ($servers{$hostid} eq $servers{$lonhost});
my $selected = '';
- if ($hostid eq $disallowed{$lonhost}) {
- $selected = 'selected="selected"';
+ if (ref($disallowed{$lonhost}) eq 'HASH') {
+ if ($hostid eq $disallowed{$lonhost}{'server'}) {
+ $selected = 'selected="selected"';
+ }
}
$datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
$servers{$hostid}.'</option>';
}
- $datatable .= '</select></td></tr>';
+ $datatable .= '</select></td>'.
+ '<td><select name="'.$lonhost.'_serverpath">';
+ foreach my $path ('','/','/adm/login','/adm/roles','custom') {
+ my $pathname = $path;
+ if ($path eq 'custom') {
+ $pathname = &mt('Custom Path').' ->';
+ }
+ my $selected = '';
+ if (ref($disallowed{$lonhost}) eq 'HASH') {
+ if ($path eq $disallowed{$lonhost}{'serverpath'}) {
+ $selected = 'selected="selected"';
+ }
+ } elsif ($path eq '') {
+ $selected = 'selected="selected"';
+ }
+ $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
+ }
+ $datatable .= '</select></td>';
+ my ($custom,$exempt);
+ if (ref($disallowed{$lonhost}) eq 'HASH') {
+ $custom = $disallowed{$lonhost}{'custompath'};
+ $exempt = $disallowed{$lonhost}{'exempt'};
+ }
+ $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
+ '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
+ '</tr>';
}
$datatable .= '</table></td></tr>';
return $datatable;
@@ -835,7 +867,10 @@
adminmail => "Display Administrator's E-mail Address?",
disallowlogin => "Login page requests redirected",
hostid => "Server",
- serverurl => "Redirect to log-in via:",
+ server => "Redirect to:",
+ serverpath => "Path",
+ custompath => "Custom",
+ exempt => "Exempt IP(s)",
directlogin => "No redirect",
newuser => "Link to create a user account",
img => "Header",
@@ -3506,19 +3541,86 @@
}
my %servers = &dom_servers($dom);
+ my @loginvia_attribs = ('serverpath','custompath','exempt');
if (keys(%servers) > 1) {
foreach my $lonhost (keys(%servers)) {
- next if ($env{'form.'.$lonhost.'_serverurl'} eq $lonhost);
- if ($env{'form.'.$lonhost.'_serverurl'} eq $curr_loginvia{$lonhost}) {
- $loginhash{login}{loginvia}{$lonhost} = $curr_loginvia{$lonhost}; next;
- }
- if ($curr_loginvia{$lonhost} ne '') {
- $loginhash{login}{loginvia}{$lonhost} = $env{'form.'.$lonhost.'_serverurl'};
- $changes{'loginvia'}{$lonhost} = 1;
+ next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
+ if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
+ if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
+ $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
+ } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
+ if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
+ $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
+ $changes{'loginvia'}{$lonhost} = 1;
+ } else {
+ $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
+ $changes{'loginvia'}{$lonhost} = 1;
+ }
+ } else {
+ if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
+ $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
+ $changes{'loginvia'}{$lonhost} = 1;
+ }
+ }
+ if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
+ foreach my $item (@loginvia_attribs) {
+ $loginhash{login}{loginvia}{$lonhost}{$item} = '';
+ }
+ } else {
+ foreach my $item (@loginvia_attribs) {
+ my $new = $env{'form.'.$lonhost.'_'.$item};
+ if (($item eq 'serverpath') && ($new eq 'custom')) {
+ $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
+ if ($env{'form.'.$lonhost.'_custompath'} eq '') {
+ $new = '/';
+ }
+ }
+ if (($item eq 'custompath') &&
+ ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
+ $new = '';
+ }
+ if ($new ne $curr_loginvia{$lonhost}{$item}) {
+ $changes{'loginvia'}{$lonhost} = 1;
+ }
+ if ($item eq 'exempt') {
+ $new =~ s/^\s+//;
+ $new =~ s/\s+$//;
+ my @poss_ips = split(/\s*[,:]\s*/,$new);
+ my @okips;
+ foreach my $ip (@poss_ips) {
+ if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
+ if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
+ push(@okips,$ip);
+ }
+ }
+ }
+ if (@okips > 0) {
+ $new = join(',',@okips);
+ } else {
+ $new = '';
+ }
+ }
+
+ $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
+ }
+ }
} else {
- if (defined($servers{$env{'form.'.$lonhost.'_serverurl'}})) {
- $loginhash{login}{loginvia}{$lonhost} = $env{'form.'.$lonhost.'_serverurl'};
+ if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
+ $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
$changes{'loginvia'}{$lonhost} = 1;
+ foreach my $item (@loginvia_attribs) {
+ my $new = $env{'form.'.$lonhost.'_'.$item};
+ if (($item eq 'serverpath') && ($new eq 'custom')) {
+ if ($env{'form.'.$lonhost.'_custompath'} eq '') {
+ $new = '/';
+ }
+ }
+ if (($item eq 'custompath') &&
+ ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
+ $new = '';
+ }
+ $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
+ }
}
}
}
@@ -3574,13 +3676,30 @@
if (ref($changes{$item}) eq 'HASH') {
$resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
- if ($servers{$env{'form.'.$lonhost.'_serverurl'}} ne '') {
- $resulttext .= '<li>'.&mt('Server: [_1] log-in page now redirects to [_2]',$lonhost,$servers{$env{'form.'.$lonhost.'_serverurl'}}).'</li>';
+ if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
+ if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
+ my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
+ $protocol = 'http' if ($protocol ne 'https');
+ my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
+
+ if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
+ $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
+ } else {
+ $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
+ }
+ $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
+ if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
+ $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
+ }
+ $resulttext .= '</li>';
+ } else {
+ $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
+ }
} else {
- $resulttext .= '<li>'.&mt('Server: [_1] now has standard log-in page.',$lonhost).'</li>';
+ $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
}
}
- $resulttext .= '</ul></li>';
+ $resulttext .= '</ul></li>';
}
} else {
$resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
--raeburn1267634622--