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

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


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