Diff for /loncom/auth/lonauth.pm between versions 1.121.2.4 and 1.148

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


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