Diff for /loncom/auth/lonlogin.pm between versions 1.191 and 1.192

version 1.191, 2021/10/10 23:22:30 version 1.192, 2021/10/26 15:52:54
Line 49  sub handler { Line 49  sub handler {
  (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},   (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
       $ENV{'REDIRECT_QUERY_STRING'}),        $ENV{'REDIRECT_QUERY_STRING'}),
  ['interface','username','domain','firsturl','localpath','localres',   ['interface','username','domain','firsturl','localpath','localres',
   'token','role','symb','iptoken','btoken','ltoken','linkkey','saml']);    'token','role','symb','iptoken','btoken','ltoken','linkkey','saml',
     if (!defined($env{'form.firsturl'})) {            'sso','retry']);
         &Apache::lonacc::get_posted_cgi($r,['firsturl']);      my $lonhost = $r->dir_config('lonHostID');
     }      my $linkkey;
     if (!defined($env{'form.firsturl'})) {      if (($env{'form.sso'}) || ($env{'form.retry'})) {
         if ($ENV{'REDIRECT_URL'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) {          my $infotoken;
             $env{'form.firsturl'} = $ENV{'REDIRECT_URL'};          if ($env{'form.sso'}) {
               $infotoken = $env{'form.sso'};
           } else {
               $infotoken = $env{'form.retry'};
           }
           my $data = &Apache::lonnet::reply('tmpget:'.$infotoken,$lonhost);
           unless (($data=~/^error/) || ($data eq 'con_lost') ||
                   ($data eq 'no_such_host')) {
               my %info = &decode_token($data);
               foreach my $item (keys(%info)) {
                   $env{'form.'.$item} = $info{$item};
               }
               &Apache::lonnet::tmpdel($infotoken);
           }
       } else {
           if ($env{'form.linkkey'}) {
               $linkkey = $env{'form.linkkey'};
           }        
           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.linkkey'})) {
               &Apache::lonacc::get_posted_cgi($r,['linkkey']);
           }
           if ($env{'form.firsturl'} eq '/adm/logout') {
               delete($env{'form.firsturl'});
         }          }
     }  
     if (($env{'form.firsturl'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) &&  
         (!$env{'form.ltoken'}) && (!$env{'form.linkkey'})) {  
         &Apache::lonacc::get_posted_cgi($r,['linkkey']);  
     }  
     if ($env{'form.firsturl'} eq '/adm/logout') {  
         delete($env{'form.firsturl'});  
     }      }
   
 # -- check if they are a migrating user  # -- check if they are a migrating user
Line 115  sub handler { Line 139  sub handler {
  return OK;   return OK;
     }      }
   
     my $lonhost = $r->dir_config('lonHostID');  
   
 # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)  # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
   
     my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1);      my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1);
Line 306  sub handler { Line 328  sub handler {
     $env{'form.interface'}=~s/\W//g;      $env{'form.interface'}=~s/\W//g;
   
     (undef,undef,undef,undef,undef,undef,my $clientmobile) =      (undef,undef,undef,undef,undef,undef,my $clientmobile) =
         &Apache::loncommon::decode_user_agent();          &Apache::loncommon::decode_user_agent($r);
   
     my $iconpath=      my $iconpath=
  &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));   &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
