Diff for /loncom/auth/lonauth.pm between versions 1.121.2.23 and 1.169

version 1.121.2.23, 2021/12/16 21:48:19 version 1.169, 2021/11/03 01:04:02
Line 1 Line 1
 # The LearningOnline Network  # The LearningOnline Network
 # User Authentication Module  # User Authentication Module
 #  #
 # $Id$  # $Id$
 #  #
 # Copyright Michigan State University Board of Trustees  # Copyright Michigan State University Board of Trustees
 #  #
 # This file is part of the LearningOnline Network with CAPA (LON-CAPA).  # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
 #  #
 # LON-CAPA is free software; you can redistribute it and/or modify  # LON-CAPA is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by  # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 2 of the License, or  # the Free Software Foundation; either version 2 of the License, or
 # (at your option) any later version.  # (at your option) any later version.
 #  #
 # LON-CAPA is distributed in the hope that it will be useful,  # LON-CAPA is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of  # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.  # GNU General Public License for more details.
 #  #
 # You should have received a copy of the GNU General Public License  # You should have received a copy of the GNU General Public License
 # along with LON-CAPA; if not, write to the Free Software  # along with LON-CAPA; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #  #
 # /home/httpd/html/adm/gpl.txt  # /home/httpd/html/adm/gpl.txt
 #  #
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
 #  #
   
 package Apache::lonauth;  package Apache::lonauth;
   
 use strict;  use strict;
 use LONCAPA;  use LONCAPA qw(:DEFAULT :match);
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use CGI qw(:standard);  use CGI qw(:standard);
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::lonmenu();  use Apache::lonmenu();
 use Apache::createaccount;  use Apache::createaccount;
 use Fcntl qw(:flock);  use Apache::ltiauth;
 use Apache::lonlocal;  use Fcntl qw(:flock);
 use Apache::File();  use Apache::lonlocal;
 use HTML::Entities;  use Apache::File();
 use Digest::MD5;  use HTML::Entities;
    use Digest::MD5;
 # ------------------------------------------------------------ Successful login   
 sub success {  # ------------------------------------------------------------ Successful login
     my ($r, $username, $domain, $authhost, $lowerurl, $extra_env,  sub success {
  $form,$cid,$expirepub) = @_;      my ($r, $username, $domain, $authhost, $lowerurl, $extra_env,
    $form,$skipcritical,$cid) = @_;
 # ------------------------------------------------------------ Get cookie ready  
     my $cookie =  # ------------------------------------------------------------ Get cookie ready
  &Apache::loncommon::init_user_environment($r, $username, $domain,      my $cookie =
   $authhost, $form,   &Apache::loncommon::init_user_environment($r, $username, $domain,
   {'extra_env' => $extra_env,});    $authhost, $form,
     {'extra_env' => $extra_env,});
     my $public=($username eq 'public' && $domain eq 'public');  
       my $public=($username eq 'public' && $domain eq 'public');
     if ($public or $lowerurl eq 'noredirect') { return $cookie; }  
       if ($public or $lowerurl eq 'noredirect') { return $cookie; }
 # -------------------------------------------------------------------- Log this  
   # -------------------------------------------------------------------- Log this
     my $ip = &Apache::lonnet::get_requestor_ip();  
     &Apache::lonnet::log($domain,$username,$authhost,      my $ip = &Apache::lonnet::get_requestor_ip();
                          "Login $ip");      &Apache::lonnet::log($domain,$username,$authhost,
                            "Login $ip");
 # ------------------------------------------------- Check for critical messages  
   # ------------------------------------------------- Check for critical messages
     my @what=&Apache::lonnet::dump('critical',$domain,$username);  
     if ($what[0]) {      unless ($skipcritical) {
  if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {          my @what=&Apache::lonnet::dump('critical',$domain,$username);
     $lowerurl='/adm/email?critical=display';          if ($what[0]) {
         }      if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
     }          $lowerurl='/adm/email?critical=display';
               }
 # ------------------------------------------------------------ Get cookies ready          }
     my ($securecookie,$defaultcookie);      }
     my $ssl = $r->subprocess_env('https');  
     if ($ssl) {  # ----------------------------------------------------------- Get cookies ready
         $securecookie="lonSID=$cookie; path=/; HttpOnly; secure";      my ($securecookie,$defaultcookie);
         my $lonidsdir=$r->dir_config('lonIDsDir');      my $ssl = $r->subprocess_env('https');
         if (($lonidsdir) && (-e "$lonidsdir/$cookie.id")) {      if ($ssl) {
             my $linkname=substr(Digest::MD5::md5_hex(Digest::MD5::md5_hex(time(). {}. rand(). $$)), 0, 32).'_linked';          $securecookie="lonSID=$cookie; path=/; HttpOnly; secure";
             if (-e "$lonidsdir/$linkname.id") {          my $lonidsdir=$r->dir_config('lonIDsDir');
                 unlink("$lonidsdir/$linkname.id");          if (($lonidsdir) && (-e "$lonidsdir/$cookie.id")) {
             }              my $linkname=substr(Digest::MD5::md5_hex(Digest::MD5::md5_hex(time(). {}. rand(). $$)), 0, 32).'_linked';
             my $made_symlink = eval { symlink("$lonidsdir/$cookie.id",              if (-e "$lonidsdir/$linkname.id") {
                                               "$lonidsdir/$linkname.id"); 1 };                  unlink("$lonidsdir/$linkname.id");
             if ($made_symlink) {              }
                 $defaultcookie = "lonLinkID=$linkname; path=/; HttpOnly;";              my $made_symlink = eval { symlink("$lonidsdir/$cookie.id",
                 &Apache::lonnet::appenv({'user.linkedenv' => $linkname});                                                "$lonidsdir/$linkname.id"); 1 };
             }              if ($made_symlink) {
         }                  $defaultcookie = "lonLinkID=$linkname; path=/; HttpOnly;";
     } else {                  &Apache::lonnet::appenv({'user.linkedenv' => $linkname});
         $defaultcookie = "lonID=$cookie; path=/; HttpOnly;";              }
     }          }
 # -------------------------------------------------------- Menu script and info      } else {
     my $destination = $lowerurl;          $defaultcookie = "lonID=$cookie; path=/; HttpOnly;";
       }
     if (defined($form->{role})) {  # -------------------------------------------------------- Menu script and info
         my $envkey = 'user.role.'.$form->{role};      my $destination = $lowerurl;
         my $now=time;      if ($env{'request.lti.login'}) {
         my $then=$env{'user.login.time'};          if (($env{'request.lti.reqcrs'}) && ($env{'request.lti.reqrole'} eq 'cc')) {
         my $refresh=$env{'user.refresh.time'};              &Apache::loncommon::content_type($r,'text/html');
         my $update=$env{'user.update.time'};              if ($securecookie) {
         if (!$update) {                  $r->headers_out->add('Set-cookie' => $securecookie);
             $update = $then;              }
         }              if ($defaultcookie) {
         if (exists($env{$envkey})) {                  $r->headers_out->add('Set-cookie' => $defaultcookie);
             my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus);              }
             &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,              $r->send_http_header;
                                          \$trolecode,\$tstatus,\$tstart,\$tend);              if (ref($form) eq 'HASH') {
             if ($tstatus eq 'is') {                  $form->{'lti.login'} = $env{'request.lti.login'};
                 $destination  .= ($destination =~ /\?/) ? '&' : '?';                  $form->{'lti.reqcrs'} = $env{'request.lti.reqcrs'};
                 my $newrole = &HTML::Entities::encode($form->{role},'"<>&');                  $form->{'lti.reqrole'} = $env{'request.lti.reqrole'};
                 $destination .= 'selectrole=1&'.$newrole.'=1';                  $form->{'lti.sourcecrs'} = $env{'request.lti.sourcecrs'};
             }              }
         }              &Apache::ltiauth::lti_reqcrs($r,$domain,$form,$username,$domain);
     }              return;
     if (defined($form->{symb})) {          }
         my $destsymb = $form->{symb};          if ($env{'request.lti.selfenrollrole'}) {
         my $encrypted;              if (&Apache::ltiauth::lti_enroll($username,$domain,
         if ($destsymb =~ m{^/enc/}) {                                               $env{'request.lti.selfenrollrole'}) eq 'ok') {
             $encrypted = 1;                  $form->{'role'} = $env{'request.lti.selfenrollrole'};
             if ($cid) {                  &Apache::lonnet::delenv('request.lti.selfenrollrole');
                 $destsymb = &Apache::lonenc::unencrypted($destsymb,$cid);              } else {
             }                  &Apache::ltiauth::invalid_request($r,24);
         }              }
         $destination  .= ($destination =~ /\?/) ? '&' : '?';          }
         if ($destsymb =~ /___/) {      }
             my ($map,$resid,$desturl)=split(/___/,$destsymb);      if (defined($form->{role})) {
             $desturl = &Apache::lonnet::clutter($desturl);          my $envkey = 'user.role.'.$form->{role};
             if ($encrypted) {          my $now=time;
                 $desturl = &Apache::lonenc::encrypted($desturl,1,$cid);          my $then=$env{'user.login.time'};
                 $destsymb = $form->{symb};          my $refresh=$env{'user.refresh.time'};
             }          my $update=$env{'user.update.time'};
             $desturl = &HTML::Entities::encode($desturl,'"<>&');          if (!$update) {
             $destsymb = &HTML::Entities::encode($destsymb,'"<>&');              $update = $then;
             $destination .= 'destinationurl='.$desturl.          }
                             '&destsymb='.$destsymb;          if (exists($env{$envkey})) {
         } elsif (!$encrypted) {              my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus);
             $destsymb = &HTML::Entities::encode($destsymb,'"<>&');              &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,
             $destination .= 'destinationurl='.$destsymb;                                           \$trolecode,\$tstatus,\$tstart,\$tend);
         }              if ($tstatus eq 'is') {
     }                  $destination  .= ($destination =~ /\?/) ? '&' : '?';
     if ($destination =~ m{^/adm/roles}) {                  my $newrole = &HTML::Entities::encode($form->{role},'"<>&');
         $destination  .= ($destination =~ /\?/) ? '&' : '?';                  $destination .= 'selectrole=1&'.$newrole.'=1';
         $destination .= 'source=login';              }
     }          }
       }
     my $windowinfo=&Apache::lonmenu::open($env{'browser.os'});      if (defined($form->{symb})) {
     my $startupremote=&Apache::lonmenu::startupremote($destination);          my $destsymb = $form->{symb};
     my $remoteinfo=&Apache::lonmenu::load_remote_msg($lowerurl);          my $encrypted;
     my $setflags=&Apache::lonmenu::setflags();          if ($destsymb =~ m{^/enc/}) {
     my $maincall=&Apache::lonmenu::maincall();              $encrypted = 1;
     my $brcrum = [{'href' => '',              if ($cid) {
                    'text' => 'Successful Login'},];                  $destsymb = &Apache::lonenc::unencrypted($destsymb,$cid);
     my $start_page=&Apache::loncommon::start_page('Successful Login',              }
                                                   $startupremote,          }
                                                   {'no_inline_link' => 1,          $destination  .= ($destination =~ /\?/) ? '&' : '?';
                                                    'bread_crumbs' => $brcrum,});          if ($destsymb =~ /___/) {
     my $end_page  =&Apache::loncommon::end_page();              my ($map,$resid,$desturl)=split(/___/,$destsymb);
               $desturl = &Apache::lonnet::clutter($desturl);
     my $continuelink;              if ($encrypted) {
     if ($env{'environment.remote'} eq 'off') {                  $desturl = &Apache::lonenc::encrypted($desturl,1,$cid);
  $continuelink='<a href="'.$destination.'">'.&mt('Continue').'</a>';                  $destsymb = $form->{symb};
     }              }
 # ------------------------------------------------- Output for successful login              $desturl = &HTML::Entities::encode($desturl,'"<>&');
               $destsymb = &HTML::Entities::encode($destsymb,'"<>&');
     &Apache::loncommon::content_type($r,'text/html');              $destination .= 'destinationurl='.$desturl.
     if ($securecookie) {                              '&destsymb='.$destsymb;
         $r->headers_out->add('Set-cookie' => $securecookie);          } elsif (!$encrypted) {
     }              $destsymb = &HTML::Entities::encode($destsymb,'"<>&');
     if ($defaultcookie) {              $destination .= 'destinationurl='.$destsymb;
         $r->headers_out->add('Set-cookie' => $defaultcookie);          }
     }      }
     if ($expirepub) {      if ($destination =~ m{^/adm/roles}) {
         my $c = new CGI::Cookie(-name    => 'lonPubID',          $destination  .= ($destination =~ /\?/) ? '&' : '?';
                                 -value   => '',          $destination .= 'source=login';
                                 -expires => '-10y',);      }
         $r->headers_out->add('Set-cookie' => $c);  
     }      if (($env{'request.deeplink.login'} eq $lowerurl) &&
     $r->send_http_header;          (($env{'request.linkprot'}) || ($env{'request.linkkey'} ne ''))) {
           my %info;
     my %lt=&Apache::lonlocal::texthash(          if ($env{'request.linkprot'}) {
        'wel' => 'Welcome',              $info{'linkprot'} = $env{'request.linkprot'};
        'pro' => 'Login problems?',          } elsif ($env{'request.linkkey'} ne '') {
        );              $info{'linkkey'} = $env{'request.linkkey'};
     my $loginhelp = &loginhelpdisplay($domain);          }
     if ($loginhelp) {          $info{'origurl'} = $lowerurl;
         $loginhelp = '<p><a href="'.$loginhelp.'">'.$lt{'pro'}.'</a></p>';          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')) {
     my $welcome = &mt('Welcome to the Learning[_1]Online[_2] Network with CAPA. Please wait while your session is being set up.','<i>','</i>');               $destination .= (($destination =~ /\?/) ? '&' : '?') . 'ttoken='.$token;
     $r->print(<<ENDSUCCESS);          }
 $start_page      }
 $setflags  
 $windowinfo      my $windowname = 'loncapaclient';
 <h1>$lt{'wel'}</h1>      if ($env{'request.lti.login'}) {
 $welcome          $windowname .= 'lti';
 $loginhelp      }
 $remoteinfo      my $windowinfo = Apache::lonhtmlcommon::scripttag('self.name="'.$windowname.'";');
 $maincall      my $brcrum = [{'href' => '',
 $continuelink                     'text' => 'Successful Login'},];
 $end_page      my $args = {'bread_crumbs' => $brcrum,};
 ENDSUCCESS      unless ((defined($form->{role})) || (defined($form->{symb}))) {
     return;          my $update=$env{'user.update.time'};
 }          if (!$update) {
               $update = $env{'user.login.time'};
 # --------------------------------------------------------------- Failed login!          }
           my %roles_in_env;
 sub failed {          my $showcount = &Apache::lonroles::roles_from_env(\%roles_in_env,$update);
     my ($r,$message,$form,$authhost) = @_;          if ($showcount == 1) {
     (undef,undef,undef,my $clientmathml,my $clientunicode) =              foreach my $rolecode (keys(%roles_in_env)) {
         &Apache::loncommon::decode_user_agent();                  my ($cid) = ($rolecode =~ m{^\Quser.role.st./\E($match_domain/$match_courseid)(?:/|$)});
     my $args = {};                  if ($cid) {
     if ($clientunicode && !$clientmathml) {                      my %coursedescription =
         $args = {'browser.unicode' => 1};                          &Apache::lonnet::coursedescription($cid,{'one_time' => '1'});
     }                      if ($coursedescription{'type'} eq 'Placement') {
                           $args->{'crstype'} = 'Placement';
     my $start_page = &Apache::loncommon::start_page('Unsuccessful Login',undef,$args);                      }
     my $uname = &Apache::loncommon::cleanup_html($form->{'uname'});                      last;
     my $udom = &Apache::loncommon::cleanup_html($form->{'udom'});                  }
     if (&Apache::lonnet::domain($udom,'description') eq '') {              }
         undef($udom);          }
     }      }
     my $retry = '/adm/login';  
     if ($uname eq $form->{'uname'}) {  # ------------------------------------------------- Output for successful login
         $retry .= '?username='.$uname;  
     }      &Apache::loncommon::content_type($r,'text/html');
     if ($udom) {      if ($securecookie) {
         $retry .= (($retry=~/\?/)?'&amp;':'?').'domain='.$udom;          $r->headers_out->add('Set-cookie' => $securecookie);
     }      }
     my $lonhost = $r->dir_config('lonHostID');      if ($defaultcookie) {
     my $querystr;          $r->headers_out->add('Set-cookie' => $defaultcookie);
     my $result = &set_retry_token($form,$lonhost,\$querystr);      }
     if ($result eq 'fail') {      $r->send_http_header;
         if (exists($form->{role})) {  
             my $role = &Apache::loncommon::cleanup_html($form->{role});      my ($start_page,$js,$pagebody,$end_page);
             if ($role ne '') {      if ($env{'request.lti.login'}) {
                 $retry .= (($retry=~/\?/)?'&amp;':'?').'role='.$role;          $args = {'only_body' => 1};
             }          if ($env{'request.lti.target'} eq '') {
         }              my $ltitarget = (($destination =~ /\?/) ? '&' : '?').
         if (exists($form->{symb})) {                              'ltitarget=iframe';
             my $symb = &Apache::loncommon::cleanup_html($form->{symb});              $js = <<"ENDJS";
             if ($symb ne '') {  
                 $retry .= (($retry=~/\?/)?'&amp;':'?').'symb='.$symb;  <script type="text/javascript">
             }  // <![CDATA[
         }  function setLTItarget() {
         if (exists($form->{firsturl})) {      var newloc = '$destination';
             my $firsturl = &Apache::loncommon::cleanup_html($form->{firsturl});      if (parent !== window) {
             if ($firsturl ne '') {          newloc += '$ltitarget';
                 $retry .= (($retry=~/\?/)?'&amp;':'?').'firsturl='.$firsturl;      }
             }      window.location.href=newloc;
         }  }
     } elsif ($querystr ne '') {  // ]]>
         $retry .= (($retry=~/\?/)?'&amp;':'?').$querystr;  </script>
     }  
     my $end_page = &Apache::loncommon::end_page();  ENDJS
     &Apache::loncommon::content_type($r,'text/html');              $args->{'add_entries'} = {'onload' => "javascript:setLTItarget();"};
     $r->send_http_header;              $pagebody =  '<noscript><span class="LC_warning">'
     my @actions =                          .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
          (&mt('Please [_1]log in again[_2].','<a href="'.$retry.'">','</a>'));                          .'</span></noscript>';
     my $loginhelp = &loginhelpdisplay($udom);          } else {
     if ($loginhelp) {              $args->{'redirect'} = [0,$destination,1];
         push(@actions, '<a href="'.$loginhelp.'">'.&mt('Login problems?').'</a>');          }
     }          $start_page=&Apache::loncommon::start_page('',$js,$args);
     #FIXME: link to helpdesk might be added here      } else {
           $args->{'redirect'} = [0,$destination];
     $r->print(          $start_page=&Apache::loncommon::start_page('Successful Login',
        $start_page                                                     $js,$args);
       .'<h2>'.&mt('Sorry ...').'</h2>'  
       .&Apache::lonhtmlcommon::confirm_success(&mt($message),1).'<br /><br />'          my %lt=&Apache::lonlocal::texthash(
       .&Apache::lonhtmlcommon::actionbox(\@actions)             'wel' => 'Welcome',
       .$end_page             'pro' => 'Login problems?',
     );            );
  }          $pagebody = "<h1>$lt{'wel'}</h1>\n".
                       &mt('Welcome to the Learning[_1]Online[_2] Network with CAPA. Please wait while your session is being set up.','<i>','</i>');
 # ------------------------------------------------------------------ Rerouting!          my $loginhelp = &loginhelpdisplay($domain);
           if ($loginhelp) {
 sub reroute {              $pagebody .= '<p><a href="'.$loginhelp.'">'.$lt{'pro'}.'</a></p>';
     my ($r) = @_;          }
     &Apache::loncommon::content_type($r,'text/html');      }
     $r->send_http_header;      $end_page = &Apache::loncommon::end_page();
     my $msg='<b>'.&mt('Sorry ...').'</b><br />'      $r->print(<<ENDSUCCESS);
            .&mt('Please [_1]log in again[_2].');  $start_page
     &Apache::loncommon::simple_error_page($r,'Rerouting',$msg,{'no_auto_mt_msg' => 1});  $windowinfo
 }  $pagebody
   $end_page
 # ---------------------------------------------------------------- Main handler  ENDSUCCESS
       return;
 sub handler {  }
     my $r = shift;  
     my $londocroot = $r->dir_config('lonDocRoot');  # --------------------------------------------------------------- Failed login!
 # Are we re-routing?  
     if (-e "$londocroot/lon-status/reroute.txt") {  sub failed {
  &reroute($r);      my ($r,$message,$form) = @_;
  return OK;      (undef,undef,undef,my $clientmathml,my $clientunicode) =
     }          &Apache::loncommon::decode_user_agent();
       my $args = {};
     &Apache::lonlocal::get_language_handle($r);      if ($clientunicode && !$clientmathml) {
           $args = {'browser.unicode' => 1};
 # -------------------------------- Prevent users from attempting to login twice      }
     my $handle = &Apache::lonnet::check_for_valid_session($r);  
     if ($handle ne '') {      my $start_page = &Apache::loncommon::start_page('Unsuccessful Login',undef,$args);
         my $lonidsdir=$r->dir_config('lonIDsDir');      my $uname = &Apache::loncommon::cleanup_html($form->{'uname'});
         if ($handle=~/^publicuser\_/) {      my $udom = &Apache::loncommon::cleanup_html($form->{'udom'});
 # For "public user" - remove it, we apparently really want to login      if (&Apache::lonnet::domain($udom,'description') eq '') {
             unlink($r->dir_config('lonIDsDir')."/$handle.id");          undef($udom);
         } else {      }
 # Indeed, a valid token is found      my $retry = '/adm/login';
             &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);      if ($uname eq $form->{'uname'}) {
     &Apache::loncommon::content_type($r,'text/html');          $retry .= '?username='.$uname;
     $r->send_http_header;      }
     my $start_page =       if ($udom) {
         &Apache::loncommon::start_page('Already logged in');          $retry .= (($retry=~/\?/)?'&amp;':'?').'domain='.$udom;
     my $end_page =       }
         &Apache::loncommon::end_page();      my $lonhost = $r->dir_config('lonHostID');
             my $dest = '/adm/roles';      my $querystr;
             my %form = &get_form_items($r);      my $result = &set_retry_token($form,$lonhost,\$querystr);
             if ($form{'logtoken'}) {      if ($result eq 'fail') {
                 my $tmpinfo = &Apache::lonnet::reply('tmpget:'.$form{'logtoken'},          if (exists($form->{role})) {
                                                      $form{'serverid'});              my $role = &Apache::loncommon::cleanup_html($form->{role});
                 unless (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost') ||              if ($role ne '') {
                         ($tmpinfo eq 'no_such_host')) {                  $retry .= (($retry=~/\?/)?'&amp;':'?').'role='.$role;
                     my ($des_key,$firsturl,@rest)=split(/&/,$tmpinfo);              }
                     $firsturl = &unescape($firsturl);          }
                     my %info;          if (exists($form->{symb})) {
                     foreach my $item (@rest) {              my $symb = &Apache::loncommon::cleanup_html($form->{symb});
                         my ($key,$value) = split(/=/,$item);              if ($symb ne '') {
                         $info{$key} = &unescape($value);                  $retry .= (($retry=~/\?/)?'&amp;':'?').'symb='.$symb;
                     }              }
                     if ($firsturl ne '') {          }
                         $info{'firsturl'} = $firsturl;          if (exists($form->{firsturl})) {
                         $dest = $firsturl;              my $firsturl = &Apache::loncommon::cleanup_html($form->{firsturl});
                     }              if ($firsturl ne '') {
                 }                  $retry .= (($retry=~/\?/)?'&amp;':'?').'firsturl='.$firsturl;
             }                  if ($form->{firsturl} =~ m{^/tiny/$match_domain/\w+$}) {
             $r->print(                      unless (exists($form->{linkprot})) {
                $start_page                          if (exists($form->{linkkey})) {
               .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'                              $retry .= 'linkkey='.$form->{linkkey};
               .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].'                          }
                     ,'<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>')                      }
               .'</p>'                  }
               .$end_page              }
             );          }
             return OK;          if (exists($form->{linkprot})) {
         }              my $ltoken = &Apache::lonnet::tmpput({linkprot => $form->{'linkprot'}},
     }                                                   $r->dir_config('lonHostID'),'retry');
               if ($ltoken) {
 # ---------------------------------------------------- No valid token, continue                  $retry .= (($retry =~ /\?/) ? '&' : '?').'ltoken='.$ltoken;
               }
     my %form = &get_form_items($r);          }
     if ((!$form{'uname'}) || (!$form{'upass0'}) || (!$form{'udom'})) {      } elsif ($querystr ne '') {
  &failed($r,'Username, password and domain need to be specified.',          $retry .= (($retry=~/\?/)?'&amp;':'?').$querystr;
  \%form);      }
         return OK;      my $end_page = &Apache::loncommon::end_page();
     }      &Apache::loncommon::content_type($r,'text/html');
       $r->send_http_header;
 # split user logging in and "su"-user      my @actions =
            (&mt('Please [_1]log in again[_2].','<a href="'.$retry.'">','</a>'));
     ($form{'uname'},$form{'suname'},$form{'sudom'})=split(/\:/,$form{'uname'});      my $loginhelp = &loginhelpdisplay($udom);
     $form{'uname'} = &LONCAPA::clean_username($form{'uname'});      if ($loginhelp) {
     $form{'suname'}= &LONCAPA::clean_username($form{'suname'});          push(@actions, '<a href="'.$loginhelp.'">'.&mt('Login problems?').'</a>');
     $form{'udom'}  = &LONCAPA::clean_domain($form{'udom'});      }
     $form{'sudom'} = &LONCAPA::clean_domain($form{'sudom'});      #FIXME: link to helpdesk might be added here
   
     my $role   = $r->dir_config('lonRole');      $r->print(
     my $domain = $r->dir_config('lonDefDomain');         $start_page
     my $prodir = $r->dir_config('lonUsersDir');        .'<h2>'.&mt('Sorry ...').'</h2>'
     my $contact_name = &mt('LON-CAPA helpdesk');        .&Apache::lonhtmlcommon::confirm_success(&mt($message),1).'<br /><br />'
         .&Apache::lonhtmlcommon::actionbox(\@actions)
 # ---------------------------------------- Get the information from login token        .$end_page
       );
     my $tmpinfo=Apache::lonnet::reply('tmpget:'.$form{'logtoken'},   }
                                       $form{'serverid'});  
   # ------------------------------------------------------------------ Rerouting!
     if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost') ||   
         ($tmpinfo eq 'no_such_host')) {  sub reroute {
  &failed($r,'Information needed to verify your login information is missing, inaccessible or expired.',\%form);      my ($r) = @_;
         return OK;      &Apache::loncommon::content_type($r,'text/html');
     } else {      $r->send_http_header;
  my $reply = &Apache::lonnet::reply('tmpdel:'.$form{'logtoken'},      my $msg='<b>'.&mt('Sorry ...').'</b><br />'
    $form{'serverid'});             .&mt('Please [_1]log in again[_2].');
         if ( $reply ne 'ok' ) {      &Apache::loncommon::simple_error_page($r,'Rerouting',$msg,{'no_auto_mt_msg' => 1});
             &failed($r,'Session could not be opened.',\%form);  }
     &Apache::lonnet::logthis("ERROR got a reply of $reply when trying to contact ". $form{'serverid'}." to get login token");  
     return OK;  # ---------------------------------------------------------------- Main handler
  }  
     }  sub handler {
       my $r = shift;
     if (!&Apache::lonnet::domain($form{'udom'})) {      my $londocroot = $r->dir_config('lonDocRoot');
         &failed($r,'The domain you provided is not a valid LON-CAPA domain.',\%form);  # Are we re-routing?
         return OK;      if (-e "$londocroot/lon-status/reroute.txt") {
     }   &reroute($r);
    return OK;
     my ($des_key,$firsturl,@rest)=split(/&/,$tmpinfo);      }
     $firsturl = &unescape($firsturl);  
     foreach my $item (@rest) {      &Apache::lonlocal::get_language_handle($r);
         my ($key,$value) = split(/=/,$item);  
         $form{$key} = &unescape($value);  # -------------------------------- Prevent users from attempting to login twice
     }      my $handle = &Apache::lonnet::check_for_valid_session($r);
     my $upass = &Apache::loncommon::des_decrypt($des_key,$form{'upass0'});      if ($handle ne '') {
           my $lonidsdir=$r->dir_config('lonIDsDir');
 # ---------------------------------------------------------------- Authenticate          if ($handle=~/^publicuser\_/) {
   # For "public user" - remove it, we apparently really want to login
     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$form{'udom'});              unlink($r->dir_config('lonIDsDir')."/$handle.id");
     my ($cancreate,$statustocreate) =          } else {
         &Apache::createaccount::get_creation_controls($form{'udom'},$domconfig{'usercreation'});  # Indeed, a valid token is found
     my $defaultauth;              &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
     if (ref($cancreate) eq 'ARRAY') {      &Apache::loncommon::content_type($r,'text/html');
         if (grep(/^login$/,@{$cancreate})) {      $r->send_http_header;
             $defaultauth = 1;      my $start_page =
         }          &Apache::loncommon::start_page('Already logged in');
     }      my $end_page =
     my $clientcancheckhost = 1;          &Apache::loncommon::end_page();
     my $authhost=Apache::lonnet::authenticate($form{'uname'},$upass,              my $dest = '/adm/roles';
                                               $form{'udom'},$defaultauth,              my %form = &get_form_items($r);
                                               $clientcancheckhost);              if ($form{'logtoken'}) {
                       my $tmpinfo = &Apache::lonnet::reply('tmpget:'.$form{'logtoken'},
 # --------------------------------------------------------------------- Failed?                                                       $form{'serverid'});
                   unless (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost') ||
     if ($authhost eq 'no_host') {                          ($tmpinfo eq 'no_such_host')) {
  &failed($r,'Username and/or password could not be authenticated.',                      my ($des_key,$firsturl,@rest)=split(/&/,$tmpinfo);
  \%form);                      $firsturl = &unescape($firsturl);
         return OK;                      my %info;
     } elsif ($authhost eq 'no_account_on_host') {                      foreach my $item (@rest) {
         if ($defaultauth) {                          my ($key,$value) = split(/=/,$item);
             my $domdesc = &Apache::lonnet::domain($form{'udom'},'description');                          $info{$key} = &unescape($value);
             unless (&check_can_host($r,\%form,'no_account_on_host',$domdesc)) {                      }
                 return OK;                      if ($firsturl ne '') {
             }                          $info{'firsturl'} = $firsturl;
             my $start_page =                           $dest = $firsturl;
                 &Apache::loncommon::start_page('Create a user account in LON-CAPA',                          my $relogin;
                                                '',{'no_inline_link'   => 1,});                          if ($dest =~ m{^/tiny/$match_domain/\w+$}) {
             my $lonhost = $r->dir_config('lonHostID');                              if ($env{'request.course.id'}) {
             my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};                                  my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
             my $contacts =                                   my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                 &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',                                  my $symb = &Apache::loncommon::symb_from_tinyurl($dest,$cnum,$cdom);
                                                         $form{'udom'},$origmail);                                  if ($symb) {
             my ($contact_email) = split(',',$contacts);                                       unless (&set_deeplink_login(%info) eq 'ok') {
             my $output =                                           $relogin = 1;
                 &Apache::createaccount::username_check($form{'uname'},$form{'udom'},                                      }
                                                        $domdesc,'',$lonhost,                                  }
                                                        $contact_email,$contact_name,                              }
                                                        undef,$statustocreate);                              if ($relogin) {
             &Apache::loncommon::content_type($r,'text/html');                                  $r->print(
             $r->send_http_header;                                        $start_page
             &Apache::createaccount::print_header($r,$start_page);                                       .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
             $r->print('<h3>'.&mt('Account creation').'</h3>'.                                       .'<p>'.&mt('Please [_1]log out[_2] first, and then try your access again',
                       &mt('Although your username and password were authenticated, you do not currently have a LON-CAPA account at this institution.').'<br />'.                                                  '<a href="/adm/logout">','</a>')
                       $output.&Apache::loncommon::end_page());                                       .'</p>'
             return OK;                                       .$end_page);
         } else {                              } else {
             &failed($r,'Although your username and password were authenticated, you do not currently have a LON-CAPA account in this domain, and you are not permitted to create one.',\%form);                                  if (($info{'linkprot'}) || ($info{'linkkey'} ne '')) {
             return OK;                                      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')) {
                                           $dest .= (($dest =~ /\?/) ? '&' : '?') . 'ttoken='.$token;
     if (($firsturl eq '') ||                                       }
  ($firsturl=~/^\/adm\/(logout|remote)/)) {                                  }
  $firsturl='/adm/roles';                                  $r->print(
     }                                        $start_page
                                        .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
     my ($hosthere,%sessiondata);                                       .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4] first, and then try your access again',
     if ($form{'iptoken'}) {                                                  '<a href="'.$dest.'">','</a>',
         %sessiondata = &Apache::lonnet::tmpget($form{'iptoken'});                                                  '<a href="/adm/logout">','</a>')
         my $delete = &Apache::lonnet::tmpdel($form{'iptoken'});                                       .'</p>'
         if (($sessiondata{'domain'} eq $form{'udom'}) &&                                       .$end_page);
             ($sessiondata{'username'} eq $form{'uname'})) {                              }
             $hosthere = 1;                              return OK;
         }                          }
     }                      }
                   }
 # --------------------------------- Are we attempting to login as somebody else?              }
     if ($form{'suname'}) {              $r->print(
         my ($suname,$sudom,$sudomref);                    $start_page
         $suname = $form{'suname'};                   .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
         $sudom = $form{'udom'};                   .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].'
         if ($form{'sudom'}) {                            ,'<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>')
             unless ($sudom eq $form{'sudom'}) {                   .'</p>'
                 if (&Apache::lonnet::domain($form{'sudom'})) {                   .$end_page
                     $sudomref = [$form{'sudom'}];              );
                     $sudom = $form{'sudom'};              return OK;
                 }          }
             }      }
         }  
 # ------------ see if the original user has enough privileges to pull this stunt  # ---------------------------------------------------- No valid token, continue
  if (&Apache::lonnet::privileged($form{'uname'},$form{'udom'},$sudomref)) {  
 # ---------------------------------------------------- see if the su-user exists      my %form = &get_form_items($r);
     unless (&Apache::lonnet::homeserver($suname,$sudom) eq 'no_host') {      if ((!$form{'uname'}) || (!$form{'upass0'}) || (!$form{'udom'})) {
 # ------------------------------ see if the su-user is not too highly privileged   &failed($r,'Username, password and domain need to be specified.',
  if (&Apache::lonnet::privileged($suname,$sudom)) {   \%form);
                     &Apache::lonnet::logthis('Attempted switch user to privileged user');          return OK;
                 } else {      }
                     my $noprivswitch;  
 #  # split user logging in and "su"-user
 # su-user's home server and user's home server must have one of:  
 # (a) same domain      ($form{'uname'},$form{'suname'},$form{'sudom'})=split(/\:/,$form{'uname'});
 # (b) same primary library server for the two domains      $form{'uname'} = &LONCAPA::clean_username($form{'uname'});
 # (c) same "internet domain" for primary library server(s) for home servers' domains      $form{'suname'}= &LONCAPA::clean_username($form{'suname'});
 #      $form{'udom'}  = &LONCAPA::clean_domain($form{'udom'});
                     my $suprim = &Apache::lonnet::domain($sudom,'primary');      $form{'sudom'} = &LONCAPA::clean_domain($form{'sudom'});
                     my $suintdom = &Apache::lonnet::internet_dom($suprim);  
                     unless ($sudom eq $form{'udom'}) {      my $role   = $r->dir_config('lonRole');
                         my $uprim = &Apache::lonnet::domain($form{'udom'},'primary');      my $domain = $r->dir_config('lonDefDomain');
                         my $uintdom = &Apache::lonnet::internet_dom($uprim);      my $prodir = $r->dir_config('lonUsersDir');
                         unless ($suprim eq $uprim) {      my $contact_name = &mt('LON-CAPA helpdesk');
                             unless ($suintdom eq $uintdom) {  
                                 &Apache::lonnet::logthis('Attempted switch user '  # ---------------------------------------- Get the information from login token
                                    .'to user with different "internet domain".');  
                                 $noprivswitch = 1;      my $tmpinfo=Apache::lonnet::reply('tmpget:'.$form{'logtoken'},
                             }                                        $form{'serverid'});
                         }  
                     }      if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost') ||
           ($tmpinfo eq 'no_such_host')) {
                     unless ($noprivswitch) {   &failed($r,'Information needed to verify your login information is missing, inaccessible or expired.',\%form);
 #          return OK;
 # server where log-in occurs must have same "internet domain" as su-user's home      } else {
 # server   my $reply = &Apache::lonnet::reply('tmpdel:'.$form{'logtoken'},
 #     $form{'serverid'});
                         my $lonhost = $r->dir_config('lonHostID');          if ( $reply ne 'ok' ) {
                         my $hostintdom = &Apache::lonnet::internet_dom($lonhost);              &failed($r,'Session could not be opened.',\%form);
                         if ($hostintdom ne $suintdom) {      &Apache::lonnet::logthis("ERROR got a reply of $reply when trying to contact ". $form{'serverid'}." to get login token");
                             &Apache::lonnet::logthis('Attempted switch user on a '      return OK;
                                 .'server with a different "internet domain".');   }
                         } else {      }
   
 # -------------------------------------------------------- actually switch users      if (!&Apache::lonnet::domain($form{'udom'})) {
           &failed($r,'The domain you provided is not a valid LON-CAPA domain.',\%form);
     &Apache::lonnet::logperm('User '.$form{'uname'}.' at '.          return OK;
  $form{'udom'}.' logging in as '.$suname.':'.$sudom);      }
     $form{'uname'}=$suname;  
                             if ($form{'udom'} ne $sudom) {      my ($des_key,$firsturl,@rest)=split(/&/,$tmpinfo);
                                 $form{'udom'}=$sudom;      $firsturl = &unescape($firsturl);
                             }      foreach my $item (@rest) {
                         }          my ($key,$value) = split(/=/,$item);
                     }          $form{$key} = &unescape($value);
  }      }
     }      if ($firsturl =~ m{^/tiny/$match_domain/\w+$}) {
  } else {          $form{'firsturl'} = $firsturl;
     &Apache::lonnet::logthis('Non-privileged user attempting switch user');      }
  }      my $upass = $ENV{HTTPS} ? $form{'upass0'}
     }          : &Apache::loncommon::des_decrypt($des_key,$form{'upass0'});
   
     my ($is_balancer,$otherserver);  # ---------------------------------------------------------------- Authenticate
   
     unless ($hosthere) {      my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$form{'udom'});
         ($is_balancer,$otherserver) =      my ($cancreate,$statustocreate) =
             &Apache::lonnet::check_loadbalancing($form{'uname'},$form{'udom'},'login');          &Apache::createaccount::get_creation_controls($form{'udom'},$domconfig{'usercreation'});
         if ($is_balancer) {      my $defaultauth;
             # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)      if (ref($cancreate) eq 'ARRAY') {
             my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r);          if (grep(/^login$/,@{$cancreate})) {
             if (($found_server) && ($balancer_cookie =~ /^\Q$env{'user.domain'}\E_\Q$env{'user.name'}\E_/)) {              $defaultauth = 1;
                 $otherserver = $found_server;          }
             }      }
             if ($otherserver eq '') {      my $clientcancheckhost = 1;
                 my $lowest_load;      my $authhost=Apache::lonnet::authenticate($form{'uname'},$upass,
                 ($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($form{'udom'});                                                $form{'udom'},$defaultauth,
                 if ($lowest_load > 100) {                                                $clientcancheckhost);
                     $otherserver = &Apache::lonnet::spareserver($r,$lowest_load,$lowest_load,1,$form{'udom'});  
                 }  # --------------------------------------------------------------------- Failed?
             }  
             if ($otherserver ne '') {      if ($authhost eq 'no_host') {
                 my @hosts = &Apache::lonnet::current_machine_ids();   &failed($r,'Username and/or password could not be authenticated.',
                 if (grep(/^\Q$otherserver\E$/,@hosts)) {   \%form);
                     $hosthere = $otherserver;          return OK;
                 }      } elsif ($authhost eq 'no_account_on_host') {
             }          if ($defaultauth) {
         }              my $domdesc = &Apache::lonnet::domain($form{'udom'},'description');
     }              unless (&check_can_host($r,\%form,'no_account_on_host',$domdesc)) {
                   return OK;
     if (($is_balancer) && (!$hosthere)) {              }
         if ($otherserver) {              my $start_page =
             &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,                  &Apache::loncommon::start_page('Create a user account in LON-CAPA',
                      \%form);                                                 '',{'no_inline_link'   => 1,});
             my $switchto = '/adm/switchserver?otherserver='.$otherserver;              my $lonhost = $r->dir_config('lonHostID');
             if (($firsturl) && ($firsturl ne '/adm/switchserver') && ($firsturl ne '/adm/roles')) {              my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
                 $switchto .= '&origurl='.$firsturl;              my $contacts =
             }                  &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
             if ($form{'role'}) {                                                          $form{'udom'},$origmail);
                 $switchto .= '&role='.$form{'role'};              my ($contact_email) = split(',',$contacts);
             }              my $output =
             if ($form{'symb'}) {                  &Apache::createaccount::username_check($form{'uname'},$form{'udom'},
                 $switchto .= '&symb='.$form{'symb'};                                                         $domdesc,'',$lonhost,
             }                                                         $contact_email,$contact_name,
             $r->internal_redirect($switchto);                                                         undef,$statustocreate);
         } else {              &Apache::loncommon::content_type($r,'text/html');
             &Apache::loncommon::content_type($r,'text/html');              $r->send_http_header;
             $r->send_http_header;              &Apache::createaccount::print_header($r,$start_page);
             $r->print(&noswitch());              $r->print('<h3>'.&mt('Account creation').'</h3>'.
         }                        &mt('Although your username and password were authenticated, you do not currently have a LON-CAPA account at this institution.').'<br />'.
         return OK;                        $output.&Apache::loncommon::end_page());
     } else {              return OK;
         if (!&check_can_host($r,\%form,$authhost)) {          } else {
             my ($otherserver) = &Apache::lonnet::choose_server($form{'udom'});              &failed($r,'Although your username and password were authenticated, you do not currently have a LON-CAPA account in this domain, and you are not permitted to create one.',\%form);
             if ($otherserver) {              return OK;
                 &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,          }
                          \%form);      }
                 my $switchto = '/adm/switchserver?otherserver='.$otherserver;  
                 if (($firsturl) && ($firsturl ne '/adm/switchserver') && ($firsturl ne '/adm/roles')) {      if (($firsturl eq '') ||
                     $switchto .= '&origurl='.$firsturl;   ($firsturl=~/^\/adm\/(logout|remote)/)) {
                 }   $firsturl='/adm/roles';
                 if ($form{'role'}) {      }
                     $switchto .= '&role='.$form{'role'};  
                 }      my ($hosthere,%sessiondata);
                 if ($form{'symb'}) {      if ($form{'iptoken'}) {
                     $switchto .= '&symb='.$form{'symb'};          %sessiondata = &Apache::lonnet::tmpget($form{'iptoken'});
                 }          my $delete = &Apache::lonnet::tmpdel($form{'iptoken'});
                 $r->internal_redirect($switchto);          if (($sessiondata{'domain'} eq $form{'udom'}) &&
             } else {              ($sessiondata{'username'} eq $form{'uname'})) {
                 &Apache::loncommon::content_type($r,'text/html');              $hosthere = 1;
                 $r->send_http_header;          }
                 $r->print(&noswitch());      }
             }  
             return OK;  # --------------------------------- Are we attempting to login as somebody else?
         }      if ($form{'suname'}) {
           my ($suname,$sudom,$sudomref);
 # ------------------------------------------------------- Do the load balancing          $suname = $form{'suname'};
           $sudom = $form{'udom'};
 # ---------------------------------------------------------- Determine own load          if ($form{'sudom'}) {
         my $loadlim = $r->dir_config('lonLoadLim');              unless ($sudom eq $form{'sudom'}) {
         my $loadavg;                  if (&Apache::lonnet::domain($form{'sudom'})) {
         {                      $sudomref = [$form{'sudom'}];
             my $loadfile=Apache::File->new('/proc/loadavg');                      $sudom = $form{'sudom'};
             $loadavg=<$loadfile>;                  }
         }              }
         $loadavg =~ s/\s.*//g;          }
         my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);  # ------------ see if the original user has enough privileges to pull this stunt
         my $userloadpercent=&Apache::lonnet::userload();   if (&Apache::lonnet::privileged($form{'uname'},$form{'udom'},$sudomref)) {
   # ---------------------------------------------------- see if the su-user exists
 # ---------------------------------------------------------- Are we overloaded?      unless (&Apache::lonnet::homeserver($suname,$sudom) eq 'no_host') {
         if ((($userloadpercent>100.0)||($loadpercent>100.0))) {  # ------------------------------ see if the su-user is not too highly privileged
             my $unloaded=Apache::lonnet::spareserver($r,$loadpercent,$userloadpercent,1,$form{'udom'});   if (&Apache::lonnet::privileged($suname,$sudom)) {
             if (!$unloaded) {                      &Apache::lonnet::logthis('Attempted switch user to privileged user');
                 ($unloaded) = &Apache::lonnet::choose_server($form{'udom'});                  } else {
             }                      my $noprivswitch;
             if ($unloaded) {  #
                 &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',  # su-user's home server and user's home server must have one of:
                          undef,\%form);  # (a) same domain
                 $r->internal_redirect('/adm/switchserver?otherserver='.$unloaded.'&origurl='.$firsturl);  # (b) same primary library server for the two domains
                 return OK;  # (c) same "internet domain" for primary library server(s) for home servers' domains
             }  #
         }                      my $suprim = &Apache::lonnet::domain($sudom,'primary');
         if (($is_balancer) && ($hosthere)) {                      my $suintdom = &Apache::lonnet::internet_dom($suprim);
             $form{'noloadbalance'} = $hosthere;                      unless ($sudom eq $form{'udom'}) {
         }                          my $uprim = &Apache::lonnet::domain($form{'udom'},'primary');
         my $extra_env;                          my $uintdom = &Apache::lonnet::internet_dom($uprim);
         if (($hosthere) && ($sessiondata{'sessionserver'} ne '')) {                          unless ($suprim eq $uprim) {
             if ($sessiondata{'origurl'} ne '') {                              unless ($suintdom eq $uintdom) {
                 $firsturl = $sessiondata{'origurl'};                                  &Apache::lonnet::logthis('Attempted switch user '
                 $form{'firsturl'} = $sessiondata{'origurl'};                                     .'to user with different "internet domain".');
                 my @names = ('role','symb','linkprot','linkkey');                                  $noprivswitch = 1;
                 foreach my $item (@names) {                              }
                     if ($sessiondata{$item} ne '') {                          }
                         $form{$item} = $sessiondata{$item};                      }
                     }  
                 }                      unless ($noprivswitch) {
             }  #
         }  # server where log-in occurs must have same "internet domain" as su-user's home
         &success($r,$form{'uname'},$form{'udom'},$authhost,$firsturl,undef,  # server
                  \%form);  #
         return OK;                          my $lonhost = $r->dir_config('lonHostID');
     }                          my $hostintdom = &Apache::lonnet::internet_dom($lonhost);
 }                          if ($hostintdom ne $suintdom) {
                               &Apache::lonnet::logthis('Attempted switch user on a '
 sub get_form_items {                                  .'server with a different "internet domain".');
     my ($r) = @_;                          } else {
     my $buffer;  
     if ($r->header_in('Content-length') > 0) {  # -------------------------------------------------------- actually switch users
         $r->read($buffer,$r->header_in('Content-length'),0);  
     }              &Apache::lonnet::logperm('User '.$form{'uname'}.' at '.
     my %form;                                $form{'udom'}.' logging in as '.$suname.':'.$sudom);
     foreach my $pair (split(/&/,$buffer)) {              $form{'uname'}=$suname;
        my ($name,$value) = split(/=/,$pair);                              if ($form{'udom'} ne $sudom) {
        $value =~ tr/+/ /;                                  $form{'udom'}=$sudom;
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;                              }
        $form{$name}=$value;                          }
     }                      }
     return %form;   }
 }      }
    } else {
 sub set_retry_token {      &Apache::lonnet::logthis('Non-privileged user attempting switch user');
     my ($form,$lonhost,$querystr) = @_;   }
     if (ref($form) eq 'HASH') {      }
         my ($firsturl,$token,$extras,@names);  
         @names = ('role','symb','iptoken');      my ($is_balancer,$otherserver);
         foreach my $name (@names) {  
             if ($form->{$name} ne '') {      unless ($hosthere) {
                 $extras .= '&'.$name.'='.&escape($form->{$name});          ($is_balancer,$otherserver) =
                 last if ($name eq 'linkprot');              &Apache::lonnet::check_loadbalancing($form{'uname'},$form{'udom'},'login');
             }          if ($is_balancer) {
         }              # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
         my $firsturl = $form->{'firsturl'};              my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r);
         if (($firsturl ne '') || ($extras ne '')) {              if (($found_server) && ($balancer_cookie =~ /^\Q$env{'user.domain'}\E_\Q$env{'user.name'}\E_/)) {
             $extras .= ':retry';                  $otherserver = $found_server;
             $token = &Apache::lonnet::reply('tmpput:'.&escape($firsturl).              }
                                             $extras,$lonhost);              if ($otherserver eq '') {
             if (($token eq 'con_lost') || ($token eq 'no_such_host')) {                  my $lowest_load;
                 return 'fail';                  ($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($form{'udom'});
             } else {                  if ($lowest_load > 100) {
                 if (ref($querystr)) {                      $otherserver = &Apache::lonnet::spareserver($r,$lowest_load,$lowest_load,1,$form{'udom'});
                     $$querystr = 'retry='.$token;                  }
                 }              }
                 return 'ok';              if ($otherserver ne '') {
             }                  my @hosts = &Apache::lonnet::current_machine_ids();
         }                  if (grep(/^\Q$otherserver\E$/,@hosts)) {
     }                      $hosthere = $otherserver;
     return;                  }
 }              }
           }
 sub check_can_host {      }
     my ($r,$form,$authhost,$domdesc) = @_;  
     return unless (ref($form) eq 'HASH');      if (($is_balancer) && (!$hosthere)) {
     my $canhost = 1;          if ($otherserver) {
     my $lonhost = $r->dir_config('lonHostID');              &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
     my $udom = $form->{'udom'};                       \%form);
     my @intdoms;              my $switchto = '/adm/switchserver?otherserver='.$otherserver;
     my $internet_names = &Apache::lonnet::get_internet_names($lonhost);              if (($firsturl) && ($firsturl ne '/adm/switchserver') && ($firsturl ne '/adm/roles')) {
     if (ref($internet_names) eq 'ARRAY') {                  $switchto .= '&origurl='.$firsturl;
         @intdoms = @{$internet_names};              }
     }              if ($form{'role'}) {
     my $uprimary_id = &Apache::lonnet::domain($udom,'primary');                  $switchto .= '&role='.$form{'role'};
     my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);              }
     unless ($uint_dom ne '' && grep(/^\Q$uint_dom\E$/,@intdoms)) {              if ($form{'symb'}) {
         my $machine_dom = &Apache::lonnet::host_domain($lonhost);                  $switchto .= '&symb='.$form{'symb'};
         my $hostname = &Apache::lonnet::hostname($lonhost);              }
         my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);              if ($form{'linkprot'}) {
         my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);                  $env{'request.linkprot'} = $form{'linkprot'};
         my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);              } elsif ($form{'linkkey'} ne '') {
         my %udomdefaults = &Apache::lonnet::get_domain_defaults($udom);                  $env{'request.linkkey'} = $form{'linkkey'};
         my $loncaparev;              }
         if ($authhost eq 'no_account_on_host') {              if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
             $loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom);                  &set_deeplink_login(%form);
         } else {              }
             $loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom,$lonhost);              $r->internal_redirect($switchto);
         }          } else {
         $canhost = &Apache::lonnet::can_host_session($udom,$lonhost,$loncaparev,              &Apache::loncommon::content_type($r,'text/html');
                                                      $udomdefaults{'remotesessions'},              $r->send_http_header;
                                                      $defdomdefaults{'hostedsessions'});              $r->print(&noswitch());
     }          }
     unless ($canhost) {          return OK;
         if ($authhost eq 'no_account_on_host') {      } else {
             my $checkloginvia = 1;          if (!&check_can_host($r,\%form,$authhost)) {
             my ($login_host,$hostname) =               my ($otherserver) = &Apache::lonnet::choose_server($form{'udom'});
                 &Apache::lonnet::choose_server($udom,$checkloginvia);              if ($otherserver) {
             &Apache::loncommon::content_type($r,'text/html');                  &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
             $r->send_http_header;                           \%form);
             if ($login_host ne '') {                  my $switchto = '/adm/switchserver?otherserver='.$otherserver;
                 my $protocol = $Apache::lonnet::protocol{$login_host};                  if (($firsturl) && ($firsturl ne '/adm/switchserver') && ($firsturl ne '/adm/roles')) {
                 $protocol = 'http' if ($protocol ne 'https');                      $switchto .= '&origurl='.$firsturl;
                 my $alias = &Apache::lonnet::use_proxy_alias($r,$login_host);                  }
                 $hostname = $alias if ($alias ne '');                  if ($form{'role'}) {
                 my $newurl = $protocol.'://'.$hostname.'/adm/createaccount';                      $switchto .= '&role='.$form{'role'};
                 $r->print(&Apache::loncommon::start_page('Create a user account in LON-CAPA').                  }
                           '<h3>'.&mt('Account creation').'</h3>'.                  if ($form{'symb'}) {
                           &mt('You do not currently have a LON-CAPA account at this institution.').'<br />'.                      $switchto .= '&symb='.$form{'symb'};
                           '<p>'.&mt('You will be able to create one by logging into a LON-CAPA server within the [_1] domain.',$domdesc).'</p>'.                  }
                           '<p>'.&mt('[_1]Log in[_2]','<a href="'.$newurl.'">','</a>').                  if ($form{'linkprot'}) {
                           &Apache::loncommon::end_page());                      $env{'request.linkprot'} = $form{'linkprot'};
             } else {                  } elsif ($form{'linkkey'} ne '') {
                 $r->print(&Apache::loncommon::start_page('Access to LON-CAPA unavailable').                      $env{'request.linkkey'} = $form{'linkkey'};
                           '<h3>'.&mt('Account creation unavailable').'</h3>'.                  }
                           &mt('You do not currently have a LON-CAPA account at this institution.').'<br />'.                  if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
                           '<p>'.&mt('Currently a LON-CAPA server is not available within the [_1] domain for you to log-in to, to create an account.',$domdesc).'</p>'.                      &set_deeplink_login(%form);
                           &Apache::loncommon::end_page());                  }
             }                  $r->internal_redirect($switchto);
         } else {              } else {
             &success($r,$form->{'uname'},$udom,$authhost,'noredirect',undef,                  &Apache::loncommon::content_type($r,'text/html');
                      $form);                  $r->send_http_header;
             my ($otherserver) = &Apache::lonnet::choose_server($udom);                  $r->print(&noswitch());
             $r->internal_redirect('/adm/switchserver?otherserver='.$otherserver);              }
         }              return OK;
     }          }
     return $canhost;  
 }  # ------------------------------------------------------- Do the load balancing
   
 sub noswitch {  # ---------------------------------------------------------- Determine own load
     my $result = &Apache::loncommon::start_page('Access to LON-CAPA unavailable').          my $loadlim = $r->dir_config('lonLoadLim');
                  '<h3>'.&mt('Session unavailable').'</h3>'.          my $loadavg;
                  &mt('This LON-CAPA server is unable to host your session.').'<br />'.          {
                  '<p>'.&mt('Currently no other LON-CAPA server is available to host your session either.').'</p>'.              my $loadfile=Apache::File->new('/proc/loadavg');
                  &Apache::loncommon::end_page();              $loadavg=<$loadfile>;
     return $result;          }
 }          $loadavg =~ s/\s.*//g;
           my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
 sub loginhelpdisplay {          my $userloadpercent=&Apache::lonnet::userload();
     my ($authdomain) = @_;  
     my $login_help = 1;  # ---------------------------------------------------------- Are we overloaded?
     my $lang = &Apache::lonlocal::current_language();          if ((($userloadpercent>100.0)||($loadpercent>100.0))) {
     if ($login_help) {              my $unloaded=Apache::lonnet::spareserver($r,$loadpercent,$userloadpercent,1,$form{'udom'});
         my $dom = $authdomain;              if (!$unloaded) {
         if ($dom eq '') {                  ($unloaded) = &Apache::lonnet::choose_server($form{'udom'});
             $dom = &Apache::lonnet::default_login_domain();              }
         }              if ($unloaded) {
         my %domconfhash = &Apache::loncommon::get_domainconf($dom);                  &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',
         my $loginhelp_url;                           undef,\%form);
         if ($lang) {                  if ($form{'linkprot'}) {
             $loginhelp_url = $domconfhash{$dom.'.login.helpurl_'.$lang};                      $env{'request.linkprot'} = $form{'linkprot'};
             if ($loginhelp_url ne '') {                  } elsif ($form{'linkkey'} ne '') {
                 return $loginhelp_url;                      $env{'request.linkkey'} = $form{'linkkey'};
             }                  }
         }                  if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
         $loginhelp_url = $domconfhash{$dom.'.login.helpurl_nolang'};                      &set_deeplink_login(%form);
         if ($loginhelp_url ne '') {                  }
             return $loginhelp_url;                  $r->internal_redirect('/adm/switchserver?otherserver='.$unloaded.'&origurl='.$firsturl);
         } else {                  return OK;
             return '/adm/loginproblems.html';              }
         }          }
     }          if (($is_balancer) && ($hosthere)) {
     return;              $form{'noloadbalance'} = $hosthere;
 }          }
           my $extra_env;
 1;          if (($hosthere) && ($sessiondata{'sessionserver'} ne '')) {
 __END__              if ($sessiondata{'origurl'} ne '') {
                   $firsturl = $sessiondata{'origurl'};
                   $form{'firsturl'} = $sessiondata{'origurl'};
                   my @names = ('role','symb','linkprot','linkkey');
                   foreach my $item (@names) {
                       if ($sessiondata{$item} ne '') {
                           $form{$item} = $sessiondata{$item};
                       }
                   }
               }
           }
           if ($form{'linkprot'}) {
               my ($linkprotector,$uri) = split(/:/,$form{'linkprot'},2);
               if ($linkprotector) {
                   $extra_env = {'user.linkprotector' => $linkprotector,
                                 'user.linkproturi'   => $uri};
               }
           } elsif ($form{'linkkey'} ne '') {
               $extra_env = {'user.deeplinkkey'  => $form{'linkkey'},
                             'user.keyedlinkuri' => $form{'firsturl'}};
           }
           if ($form{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
               &set_deeplink_login(%form);
               if ($form{'linkprot'}) {
                   if (ref($extra_env) eq 'HASH') {
                       %{$extra_env} = ( %{$extra_env}, 'request.linkprot' => $form{'linkprot'} );
                   } else {
                       $extra_env = {'request.linkprot' => $form{'linkprot'}};
                   }
               } elsif ($form{'linkkey'} ne '') {
                   if (ref($extra_env) eq 'HASH') {
                       %{$extra_env} = ( %{$extra_env}, 'request.linkkey' => $form{'linkkey'} );
                   } else {
                       $extra_env = {'request.linkkey' => $form{'linkkey'}};
                   }
               }
               if ($env{'request.deeplink.login'}) {
                   if (ref($extra_env) eq 'HASH') {
                       %{$extra_env} = ( %{$extra_env}, 'request.deeplink.login' => $form{'firsturl'} );
                   } else {
                       $extra_env = {'request.deeplink.login' => $form{'firsturl'}};
                   }
               }
           }
           &success($r,$form{'uname'},$form{'udom'},$authhost,$firsturl,$extra_env,
                    \%form);
           return OK;
       }
   }
   
   sub get_form_items {
       my ($r) = @_;
       my $buffer;
       if ($r->header_in('Content-length') > 0) {
           $r->read($buffer,$r->header_in('Content-length'),0);
       }
       my %form;
       foreach my $pair (split(/&/,$buffer)) {
          my ($name,$value) = split(/=/,$pair);
          $value =~ tr/+/ /;
          $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
          $form{$name}=$value;
       }
       return %form;
   }
   
   sub set_deeplink_login {
       my (%form) = @_;
       my $disallow;
       if ($form{'firsturl'} =~ m{^/tiny/($match_domain)/\w+$}) {
           my $cdom = $1;
           my ($cnum,$symb) = &Apache::loncommon::symb_from_tinyurl($form{'firsturl'},'',$cdom);
           if ($symb) {
               if ($env{'request.course.id'} eq $cdom.'_'.$cnum) {
                   my $deeplink;
                   if ($symb =~ /\.(page|sequence)$/) {
                       my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($symb))[2]);
                       my $navmap = Apache::lonnavmaps::navmap->new();
                       if (ref($navmap)) {
                           $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
                       }
                   } else {
                       $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$symb);
                   }
                   if ($deeplink ne '') {
                       my ($state,$others,$listed,$scope,$protect) = split(/,/,$deeplink);
                       if (($protect ne 'none') && ($protect ne '')) {
                           my ($acctype,$item) = split(/:/,$protect);
                           if ($acctype =~ /lti(c|d)$/) {
                               unless ($form{'linkprot'} eq $item.$1.':'.$env{'request.deeplink.login'}) {
                                   $disallow = 1;
                               }
                           } elsif ($acctype eq 'key') {
                               unless ($form{'linkkey'} eq $item) {
                                   $disallow = 1;
                               }
                           }
                       }
                   }
                   unless ($disallow) {
                       $env{'request.deeplink.login'} = $form{'firsturl'};
                   }
               } else {
                   $env{'request.deeplink.login'} = $form{'firsturl'};
               }
           }
       }
       if ($disallow) {
           return;
       }
       return 'ok';
   }
   
   sub set_retry_token {
       my ($form,$lonhost,$querystr) = @_;
       if (ref($form) eq 'HASH') {
           my ($firsturl,$token,$extras,@names);
           @names = ('role','symb','linkprot','linkkey','iptoken');
           foreach my $name (@names) {
               if ($form->{$name} ne '') {
                   $extras .= '&'.$name.'='.&escape($form->{$name});
                   last if ($name eq 'linkprot');
               }
           }
           my $firsturl = $form->{'firsturl'};
           if (($firsturl ne '') || ($extras ne '')) {
               $extras .= ':retry';
               $token = &Apache::lonnet::reply('tmpput:'.&escape($firsturl).
                                               $extras,$lonhost);
               if (($token eq 'con_lost') || ($token eq 'no_such_host')) {
                   return 'fail';
               } else {
                   if (ref($querystr)) {
                       $$querystr = 'retry='.$token;
                   }
                   return 'ok';
               }
           }
       }
       return;
   }
   
   sub check_can_host {
       my ($r,$form,$authhost,$domdesc) = @_;
       return unless (ref($form) eq 'HASH');
       my $canhost = 1;
       my $lonhost = $r->dir_config('lonHostID');
       my $udom = $form->{'udom'};
       my @intdoms;
       my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
       if (ref($internet_names) eq 'ARRAY') {
           @intdoms = @{$internet_names};
       }
       my $uprimary_id = &Apache::lonnet::domain($udom,'primary');
       my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
       unless ($uint_dom ne '' && grep(/^\Q$uint_dom\E$/,@intdoms)) {
           my $machine_dom = &Apache::lonnet::host_domain($lonhost);
           my $hostname = &Apache::lonnet::hostname($lonhost);
           my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
           my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
           my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
           my %udomdefaults = &Apache::lonnet::get_domain_defaults($udom);
           my $loncaparev;
           if ($authhost eq 'no_account_on_host') {
               $loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom);
           } else {
               $loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom,$lonhost);
           }
           $canhost = &Apache::lonnet::can_host_session($udom,$lonhost,$loncaparev,
                                                        $udomdefaults{'remotesessions'},
                                                        $defdomdefaults{'hostedsessions'});
       }
       unless ($canhost) {
           if ($authhost eq 'no_account_on_host') {
               my $checkloginvia = 1;
               my ($login_host,$hostname) =
                   &Apache::lonnet::choose_server($udom,$checkloginvia);
               &Apache::loncommon::content_type($r,'text/html');
               $r->send_http_header;
               if ($login_host ne '') {
                   my $protocol = $Apache::lonnet::protocol{$login_host};
                   $protocol = 'http' if ($protocol ne 'https');
                   my $alias = &Apache::lonnet::use_proxy_alias($r,$login_host);
                   $hostname = $alias if ($alias ne '');
                   my $newurl = $protocol.'://'.$hostname.'/adm/createaccount';
   #FIXME Should preserve where user was going and linkprot by setting ltoken at $login_host
                   $r->print(&Apache::loncommon::start_page('Create a user account in LON-CAPA').
                             '<h3>'.&mt('Account creation').'</h3>'.
                             &mt('You do not currently have a LON-CAPA account at this institution.').'<br />'.
                             '<p>'.&mt('You will be able to create one by logging into a LON-CAPA server within the [_1] domain.',$domdesc).'</p>'.
                             '<p>'.&mt('[_1]Log in[_2]','<a href="'.$newurl.'">','</a>').
                             &Apache::loncommon::end_page());
               } else {
                   $r->print(&Apache::loncommon::start_page('Access to LON-CAPA unavailable').
                             '<h3>'.&mt('Account creation unavailable').'</h3>'.
                             &mt('You do not currently have a LON-CAPA account at this institution.').'<br />'.
                             '<p>'.&mt('Currently a LON-CAPA server is not available within the [_1] domain for you to log-in to, to create an account.',$domdesc).'</p>'.
                             &Apache::loncommon::end_page());
               }
           } else {
               &success($r,$form->{'uname'},$udom,$authhost,'noredirect',undef,
                        $form);
               if ($form->{'firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
                   $env{'request.deeplink.login'} = $form->{'firsturl'};
               }
               if ($form->{'linkprot'}) {
                   $env{'request.linkprot'} = $form->{'linkprot'};
               } elsif ($form->{'linkkey'} ne '') {
                   $env{'request.linkkey'} = $form->{'linkkey'};
               }
               my ($otherserver) = &Apache::lonnet::choose_server($udom);
               $r->internal_redirect('/adm/switchserver?otherserver='.$otherserver);
           }
       }
       return $canhost;
   }
   
   sub noswitch {
       my $result = &Apache::loncommon::start_page('Access to LON-CAPA unavailable').
                    '<h3>'.&mt('Session unavailable').'</h3>'.
                    &mt('This LON-CAPA server is unable to host your session.').'<br />'.
                    '<p>'.&mt('Currently no other LON-CAPA server is available to host your session either.').'</p>'.
                    &Apache::loncommon::end_page();
       return $result;
   }
   
   sub loginhelpdisplay {
       my ($authdomain) = @_;
       my $login_help = 1;
       my $lang = &Apache::lonlocal::current_language();
       if ($login_help) {
           my $dom = $authdomain;
           if ($dom eq '') {
               $dom = &Apache::lonnet::default_login_domain();
           }
           my %domconfhash = &Apache::loncommon::get_domainconf($dom);
           my $loginhelp_url;
           if ($lang) {
               $loginhelp_url = $domconfhash{$dom.'.login.helpurl_'.$lang};
               if ($loginhelp_url ne '') {
                   return $loginhelp_url;
               }
           }
           $loginhelp_url = $domconfhash{$dom.'.login.helpurl_nolang'};
           if ($loginhelp_url ne '') {
               return $loginhelp_url;
           } else {
               return '/adm/loginproblems.html';
           }
       }
       return;
   }
   
   1;
   __END__
   
   

Removed from v.1.121.2.23  
changed lines
  Added in v.1.169


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