--- loncom/auth/lonlogin.pm 2021/12/12 11:47:03 1.158.2.13 +++ loncom/auth/lonlogin.pm 2021/12/31 21:56:01 1.158.2.13.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network # Login Screen # -# $Id: lonlogin.pm,v 1.158.2.13 2021/12/12 11:47:03 raeburn Exp $ +# $Id: lonlogin.pm,v 1.158.2.13.2.1 2021/12/31 21:56:01 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -49,7 +49,8 @@ sub handler { (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'}, $ENV{'REDIRECT_QUERY_STRING'}), ['interface','username','domain','firsturl','localpath','localres', - 'token','role','symb','iptoken','btoken','saml','sso','retry']); + 'token','role','symb','iptoken','btoken','ltoken','ttoken','linkkey', + 'saml','sso','retry']); # -- check if they are a migrating user if (defined($env{'form.token'})) { @@ -57,7 +58,20 @@ sub handler { } my $lonhost = $r->dir_config('lonHostID'); - if (($env{'form.sso'}) || ($env{'form.retry'})) { + if ($env{'form.ttoken'}) { + my %info = &Apache::lonnet::tmpget($env{'form.ttoken'}); + &Apache::lonnet::tmpdel($env{'form.ttoken'}); + if ($info{'origurl'}) { + $env{'form.firsturl'} = $info{'origurl'}; + } + if ($info{'ltoken'}) { + $env{'form.ltoken'} = $info{'ltoken'}; + } elsif ($info{'linkprot'}) { + $env{'form.linkprot'} = $info{'linkprot'}; + } elsif ($info{'linkkey'} ne '') { + $env{'form.linkkey'} = $info{'linkkey'}; + } + } elsif (($env{'form.sso'}) || ($env{'form.retry'})) { my $infotoken; if ($env{'form.sso'}) { $infotoken = $env{'form.sso'}; @@ -77,6 +91,15 @@ sub handler { if (!defined($env{'form.firsturl'})) { &Apache::lonacc::get_posted_cgi($r,['firsturl']); } + if (!defined($env{'form.firsturl'})) { + if ($ENV{'REDIRECT_URL'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) { + $env{'form.firsturl'} = $ENV{'REDIRECT_URL'}; + } + } + if (($env{'form.firsturl'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) && + (!$env{'form.ltoken'}) && (!$env{'form.linkprot'}) && (!$env{'form.linkkey'})) { + &Apache::lonacc::get_posted_cgi($r,['linkkey']); + } if ($env{'form.firsturl'} eq '/adm/logout') { delete($env{'form.firsturl'}); } @@ -152,6 +175,24 @@ sub handler { ($balancer_token eq 'unknown_cmd') || ($balancer_token eq 'no_such_host')) { $dest .= (($dest=~/\?/)?'&':'?') . 'btoken='.$balancer_token; } + if ($env{'form.firsturl'} =~ m{^/tiny/$match_domain/\w+$}) { + my %link_info; + if ($env{'form.ltoken'}) { + $link_info{'ltoken'} = $env{'form.ltoken'}; + } elsif ($env{'form.linkprot'}) { + $link_info{'linkprot'} = $env{'form.linkprot'}; + } elsif ($env{'form.linkkey'} ne '') { + $link_info{'linkkey'} = $env{'form.linkkey'}; + } + if (keys(%link_info)) { + $link_info{'origurl'} = $env{'form.firsturl'}; + my $token = &Apache::lonnet::tmpput(\%link_info,$found_server,'link'); + unless (($token eq 'con_lost') || ($token eq 'refused') || + ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) { + $dest .= (($dest=~/\?/)?'&':'?') . 'ttoken='.$token; + } + } + } unless ($found_server eq $lonhost) { my $alias = &Apache::lonnet::use_proxy_alias($r,$found_server); $hostname = $alias if ($alias ne ''); @@ -207,6 +248,62 @@ sub handler { if ($env{'form.firsturl'} ne '') { $dest = &HTML::Entities::encode($env{'form.firsturl'},'\'"<>&'); } + if (($env{'form.ltoken'}) || ($env{'form.linkprot'})) { + my $linkprot; + if ($env{'form.ltoken'}) { + my %info = &Apache::lonnet::tmpget($env{'form.ltoken'}); + $linkprot = $info{'linkprot'}; + my $delete = &Apache::lonnet::tmpdel($env{'form.ltoken'}); + } else { + $linkprot = $env{'form.linkprot'}; + } + if ($linkprot) { + my ($linkprotector,$deeplink) = split(/:/,$linkprot,2); + if ($env{'user.linkprotector'}) { + my @protectors = split(/,/,$env{'user.linkprotector'}); + unless (grep(/^\Q$linkprotector\E$/,@protectors)) { + push(@protectors,$linkprotector); + @protectors = sort { $a <=> $b } @protectors; + &Apache::lonnet::appenv({'user.linkprotector' => join(',',@protectors)}); + } + } else { + &Apache::lonnet::appenv({'user.linkprotector' => $linkprotector }); + } + if ($env{'user.linkproturi'}) { + my @proturis = split(/,/,$env{'user.linkproturi'}); + unless (grep(/^\Q$deeplink\E$/,@proturis)) { + push(@proturis,$deeplink); + @proturis = sort @proturis; + &Apache::lonnet::appenv({'user.linkproturi' => join(',',@proturis)}); + } + } else { + &Apache::lonnet::appenv({'user.linkproturi' => $deeplink}); + } + } + } elsif ($env{'form.linkkey'} ne '') { + if ($env{'form.firsturl'} =~ m{^/tiny/$match_domain/\w+$}) { + my $linkkey = $env{'form.linkkey'}; + if ($env{'user.deeplinkkey'}) { + my @linkkeys = split(/,/,$env{'user.deeplinkkey'}); + unless (grep(/^\Q$linkkey\E$/,@linkkeys)) { + push(@linkkeys,$linkkey); + &Apache::lonnet::appenv({'user.deeplinkkey' => join(',',sort(@linkkeys))}); + } + } else { + &Apache::lonnet::appenv({'user.deeplinkkey' => $linkkey}); + } + my $deeplink = $env{'form.firsturl'}; + if ($env{'user.keyedlinkuri'}) { + my @keyeduris = split(/,/,$env{'user.keyedlinkuri'}); + unless (grep(/^\Q$deeplink\E$/,@keyeduris)) { + push(@keyeduris,$deeplink); + &Apache::lonnet::appenv({'user.keyedlinkuri' => join(',',sort(@keyeduris))}); + } + } else { + &Apache::lonnet::appenv({'user.keyedlinkuri' => $deeplink}); + } + } + } $r->print( $start_page .'

