Diff for /loncom/auth/lonauth.pm between versions 1.121.2.17 and 1.136

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

Removed from v.1.121.2.17  
changed lines
  Added in v.1.136


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