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

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


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