version 1.14.10.2, 2021/12/14 20:59:19
|
version 1.24, 2018/07/26 19:01:25
|
Line 29
|
Line 29
|
package Apache::lontrans; |
package Apache::lontrans; |
|
|
use strict; |
use strict; |
use Apache::Constants qw(:common :remotehost); |
use Apache::Constants qw(:common :remotehost REDIRECT :http); |
use Apache::lonnet(); |
use Apache::lonnet; |
use Apache::loncommon; |
|
use Apache::File(); |
use Apache::File(); |
use LONCAPA; |
use LONCAPA qw(:DEFAULT :match); |
|
|
|
|
sub handler { |
sub handler { |
my $r = shift; |
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' => ''); |
$r->notes->set('error-notes' => ''); |
my $alias = &Apache::lonnet::get_proxy_alias(); |
if ($r->uri =~ m{^/+tiny/+($match_domain)/+(\w+)$}) { |
if ($alias) { |
my ($cdom,$key) = ($1,$2); |
my $hdrhost = $r->headers_in->get('Host'); |
if (&Apache::lonnet::domain($cdom) ne '') { |
my $lonhost = $r->dir_config('lonHostID'); |
my %user; |
my $hostname = &Apache::lonnet::hostname($lonhost); |
my $handle = &Apache::lonnet::check_for_valid_session($r,undef,\%user); |
my $ssourl = '/adm/sso'; |
if ($handle ne '') { |
if ($r->dir_config('lonOtherAuthenUrl') ne '') { |
my $lonidsdir=$r->dir_config('lonIDsDir'); |
$ssourl = $r->dir_config('lonOtherAuthenUrl'); |
&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle); |
} |
if ($env{'request.course.id'}) { |
if (($hdrhost eq $alias) || ($hdrhost eq $hostname)) { |
my $tinyurl; |
my $proxyinfo = &Apache::lonnet::get_proxy_settings($r->dir_config('lonDefDomain')); |
my ($result,$cached)=&Apache::lonnet::is_cached_new('tiny',$cdom."\0".$key); |
my ($vpnint,$vpnext); |
if (defined($cached)) { |
if (ref($proxyinfo) eq 'HASH') { |
$tinyurl = $result; |
$vpnint = $proxyinfo->{'vpnint'}; |
|
$vpnext = $proxyinfo->{'vpnext'}; |
|
} |
|
my ($redirect,$remote_ip); |
|
if ($hdrhost eq $alias) { |
|
$remote_ip = &Apache::lonnet::get_requestor_ip($r,REMOTE_NOLOOKUP); |
|
if (($vpnext && &Apache::lonnet::ip_match($remote_ip,$vpnext))) { |
|
$redirect = $hostname; |
|
} |
|
if ($r->uri eq $ssourl) { |
|
if (&Apache::lonnet::alias_sso($lonhost)) { |
|
undef($redirect); |
|
} else { |
} else { |
$redirect = $hostname; |
my $configuname = &Apache::lonnet::get_domainconfiguser($cdom); |
} |
my %currtiny = &Apache::lonnet::get('tiny',[$key],$cdom,$configuname); |
} |
if ($currtiny{$key} ne '') { |
if ($redirect eq $hdrhost) { |
$tinyurl = $currtiny{$key}; |
undef($redirect); |
&Apache::lonnet::do_cache_new('tiny',$cdom."\0".$key,$currtiny{$key},600); |
} |
|
} elsif ($hdrhost eq $hostname) { |
|
$remote_ip = &Apache::lonnet::get_requestor_ip($r,REMOTE_NOLOOKUP,1); |
|
unless (($remote_ip eq '127.0.0.1') || ($remote_ip eq '::1') || |
|
($remote_ip eq &Apache::lonnet::get_host_ip($lonhost)) || |
|
($vpnint && &Apache::lonnet::ip_match($remote_ip,$vpnint))) { |
|
$redirect = $alias; |
|
if (($r->uri=~m{^/raw/}) || ($r->uri=~m{^/adm/dns/})) { |
|
my %iphost = &Apache::lonnet::get_iphost(); |
|
if (exists($iphost{$remote_ip})) { |
|
undef($redirect); |
|
} |
|
} elsif ($r->uri eq $ssourl) { |
|
unless (&Apache::lonnet::alias_sso($lonhost)) { |
|
undef($redirect); |
|
} |
} |
} |
} |
} |
if ($tinyurl ne '') { |
} |
my ($cnum,$symb) = split(/\&/,$tinyurl); |
if ($redirect) { |
if (($cnum =~ /^$match_courseid$/) && |
my $uri = $r->uri; |
(&Apache::lonnet::homeserver($cnum,$cdom) ne 'no_host')) { |
if (($uri eq '/adm/switchserver') || ($uri =~ m{^/Shibboleth.sso/})) { |
if ($env{'request.course.id'} eq $cdom.'_'.$cnum) { |
return DECLINED; |
my ($map,$resid,$url) = &Apache::lonnet::decode_symb($symb); |
} |
if (&Apache::lonnet::is_on_map($url)) { |
unless (($uri eq '/adm/migrateuser') || ($uri eq $ssourl)) { |
my $realuri; |
my %user; |
if ((&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) && |
my $handle = &Apache::lonnet::check_for_valid_session($r,undef,\%user); |
(!$env{'request.role.adv'})) { |
if (($handle) && ($user{'name'} ne '') && ($user{'domain'} ne '')) { |
$env{'user.error.msg'}=$r->uri.':bre:1:1:Access to resource denied'; |
unless (($user{'name'} eq 'public') && ($user{'domain'} eq 'public')) { |
return HTTP_NOT_ACCEPTABLE; |
my $dest = '/adm/migrateuser'; |
} |
my $token = &set_token($r,$dest,$remote_ip,\%user); |
if ((&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i) && |
unless ($token eq '') { |
(!$env{'request.role.adv'})) { |
$r->internal_redirect("$dest?token=$token"); |
$realuri = &Apache::lonenc::encrypted(&Apache::lonnet::clutter($url)); |
$r->set_handlers('PerlHandler'=> undef); |
if (($url =~ /\.sequence$/) && |
return DECLINED; |
($env{'course.'.$env{'request.course.id'}.'.type'} ne 'Placement')) { |
|
$realuri .= '?navmap=1'; |
|
} else { |
|
$realuri .= '?symb='.&Apache::lonenc::encrypted($symb); |
|
} |
|
} else { |
|
$realuri = &Apache::lonnet::clutter($url); |
|
if (($url =~ /\.sequence$/) && |
|
($env{'course.'.$env{'request.course.id'}.'.type'} ne 'Placement')) { |
|
$realuri .= '?navmap=1'; |
|
} else { |
|
$realuri .= '?symb='.$symb; |
|
} |
|
} |
|
my $host = $r->headers_in->get('Host'); |
|
if ($r->is_initial_req() || !$host) { |
|
$r->internal_redirect($realuri); |
|
return OK; |
|
} else { |
|
my $protocol = 'http'; |
|
if ($r->get_server_port == 443) { |
|
$protocol = 'https'; |
|
} |
|
my $location = $protocol.'://'.$host.$realuri; |
|
$r->headers_out->set(Location => $location); |
|
return REDIRECT; |
|
} |
|
} |
} |
} |
} |
} |
} |
} |
} |
} |
my $protocol = 'http'; |
} |
my $port = $r->get_server_port(); |
} |
if ($port eq '443') { |
} elsif ($r->uri=~m{^/raw/}) { |
$protocol = 'https'; |
my $host = $r->headers_in->get('Host'); |
} |
if ($host) { |
if ($uri =~ m{^(/adm/css/)(.+)(.css)$}) { |
unless ($host =~ /^internal\-/) { |
$uri = $1.&escape($2).$3; |
my $remote_ip = $r->get_remote_host(); |
} |
my $lonhost = $r->dir_config('lonHostID'); |
my $location = $protocol.'://'.$redirect.$uri; |
if (&redirect_raw($remote_ip,$lonhost)) { |
if ($r->args) { |
my $location = 'https://internal-'.$host.$r->uri; |
$location .= '?'.$r->args; |
$r->headers_out->set(Location => $location); |
|
return REDIRECT; |
} |
} |
$r->header_out(Location => $location); |
|
return REDIRECT; |
|
} |
} |
} |
} |
} |
} |
Line 141 sub handler {
|
Line 138 sub handler {
|
'/userfiles/'.(join('/',@ufile))); |
'/userfiles/'.(join('/',@ufile))); |
} |
} |
return OK; |
return OK; |
} elsif ($r->uri =~ m{^\Q/adm/wrapper/ext/https:/\E[^/]}) { |
} else { |
my $uri = $r->uri; |
return DECLINED; |
$uri =~ s{^(\Q/adm/wrapper/ext/https:/\E)}{$1/}; |
|
$r->uri($uri); |
|
} |
} |
return DECLINED; |
|
} |
} |
|
|
sub set_token { |
sub redirect_raw { |
my ($r,$dest,$remote_ip,$userref) = @_; |
my ($remote_ip,$lonhost) = @_; |
my (%info,%user); |
my @remhostids = &Apache::lonnet::get_hosts_from_ip($remote_ip); |
if ($dest eq '/adm/migrateuser') { |
my $redirect; |
return unless (ref($userref) eq 'HASH'); |
while (@remhostids) { |
%user = %{$userref}; |
my $try_server = pop(@remhostids); |
%info = ('ip' => $remote_ip, |
my $remhostname = &Apache::lonnet::hostname($try_server); |
'domain' => $user{'domain'}, |
if ($remhostname) { |
'username' => $user{'name'}, |
my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$try_server); |
'server' => $r->dir_config('lonHostID'), |
my ($remmajor,$remminor) = ($remoterev =~ /^(\d+)\.(\d+)/); |
); |
if (($remmajor > 2) || (($remmajor == 2) && $remminor >= 12)) { |
} |
my $internet_names = &Apache::lonnet::get_internet_names($try_server); |
if ($r->args) { |
if (ref($internet_names) eq 'ARRAY') { |
foreach my $pair (split(/&/,$r->args)) { |
my $intdom = &Apache::lonnet::internet_dom($lonhost); |
my ($name,$value) = split(/=/,$pair); |
unless (grep(/^\Q$intdom\E$/,@{$internet_names})) { |
$name = &LONCAPA::unescape($name); |
my $lonhostname = &Apache::lonnet::hostname($lonhost); |
next unless (($name eq 'role') || ($name eq 'symb')); |
my $serverhomeID = &Apache::lonnet::get_server_homeID($lonhostname); |
$value =~ tr/+/ /; |
my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID); |
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; |
my %domdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom); |
$info{$name} = $value; |
my $replication = $domdefaults{'replication'}; |
} |
if (ref($replication) eq 'HASH') { |
} |
my $remhomeID = &Apache::lonnet::get_server_homeID($remhostname); |
if ($dest eq '/adm/migrateuser') { |
my $remhomedom = &Apache::lonnet::host_domain($remhomeID); |
unless ($info{'role'}) { |
my $remprimary = &Apache::lonnet::domain($remhomedom,'primary'); |
if ($user{'role'} ne '') { |
my $remintdom = &Apache::lonnet::internet_dom($remprimary); |
$info{'role'} = $user{'role'}; |
if (ref($replication->{'certreq'}) eq 'ARRAY') { |
} |
if (grep(/^\Q$remintdom\E$/,@{$replication->{'certreq'}})) { |
} |
$redirect = 0; |
unless ($info{'symb'}) { |
} else { |
unless ($r->uri eq '/adm/roles') { |
$redirect = 1; |
$info{'origurl'} = $r->uri; |
} |
|
} |
|
if (ref($replication->{'nocertreq'}) eq 'ARRAY') { |
|
if (grep(/^\Q$remintdom\E$/,@{$replication->{'nocertreq'}})) { |
|
$redirect = 1; |
|
} else { |
|
$redirect = 0; |
|
} |
|
} |
|
} |
|
} |
|
} |
} |
} |
|
last; |
} |
} |
} |
} |
if (($dest eq '/adm/migrateuser') || (keys(%info) > 0)) { |
return $redirect; |
unless ($dest eq '/adm/migrateuser') { |
|
$info{'origurl'} = $r->uri; |
|
} |
|
my $token = &Apache::lonnet::tmpput(\%info,$r->dir_config('lonHostID'),'link'); |
|
unless (($token eq 'con_lost') || ($token eq 'refused') || |
|
($token eq 'unknown_cmd') || ($token eq 'no_such_host')) { |
|
return $token; |
|
} |
|
} |
|
return; |
|
} |
} |
|
|
1; |
1; |
__END__ |
__END__ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|