--- loncom/lontrans.pm 2022/01/05 00:51:20 1.14.10.2.2.2 +++ loncom/lontrans.pm 2021/11/03 01:04:03 1.37 @@ -1,7 +1,7 @@ # The LearningOnline Network # URL translation for User Files # -# $Id: lontrans.pm,v 1.14.10.2.2.2 2022/01/05 00:51:20 raeburn Exp $ +# $Id: lontrans.pm,v 1.37 2021/11/03 01:04:03 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -37,17 +37,26 @@ use LONCAPA qw(:DEFAULT :match); sub handler { my $r = shift; - # FIXME line remove when mod_perl fixes BUG#4948 + # FIXME line remove when mod_perl fixes BUG#4948 $r->notes->set('error-notes' => ''); + my $hdrhost = $r->headers_in->get('Host'); + if ($r->uri=~m{^/raw/}) { + if ($hdrhost) { + unless ($hdrhost =~ /^internal\-/) { + my $remote_ip = &Apache::lonnet::get_requestor_ip($r,REMOTE_NOLOOKUP,1); + my $lonhost = $r->dir_config('lonHostID'); + if (&redirect_raw($remote_ip,$lonhost)) { + my $location = 'https://internal-'.$hdrhost.$r->uri; + $r->headers_out->set(Location => $location); + return REDIRECT; + } + } + } + } my $alias = &Apache::lonnet::get_proxy_alias(); if ($alias) { - my $hdrhost = $r->headers_in->get('Host'); my $lonhost = $r->dir_config('lonHostID'); my $hostname = &Apache::lonnet::hostname($lonhost); - my $ssourl = '/adm/sso'; - if ($r->dir_config('lonOtherAuthenUrl') ne '') { - $ssourl = $r->dir_config('lonOtherAuthenUrl'); - } if (($hdrhost eq $alias) || ($hdrhost eq $hostname)) { my $proxyinfo = &Apache::lonnet::get_proxy_settings($r->dir_config('lonDefDomain')); my ($vpnint,$vpnext); @@ -62,8 +71,8 @@ sub handler { ($r->uri !~ m{^/adm/(lti|launch)/})) { $redirect = $hostname; } - if ($r->uri eq $ssourl) { - if (&Apache::lonnet::alias_sso($lonhost)) { + if ($r->uri eq '/adm/sso') { + if (&Apache::lonnet::alias_shibboleth($lonhost)) { undef($redirect); } else { $redirect = $hostname; @@ -84,8 +93,8 @@ sub handler { if (exists($iphost{$remote_ip})) { undef($redirect); } - } elsif ($r->uri eq $ssourl) { - unless (&Apache::lonnet::alias_sso($lonhost)) { + } elsif ($r->uri eq '/adm/sso') { + unless (&Apache::lonnet::alias_shibboleth($lonhost)) { undef($redirect); } } @@ -96,7 +105,7 @@ sub handler { if (($uri eq '/adm/switchserver') || ($uri =~ m{^/Shibboleth.sso/})) { return DECLINED; } - unless (($uri eq '/adm/migrateuser') || ($uri eq $ssourl)) { + unless (($uri eq '/adm/migrateuser') || ($uri eq '/adm/sso')) { my %user; my $handle = &Apache::lonnet::check_for_valid_session($r,undef,\%user); if (($handle) && ($user{'name'} ne '') && ($user{'domain'} ne '')) { @@ -161,6 +170,55 @@ sub handler { return DECLINED; } +sub redirect_raw { + my ($remote_ip,$lonhost) = @_; + my @remhostids = &Apache::lonnet::get_hosts_from_ip($remote_ip); + my $redirect; + while (@remhostids) { + my $try_server = pop(@remhostids); + my $remhostname = &Apache::lonnet::hostname($try_server); + if ($remhostname) { + my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$try_server); + my ($remmajor,$remminor) = ($remoterev =~ /^(\d+)\.(\d+)/); + if (($remmajor > 2) || (($remmajor == 2) && $remminor >= 12)) { + my $internet_names = &Apache::lonnet::get_internet_names($try_server); + if (ref($internet_names) eq 'ARRAY') { + my $intdom = &Apache::lonnet::internet_dom($lonhost); + unless (grep(/^\Q$intdom\E$/,@{$internet_names})) { + my $lonhostname = &Apache::lonnet::hostname($lonhost); + my $serverhomeID = &Apache::lonnet::get_server_homeID($lonhostname); + my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID); + my %domdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom); + my $replication = $domdefaults{'replication'}; + if (ref($replication) eq 'HASH') { + my $remhomeID = &Apache::lonnet::get_server_homeID($remhostname); + my $remhomedom = &Apache::lonnet::host_domain($remhomeID); + my $remprimary = &Apache::lonnet::domain($remhomedom,'primary'); + my $remintdom = &Apache::lonnet::internet_dom($remprimary); + if (ref($replication->{'certreq'}) eq 'ARRAY') { + if (grep(/^\Q$remintdom\E$/,@{$replication->{'certreq'}})) { + $redirect = 0; + } else { + $redirect = 1; + } + } + if (ref($replication->{'nocertreq'}) eq 'ARRAY') { + if (grep(/^\Q$remintdom\E$/,@{$replication->{'nocertreq'}})) { + $redirect = 1; + } else { + $redirect = 0; + } + } + } + } + } + } + last; + } + } + return $redirect; +} + sub set_token { my ($r,$dest,$remote_ip,$userref) = @_; my (%info,%user);