[LON-CAPA-cvs] cvs: loncom / lontrans.pm /auth lonlogin.pm switchserver.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Mon May 3 11:27:45 EDT 2021


raeburn		Mon May  3 15:27:45 2021 EDT

  Modified files:              
    /loncom	lontrans.pm 
    /loncom/auth	switchserver.pm lonlogin.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Bug 6914
   - Check whether WAF proxy alias should be used when using switchserver.
   - Requests for /adm/dns/hosts and /adm/dns/domain from other nodes in the
     network do not require redirecting to an alias (if in use). 
  
  
Index: loncom/lontrans.pm
diff -u loncom/lontrans.pm:1.30 loncom/lontrans.pm:1.31
--- loncom/lontrans.pm:1.30	Sun Apr 18 02:08:46 2021
+++ loncom/lontrans.pm	Mon May  3 15:27:42 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # URL translation for User Files
 #
-# $Id: lontrans.pm,v 1.30 2021/04/18 02:08:46 raeburn Exp $
+# $Id: lontrans.pm,v 1.31 2021/05/03 15:27:42 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -79,7 +79,7 @@
                         ($remote_ip eq &Apache::lonnet::get_host_ip($lonhost)) ||
                         ($vpnint && &Apache::lonnet::ip_match($remote_ip,$vpnint))) {
                     $redirect = $alias;
-                    if ($r->uri=~m{^/raw/}){
+                    if (($r->uri=~m{^/raw/}) || ($r->uri=~m{^/adm/dns/(hosts|domain)$})) {
                         my %iphost = &Apache::lonnet::get_iphost();
                         if (exists($iphost{$remote_ip})) {
                             undef($redirect);
Index: loncom/auth/switchserver.pm
diff -u loncom/auth/switchserver.pm:1.53 loncom/auth/switchserver.pm:1.54
--- loncom/auth/switchserver.pm:1.53	Sun Jan  3 23:53:15 2021
+++ loncom/auth/switchserver.pm	Mon May  3 15:27:43 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Switch Servers Handler
 #
-# $Id: switchserver.pm,v 1.53 2021/01/03 23:53:15 raeburn Exp $
+# $Id: switchserver.pm,v 1.54 2021/05/03 15:27:43 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -123,6 +123,10 @@
         if ($Apache::lonnet::protocol{$env{'form.otherserver'}} eq 'https') {
             $protocol = $Apache::lonnet::protocol{$env{'form.otherserver'}};
         }
+        unless ($env{'form.otherserver'} eq $r->dir_config('lonHostID')) {
+            my $alias = &Apache::lonnet::use_proxy_alias($r,$env{'form.otherserver'});
+            $switch_to = $alias if ($alias ne '');
+        }
     }
 
     if ($env{'user.name'} eq 'public'
Index: loncom/auth/lonlogin.pm
diff -u loncom/auth/lonlogin.pm:1.182 loncom/auth/lonlogin.pm:1.183
--- loncom/auth/lonlogin.pm:1.182	Fri Dec 18 15:23:03 2020
+++ loncom/auth/lonlogin.pm	Mon May  3 15:27:44 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Login Screen
 #
-# $Id: lonlogin.pm,v 1.182 2020/12/18 15:23:03 raeburn Exp $
+# $Id: lonlogin.pm,v 1.183 2021/05/03 15:27:44 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -143,6 +143,10 @@
             if ($balancer_token) {
                 $dest .=  (($dest=~/\?/)?'&;':'?') . 'btoken='.$balancer_token;
             }
+            unless ($found_server eq $lonhost) {
+                my $alias = &Apache::lonnet::use_proxy_alias($r,$found_server);
+                $hostname = $alias if ($alias ne '');
+            }
             my $url = $protocol.'://'.$hostname.$dest;
             my $start_page =
                 &Apache::loncommon::start_page('Switching Server ...',undef,
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1449 loncom/lonnet/perl/lonnet.pm:1.1450
--- loncom/lonnet/perl/lonnet.pm:1.1449	Thu Apr 29 17:45:23 2021
+++ loncom/lonnet/perl/lonnet.pm	Mon May  3 15:27:45 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1449 2021/04/29 17:45:23 raeburn Exp $
+# $Id: lonnet.pm,v 1.1450 2021/05/03 15:27:45 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -14453,13 +14453,19 @@
 }
 
 sub get_proxy_alias {
-    my $lonhost = $perlvar{'lonHostID'};
-    if ($lonhost ne '') {
-        my ($alias,$cached) = &is_cached_new('proxyalias',$lonhost);
+    my ($lonid) = @_;
+    if ($lonid eq '') {
+        $lonid = $perlvar{'lonHostID'};
+    }
+    if (!defined(&hostname($lonid))) {
+        return;
+    }
+    if ($lonid ne '') {
+        my ($alias,$cached) = &is_cached_new('proxyalias',$lonid);
         if ($cached) {
             return $alias;
         }
-        my $dom = &Apache::lonnet::host_domain($lonhost);
+        my $dom = &Apache::lonnet::host_domain($lonid);
         if ($dom ne '') {
             my $cachetime = 60*60*24;
             my %domconfig =
@@ -14467,10 +14473,32 @@
             my $alias;
             if (ref($domconfig{'wafproxy'}) eq 'HASH') {
                 if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
-                    $alias = $domconfig{'wafproxy'}{'alias'}{$lonhost};
+                    $alias = $domconfig{'wafproxy'}{'alias'}{$lonid};
+                }
+            }
+            return &do_cache_new('proxyalias',$lonid,$alias,$cachetime);
+        }
+    }
+    return;
+}
+
+sub use_proxy_alias {
+    my ($r,$lonid) = @_;
+    my $alias = &get_proxy_alias($lonid);
+    if ($alias) {
+        my $dom = &host_domain($lonid);
+        if ($dom ne '') {
+            my $proxyinfo = &get_proxy_settings($dom );
+            my ($vpnint,$remote_ip);
+            if (ref($proxyinfo) eq 'HASH') {
+                $vpnint = $proxyinfo->{'vpnint'};
+                if ($vpnint) {
+                    $remote_ip = &get_requestor_ip($r,1,1);
                 }
             }
-            return &do_cache_new('proxyalias',$lonhost,$alias,$cachetime);
+            unless ($vpnint && &ip_match($remote_ip,$vpnint)) {
+                return $alias;
+            }
         }
     }
     return;




More information about the LON-CAPA-cvs mailing list