Diff for /loncom/auth/lonauth.pm between versions 1.121.2.14 and 1.142

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


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