--- loncom/auth/lonlogin.pm 2023/12/29 23:49:12 1.158.2.13.2.11 +++ loncom/auth/lonlogin.pm 2022/01/16 19:43:41 1.158.2.14 @@ -1,7 +1,7 @@ # The LearningOnline Network # Login Screen # -# $Id: lonlogin.pm,v 1.158.2.13.2.11 2023/12/29 23:49:12 raeburn Exp $ +# $Id: lonlogin.pm,v 1.158.2.14 2022/01/16 19:43:41 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -49,8 +49,7 @@ sub handler { (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'}, $ENV{'REDIRECT_QUERY_STRING'}), ['interface','username','domain','firsturl','localpath','localres', - 'token','role','symb','iptoken','btoken','ltoken','ttoken','linkkey', - 'saml','sso','retry','display']); + 'token','role','symb','iptoken','btoken','saml','sso','retry']); # -- check if they are a migrating user if (defined($env{'form.token'})) { @@ -58,25 +57,7 @@ sub handler { } my $lonhost = $r->dir_config('lonHostID'); - 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'}; - foreach my $item ('linkprotuser','linkprotexit','linkprotpbid','linkprotpburl') { - if ($info{$item} ne '') { - $env{'form.'.$item} = $info{$item}; - } - } - } elsif ($info{'linkkey'} ne '') { - $env{'form.linkkey'} = $info{'linkkey'}; - } - } elsif (($env{'form.sso'}) || ($env{'form.retry'})) { + if (($env{'form.sso'}) || ($env{'form.retry'})) { my $infotoken; if ($env{'form.sso'}) { $infotoken = $env{'form.sso'}; @@ -96,15 +77,6 @@ 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'}); } @@ -175,47 +147,11 @@ sub handler { if ($env{'form.symb'}) { $info{'symb'} = $env{'form.symb'}; } - if (($env{'form.firsturl'} eq '/adm/email') && ($env{'form.display'} ne '')) { - if ($env{'form.sso'}) { - if ($env{'form.mailrecip'}) { - $info{'display'} = &escape($env{'form.display'}); - $info{'mailrecip'} = &escape($env{'form.mailrecip'}); - } - } else { - if (($env{'form.username'}) && ($env{'form.domain'})) { - $info{'display'} = &escape($env{'form.display'}); - $info{'mailrecip'} = &escape($env{'form.username'}.':'.$env{'form.domain'}); - } - } - } my $balancer_token = &Apache::lonnet::tmpput(\%info,$found_server); unless (($balancer_token eq 'con_lost') || ($balancer_token eq 'refused') || ($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'}; - foreach my $item ('linkprotuser','linkprotexit','linkprotpbid','linkprotpburl') { - if ($env{'form.'.$item} ne '') { - $link_info{$item} = $env{'form.'.$item}; - } - } - } 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 ''); @@ -241,11 +177,6 @@ sub handler { $balcookie = $info{'balcookie'}; &Apache::lonnet::tmpdel($env{'form.btoken'}); delete($env{'form.btoken'}); - if (($env{'form.firsturl'} eq '/adm/email') && - (exists($info{'display'})) && (exists($info{'mailrecip'}))) { - $env{'form.display'} = &unescape($info{'display'}); - $env{'form.mailrecip'} = &unescape($info{'mailrecip'}); - } } # @@ -276,108 +207,6 @@ sub handler { if ($env{'form.firsturl'} ne '') { $dest = &HTML::Entities::encode($env{'form.firsturl'},'\'"<>&'); } - if (($env{'form.ltoken'}) || ($env{'form.linkprot'})) { - my ($linkprot,$linkprotuser,$linkprotexit,$linkprotpbid,$linkprotpburl); - if ($env{'form.ltoken'}) { - my %info = &Apache::lonnet::tmpget($env{'form.ltoken'}); - $linkprot = $info{'linkprot'}; - if ($info{'linkprotuser'} ne '') { - $linkprotuser = $info{'linkprotuser'}; - } - if ($info{'linkprotexit'} ne '') { - $linkprotexit = $info{'linkprotexit'}; - } - if ($info{'linkprotpbid'} ne '') { - $linkprotpbid = $info{'linkprotpbid'}; - } - if ($info{'linkprotpburl'} ne '') { - $linkprotpburl = $info{'linkprotpburl'}; - } - } else { - $linkprot = $env{'form.linkprot'}; - $linkprotuser = $env{'form.linkprotuser'}; - $linkprotexit = $env{'form.linkprotexit'}; - $linkprotpbid = $env{'form.linkprotpbid'}; - $linkprotpburl = $env{'form.linkprotpburl'}; - } - if ($linkprot) { - my ($linkprotector,$deeplink) = split(/:/,$linkprot,2); - if (($deeplink =~ m{^/tiny/$match_domain/\w+$}) && - ($linkprotuser ne '') && ($linkprotuser ne $env{'user.name'}.':'.$env{'user.domain'})) { - my $ip = &Apache::lonnet::get_requestor_ip(); - my %linkprotinfo = ( - origurl => $deeplink, - linkprot => $linkprot, - linkprotuser => $linkprotuser, - linkprotexit => $linkprotexit, - linkprotpbid => $linkprotpbid, - linkprotpburl => $linkprotpburl, - ); - if ($env{'form.ltoken'}) { - my $delete = &Apache::lonnet::tmpdel($env{'form.ltoken'}); - } - &Apache::migrateuser::logout($r,$ip,$handle,undef,undef,\%linkprotinfo); - return OK; - } - 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}); - } - } - } - if ($env{'form.ltoken'}) { - my $delete = &Apache::lonnet::tmpdel($env{'form.ltoken'}); - } - if (($env{'form.firsturl'} eq '/adm/email') && ($env{'form.display'})) { - if ($env{'form.mailrecip'}) { - if ($env{'form.mailrecip'} eq "$env{'user.name'}:$env{'user.domain'}") { - $dest .= (($dest=~/\?/)?'&':'?') . 'display='.&escape($env{'form.display'}). - '&mailrecip='.&escape($env{'form.mailrecip'}); - } - } elsif (($env{'form.username'} eq $env{'user.name'}) && ($env{'form.domain'} eq $env{'user.domain'})) { - $dest .= (($dest=~/\?/)?'&':'?') . 'display='.&escape($env{'form.display'}). - '&mailrecip='.&escape("$env{'user.name'}:$env{'form.domain'}"); - } - } $r->print( $start_page .'

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

