Diff for /loncom/auth/lonauth.pm between versions 1.128 and 1.145

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


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