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

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


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