'.&mt('You are already logged in!').'

' @@ -331,13 +428,28 @@ sub handler { if ($uextkey>2147483647) { $uextkey-=4294967296; } # -------------------------------------------------------- Store away log token - my $tokenextras; - my @names = ('role','symb','iptoken'); + my ($tokenextras,$tokentype); + my @names = ('role','symb','iptoken','ltoken','linkprot','linkkey'); foreach my $name (@names) { if ($env{'form.'.$name} ne '') { - $tokenextras .= '&'.$name.'='.&escape($env{'form.'.$name}); + if ($name eq 'ltoken') { + my %info = &Apache::lonnet::tmpget($env{'form.'.$name}); + if ($info{'linkprot'}) { + $tokenextras .= '&linkprot='.&escape($info{'linkprot'}); + $tokentype = 'link'; + last; + } + } else { + $tokenextras .= '&'.$name.'='.&escape($env{'form.'.$name}); + if (($name eq 'linkkey') || ($name eq 'linkprot')) { + $tokentype = 'link'; + } + } } } + if ($tokentype) { + $tokenextras .= ":$tokentype"; + } my $logtoken=Apache::lonnet::reply( 'tmpput:'.$ukey.$lkey.'&'.&escape($firsturl).$tokenextras, $lonhost); @@ -349,6 +461,10 @@ sub handler { if ($logtoken eq 'no_such_host') { &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab'); } + if ($env{'form.ltoken'}) { + &Apache::lonnet::tmpdel($env{'form.ltoken'}); + delete($env{'form.ltoken'}); + } my $spares=''; my (@sparehosts,%spareservers); my $sparesref = &Apache::lonnet::this_host_spares($defdom); @@ -722,6 +838,13 @@ HEADER } $querystring = &HTML::Entities::encode($querystring,"'"); } + if ($env{'form.ltoken'} ne '') { + $querystring .= (($querystring eq '')?'':'&') . 'ltoken='. + &HTML::Entities::encode(&uri_escape($env{'form.ltoken'})); + } elsif ($env{'form.linkkey'}) { + $querystring .= (($querystring eq '')?'':'&') . 'linkkey='. + &HTML::Entities::encode(&uri_escape($env{'form.linkkey'})); + } if ($querystring ne '') { $ssologin .= (($ssologin=~/\?/)?'&':'?') . $querystring; } @@ -758,6 +881,11 @@ $coursecatalog ENDSAML + } else { + if ($env{'form.ltoken'}) { + &Apache::lonnet::tmpdel($env{'form.ltoken'}); + delete($env{'form.ltoken'}); + } } $r->print(< [0,$url],}); my $end_page = &Apache::loncommon::end_page();