Diff for /loncom/auth/lonauth.pm between versions 1.128 and 1.143

version 1.128, 2013/11/26 01:19:12 version 1.143, 2017/02/25 20:00:36
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 DynaLoader; # for Crypt::DES version  use DynaLoader; # for Crypt::DES version
 use Crypt::DES;  use Crypt::DES;
 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 Fcntl qw(:flock);
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::File();  use Apache::File();
 use HTML::Entities;  use HTML::Entities;
    use Digest::MD5;
 # ------------------------------------------------------------ Successful login   
 sub success {  # ------------------------------------------------------------ Successful login
     my ($r, $username, $domain, $authhost, $lowerurl, $extra_env,  sub success {
  $form) = @_;      my ($r, $username, $domain, $authhost, $lowerurl, $extra_env,
    $form) = @_;
 # ------------------------------------------------------------ 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
     &Apache::lonnet::log($domain,$username,$authhost,  
                          "Login $ENV{'REMOTE_ADDR'}");      &Apache::lonnet::log($domain,$username,$authhost,
                            "Login $ENV{'REMOTE_ADDR'}");
 # ------------------------------------------------- Check for critical messages  
   # ------------------------------------------------- Check for critical messages
     my @what=&Apache::lonnet::dump('critical',$domain,$username);  
     if ($what[0]) {      my @what=&Apache::lonnet::dump('critical',$domain,$username);
  if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {      if ($what[0]) {
     $lowerurl='/adm/email?critical=display';   if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
         }      $lowerurl='/adm/email?critical=display';
     }          }
       }
 # ------------------------------------------------------------ Get cookie ready  
     $cookie="lonID=$cookie; path=/";  # ----------------------------------------------------------- Get cookies ready
 # -------------------------------------------------------- Menu script and info      my ($securecookie,$defaultcookie);
     my $destination = $lowerurl;      if ($ENV{'SERVER_PORT'} == 443) {
           $securecookie="lonID=$cookie; path=/; HttpOnly; secure";
     if (defined($form->{role})) {          my $lonidsdir=$r->dir_config('lonIDsDir');
         my $envkey = 'user.role.'.$form->{role};          if (($lonidsdir) && (-e "$lonidsdir/$cookie.id")) {
         my $now=time;              my $linkname=substr(Digest::MD5::md5_hex(Digest::MD5::md5_hex(time(). {}. rand(). $$)), 0, 32).'_linked';
         my $then=$env{'user.login.time'};              if (-e "$lonidsdir/$linkname.id") {
         my $refresh=$env{'user.refresh.time'};                  unlink("$lonidsdir/$linkname.id");
         my $update=$env{'user.update.time'};              }
         if (!$update) {              my $made_symlink = eval { symlink("$lonidsdir/$cookie.id",
             $update = $then;                                                "$lonidsdir/$linkname.id"); 1 };
         }              if ($made_symlink) {
         if (exists($env{$envkey})) {                  $defaultcookie = "lonLinkID=$linkname; path=/; HttpOnly;";
             my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus);                  &Apache::lonnet::appenv({'user.linkedenv' => "$lonidsdir/$linkname.id"});
             &Apache::lonnet::role_status($envkey,$update,$refresh,$now,\$role,\$where,              }
                                          \$trolecode,\$tstatus,\$tstart,\$tend);          }
             if ($tstatus eq 'is') {      } else {
                 $destination  .= ($destination =~ /\?/) ? '&' : '?';          $defaultcookie = "lonID=$cookie; path=/; HttpOnly;";
                 my $newrole = &HTML::Entities::encode($form->{role},'"<>&');      }
                 $destination .= 'selectrole=1&'.$newrole.'=1';  # -------------------------------------------------------- Menu script and info
             }      my $destination = $lowerurl;
         }  
     }      if (defined($form->{role})) {
     if (defined($form->{symb})) {          my $envkey = 'user.role.'.$form->{role};
         my $destsymb = $form->{symb};          my $now=time;
         $destination  .= ($destination =~ /\?/) ? '&' : '?';          my $then=$env{'user.login.time'};
         if ($destsymb =~ /___/) {          my $refresh=$env{'user.refresh.time'};
             # FIXME Need to deal with encrypted symbs and urls as needed.          my $update=$env{'user.update.time'};
             my ($map,$resid,$desturl)=split(/___/,$destsymb);          if (!$update) {
             unless ($desturl=~/^(adm|editupload|public)/) {              $update = $then;
                 $desturl = &Apache::lonnet::clutter($desturl);          }
             }          if (exists($env{$envkey})) {
             $desturl = &HTML::Entities::encode($desturl,'"<>&');              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='.$desturl.                                           \$trolecode,\$tstatus,\$tstart,\$tend);
                             '&destsymb='.$destsymb;              if ($tstatus eq 'is') {
         } else {                  $destination  .= ($destination =~ /\?/) ? '&' : '?';
             $destsymb = &HTML::Entities::encode($destsymb,'"<>&');                  my $newrole = &HTML::Entities::encode($form->{role},'"<>&');
             $destination .= '&destinationurl='.$destsymb;                  $destination .= 'selectrole=1&'.$newrole.'=1';
         }              }
     }          }
     if ($destination =~ m{^/adm/roles}) {      }
         $destination  .= ($destination =~ /\?/) ? '&' : '?';      if (defined($form->{symb})) {
         $destination .= 'source=login';          my $destsymb = $form->{symb};
     }          $destination  .= ($destination =~ /\?/) ? '&' : '?';
           if ($destsymb =~ /___/) {
     my $windowinfo = Apache::lonhtmlcommon::scripttag('self.name="loncapaclient";');              # FIXME Need to deal with encrypted symbs and urls as needed.
     my $header = '<meta HTTP-EQUIV="Refresh" CONTENT="0; url='.$destination.'" />';              my ($map,$resid,$desturl)=split(/___/,$destsymb);
     my $brcrum = [{'href' => '',              $desturl = &Apache::lonnet::clutter($desturl);
                    'text' => 'Successful Login'},];              $desturl = &HTML::Entities::encode($desturl,'"<>&');
     my $start_page=&Apache::loncommon::start_page('Successful Login',              $destsymb = &HTML::Entities::encode($destsymb,'"<>&');
                                                   $header,              $destination .= 'destinationurl='.$desturl.
                                                   {'bread_crumbs' => $brcrum,});                              '&destsymb='.$destsymb;
     my $end_page  =&Apache::loncommon::end_page();          } else {
               $destsymb = &HTML::Entities::encode($destsymb,'"<>&');
  my $continuelink='<a href="'.$destination.'">'.&mt('Continue').'</a>';              $destination .= 'destinationurl='.$destsymb;
 # ------------------------------------------------- Output for successful login          }
       }
     &Apache::loncommon::content_type($r,'text/html');      if ($destination =~ m{^/adm/roles}) {
     $r->header_out('Set-cookie' => $cookie);          $destination  .= ($destination =~ /\?/) ? '&' : '?';
     $r->send_http_header;          $destination .= 'source=login';
       }
     my %lt=&Apache::lonlocal::texthash(  
        'wel' => 'Welcome',      my $windowinfo = Apache::lonhtmlcommon::scripttag('self.name="loncapaclient";');
        'pro' => 'Login problems?',      my $header = '<meta HTTP-EQUIV="Refresh" CONTENT="0; url='.$destination.'" />';
        );      my $brcrum = [{'href' => '',
     my $loginhelp = &loginhelpdisplay($domain);                     'text' => 'Successful Login'},];
     if ($loginhelp) {      my $args = {'bread_crumbs' => $brcrum,};
         $loginhelp = '<p><a href="'.$loginhelp.'">'.$lt{'pro'}.'</a></p>';      unless ((defined($form->{role})) || (defined($form->{symb}))) {
     }          my $update=$env{'user.update.time'};
           if (!$update) {
     my $welcome = &mt('Welcome to the Learning[_1]Online[_2] Network with CAPA. Please wait while your session is being set up.','<i>','</i>');               $update = $env{'user.login.time'};
     $r->print(<<ENDSUCCESS);          }
 $start_page          my %roles_in_env;
 $windowinfo          my $showcount = &Apache::lonroles::roles_from_env(\%roles_in_env,$update);
 <h1>$lt{'wel'}</h1>          if ($showcount == 1) {
 $welcome              foreach my $rolecode (keys(%roles_in_env)) {
 $loginhelp                  my ($cid) = ($rolecode =~ m{^\Quser.role.st./\E($match_domain/$match_courseid)(?:/|$)});
 $continuelink                  if ($cid) {
 $end_page                      my %coursedescription =
 ENDSUCCESS                          &Apache::lonnet::coursedescription($cid,{'one_time' => '1'});
 }                      if ($coursedescription{'type'} eq 'Placement') {
                           $args->{'crstype'} = 'Placement';
 # --------------------------------------------------------------- Failed login!                      }
                       last;
 sub failed {                  }
     my ($r,$message,$form) = @_;              }
     (undef,undef,undef,my $clientmathml,my $clientunicode) =          }
         &Apache::loncommon::decode_user_agent();      }
     my $args = {};      my $start_page=&Apache::loncommon::start_page('Successful Login',
     if ($clientunicode && !$clientmathml) {                                                    $header,$args);
         $args = {'browser.unicode' => 1};      my $end_page  =&Apache::loncommon::end_page();
     }  
    my $continuelink='<a href="'.$destination.'">'.&mt('Continue').'</a>';
     my $start_page = &Apache::loncommon::start_page('Unsuccessful Login',undef,$args);  # ------------------------------------------------- Output for successful login
     my $uname = $form->{'uname'};  
     my $udom;      &Apache::loncommon::content_type($r,'text/html');
     if (&Apache::lonnet::domain($form->{'udom'},'description') ne '') {      if ($securecookie) {
         $udom = $form->{'udom'};          $r->headers_out->add('Set-cookie' => $securecookie);
     }        }
     my $retry = '/adm/login?username='.$form->{'uname'};      if ($defaultcookie) {
     if ($udom) {          $r->headers_out->add('Set-cookie' => $defaultcookie);
         $retry .= '&amp;domain='.$form->{'udom'}      }
     }      $r->send_http_header;
     if (exists($form->{role})) {  
         $retry .= '&amp;role='.$form->{role};      my %lt=&Apache::lonlocal::texthash(
     }         'wel' => 'Welcome',
     if (exists($form->{symb})) {         'pro' => 'Login problems?',
         $retry .= '&amp;symb='.$form->{symb};         );
     }      my $loginhelp = &loginhelpdisplay($domain);
     my $end_page   = &Apache::loncommon::end_page();      if ($loginhelp) {
     &Apache::loncommon::content_type($r,'text/html');          $loginhelp = '<p><a href="'.$loginhelp.'">'.$lt{'pro'}.'</a></p>';
     $r->send_http_header;      }
     my $loginhelp = &loginhelpdisplay($udom);  
     if ($loginhelp) {      my $welcome = &mt('Welcome to the Learning[_1]Online[_2] Network with CAPA. Please wait while your session is being set up.','<i>','</i>');
         $loginhelp = '<p><a href="'.$loginhelp.'">'.&mt('Login problems?').'</a></p>';      $r->print(<<ENDSUCCESS);
     }  $start_page
   $windowinfo
     $r->print(  <h1>$lt{'wel'}</h1>
        $start_page  $welcome
       .'<h1>'.&mt('Sorry ...').'</h1>'  $loginhelp
       .'<p class="LC_warning">'.&mt($message).'</p>'  $continuelink
       .'<p>'.&mt('Please [_1]log in again[_2].','<a href="'.$retry.'">','</a>')  $end_page
       .'</p>'  ENDSUCCESS
       .$loginhelp      return;
       .$end_page  }
     );  
  }  # --------------------------------------------------------------- Failed login!
   
 # ------------------------------------------------------------------ Rerouting!  sub failed {
       my ($r,$message,$form) = @_;
 sub reroute {      (undef,undef,undef,my $clientmathml,my $clientunicode) =
     my ($r) = @_;          &Apache::loncommon::decode_user_agent();
     &Apache::loncommon::content_type($r,'text/html');      my $args = {};
     $r->send_http_header;      if ($clientunicode && !$clientmathml) {
     my $msg='<b>'.&mt('Sorry ...').'</b><br />'          $args = {'browser.unicode' => 1};
            .&mt('Please [_1]log in again[_2].');      }
     &Apache::loncommon::simple_error_page($r,'Rerouting',$msg,{'no_auto_mt_msg' => 1});  
 }      my $start_page = &Apache::loncommon::start_page('Unsuccessful Login',undef,$args);
       my $uname = &Apache::loncommon::cleanup_html($form->{'uname'});
 # ---------------------------------------------------------------- Main handler      my $udom = &Apache::loncommon::cleanup_html($form->{'udom'});
       if (&Apache::lonnet::domain($udom,'description') eq '') {
 sub handler {          undef($udom);
     my $r = shift;      }
     my $londocroot = $r->dir_config('lonDocRoot');      my $retry = '/adm/login';
     my $form;      if ($uname eq $form->{'uname'}) {
 # Are we re-routing?          $retry .= '?username='.$uname;
     if (-e "$londocroot/lon-status/reroute.txt") {      }
  &reroute($r);      if ($udom) {
  return OK;          $retry .= (($retry=~/\?/)?'&amp;':'?').'domain='.$udom;
     }      }
       if (exists($form->{role})) {
     &Apache::lonlocal::get_language_handle($r);          my $role = &Apache::loncommon::cleanup_html($form->{role});
           if ($role ne '') {
 # -------------------------------- Prevent users from attempting to login twice              $retry .= (($retry=~/\?/)?'&amp;':'?').'role='.$role;
     my $handle = &Apache::lonnet::check_for_valid_session($r);          }
     if ($handle ne '') {      }
         my $lonidsdir=$r->dir_config('lonIDsDir');      if (exists($form->{symb})) {
         if ($handle=~/^publicuser\_/) {          my $symb = &Apache::loncommon::cleanup_html($form->{symb});
 # For "public user" - remove it, we apparently really want to login          if ($symb ne '') {
             unlink($r->dir_config('lonIDsDir')."/$handle.id");              $retry .= (($retry=~/\?/)?'&amp;':'?').'symb='.$symb;
         } else {          }
 # Indeed, a valid token is found      }
             &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);      my $end_page = &Apache::loncommon::end_page();
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;      $r->send_http_header;
     my $start_page =       my @actions =
         &Apache::loncommon::start_page('Already logged in');           (&mt('Please [_1]log in again[_2].','<a href="'.$retry.'">','</a>'));
     my $end_page =       my $loginhelp = &loginhelpdisplay($udom);
         &Apache::loncommon::end_page();      if ($loginhelp) {
             my $dest = '/adm/roles';          push(@actions, '<a href="'.$loginhelp.'">'.&mt('Login problems?').'</a>');
             if ($env{'form.firsturl'} ne '') {      }
                 $dest = $env{'form.firsturl'};      #FIXME: link to helpdesk might be added here
             }  
             $r->print(      $r->print(
                $start_page         $start_page
               .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'        .'<h2>'.&mt('Sorry ...').'</h2>'
               .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].'        .&Apache::lonhtmlcommon::confirm_success(&mt($message),1).'<br /><br />'
                     ,'<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>')        .&Apache::lonhtmlcommon::actionbox(\@actions)
               .'</p>'        .$end_page
               .$end_page      );
             );   }
             return OK;  
         }  # ------------------------------------------------------------------ Rerouting!
     }  
   sub reroute {
 # ---------------------------------------------------- No valid token, continue      my ($r) = @_;
       &Apache::loncommon::content_type($r,'text/html');
       $r->send_http_header;
     my $buffer;      my $msg='<b>'.&mt('Sorry ...').'</b><br />'
     if ($r->header_in('Content-length') > 0) {             .&mt('Please [_1]log in again[_2].');
  $r->read($buffer,$r->header_in('Content-length'),0);      &Apache::loncommon::simple_error_page($r,'Rerouting',$msg,{'no_auto_mt_msg' => 1});
     }  }
     my %form;  
     foreach my $pair (split(/&/,$buffer)) {  # ---------------------------------------------------------------- Main handler
        my ($name,$value) = split(/=/,$pair);  
        $value =~ tr/+/ /;  sub handler {
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;      my $r = shift;
        $form{$name}=$value;      my $londocroot = $r->dir_config('lonDocRoot');
     }  # Are we re-routing?
       if (-e "$londocroot/lon-status/reroute.txt") {
     if ((!$form{'uname'}) || (!$form{'upass0'}) || (!$form{'udom'})) {   &reroute($r);
  &failed($r,'Username, password and domain need to be specified.',   return OK;
  \%form);      }
         return OK;  
     }      &Apache::lonlocal::get_language_handle($r);
   
 # split user logging in and "su"-user  # -------------------------------- Prevent users from attempting to login twice
       my $handle = &Apache::lonnet::check_for_valid_session($r);
     ($form{'uname'},$form{'suname'})=split(/\:/,$form{'uname'});      if ($handle ne '') {
     $form{'uname'} = &LONCAPA::clean_username($form{'uname'});          my $lonidsdir=$r->dir_config('lonIDsDir');
     $form{'suname'}= &LONCAPA::clean_username($form{'suname'});          if ($handle=~/^publicuser\_/) {
     $form{'udom'}  = &LONCAPA::clean_domain(  $form{'udom'});  # For "public user" - remove it, we apparently really want to login
               unlink($r->dir_config('lonIDsDir')."/$handle.id");
     my $role   = $r->dir_config('lonRole');          } else {
     my $domain = $r->dir_config('lonDefDomain');  # Indeed, a valid token is found
     my $prodir = $r->dir_config('lonUsersDir');              &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
     my $contact_name = &mt('LON-CAPA helpdesk');      &Apache::loncommon::content_type($r,'text/html');
       $r->send_http_header;
 # ---------------------------------------- Get the information from login token      my $start_page =
           &Apache::loncommon::start_page('Already logged in');
     my $tmpinfo=Apache::lonnet::reply('tmpget:'.$form{'logtoken'},      my $end_page =
                                       $form{'serverid'});          &Apache::loncommon::end_page();
               my $dest = '/adm/roles';
     my %sessiondata;              if ($env{'form.firsturl'} ne '') {
     if ($form{'iptoken'}) {                  $dest = $env{'form.firsturl'};
         %sessiondata = &Apache::lonnet::tmpget($form{'iptoken'});              }
         my $delete = &Apache::lonnet::tmpdel($form{'token'});              $r->print(
     }                 $start_page
                 .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
     if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost') ||                 .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].'
         ($tmpinfo eq 'no_such_host')) {                      ,'<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>')
  &failed($r,'Information needed to verify your login information is missing, inaccessible or expired.',\%form);                .'</p>'
         return OK;                .$end_page
     } else {              );
  my $reply = &Apache::lonnet::reply('tmpdel:'.$form{'logtoken'},              return OK;
    $form{'serverid'});          }
         if ( $reply ne 'ok' ) {      }
             &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");  # ---------------------------------------------------- No valid token, continue
     return OK;  
  }  
     }      my $buffer;
       if ($r->header_in('Content-length') > 0) {
     if (!&Apache::lonnet::domain($form{'udom'})) {   $r->read($buffer,$r->header_in('Content-length'),0);
         &failed($r,'The domain you provided is not a valid LON-CAPA domain.',\%form);      }
         return OK;      my %form;
     }      foreach my $pair (split(/&/,$buffer)) {
          my ($name,$value) = split(/=/,$pair);
     my ($key,$firsturl,$rolestr,$symbstr)=split(/&/,$tmpinfo);         $value =~ tr/+/ /;
     if ($rolestr) {         $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
         $rolestr = &unescape($rolestr);         $form{$name}=$value;
     }      }
     if ($symbstr) {  
         $symbstr= &unescape($symbstr);      if ((!$form{'uname'}) || (!$form{'upass0'}) || (!$form{'udom'})) {
     }   &failed($r,'Username, password and domain need to be specified.',
     if ($rolestr =~ /^role=/) {   \%form);
         (undef,$form{'role'}) = split('=',$rolestr);          return OK;
     }      }
     if ($symbstr =~ /^symb=/) {   
         (undef,$form{'symb'}) = split('=',$symbstr);  # split user logging in and "su"-user
     }  
       ($form{'uname'},$form{'suname'})=split(/\:/,$form{'uname'});
     my $keybin=pack("H16",$key);      $form{'uname'} = &LONCAPA::clean_username($form{'uname'});
       $form{'suname'}= &LONCAPA::clean_username($form{'suname'});
     my $cipher;      $form{'udom'}  = &LONCAPA::clean_domain(  $form{'udom'});
     if ($Crypt::DES::VERSION>=2.03) {  
  $cipher=new Crypt::DES $keybin;      my $role   = $r->dir_config('lonRole');
     }      my $domain = $r->dir_config('lonDefDomain');
     else {      my $prodir = $r->dir_config('lonUsersDir');
  $cipher=new DES $keybin;      my $contact_name = &mt('LON-CAPA helpdesk');
     }  
     my $upass='';  # ---------------------------------------- Get the information from login token
     for (my $i=0;$i<=2;$i++) {  
  my $chunk=      my $tmpinfo=Apache::lonnet::reply('tmpget:'.$form{'logtoken'},
     $cipher->decrypt(unpack("a8",pack("H16",substr($form{'upass'.$i},0,16))));                                        $form{'serverid'});
   
  $chunk.=      if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost') ||
     $cipher->decrypt(unpack("a8",pack("H16",substr($form{'upass'.$i},16,16))));          ($tmpinfo eq 'no_such_host')) {
    &failed($r,'Information needed to verify your login information is missing, inaccessible or expired.',\%form);
  $chunk=substr($chunk,1,ord(substr($chunk,0,1)));          return OK;
  $upass.=$chunk;      } else {
     }   my $reply = &Apache::lonnet::reply('tmpdel:'.$form{'logtoken'},
      $form{'serverid'});
 # ---------------------------------------------------------------- Authenticate          if ( $reply ne 'ok' ) {
               &failed($r,'Session could not be opened.',\%form);
     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$form{'udom'});      &Apache::lonnet::logthis("ERROR got a reply of $reply when trying to contact ". $form{'serverid'}." to get login token");
     my ($cancreate,$statustocreate) =      return OK;
         &Apache::createaccount::get_creation_controls($form{'udom'},$domconfig{'usercreation'});   }
     my $defaultauth;      }
     if (ref($cancreate) eq 'ARRAY') {  
         if (grep(/^login$/,@{$cancreate})) {      if (!&Apache::lonnet::domain($form{'udom'})) {
             $defaultauth = 1;          &failed($r,'The domain you provided is not a valid LON-CAPA domain.',\%form);
         }          return OK;
     }      }
     my $clientcancheckhost = 1;  
     my $authhost=Apache::lonnet::authenticate($form{'uname'},$upass,      my ($key,$firsturl,$rolestr,$symbstr,$iptokenstr)=split(/&/,$tmpinfo);
                                               $form{'udom'},$defaultauth,      if ($rolestr) {
                                               $clientcancheckhost);          $rolestr = &unescape($rolestr);
           }
 # --------------------------------------------------------------------- Failed?      if ($symbstr) {
           $symbstr= &unescape($symbstr);
     if ($authhost eq 'no_host') {      }
  &failed($r,'Username and/or password could not be authenticated.',      if ($iptokenstr) {
  \%form);          $iptokenstr = &unescape($iptokenstr);
         return OK;      }
     } elsif ($authhost eq 'no_account_on_host') {      if ($rolestr =~ /^role=/) {
         if ($defaultauth) {          (undef,$form{'role'}) = split('=',$rolestr);
             my $domdesc = &Apache::lonnet::domain($form{'udom'},'description');      }
             unless (&check_can_host($r,\%form,'no_account_on_host',$domdesc)) {      if ($symbstr =~ /^symb=/) {
                 return OK;          (undef,$form{'symb'}) = split('=',$symbstr);
             }      }
             my $start_page =       if ($iptokenstr =~ /^iptoken=/) {
                 &Apache::loncommon::start_page('Create a user account in LON-CAPA');          (undef,$form{'iptoken'}) = split('=',$iptokenstr);
             my $lonhost = $r->dir_config('lonHostID');      }
             my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};  
             my $contacts =       my $upass = $ENV{HTTPS} ? $form{'upass0'}
                 &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',          : &Apache::loncommon::des_decrypt($key,$form{'upass0'});
                                                         $form{'udom'},$origmail);  
             my ($contact_email) = split(',',$contacts);   # ---------------------------------------------------------------- Authenticate
             my $output =   
                 &Apache::createaccount::username_check($form{'uname'},$form{'udom'},      my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$form{'udom'});
                                                        $domdesc,'',$lonhost,      my ($cancreate,$statustocreate) =
                                                        $contact_email,$contact_name,          &Apache::createaccount::get_creation_controls($form{'udom'},$domconfig{'usercreation'});
                                                        undef,$statustocreate);      my $defaultauth;
             &Apache::loncommon::content_type($r,'text/html');      if (ref($cancreate) eq 'ARRAY') {
             $r->send_http_header;          if (grep(/^login$/,@{$cancreate})) {
             &Apache::createaccount::print_header($r,$start_page);              $defaultauth = 1;
             $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 />'.      }
                       $output.&Apache::loncommon::end_page());      my $clientcancheckhost = 1;
             return OK;      my $authhost=Apache::lonnet::authenticate($form{'uname'},$upass,
         } else {                                                $form{'udom'},$defaultauth,
             &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);                                                $clientcancheckhost);
             return OK;     
         }  # --------------------------------------------------------------------- Failed?
     }  
       if ($authhost eq 'no_host') {
     if (($firsturl eq '') ||    &failed($r,'Username and/or password could not be authenticated.',
  ($firsturl=~/^\/adm\/(logout|remote)/)) {   \%form);
  $firsturl='/adm/roles';          return OK;
     }      } elsif ($authhost eq 'no_account_on_host') {
           if ($defaultauth) {
     my $hosthere;              my $domdesc = &Apache::lonnet::domain($form{'udom'},'description');
     if ($form{'iptoken'}) {              unless (&check_can_host($r,\%form,'no_account_on_host',$domdesc)) {
         if (($sessiondata{'domain'} eq $form{'udom'}) &&                  return OK;
             ($sessiondata{'username'} eq $form{'uname'})) {              }
             $hosthere = 1;              my $start_page =
         }                  &Apache::loncommon::start_page('Create a user account in LON-CAPA');
     }              my $lonhost = $r->dir_config('lonHostID');
               my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
 # --------------------------------- Are we attempting to login as somebody else?              my $contacts =
     if ($form{'suname'}) {                  &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
 # ------------ see if the original user has enough privileges to pull this stunt                                                          $form{'udom'},$origmail);
  if (&Apache::lonnet::privileged($form{'uname'},$form{'udom'})) {              my ($contact_email) = split(',',$contacts);
 # ---------------------------------------------------- see if the su-user exists              my $output =
     unless (&Apache::lonnet::homeserver($form{'suname'},$form{'udom'})                  &Apache::createaccount::username_check($form{'uname'},$form{'udom'},
  eq 'no_host') {                                                         $domdesc,'',$lonhost,
  &Apache::lonnet::logthis(&Apache::lonnet::homeserver($form{'suname'},$form{'udom'}));                                                         $contact_email,$contact_name,
 # ------------------------------ see if the su-user is not too highly privileged                                                         undef,$statustocreate);
  unless (&Apache::lonnet::privileged($form{'suname'},$form{'udom'})) {              &Apache::loncommon::content_type($r,'text/html');
 # -------------------------------------------------------- actually switch users              $r->send_http_header;
     &Apache::lonnet::logperm('User '.$form{'uname'}.' at '.$form{'udom'}.              &Apache::createaccount::print_header($r,$start_page);
  ' logging in as '.$form{'suname'});              $r->print('<h3>'.&mt('Account creation').'</h3>'.
     $form{'uname'}=$form{'suname'};                        &mt('Although your username and password were authenticated, you do not currently have a LON-CAPA account at this institution.').'<br />'.
  } else {                        $output.&Apache::loncommon::end_page());
     &Apache::lonnet::logthis('Attempted switch user to privileged user');              return OK;
  }          } 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);
  } else {              return OK;
     &Apache::lonnet::logthis('Non-privileged user attempting switch user');          }
  }      }
     }  
       if (($firsturl eq '') ||
     my ($is_balancer,$otherserver);   ($firsturl=~/^\/adm\/(logout|remote)/)) {
    $firsturl='/adm/roles';
     unless ($hosthere) {      }
         ($is_balancer,$otherserver) =  
             &Apache::lonnet::check_loadbalancing($form{'uname'},$form{'udom'});      my $hosthere;
     }      if ($form{'iptoken'}) {
           my %sessiondata = &Apache::lonnet::tmpget($form{'iptoken'});
     if ($is_balancer) {          my $delete = &Apache::lonnet::tmpdel($form{'iptoken'});
         if (!$otherserver) {           if (($sessiondata{'domain'} eq $form{'udom'}) &&
             ($otherserver) = &Apache::lonnet::choose_server($form{'udom'});              ($sessiondata{'username'} eq $form{'uname'})) {
         }              $hosthere = 1;
         if ($otherserver) {          }
             &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,      }
                      \%form);  
     $r->internal_redirect('/adm/switchserver?otherserver='.$otherserver.'&origurl='.$firsturl);  # --------------------------------- Are we attempting to login as somebody else?
         } else {      if ($form{'suname'}) {
             $r->print(&noswitch());  # ------------ see if the original user has enough privileges to pull this stunt
         }   if (&Apache::lonnet::privileged($form{'uname'},$form{'udom'})) {
         return OK;  # ---------------------------------------------------- see if the su-user exists
     } else {      unless (&Apache::lonnet::homeserver($form{'suname'},$form{'udom'})
         if (!&check_can_host($r,\%form,$authhost)) {   eq 'no_host') {
             my ($otherserver) = &Apache::lonnet::choose_server($form{'udom'});   &Apache::lonnet::logthis(&Apache::lonnet::homeserver($form{'suname'},$form{'udom'}));
             if ($otherserver) {  # ------------------------------ see if the su-user is not too highly privileged
                 &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,   unless (&Apache::lonnet::privileged($form{'suname'},$form{'udom'})) {
                          \%form);  # -------------------------------------------------------- actually switch users
                 $r->internal_redirect('/adm/switchserver?otherserver='.$otherserver.'&origurl='.$firsturl);      &Apache::lonnet::logperm('User '.$form{'uname'}.' at '.$form{'udom'}.
             } else {   ' logging in as '.$form{'suname'});
                 $r->print(&noswitch());      $form{'uname'}=$form{'suname'};
             }   } else {
             return OK;      &Apache::lonnet::logthis('Attempted switch user to privileged user');
         }   }
       }
 # ------------------------------------------------------- Do the load balancing   } else {
       &Apache::lonnet::logthis('Non-privileged user attempting switch user');
 # ---------------------------------------------------------- Determine own load   }
         my $loadlim = $r->dir_config('lonLoadLim');      }
         my $loadavg;  
         {      my ($is_balancer,$otherserver);
             my $loadfile=Apache::File->new('/proc/loadavg');  
             $loadavg=<$loadfile>;      unless ($hosthere) {
         }          ($is_balancer,$otherserver) =
         $loadavg =~ s/\s.*//g;              &Apache::lonnet::check_loadbalancing($form{'uname'},$form{'udom'},'login');
         my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);          if ($is_balancer) {
         my $userloadpercent=&Apache::lonnet::userload();              if ($otherserver eq '') {
                   my $lowest_load;
 # ---------------------------------------------------------- Are we overloaded?                  ($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($form{'udom'});
         if ((($userloadpercent>100.0)||($loadpercent>100.0))) {                  if ($lowest_load > 100) {
             my $unloaded=Apache::lonnet::spareserver($loadpercent,$userloadpercent,1,$form{'udom'});                      $otherserver = &Apache::lonnet::spareserver($lowest_load,$lowest_load,1,$form{'udom'});
             if (!$unloaded) {                  }
                 ($unloaded) = &Apache::lonnet::choose_server($form{'udom'});              }
             }              if ($otherserver ne '') {
             if ($unloaded) {                  my @hosts = &Apache::lonnet::current_machine_ids();
                 &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',                  if (grep(/^\Q$otherserver\E$/,@hosts)) {
                          undef,\%form);                      $hosthere = $otherserver;
                 $r->internal_redirect('/adm/switchserver?otherserver='.$unloaded.'&origurl='.$firsturl);                  }
                 return OK;              }
             }          }
         }      }
         &success($r,$form{'uname'},$form{'udom'},$authhost,$firsturl,undef,  
                  \%form);      if (($is_balancer) && (!$hosthere)) {
         return OK;          if ($otherserver) {
     }              &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
 }                       \%form);
               my $switchto = '/adm/switchserver?otherserver='.$otherserver;
 sub check_can_host {              if (($firsturl) && ($firsturl ne '/adm/switchserver') && ($firsturl ne '/adm/roles')) {
     my ($r,$form,$authhost,$domdesc) = @_;                  $switchto .= '&origurl='.$firsturl;
     return unless (ref($form) eq 'HASH');              }
     my $canhost = 1;              if ($form{'role'}) {
     my $lonhost = $r->dir_config('lonHostID');                  $switchto .= '&role='.$form{'role'};
     my $udom = $form->{'udom'};              }
     my @intdoms;              if ($form{'symb'}) {
     my $internet_names = &Apache::lonnet::get_internet_names($lonhost);                  $switchto .= '&symb='.$form{'symb'};
     if (ref($internet_names) eq 'ARRAY') {              }
         @intdoms = @{$internet_names};              $r->internal_redirect($switchto);
     }          } else {
     my $uprimary_id = &Apache::lonnet::domain($udom,'primary');              $r->print(&noswitch());
     my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);          }
     unless ($uint_dom ne '' && grep(/^\Q$uint_dom\E$/,@intdoms)) {          return OK;
         my $machine_dom = &Apache::lonnet::host_domain($lonhost);      } else {
         my $hostname = &Apache::lonnet::hostname($lonhost);          if (!&check_can_host($r,\%form,$authhost)) {
         my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);              my ($otherserver) = &Apache::lonnet::choose_server($form{'udom'});
         my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);              if ($otherserver) {
         my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);                  &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
         my %udomdefaults = &Apache::lonnet::get_domain_defaults($udom);                           \%form);
         my $loncaparev;                  my $switchto = '/adm/switchserver?otherserver='.$otherserver;
         if ($authhost eq 'no_account_on_host') {                  if (($firsturl) && ($firsturl ne '/adm/switchserver') && ($firsturl ne '/adm/roles')) {
             $loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom);                      $switchto .= '&origurl='.$firsturl;
         } else {                  }
             $loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom,$lonhost);                  if ($form{'role'}) {
         }                      $switchto .= '&role='.$form{'role'};
         $canhost = &Apache::lonnet::can_host_session($udom,$lonhost,$loncaparev,                  }
                                                      $udomdefaults{'remotesessions'},                  if ($form{'symb'}) {
                                                      $defdomdefaults{'hostedsessions'});                      $switchto .= '&symb='.$form{'symb'};
     }                  }
     unless ($canhost) {                  $r->internal_redirect($switchto);
         if ($authhost eq 'no_account_on_host') {              } else {
             my $checkloginvia = 1;                  $r->print(&noswitch());
             my ($login_host,$hostname) =               }
                 &Apache::lonnet::choose_server($udom,$checkloginvia);              return OK;
             &Apache::loncommon::content_type($r,'text/html');          }
             $r->send_http_header;  
             if ($login_host ne '') {  # ------------------------------------------------------- Do the load balancing
                 my $protocol = $Apache::lonnet::protocol{$login_host};  
                 $protocol = 'http' if ($protocol ne 'https');  # ---------------------------------------------------------- Determine own load
                 my $newurl = $protocol.'://'.$hostname.'/adm/createaccount';          my $loadlim = $r->dir_config('lonLoadLim');
                 $r->print(&Apache::loncommon::start_page('Create a user account in LON-CAPA').          my $loadavg;
                           '<h3>'.&mt('Account creation').'</h3>'.          {
                           &mt('You do not currently have a LON-CAPA account at this institution.').'<br />'.              my $loadfile=Apache::File->new('/proc/loadavg');
                           '<p>'.&mt('You will be able to create one by logging into a LON-CAPA server within the [_1] domain.',$domdesc).'</p>'.              $loadavg=<$loadfile>;
                           '<p>'.&mt('[_1]Log in[_2]','<a href="'.$newurl.'">','</a>').          }
                           &Apache::loncommon::end_page());          $loadavg =~ s/\s.*//g;
             } else {          my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
                 $r->print(&Apache::loncommon::start_page('Access to LON-CAPA unavailable').          my $userloadpercent=&Apache::lonnet::userload();
                           '<h3>'.&mt('Account creation unavailable').'</h3>'.  
                           &mt('You do not currently have a LON-CAPA account at this institution.').'<br />'.  # ---------------------------------------------------------- Are we overloaded?
                           '<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>'.          if ((($userloadpercent>100.0)||($loadpercent>100.0))) {
                           &Apache::loncommon::end_page());              my $unloaded=Apache::lonnet::spareserver($loadpercent,$userloadpercent,1,$form{'udom'});
             }              if (!$unloaded) {
         } else {                  ($unloaded) = &Apache::lonnet::choose_server($form{'udom'});
             &success($r,$form->{'uname'},$udom,$authhost,'noredirect',undef,              }
                      $form);              if ($unloaded) {
             my ($otherserver) = &Apache::lonnet::choose_server($udom);                  &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',
             $r->internal_redirect('/adm/switchserver?otherserver='.$otherserver);                           undef,\%form);
         }                  $r->internal_redirect('/adm/switchserver?otherserver='.$unloaded.'&origurl='.$firsturl);
     }                  return OK;
     return $canhost;              }
 }          }
           if (($is_balancer) && ($hosthere)) {
 sub noswitch {              $form{'noloadbalance'} = $hosthere;
     my $result = &Apache::loncommon::start_page('Access to LON-CAPA unavailable').          }
                  '<h3>'.&mt('Session unavailable').'</h3>'.          &success($r,$form{'uname'},$form{'udom'},$authhost,$firsturl,undef,
                  &mt('This LON-CAPA server is unable to host your session.').'<br />'.                   \%form);
                  '<p>'.&mt('Currently no other LON-CAPA server is available to host your session either.').'</p>'.          return OK;
                  &Apache::loncommon::end_page();      }
     return $result;  }
 }  
   sub check_can_host {
 sub loginhelpdisplay {      my ($r,$form,$authhost,$domdesc) = @_;
     my ($authdomain) = @_;      return unless (ref($form) eq 'HASH');
     my $login_help = 1;      my $canhost = 1;
     my $lang = &Apache::lonlocal::current_language();      my $lonhost = $r->dir_config('lonHostID');
     if ($login_help) {      my $udom = $form->{'udom'};
         my $dom = $authdomain;      my @intdoms;
         if ($dom eq '') {      my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
             $dom = &Apache::lonnet::default_login_domain();      if (ref($internet_names) eq 'ARRAY') {
         }          @intdoms = @{$internet_names};
         my %domconfhash = &Apache::loncommon::get_domainconf($dom);      }
         my $loginhelp_url;      my $uprimary_id = &Apache::lonnet::domain($udom,'primary');
         if ($lang) {      my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
             $loginhelp_url = $domconfhash{$dom.'.login.helpurl_'.$lang};      unless ($uint_dom ne '' && grep(/^\Q$uint_dom\E$/,@intdoms)) {
             if ($loginhelp_url ne '') {          my $machine_dom = &Apache::lonnet::host_domain($lonhost);
                 return $loginhelp_url;          my $hostname = &Apache::lonnet::hostname($lonhost);
             }          my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
         }          my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
         $loginhelp_url = $domconfhash{$dom.'.login.helpurl_nolang'};          my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
         if ($loginhelp_url ne '') {          my %udomdefaults = &Apache::lonnet::get_domain_defaults($udom);
             return $loginhelp_url;          my $loncaparev;
         } else {          if ($authhost eq 'no_account_on_host') {
             return '/adm/loginproblems.html';              $loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom);
         }          } else {
     }              $loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom,$lonhost);
     return;          }
 }          $canhost = &Apache::lonnet::can_host_session($udom,$lonhost,$loncaparev,
                                                        $udomdefaults{'remotesessions'},
 1;                                                       $defdomdefaults{'hostedsessions'});
 __END__      }
       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 $newurl = $protocol.'://'.$hostname.'/adm/createaccount';
                   $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);
               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.128  
changed lines
  Added in v.1.143


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