Diff for /loncom/auth/lonauth.pm between versions 1.129 and 1.144

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


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