[LON-CAPA-cvs] cvs: loncom(version_2_9_X) /interface domainprefs.pm

raeburn raeburn@source.lon-capa.org
Wed, 10 Mar 2010 17:26:05 -0000


This is a MIME encoded message

--raeburn1268241965
Content-Type: text/plain

raeburn		Wed Mar 10 17:26:05 2010 EDT

  Modified files:              (Branch: version_2_9_X)
    /loncom/interface	domainprefs.pm 
  Log:
  - Backport 1.117, 1.119, 1.128.
  
  
--raeburn1268241965
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100310172605.txt"

Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.102.2.9 loncom/interface/domainprefs.pm:1.102.2.10
--- loncom/interface/domainprefs.pm:1.102.2.9	Mon Feb 22 18:39:13 2010
+++ loncom/interface/domainprefs.pm	Wed Mar 10 17:26:05 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.102.2.9 2010/02/22 18:39:13 raeburn Exp $
+# $Id: domainprefs.pm,v 1.102.2.10 2010/03/10 17:26:05 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -332,6 +332,16 @@
                               col2 => 'Value',}],
                  },
     );
+    my %servers = &dom_servers($dom);
+    if (keys(%servers) > 1) {
+        $prefs{'login'}  = { text   => 'Log-in page options',
+                             help   => 'Domain_Configuration_Login_Page',
+                            header => [{col1 => 'Log-in Service',
+                                        col2 => 'Server Setting',},
+                                       {col1 => 'Log-in Page Items',
+                                        col2 => ''}],
+                           };
+    }
     my @roles = ('student','coordinator','author','admin');
     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
     &Apache::lonhtmlcommon::add_breadcrumb
@@ -466,6 +476,9 @@
             $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'coursecategories') {
             $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
+        } elsif ($action eq 'login') {
+            $output .= &print_login('top',$dom,$confname,$phase,$settings,\$rowtotal);
+            $colspan = ' colspan="2"';
         } elsif ($action eq 'requestcourses') {
             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
         } else {
@@ -515,6 +528,8 @@
             $rowtotal ++;
         } elsif ($action eq 'coursecategories') {
             $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
+        } elsif ($action eq 'login') {
+            $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
         } elsif ($action eq 'requestcourses') {
             $output .= &print_courserequestmail($dom,$settings,\$rowtotal);
         } else {
@@ -585,7 +600,8 @@
         $output .= '</tr>';
         $rowtotal ++;
         if ($action eq 'login') {
-            $output .= &print_login($dom,$confname,$phase,$settings,\$rowtotal);
+            $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
+                                    \$rowtotal);
         } elsif ($action eq 'quotas') {
             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
         } elsif ($action eq 'autoenroll') {
@@ -615,8 +631,79 @@
 }
 
 sub print_login {
-    my ($dom,$confname,$phase,$settings,$rowtotal) = @_;
+    my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
+    my ($css_class,$datatable);
     my %choices = &login_choices();
+
+    if ($position eq 'top') {
+        my %servers = &dom_servers($dom);
+        my $choice = $choices{'disallowlogin'};
+        $css_class = ' class="LC_odd_row"';
+        $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
+                      '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
+                      '<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') {
+               %disallowed = %{$settings->{'loginvia'}};
+            }
+        }
+        foreach my $lonhost (sort(keys(%servers))) {
+            my $direct = 'selected="selected"';
+            if (ref($disallowed{$lonhost}) eq 'HASH') {
+                if ($disallowed{$lonhost}{'server'} ne '') {
+                    $direct = '';
+                }
+            }
+            $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
+                          '<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 (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>'.
+                          '<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;
+    }
+
     my %defaultchecked = ( 
                            'coursecatalog' => 'on',
                            'adminmail'     => 'off',
@@ -753,6 +840,13 @@
         &Apache::lonlocal::texthash (
             coursecatalog => 'Display Course/Community Catalog link?',
             adminmail => "Display Administrator's E-mail Address?",
+            disallowlogin => "Login page requests redirected",
+            hostid        => "Server",
+            server        => "Redirect to:",
+            serverpath    => "Path",
+            custompath    => "Custom",
+            exempt        => "Exempt IP(s)",
+            directlogin   => "No redirect",
             newuser   => "Link to create a user account",
             img => "Header",
             logo => "Main Logo",
@@ -3281,6 +3375,14 @@
                   newuser => 'Link for visitors to create a user account',
                   loginheader => 'Log-in box header');
     my @offon = ('off','on');
+    my %curr_loginvia;
+    if (ref($domconfig{login}) eq 'HASH') {
+        if (ref($domconfig{login}{loginvia}) eq 'HASH') {
+            foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
+                $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
+            }
+        }
+    }
     my %loginhash;
     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                                            \%domconfig,\%loginhash);
@@ -3293,6 +3395,93 @@
         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                                          \%loginhash);
     }
+
+    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.'_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.'_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;
+                    }
+                }
+            }
+        }
+    }
+
     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                                              $dom);
     if ($putresult eq 'ok') {
@@ -3339,6 +3528,35 @@
             foreach my $item (sort(keys(%changes))) {
                 if ($item eq 'loginheader') {
                     $resulttext .= '<li>'.&mt("$title{$item} set to $env{'form.loginheader'}").'</li>';
+                } elsif ($item eq 'loginvia') {
+                    if (ref($changes{$item}) eq 'HASH') {
+                        $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
+                        foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
+                            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 .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$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] has standard log-in page.',$servers{$lonhost}).'</li>';
+                            }
+                        }
+                        $resulttext .= '</ul></li>';
+                    }
                 } else {
                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                 }
@@ -5931,6 +6149,39 @@
     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 {
     my ($dom) = @_;
     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);

--raeburn1268241965--