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

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


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