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

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

Removed from v.1.121.2.4  
changed lines
  Added in v.1.143


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