Line 315  sub handler { Line 337  sub handler {
     my $defdom = $domain;      my $defdom = $domain;
     if ($lonhost ne '') {      if ($lonhost ne '') {
         unless ($sessiondata{'sessionserver'}) {          unless ($sessiondata{'sessionserver'}) {
             my $redirect = &check_loginvia($domain,$lonhost,$lonidsdir,$balcookie,$linkprot);              my $redirect = &check_loginvia($domain,$lonhost,$lonidsdir,$balcookie,
                                              $linkprot,$linkkey);
             if ($redirect) {              if ($redirect) {
                 $r->print($redirect);                  $r->print($redirect);
                 return OK;                  return OK;
Line 399  sub handler { Line 422  sub handler {
     if ($uextkey>2147483647) { $uextkey-=4294967296; }      if ($uextkey>2147483647) { $uextkey-=4294967296; }
   
 # -------------------------------------------------------- Store away log token  # -------------------------------------------------------- Store away log token
     my $tokenextras;      my ($tokenextras,$tokentype);
     if ($env{'form.role'}) {      my @names = ('role','symb','iptoken','ltoken','linkkey');
         $tokenextras = '&role='.&escape($env{'form.role'});      foreach my $name (@names) {
     }          if ($env{'form.'.$name} ne '') {
     if ($env{'form.symb'}) {              if ($name eq 'ltoken') {
         if (!$tokenextras) {                  my %info = &Apache::lonnet::tmpget($env{'form.ltoken'});
             $tokenextras = '&';                  if ($info{'linkprot'}) {
         }                      $tokenextras .= '&linkprot='.&escape($info{'linkprot'});
         $tokenextras .= '&symb='.&escape($env{'form.symb'});                      $tokentype = 'link';
     }                      last;
     if ($env{'form.iptoken'}) {                  }
         if (!$tokenextras) {              } else {
             $tokenextras = '&&';                  $tokenextras .= '&'.$name.'='.&escape($env{'form.'.$name});
         }                  if ($name eq 'linkkey') {
         $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});                      $tokentype = 'link';
     }                  }
     if ($env{'form.ltoken'}) {  
         my %info = &Apache::lonnet::tmpget($env{'form.ltoken'});  
         if ($info{'linkprot'}) {  
             if (!$tokenextras) {  
                 $tokenextras = '&&&';  
             }              }
             $tokenextras .= '&linkprot='.&escape($info{'linkprot'});  
         }  
     } elsif ($env{'form.linkkey'}) {  
         if (!$tokenextras) {  
             $tokenextras = '&&&';  
         }          }
         $tokenextras .= '&linkkey='.&escape($env{'form.linkkey'});      }
       if ($tokentype) {
           $tokenextras .= ":$tokentype";
     }      }
     my $logtoken=Apache::lonnet::reply(      my $logtoken=Apache::lonnet::reply(
        'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,         'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
Line 811  HEADER Line 826  HEADER
         if ($samlssourl  ne '') {          if ($samlssourl  ne '') {
             $ssologin = $samlssourl;              $ssologin = $samlssourl;
         }          }
         if ($env{'form.firsturl'} ne '') {          if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
             my $querystring = 'origurl=';              my $querystring;
             if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) {              if ($env{'form.firsturl'} ne '') {
                 $querystring .= &uri_escape_utf8($env{'form.firsturl'});                  $querystring = 'origurl=';
             } else {                  if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) {
                 $querystring .= &uri_escape($env{'form.firsturl'});                      $querystring .= &uri_escape_utf8($env{'form.firsturl'});
                   } else {
                       $querystring .= &uri_escape($env{'form.firsturl'});
                   }
                   $querystring = &HTML::Entities::encode($querystring,"'");
             }              }
             $querystring = &HTML::Entities::encode($querystring,"'");              if ($env{'form.ltoken'} ne '') {
             $ssologin .= (($ssologin=~/\?/)?'&':'?') . $querystring;                  $querystring .= (($querystring eq '')?'':'&') . 'ltoken='.
         }                                    &HTML::Entities::encode(&uri_escape($env{'form.ltoken'}));
         if ($env{'form.ltoken'} ne '') {              } elsif ($env{'form.linkkey'}) {
             $querystring .= (($querystring eq '')?'':'&') . 'ltoken='.                  $querystring .= (($querystring eq '')?'':'&') . 'linkkey='.
                               &HTML::Entities::encode(&uri_escape($env{'form.ltoken'}));                                    &HTML::Entities::encode(&uri_escape($env{'form.linkkey'}));
         } elsif ($env{'form.linkkey'}) {              }
             $querystring .= (($querystring eq '')?'':'&') . 'linkkey='.              if ($querystring ne '') {
                               &HTML::Entities::encode(&uri_escape($env{'form.linkkey'}));                  $ssologin .= (($ssologin=~/\?/)?'&':'?') . $querystring;
               }
           } elsif ($logtoken ne '') {
               $ssologin .= (($ssologin=~/\?/)?'&':'?') . 'logtoken='.$logtoken;
         }          }
         my $ssohref;          my $ssohref;
         if ($samlssoimg ne '') {          if ($samlssoimg ne '') {
Line 978  ENDDOCUMENT Line 1000  ENDDOCUMENT
 }  }
   
 sub check_loginvia {  sub check_loginvia {
     my ($domain,$lonhost,$lonidsdir,$balcookie,$linkprot) = @_;      my ($domain,$lonhost,$lonidsdir,$balcookie,$linkprot,$linkkey) = @_;
     if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {      if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {
         return;          return;
     }      }
Line 1038  sub check_loginvia { Line 1060  sub check_loginvia {
                             }                              }
                         }                          }
                     }                      }
                     $output = &redirect_page($newhost,$path,$linkprot);                      $output = &redirect_page($newhost,$path,$linkprot,$linkkey);
                 }                  }
             }              }
         }          }
