Diff for /loncom/auth/lonauth.pm between versions 1.101.8.9.2.2 and 1.147

version 1.101.8.9.2.2, 2012/02/09 22:01:34 version 1.147, 2017/08/08 18:17:13
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|uploaded|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::lonmenu::open($env{'browser.os'});              $desturl = &Apache::lonnet::clutter($desturl);
     my $startupremote=&Apache::lonmenu::startupremote($destination);              $desturl = &HTML::Entities::encode($desturl,'"<>&');
     my $remoteinfo=&Apache::lonmenu::load_remote_msg($lowerurl);              $destsymb = &HTML::Entities::encode($destsymb,'"<>&');
     my $setflags=&Apache::lonmenu::setflags();              $destination .= 'destinationurl='.$desturl.
     my $maincall=&Apache::lonmenu::maincall();                              '&destsymb='.$destsymb;
     my $brcrum = [{'href' => '',          } else {
                    'text' => 'Successful Login'},];              $destsymb = &HTML::Entities::encode($destsymb,'"<>&');
     my $start_page=&Apache::loncommon::start_page('Successful Login',              $destination .= 'destinationurl='.$destsymb;
                                                   $startupremote,          }
                                                   {'no_inline_link' => 1,      }
                                                    'bread_crumbs' => $brcrum,});      if ($destination =~ m{^/adm/roles}) {
     my $end_page  =&Apache::loncommon::end_page();          $destination  .= ($destination =~ /\?/) ? '&' : '?';
           $destination .= 'source=login';
     my $continuelink;      }
     if ($env{'environment.remote'} eq 'off') {  
  $continuelink='<a href="'.$destination.'">'.&mt('Continue').'</a>';      my $windowinfo = Apache::lonhtmlcommon::scripttag('self.name="loncapaclient";');
     }      my $header = '<meta HTTP-EQUIV="Refresh" CONTENT="0; url='.$destination.'" />';
 # ------------------------------------------------- Output for successful login      my $brcrum = [{'href' => '',
                      'text' => 'Successful Login'},];
     &Apache::loncommon::content_type($r,'text/html');      my $args = {'bread_crumbs' => $brcrum,};
     $r->header_out('Set-cookie' => $cookie);      unless ((defined($form->{role})) || (defined($form->{symb}))) {
     $r->send_http_header;          my $update=$env{'user.update.time'};
           if (!$update) {
     my %lt=&Apache::lonlocal::texthash(              $update = $env{'user.login.time'};
        'wel' => 'Welcome',          }
        'pro' => 'Login problems?',          my %roles_in_env;
        'log' => 'loginproblems.html',          my $showcount = &Apache::lonroles::roles_from_env(\%roles_in_env,$update);
        );          if ($showcount == 1) {
     my $welcome = &mt('Welcome to the Learning[_1]Online[_2] Network with CAPA. Please wait while your session is being set up.','<i>','</i>');              foreach my $rolecode (keys(%roles_in_env)) {
     $r->print(<<ENDSUCCESS);                  my ($cid) = ($rolecode =~ m{^\Quser.role.st./\E($match_domain/$match_courseid)(?:/|$)});
 $start_page                  if ($cid) {
 $setflags                      my %coursedescription =
 $windowinfo                          &Apache::lonnet::coursedescription($cid,{'one_time' => '1'});
 <h1>$lt{'wel'}</h1>                      if ($coursedescription{'type'} eq 'Placement') {
 $welcome<p>                          $args->{'crstype'} = 'Placement';
 <a href="/adm/$lt{'log'}">$lt{'pro'}</a></p>                      }
 $remoteinfo                      last;
 $maincall                  }
 $continuelink              }
 $end_page          }
 ENDSUCCESS      }
 }      my $start_page=&Apache::loncommon::start_page('Successful Login',
                                                     $header,$args);
 # --------------------------------------------------------------- Failed login!      my $end_page  =&Apache::loncommon::end_page();
   
 sub failed {   my $continuelink='<a href="'.$destination.'">'.&mt('Continue').'</a>';
     my ($r,$message,$form) = @_;  # ------------------------------------------------- Output for successful login
     my $start_page = &Apache::loncommon::start_page('Unsuccessful Login',undef,  
     {'no_inline_link' => 1,});      &Apache::loncommon::content_type($r,'text/html');
     my $retry = '/adm/login?username='.$form->{'uname'}.      if ($securecookie) {
                 '&domain='.$form->{'udom'};          $r->headers_out->add('Set-cookie' => $securecookie);
     if (exists($form->{role})) {      }
         $retry .= '&role='.$form->{role};      if ($defaultcookie) {
     }          $r->headers_out->add('Set-cookie' => $defaultcookie);
     if (exists($form->{symb})) {      }
         $retry .= '&symb='.$form->{symb};      $r->send_http_header;
     }  
     my $end_page   = &Apache::loncommon::end_page();      my %lt=&Apache::lonlocal::texthash(
     &Apache::loncommon::content_type($r,'text/html');         'wel' => 'Welcome',
     $r->send_http_header;         'pro' => 'Login problems?',
     $r->print(         );
        $start_page      my $loginhelp = &loginhelpdisplay($domain);
       .'<h1>'.&mt('Sorry ...').'</h1>'      if ($loginhelp) {
       .'<p class="LC_warning">'.&mt($message).'</p>'          $loginhelp = '<p><a href="'.$loginhelp.'">'.$lt{'pro'}.'</a></p>';
       .'<p>'.&mt('Please [_1]log in again[_2].','<a href="'.$retry.'">','</a>')      }
       .'</p>'  
       .'<p><a href="/adm/loginproblems.html">'.&mt('Login problems?').'</a></p>'      my $welcome = &mt('Welcome to the Learning[_1]Online[_2] Network with CAPA. Please wait while your session is being set up.','<i>','</i>');
       .$end_page      $r->print(<<ENDSUCCESS);
     );  $start_page
  }  $windowinfo
   <h1>$lt{'wel'}</h1>
 # ------------------------------------------------------------------ Rerouting!  $welcome
   $loginhelp
 sub reroute {  $continuelink
     my ($r) = @_;  $end_page
     &Apache::loncommon::content_type($r,'text/html');  ENDSUCCESS
     $r->send_http_header;      return;
     my $msg='<h1>'.&mt('Sorry ...').'</h1>'  }
            .&mt('Please [_1]log in again[_2].');  
     &Apache::loncommon::simple_error_page($r,'Rerouting',$msg);  # --------------------------------------------------------------- Failed login!
 }  
   sub failed {
 # ---------------------------------------------------------------- Main handler      my ($r,$message,$form) = @_;
       (undef,undef,undef,my $clientmathml,my $clientunicode) =
 sub handler {          &Apache::loncommon::decode_user_agent();
     my $r = shift;      my $args = {};
     my $form;      if ($clientunicode && !$clientmathml) {
 # Are we re-routing?          $args = {'browser.unicode' => 1};
     if (-e '/home/httpd/html/lon-status/reroute.txt') {      }
  &reroute($r);  
  return OK;      my $start_page = &Apache::loncommon::start_page('Unsuccessful Login',undef,$args);
     }      my $uname = &Apache::loncommon::cleanup_html($form->{'uname'});
       my $udom = &Apache::loncommon::cleanup_html($form->{'udom'});
     &Apache::lonlocal::get_language_handle($r);      if (&Apache::lonnet::domain($udom,'description') eq '') {
           undef($udom);
 # -------------------------------- Prevent users from attempting to login twice      }
     my $handle = &Apache::lonnet::check_for_valid_session($r);      my $retry = '/adm/login';
     if ($handle ne '') {      if ($uname eq $form->{'uname'}) {
         my $lonidsdir=$r->dir_config('lonIDsDir');          $retry .= '?username='.$uname;
         if ($handle=~/^publicuser\_/) {      }
 # For "public user" - remove it, we apparently really want to login      if ($udom) {
             unlink($r->dir_config('lonIDsDir')."/$handle.id");          $retry .= (($retry=~/\?/)?'&amp;':'?').'domain='.$udom;
         } else {      }
 # Indeed, a valid token is found      if (exists($form->{role})) {
             &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);          my $role = &Apache::loncommon::cleanup_html($form->{role});
             &Apache::loncommon::content_type($r,'text/html');          if ($role ne '') {
             $r->send_http_header;              $retry .= (($retry=~/\?/)?'&amp;':'?').'role='.$role;
             my $start_page =          }
                 &Apache::loncommon::start_page('Already logged in');      }
             my $end_page =      if (exists($form->{symb})) {
                 &Apache::loncommon::end_page();          my $symb = &Apache::loncommon::cleanup_html($form->{symb});
             my $dest = '/adm/roles';          if ($symb ne '') {
             if ($env{'form.firsturl'} ne '') {              $retry .= (($retry=~/\?/)?'&amp;':'?').'symb='.$symb;
                 $dest = $env{'form.firsturl'};          }
             }      }
             $r->print(      my $end_page = &Apache::loncommon::end_page();
                $start_page      &Apache::loncommon::content_type($r,'text/html');
               .'<h1>'.&mt('You are already logged in!').'</h1>'      $r->send_http_header;
               .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].'      my @actions =
                     ,'<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>')           (&mt('Please [_1]log in again[_2].','<a href="'.$retry.'">','</a>'));
               .'</p>'      my $loginhelp = &loginhelpdisplay($udom);
               .$end_page      if ($loginhelp) {
             );          push(@actions, '<a href="'.$loginhelp.'">'.&mt('Login problems?').'</a>');
             return OK;      }
         }      #FIXME: link to helpdesk might be added here
     }  
       $r->print(
 # ---------------------------------------------------- No valid token, continue         $start_page
         .'<h2>'.&mt('Sorry ...').'</h2>'
         .&Apache::lonhtmlcommon::confirm_success(&mt($message),1).'<br /><br />'
     my $buffer;        .&Apache::lonhtmlcommon::actionbox(\@actions)
     if ($r->header_in('Content-length') > 0) {        .$end_page
  $r->read($buffer,$r->header_in('Content-length'),0);      );
     }   }
     my %form;  
     foreach my $pair (split(/&/,$buffer)) {  # ------------------------------------------------------------------ Rerouting!
        my ($name,$value) = split(/=/,$pair);  
        $value =~ tr/+/ /;  sub reroute {
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;      my ($r) = @_;
        $form{$name}=$value;      &Apache::loncommon::content_type($r,'text/html');
     }       $r->send_http_header;
       my $msg='<b>'.&mt('Sorry ...').'</b><br />'
     if ((!$form{'uname'}) || (!$form{'upass0'}) || (!$form{'udom'})) {             .&mt('Please [_1]log in again[_2].');
  &failed($r,'Username, password and domain need to be specified.',      &Apache::loncommon::simple_error_page($r,'Rerouting',$msg,{'no_auto_mt_msg' => 1});
  \%form);  }
         return OK;  
     }  # ---------------------------------------------------------------- Main handler
   
 # split user logging in and "su"-user  sub handler {
       my $r = shift;
     ($form{'uname'},$form{'suname'})=split(/\:/,$form{'uname'});      my $londocroot = $r->dir_config('lonDocRoot');
     $form{'uname'} = &LONCAPA::clean_username($form{'uname'});  # Are we re-routing?
     $form{'suname'}= &LONCAPA::clean_username($form{'suname'});      if (-e "$londocroot/lon-status/reroute.txt") {
     $form{'udom'}  = &LONCAPA::clean_domain(  $form{'udom'});   &reroute($r);
    return OK;
     my $role   = $r->dir_config('lonRole');      }
     my $domain = $r->dir_config('lonDefDomain');  
     my $prodir = $r->dir_config('lonUsersDir');      &Apache::lonlocal::get_language_handle($r);
     my $contact_name = &mt('LON-CAPA helpdesk');  
   # -------------------------------- Prevent users from attempting to login twice
 # ---------------------------------------- Get the information from login token      my $handle = &Apache::lonnet::check_for_valid_session($r);
       if ($handle ne '') {
     my $tmpinfo=Apache::lonnet::reply('tmpget:'.$form{'logtoken'},          my $lonidsdir=$r->dir_config('lonIDsDir');
                                       $form{'serverid'});          if ($handle=~/^publicuser\_/) {
   # For "public user" - remove it, we apparently really want to login
     if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost') ||              unlink($r->dir_config('lonIDsDir')."/$handle.id");
        ($tmpinfo eq 'no_such_host')) {          } else {
  &failed($r,'Information needed to verify your login information is missing, inaccessible or expired.',\%form);  # Indeed, a valid token is found
         return OK;              &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
     } else {      &Apache::loncommon::content_type($r,'text/html');
  my $reply = &Apache::lonnet::reply('tmpdel:'.$form{'logtoken'},      $r->send_http_header;
    $form{'serverid'});      my $start_page =
         if ( $reply ne 'ok' ) {          &Apache::loncommon::start_page('Already logged in');
             &failed($r,'Session could not be opened.',\%form);      my $end_page =
     &Apache::lonnet::logthis("ERROR got a reply of $reply when trying to contact ". $form{'serverid'}." to get login token");          &Apache::loncommon::end_page();
     return OK;              my $dest = '/adm/roles';
  }              if ($env{'form.firsturl'} ne '') {
     }                  $dest = $env{'form.firsturl'};
               }
     if (!&Apache::lonnet::domain($form{'udom'})) {              $r->print(
         &failed($r,'The domain you provided is not a valid LON-CAPA domain.',\%form);                 $start_page
         return OK;                .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
     }                .'<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 ($key,$firsturl,$rolestr,$symbstr)=split(/&/,$tmpinfo);                .'</p>'
     if ($rolestr) {                .$end_page
         $rolestr = &unescape($rolestr);              );
     }              return OK;
     if ($symbstr) {          }
         $symbstr= &unescape($symbstr);      }
     }  
     if ($rolestr =~ /^role=/) {  # ---------------------------------------------------- No valid token, continue
         (undef,$form{'role'}) = split('=',$rolestr);  
     }  
     if ($symbstr =~ /^symb=/) {       my $buffer;
         (undef,$form{'symb'}) = split('=',$symbstr);      if ($r->header_in('Content-length') > 0) {
     }   $r->read($buffer,$r->header_in('Content-length'),0);
       }
     my $keybin=pack("H16",$key);      my %form;
       foreach my $pair (split(/&/,$buffer)) {
     my $cipher;         my ($name,$value) = split(/=/,$pair);
     if ($Crypt::DES::VERSION>=2.03) {         $value =~ tr/+/ /;
  $cipher=new Crypt::DES $keybin;         $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
     }         $form{$name}=$value;
     else {      }
  $cipher=new DES $keybin;  
     }      if ((!$form{'uname'}) || (!$form{'upass0'}) || (!$form{'udom'})) {
     my $upass='';   &failed($r,'Username, password and domain need to be specified.',
     for (my $i=0;$i<=2;$i++) {   \%form);
  my $chunk=          return OK;
     $cipher->decrypt(unpack("a8",pack("H16",substr($form{'upass'.$i},0,16))));      }
   
  $chunk.=  # split user logging in and "su"-user
     $cipher->decrypt(unpack("a8",pack("H16",substr($form{'upass'.$i},16,16))));  
       ($form{'uname'},$form{'suname'},$form{'sudom'})=split(/\:/,$form{'uname'});
  $chunk=substr($chunk,1,ord(substr($chunk,0,1)));      $form{'uname'} = &LONCAPA::clean_username($form{'uname'});
  $upass.=$chunk;      $form{'suname'}= &LONCAPA::clean_username($form{'suname'});
     }      $form{'udom'}  = &LONCAPA::clean_domain($form{'udom'});
       $form{'sudom'} = &LONCAPA::clean_domain($form{'sudom'});
 # ---------------------------------------------------------------- Authenticate  
       my $role   = $r->dir_config('lonRole');
     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$form{'udom'});      my $domain = $r->dir_config('lonDefDomain');
     my $domdesc = &Apache::lonnet::domain($form{'udom'},'description');      my $prodir = $r->dir_config('lonUsersDir');
     my ($cancreate,$statustocreate) =      my $contact_name = &mt('LON-CAPA helpdesk');
         &Apache::createaccount::get_creation_controls($form{'udom'},$domconfig{'usercreation'});  
     my $defaultauth;  # ---------------------------------------- Get the information from login token
     if (ref($cancreate) eq 'ARRAY') {  
         if (grep(/^login$/,@{$cancreate})) {      my $tmpinfo=Apache::lonnet::reply('tmpget:'.$form{'logtoken'},
             $defaultauth = 1;                                        $form{'serverid'});
         }  
     }      if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost') ||
     my $clientcancheckhost = 1;          ($tmpinfo eq 'no_such_host')) {
     my $uname = $form{'uname'};   &failed($r,'Information needed to verify your login information is missing, inaccessible or expired.',\%form);
     my $authhost=Apache::lonnet::authenticate($uname,$upass,          return OK;
                                               $form{'udom'},$defaultauth,      } else {
                                               $clientcancheckhost);   my $reply = &Apache::lonnet::reply('tmpdel:'.$form{'logtoken'},
          $form{'serverid'});
 # --------------------------------------------------------------------- Failed?          if ( $reply ne 'ok' ) {
               &failed($r,'Session could not be opened.',\%form);
     if ($authhost eq 'no_host') {      &Apache::lonnet::logthis("ERROR got a reply of $reply when trying to contact ". $form{'serverid'}." to get login token");
         my $lc_uname = lc($uname);      return OK;
         if ($uname eq $lc_uname) {   }
             &failed($r,'Username and/or password could not be authenticated.',      }
                     \%form);  
             return OK;      if (!&Apache::lonnet::domain($form{'udom'})) {
         } else {          &failed($r,'The domain you provided is not a valid LON-CAPA domain.',\%form);
             $authhost=Apache::lonnet::authenticate($lc_uname,$upass,          return OK;
                                                    $form{'udom'},$defaultauth);      }
             if ($authhost eq 'no_host') {  
                 &failed($r,'Username (in lower case) and/or password could not be authenticated.',      my ($key,$firsturl,$rolestr,$symbstr,$iptokenstr)=split(/&/,$tmpinfo);
                         \%form);      if ($rolestr) {
                 return OK;          $rolestr = &unescape($rolestr);
             } elsif ($authhost eq 'no_account_on_host') {      }
                 &create_account($r,\%form,$cancreate,$lc_uname,$contact_name,$domdesc);      if ($symbstr) {
                 return OK;          $symbstr= &unescape($symbstr);
             } else {      }
                 $form{'uname'} = $lc_uname;      if ($iptokenstr) {
             }          $iptokenstr = &unescape($iptokenstr);
         }      }
     } elsif ($authhost eq 'no_account_on_host') {      if ($rolestr =~ /^role=/) {
         &create_account($r,\%form,$cancreate,$uname,$contact_name,$domdesc);          (undef,$form{'role'}) = split('=',$rolestr);
         return OK;      }
     }      if ($symbstr =~ /^symb=/) {
           (undef,$form{'symb'}) = split('=',$symbstr);
     if (($firsturl eq '') ||       }
  ($firsturl=~/^\/adm\/(logout|remote)/)) {      if ($iptokenstr =~ /^iptoken=/) {
  $firsturl='/adm/roles';          (undef,$form{'iptoken'}) = split('=',$iptokenstr);
     }      }
 # --------------------------------- Are we attempting to login as somebody else?  
     if ($form{'suname'}) {      my $upass = $ENV{HTTPS} ? $form{'upass0'}
 # ------------ see if the original user has enough privileges to pull this stunt          : &Apache::loncommon::des_decrypt($key,$form{'upass0'});
  if (&Apache::lonnet::privileged($form{'uname'},$form{'udom'})) {  
 # ---------------------------------------------------- see if the su-user exists  # ---------------------------------------------------------------- Authenticate
     unless (&Apache::lonnet::homeserver($form{'suname'},$form{'udom'})  
  eq 'no_host') {      my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$form{'udom'});
  &Apache::lonnet::logthis(&Apache::lonnet::homeserver($form{'suname'},$form{'udom'}));      my ($cancreate,$statustocreate) =
 # ------------------------------ see if the su-user is not too highly privileged          &Apache::createaccount::get_creation_controls($form{'udom'},$domconfig{'usercreation'});
  unless (&Apache::lonnet::privileged($form{'suname'},$form{'udom'})) {      my $defaultauth;
 # -------------------------------------------------------- actually switch users      if (ref($cancreate) eq 'ARRAY') {
     &Apache::lonnet::logperm('User '.$form{'uname'}.' at '.$form{'udom'}.          if (grep(/^login$/,@{$cancreate})) {
  ' logging in as '.$form{'suname'});              $defaultauth = 1;
     $form{'uname'}=$form{'suname'};          }
  } else {      }
     &Apache::lonnet::logthis('Attempted switch user to privileged user');      my $clientcancheckhost = 1;
  }      my $authhost=Apache::lonnet::authenticate($form{'uname'},$upass,
     }                                                $form{'udom'},$defaultauth,
  } else {                                                $clientcancheckhost);
     &Apache::lonnet::logthis('Non-privileged user attempting switch user');     
  }  # --------------------------------------------------------------------- Failed?
     }  
       if ($authhost eq 'no_host') {
     if ($r->dir_config("lonBalancer") eq 'yes') {   &failed($r,'Username and/or password could not be authenticated.',
         my $otherserver = &Apache::lonnet::spareserver(30000,undef,1,$form{'udom'});   \%form);
         if (!$otherserver) {          return OK;
             ($otherserver) = &Apache::lonnet::choose_server($form{'udom'});      } elsif ($authhost eq 'no_account_on_host') {
         }          if ($defaultauth) {
         if ($otherserver) {              my $domdesc = &Apache::lonnet::domain($form{'udom'},'description');
             &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,              unless (&check_can_host($r,\%form,'no_account_on_host',$domdesc)) {
                      \%form);                  return OK;
             $r->internal_redirect('/adm/switchserver?otherserver='.$otherserver.'&origurl='.$firsturl);              }
         } else {              my $start_page =
             $r->print(&noswitch());                  &Apache::loncommon::start_page('Create a user account in LON-CAPA');
         }              my $lonhost = $r->dir_config('lonHostID');
         return OK;              my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
     } else {              my $contacts =
         if (!&check_can_host($r,\%form,$authhost,$domdesc)) {                  &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
             my ($otherserver) = &Apache::lonnet::choose_server($form{'udom'});                                                          $form{'udom'},$origmail);
             if ($otherserver) {              my ($contact_email) = split(',',$contacts);
                 &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,              my $output =
                          \%form);                  &Apache::createaccount::username_check($form{'uname'},$form{'udom'},
                 $r->internal_redirect('/adm/switchserver?otherserver='.$otherserver.'&origurl='.$firsturl);                                                         $domdesc,'',$lonhost,
             } else {                                                         $contact_email,$contact_name,
                 $r->print(&noswitch());                                                         undef,$statustocreate);
             }              &Apache::loncommon::content_type($r,'text/html');
             return OK;              $r->send_http_header;
         }              &Apache::createaccount::print_header($r,$start_page);
 # ------------------------------------------------------- Do the load balancing              $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 />'.
 # ---------------------------------------------------------- Determine own load                        $output.&Apache::loncommon::end_page());
         my $loadlim = $r->dir_config('lonLoadLim');              return OK;
         my $loadavg;          } 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);
             my $loadfile=Apache::File->new('/proc/loadavg');              return OK;
             $loadavg=<$loadfile>;          }
         }      }
         $loadavg =~ s/\s.*//g;  
         my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);      if (($firsturl eq '') ||
         my $userloadpercent=&Apache::lonnet::userload();   ($firsturl=~/^\/adm\/(logout|remote)/)) {
    $firsturl='/adm/roles';
 # ---------------------------------------------------------- Are we overloaded?      }
         if ((($userloadpercent>100.0)||($loadpercent>100.0))) {  
             my $unloaded=Apache::lonnet::spareserver($loadpercent,$userloadpercent,1,$form{'udom'});      my $hosthere;
             if (!$unloaded) {      if ($form{'iptoken'}) {
                 ($unloaded) = &Apache::lonnet::choose_server($form{'udom'});          my %sessiondata = &Apache::lonnet::tmpget($form{'iptoken'});
             }          my $delete = &Apache::lonnet::tmpdel($form{'iptoken'});
             if ($unloaded) {          if (($sessiondata{'domain'} eq $form{'udom'}) &&
                 &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',              ($sessiondata{'username'} eq $form{'uname'})) {
                          undef,\%form);              $hosthere = 1;
                 $r->internal_redirect('/adm/switchserver?otherserver='.$unloaded.'&origurl='.$firsturl);          }
                 return OK;      }
             }  
         }  # --------------------------------- Are we attempting to login as somebody else?
         &success($r,$form{'uname'},$form{'udom'},$authhost,$firsturl,undef,      if ($form{'suname'}) {
                  \%form);          my ($suname,$sudom,$sudomref);
         return OK;          $suname = $form{'suname'};
     }          $sudom = $form{'udom'};
 }          if ($form{'sudom'}) {
               unless ($sudom eq $form{'sudom'}) {
 sub check_can_host {                  if (&Apache::lonnet::domain($form{'sudom'})) {
     my ($r,$form,$authhost,$domdesc) = @_;                      $sudomref = [$form{'sudom'}];
     return unless (ref($form) eq 'HASH');                      $sudom = $form{'sudom'};
     my $canhost = 1;                  }
     my $lonhost = $r->dir_config('lonHostID');              }
     my $udom = $form->{'udom'};          }
     my @intdoms;  # ------------ see if the original user has enough privileges to pull this stunt
     my $internet_names = &Apache::lonnet::get_internet_names($lonhost);   if (&Apache::lonnet::privileged($form{'uname'},$form{'udom'},$sudomref)) {
     if (ref($internet_names) eq 'ARRAY') {  # ---------------------------------------------------- see if the su-user exists
         @intdoms = @{$internet_names};      unless (&Apache::lonnet::homeserver($suname,$sudom) eq 'no_host') {
     }  # ------------------------------ see if the su-user is not too highly privileged
     my $uprimary_id = &Apache::lonnet::domain($udom,'primary');   if (&Apache::lonnet::privileged($suname,$sudom)) {
     my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);                      &Apache::lonnet::logthis('Attempted switch user to privileged user');
     unless ($uint_dom ne '' && grep(/^\Q$uint_dom\E$/,@intdoms)) {                  } else {
         my $machine_dom = &Apache::lonnet::host_domain($lonhost);                      my $noprivswitch;
         my $hostname = &Apache::lonnet::hostname($lonhost);  #
         my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);  # su-user's home server and user's home server must have one of:
         my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);  # (a) same domain
         my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);  # (b) same primary library server for the two domains
         my %udomdefaults = &Apache::lonnet::get_domain_defaults($udom);  # (c) same "internet domain" for primary library server(s) for home servers' domains
         my $loncaparev;  #
         if ($authhost eq 'no_account_on_host') {                      my $uprim = &Apache::lonnet::domain($sudom,'primary');
             $loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom);                      my $uintdom = &Apache::lonnet::internet_dom($uprim);
         } else {                      unless ($sudom eq $form{'udom'}) {
             $loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom,$lonhost);                          my $suprim = &Apache::lonnet::domain($sudom,'primary');
         }                          my $suintdom = &Apache::lonnet::internet_dom($suprim);
         $canhost = &Apache::lonnet::can_host_session($udom,$lonhost,$loncaparev,                          unless ($suprim eq $uprim) {
                                                      $udomdefaults{'remotesessions'},                              unless ($suintdom eq $uintdom) {
                                                      $defdomdefaults{'hostedsessions'});                                  &Apache::lonnet::logthis('Attempted switch user '
     }                                     .'to user with different "internet domain".');                        
     unless ($canhost) {                                  $noprivswitch = 1;
         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');                      unless ($noprivswitch) {
             $r->send_http_header;  #
             if ($login_host ne '') {  # server where log-in occurs must have same "internet domain" as su-user's home
                 my $protocol = $Apache::lonnet::protocol{$login_host};  # server
                 $protocol = 'http' if ($protocol ne 'https');  #
                 my $newurl = $protocol.'://'.$hostname.'/adm/createaccount';                          my $lonhost = $r->dir_config('lonHostID');
                 $r->print(&Apache::loncommon::start_page('Create a user account in LON-CAPA').                          my $hostintdom = &Apache::lonnet::internet_dom($lonhost);
                           '<h3>'.&mt('Account creation').'</h3>'.                          if ($hostintdom ne $uintdom) {
                           &mt('You do not currently have a LON-CAPA account at this institution.').'<br />'.                              &Apache::lonnet::logthis('Attempted switch user on a '
                           '<p>'.&mt('You will be able to create one by logging into a LON-CAPA server within the [_1] domain.',$domdesc).'</p>'.                                  .'server with a different "internet domain".');
                           '<p>'.&mt('[_1]Log in[_2]','<a href="'.$newurl.'">','</a>').                          } else {
                           &Apache::loncommon::end_page());  
             } else {  # -------------------------------------------------------- actually switch users
                 $r->print(&Apache::loncommon::start_page('Access to LON-CAPA unavailable').  
                           '<h3>'.&mt('Account creation unavailable').'</h3>'.              &Apache::lonnet::logperm('User '.$form{'uname'}.' at '.
                           &mt('You do not currently have a LON-CAPA account at this institution.').'<br />'.                                $form{'udom'}.' logging in as '.$suname.':'.$sudom);
                           '<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>'.              $form{'uname'}=$suname;
                           &Apache::loncommon::end_page());                              if ($form{'udom'} ne $sudom) {
             }                                  $form{'udom'}=$sudom;
         } else {                              }
             &success($r,$form->{'uname'},$udom,$authhost,'noredirect',undef,                          }
                      $form);                      }
             my ($otherserver) = &Apache::lonnet::choose_server($udom);   }
             $r->internal_redirect('/adm/switchserver?otherserver='.$otherserver);      }
         }   } else {
     }      &Apache::lonnet::logthis('Non-privileged user attempting switch user');
     return $canhost;   }
 }      }
   
 sub noswitch {      my ($is_balancer,$otherserver);
     my $result = &Apache::loncommon::start_page('Access to LON-CAPA unavailable').  
                  '<h3>'.&mt('Session unavailable').'</h3>'.      unless ($hosthere) {
                  &mt('This LON-CAPA server is unable to host your session.').'<br />'.          ($is_balancer,$otherserver) =
                  '<p>'.&mt('Currently no other LON-CAPA server is available to host your session either.').'</p>'.              &Apache::lonnet::check_loadbalancing($form{'uname'},$form{'udom'},'login');
                  &Apache::loncommon::end_page();          if ($is_balancer) {
     return $result;              if ($otherserver eq '') {
 }                  my $lowest_load;
                   ($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($form{'udom'});
 sub create_account {                  if ($lowest_load > 100) {
     my ($r,$form,$cancreate,$uname,$contact_name,$domdesc) = @_;                      $otherserver = &Apache::lonnet::spareserver($lowest_load,$lowest_load,1,$form{'udom'});
     return unless((ref($form) eq 'HASH') && (ref($cancreate) eq 'ARRAY'));                  }
     my %domconfig =              }
         &Apache::lonnet::get_dom('configuration',['usercreation'],$form->{'udom'});              if ($otherserver ne '') {
     if (&check_can_host($r,$form,'no_account_on_host',$domdesc)) {                  my @hosts = &Apache::lonnet::current_machine_ids();
         my $start_page =                  if (grep(/^\Q$otherserver\E$/,@hosts)) {
             &Apache::loncommon::start_page('Create a user account in LON-CAPA',                      $hosthere = $otherserver;
                                            '',{'no_inline_link'   => 1,});                  }
         my $lonhost = $r->dir_config('lonHostID');              }
         my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};          }
         my $contacts =      }
             &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',  
                                                     $form->{'udom'},$origmail);      if (($is_balancer) && (!$hosthere)) {
         my ($contact_email) = split(',',$contacts);          if ($otherserver) {
         my $output =              &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
             &Apache::createaccount::username_check($uname,$form->{'udom'},                       \%form);
                                                    $domdesc,'',$lonhost,              my $switchto = '/adm/switchserver?otherserver='.$otherserver;
                                                    $contact_email,$contact_name);              if (($firsturl) && ($firsturl ne '/adm/switchserver') && ($firsturl ne '/adm/roles')) {
         &Apache::loncommon::content_type($r,'text/html');                  $switchto .= '&origurl='.$firsturl;
         $r->send_http_header;              }
         &Apache::createaccount::print_header($r,$start_page);              if ($form{'role'}) {
         $r->print('<h3>'.&mt('Account creation').'</h3>'.                  $switchto .= '&role='.$form{'role'};
                   &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());              if ($form{'symb'}) {
     } else {                  $switchto .= '&symb='.$form{'symb'};
         &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);              }
     }              $r->internal_redirect($switchto);
     return;          } else {
 }              $r->print(&noswitch());
           }
 1;          return OK;
 __END__      } else {
           if (!&check_can_host($r,\%form,$authhost)) {
               my ($otherserver) = &Apache::lonnet::choose_server($form{'udom'});
               if ($otherserver) {
                   &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
                            \%form);
                   my $switchto = '/adm/switchserver?otherserver='.$otherserver;
                   if (($firsturl) && ($firsturl ne '/adm/switchserver') && ($firsturl ne '/adm/roles')) {
                       $switchto .= '&origurl='.$firsturl;
                   }
                   if ($form{'role'}) {
                       $switchto .= '&role='.$form{'role'};
                   }
                   if ($form{'symb'}) {
                       $switchto .= '&symb='.$form{'symb'};
                   }
                   $r->internal_redirect($switchto);
               } else {
                   $r->print(&noswitch());
               }
               return OK;
           }
   
   # ------------------------------------------------------- Do the load balancing
   
   # ---------------------------------------------------------- Determine own load
           my $loadlim = $r->dir_config('lonLoadLim');
           my $loadavg;
           {
               my $loadfile=Apache::File->new('/proc/loadavg');
               $loadavg=<$loadfile>;
           }
           $loadavg =~ s/\s.*//g;
           my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
           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) {
                   ($unloaded) = &Apache::lonnet::choose_server($form{'udom'});
               }
               if ($unloaded) {
                   &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',
                            undef,\%form);
                   $r->internal_redirect('/adm/switchserver?otherserver='.$unloaded.'&origurl='.$firsturl);
                   return OK;
               }
           }
           if (($is_balancer) && ($hosthere)) {
               $form{'noloadbalance'} = $hosthere;
           }
           &success($r,$form{'uname'},$form{'udom'},$authhost,$firsturl,undef,
                    \%form);
           return OK;
       }
   }
   
   sub check_can_host {
       my ($r,$form,$authhost,$domdesc) = @_;
       return unless (ref($form) eq 'HASH');
       my $canhost = 1;
       my $lonhost = $r->dir_config('lonHostID');
       my $udom = $form->{'udom'};
       my @intdoms;
       my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
       if (ref($internet_names) eq 'ARRAY') {
           @intdoms = @{$internet_names};
       }
       my $uprimary_id = &Apache::lonnet::domain($udom,'primary');
       my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
       unless ($uint_dom ne '' && grep(/^\Q$uint_dom\E$/,@intdoms)) {
           my $machine_dom = &Apache::lonnet::host_domain($lonhost);
           my $hostname = &Apache::lonnet::hostname($lonhost);
           my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
           my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
           my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
           my %udomdefaults = &Apache::lonnet::get_domain_defaults($udom);
           my $loncaparev;
           if ($authhost eq 'no_account_on_host') {
               $loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom);
           } else {
               $loncaparev = &Apache::lonnet::get_server_loncaparev($machine_dom,$lonhost);
           }
           $canhost = &Apache::lonnet::can_host_session($udom,$lonhost,$loncaparev,
                                                        $udomdefaults{'remotesessions'},
                                                        $defdomdefaults{'hostedsessions'});
       }
       unless ($canhost) {
           if ($authhost eq 'no_account_on_host') {
               my $checkloginvia = 1;
               my ($login_host,$hostname) =
                   &Apache::lonnet::choose_server($udom,$checkloginvia);
               &Apache::loncommon::content_type($r,'text/html');
               $r->send_http_header;
               if ($login_host ne '') {
                   my $protocol = $Apache::lonnet::protocol{$login_host};
                   $protocol = 'http' if ($protocol ne 'https');
                   my $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.101.8.9.2.2  
changed lines
  Added in v.1.147


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