' @@ -502,49 +331,13 @@ sub handler { if ($uextkey>2147483647) { $uextkey-=4294967296; } # -------------------------------------------------------- Store away log token - my ($tokenextras,$tokentype,$linkprot_for_login); - my @names = ('role','symb','iptoken','ltoken','linkprotuser','linkprotexit', - 'linkprot','linkkey','display','linkprotpbid','linkprotpburl'); + my $tokenextras; + my @names = ('role','symb','iptoken'); foreach my $name (@names) { if ($env{'form.'.$name} ne '') { - if ($name eq 'ltoken') { - my %info = &Apache::lonnet::tmpget($env{'form.'.$name}); - if ($info{'linkprot'}) { - $linkprot_for_login = $info{'linkprot'}; - $tokenextras .= '&linkprot='.&escape($info{'linkprot'}); - foreach my $item ('linkprotuser','linkprotexit','linkprotpbid','linkprotpburl') { - if ($info{$item}) { - $tokenextras .= '&'.$item.'='.&escape($info{$item}); - } - } - $tokentype = 'link'; - last; - } - } elsif ($env{'form.display'} && ($env{'form.firsturl'} eq '/adm/email')) { - if (($env{'form.mailrecip'}) || - ($env{'form.username'} =~ /^$match_username$/) && ($env{'form.domain'} =~ /^$match_domain$/)) { - $tokenextras .= '&'.$name.'='.&escape($env{'form.display'}); - if ($env{'form.mailrecip'}) { - $tokenextras .= '&mailrecip='.&escape($env{'form.mailrecip'}); - } else { - $tokenextras .= '&mailrecip='.&escape($env{'form.username'}.':'.$env{'form.domain'}); - } - } - } else { - $tokenextras .= '&'.$name.'='.&escape($env{'form.'.$name}); - if (($name eq 'linkkey') || ($name eq 'linkprot')) { - if ((($env{'form.retry'}) || ($env{'form.sso'})) && - (!$env{'form.ltoken'}) && ($name eq 'linkprot')) { - $linkprot_for_login = $env{'form.linkprot'}; - } - $tokentype = 'link'; - } - } + $tokenextras .= '&'.$name.'='.&escape($env{'form.'.$name}); } } - if ($tokentype) { - $tokenextras .= ":$tokentype"; - } my $logtoken=Apache::lonnet::reply( 'tmpput:'.$ukey.$lkey.'&'.&escape($firsturl).$tokenextras, $lonhost); @@ -556,10 +349,6 @@ 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); @@ -709,8 +498,7 @@ function enableInput() { ENDSCRIPT my ($lonhost_in_use,@hosts,%defaultdomconf,$saml_prefix,$saml_landing, - $samlssotext,$samlnonsso,$samlssoimg,$samlssoalt,$samlssourl,$samltooltip, - $samlwindow); + $samlssotext,$samlnonsso,$samlssoimg,$samlssoalt,$samlssourl,$samltooltip); %defaultdomconf = &Apache::loncommon::get_domainconf($defdom); @hosts = &Apache::lonnet::current_machine_ids(); $lonhost_in_use = $lonhost; @@ -731,7 +519,6 @@ ENDSCRIPT $samlssoalt = $defaultdomconf{$saml_prefix.'alt_'.$lonhost_in_use}; $samlssourl = $defaultdomconf{$saml_prefix.'url_'.$lonhost_in_use}; $samltooltip = $defaultdomconf{$saml_prefix.'title_'.$lonhost_in_use}; - $samlwindow = $defaultdomconf{$saml_prefix.'window_'.$lonhost_in_use}; } if ($saml_landing) { if ($samlssotext eq '') { @@ -751,7 +538,6 @@ function toggleLClogin() { if (document.getElementById('LC_login_text')) { document.getElementById('LC_login_text').innerHTML = '$samlnonsso'; } - if ( document.client.uname ) { document.client.uname.focus(); } if (document.getElementById('LC_SSO_login')) { document.getElementById('LC_SSO_login').style.display = 'none'; } @@ -919,7 +705,6 @@ HEADER my $stdauthformstyle = 'inline-block'; my $ssoauthstyle = 'none'; - my $sso_onclick; my $logintype; $r->print('
'); if ($saml_landing) { @@ -930,8 +715,6 @@ HEADER if ($samlssourl ne '') { $ssologin = $samlssourl; } - my $ssologin_for_js = &js_escape($ssologin); - my $querystr_for_js; if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) { my $querystring; if ($env{'form.firsturl'} ne '') { @@ -943,53 +726,18 @@ 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; - $querystr_for_js = &js_escape($querystring); } } elsif ($logtoken ne '') { $ssologin .= (($ssologin=~/\?/)?'&':'?') . 'logtoken='.$logtoken; - $querystr_for_js = &js_escape('logtoken='.$logtoken); } my $ssohref; - if ($samlwindow) { - $sso_onclick = <<"ENDJS"; -if (document.getElementById('LC_sso_login_link')) { - var ssoelem = document.getElementById('LC_sso_login_link') - ssoelem.addEventListener('click',samlWinFunction,false); - var windows = {}; - function samlWinFunction(evt) { - evt.preventDefault(); - var url = '$ssologin_for_js'; - var name = 'lcssowin'; - var querystr = '$querystr_for_js'; - if (querystr) { - url += '?'+querystr+'&lcssowin=1'; - } else { - url += '?lcssowin=1'; - } - if ((typeof windows[name] !== 'undefined') && (!windows[name].closed)) { - windows[name].close(); - } - windows[name]=window.open(url,name,'width=350,height=600'); - windows[name].focus(); - return false; - } -} -ENDJS - } if ($samlssoimg ne '') { - $ssohref = ''. + $ssohref = ''. ''.$samlssoalt.''; } else { - $ssohref = ''.$samlssotext.''; + $ssohref = ''.$samlssotext.''; } if (($env{'form.saml'} eq 'no') || (($env{'form.username'} ne '') && ($env{'form.domain'} ne ''))) { @@ -1015,51 +763,6 @@ $coursecatalog
ENDSAML - } else { - if ($env{'form.ltoken'}) { - &Apache::lonnet::tmpdel($env{'form.ltoken'}); - delete($env{'form.ltoken'}); - } - } - my $in_frame_js; - if ($linkprot_for_login) { - my ($linkprotector,$linkproturi) = split(/:/,$linkprot_for_login,2); - if (($linkprotector =~ /^\d+(c|d)$/) && ($linkproturi =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$})) { - my $set_target; - if (($env{'form.retry'}) || ($env{'form.sso'})) { - if ($linkproturi eq $env{'form.firsturl'}) { - $set_target = " document.server.target = '_self';"; - } - } else { - $set_target = < -// - -ENDJS - } - } elsif ($samlwindow) { - $in_frame_js = < -// - -ENDJS } $r->print(< -$in_frame_js