Line 1047  sub check_loginvia { Line 1069  sub check_loginvia {
 }  }
   
 sub redirect_page {  sub redirect_page {
     my ($desthost,$path,$linkprot) = @_;      my ($desthost,$path,$linkprot,$linkkey) = @_;
     my $hostname = &Apache::lonnet::hostname($desthost);      my $hostname = &Apache::lonnet::hostname($desthost);
     my $protocol = $Apache::lonnet::protocol{$desthost};      my $protocol = $Apache::lonnet::protocol{$desthost};
     $protocol = 'http' if ($protocol ne 'https');      $protocol = 'http' if ($protocol ne 'https');
Line 1063  sub redirect_page { Line 1085  sub redirect_page {
             $querystring = &uri_escape($env{'form.firsturl'});              $querystring = &uri_escape($env{'form.firsturl'});
         }          }
         $querystring = &HTML::Entities::encode($querystring,"'");          $querystring = &HTML::Entities::encode($querystring,"'");
         $url .='?firsturl='.$querystring          $url .='?firsturl='.$querystring;
     }      }
     if ($linkprot) {      if ($linkprot) {
         my $ltoken = &Apache::lonnet::tmpput({linkprot => $linkprot},$desthost);          my $ltoken = &Apache::lonnet::tmpput({linkprot => $linkprot},$desthost);
         if ($ltoken) {          if ($ltoken) {
             $url .= (($url =~ /\?/) ? '&' : '?').'ltoken='.$ltoken;              $url .= (($url =~ /\?/) ? '&' : '?').'ltoken='.$ltoken;
         }          }
       } elsif ($linkkey) {
           $url .= (($url =~ /\?/) ? '&' : '?').'linkkey='.&uri_escape($linkkey);        
     }      }
     my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,      my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
                                                     {'redirect' => [0,$url],});                                                      {'redirect' => [0,$url],});
Line 1145  sub newuser_link { Line 1169  sub newuser_link {
     return '<a href="/adm/createaccount">'.$linkname.'</a>';      return '<a href="/adm/createaccount">'.$linkname.'</a>';
 }  }
   
   sub decode_token {
       my ($info) = @_;
       my ($firsturl,@rest)=split(/\&/,$info);
       my %form;
       if ($firsturl ne '') {
           $form{'firsturl'} = &unescape($firsturl);
       }
       foreach my $item (@rest) {
           my ($key,$value) = split(/=/,$item);
           $form{$key} = &unescape($value);
       }
       return %form;
   }
   
 1;  1;
 __END__  __END__

Removed from v.1.191  
changed lines
  Added in v.1.192


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>