Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.9.2.2 and 1.190

version 1.158.2.9.2.2, 2020/10/26 02:06:16 version 1.190, 2021/10/08 14:45:45
Line 1 Line 1
 # The LearningOnline Network  # The LearningOnline Network
 # Login Screen  # Login Screen
 #  #
 # $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::lonlogin;  package Apache::lonlogin;
   
 use strict;  use strict;
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use Apache::File ();  use Apache::File ();
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::lonauth();  use Apache::lonauth();
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::migrateuser();  use Apache::migrateuser();
 use lib '/home/httpd/lib/perl/';  use lib '/home/httpd/lib/perl/';
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA qw(:DEFAULT :match);
 use CGI::Cookie();  use URI::Escape;
    use HTML::Entities();
 sub handler {  use CGI::Cookie();
     my $r = shift;   
   sub handler {
     &Apache::loncommon::get_unprocessed_cgi      my $r = shift;
  (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},  
       $ENV{'REDIRECT_QUERY_STRING'}),      &Apache::loncommon::get_unprocessed_cgi
  ['interface','username','domain','firsturl','localpath','localres',   (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
   'token','role','symb','iptoken','btoken']);        $ENV{'REDIRECT_QUERY_STRING'}),
     if (!defined($env{'form.firsturl'})) {   ['interface','username','domain','firsturl','localpath','localres',
         &Apache::lonacc::get_posted_cgi($r,['firsturl']);    'token','role','symb','iptoken','btoken','ltoken','linkkey','saml']);
     }      if (!defined($env{'form.firsturl'})) {
     if (!defined($env{'form.firsturl'})) {          &Apache::lonacc::get_posted_cgi($r,['firsturl']);
         if ($ENV{'REDIRECT_URL'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) {      }
             $env{'form.firsturl'} = $ENV{'REDIRECT_URL'};      if (!defined($env{'form.firsturl'})) {
         }          if ($ENV{'REDIRECT_URL'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) {
     }              $env{'form.firsturl'} = $ENV{'REDIRECT_URL'};
           }
 # -- check if they are a migrating user      }
     if (defined($env{'form.token'})) {      if (($env{'form.firsturl'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) &&
  return &Apache::migrateuser::handler($r);          (!$env{'form.ltoken'}) && (!$env{'form.linkkey'})) {
     }          &Apache::lonacc::get_posted_cgi($r,['linkkey']);
       }
 # For "public user" - remove any exising "public" cookie, as user really wants to log-in      if ($env{'form.firsturl'} eq '/adm/logout') {
     my ($handle,$lonidsdir,$expirepub,$userdom);          delete($env{'form.firsturl'});
     $lonidsdir=$r->dir_config('lonIDsDir');      }
     unless ($r->header_only) {  
         $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);  # -- check if they are a migrating user
         if ($handle ne '') {      if (defined($env{'form.token'})) {
             if ($handle=~/^publicuser\_/) {   return &Apache::migrateuser::handler($r);
                 unlink($r->dir_config('lonIDsDir')."/$handle.id");      }
                 undef($handle);  
                 undef($userdom);  # For "public user" - remove any exising "public" cookie, as user really wants to log-in
                 $expirepub = 1;      my ($handle,$lonidsdir,$expirepub,$userdom);
             }      $lonidsdir=$r->dir_config('lonIDsDir');
         }      unless ($r->header_only) {
     }          $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);
           if ($handle ne '') {
     &Apache::loncommon::no_cache($r);              if ($handle=~/^publicuser\_/) {
     &Apache::lonlocal::get_language_handle($r);                  unlink($r->dir_config('lonIDsDir')."/$handle.id");
     &Apache::loncommon::content_type($r,'text/html');                  undef($handle);
     if ($expirepub) {                  undef($userdom);
         my $c = new CGI::Cookie(-name    => 'lonPubID',                  $expirepub = 1;
                                 -value   => '',              }
                                 -expires => '-10y',);          }
         $r->header_out('Set-cookie' => $c);      }
     } elsif (($handle eq '') && ($userdom ne '')) {  
         my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));      &Apache::loncommon::no_cache($r);
         foreach my $name (keys(%cookies)) {      &Apache::lonlocal::get_language_handle($r);
             next unless ($name =~ /^lon(|S|Link|Pub)ID$/);      &Apache::loncommon::content_type($r,'text/html');
             my $c = new CGI::Cookie(-name    => $name,      if ($expirepub) {
                                     -value   => '',          my $c = new CGI::Cookie(-name    => 'lonPubID',
                                     -expires => '-10y',);                                  -value   => '',
             $r->headers_out->add('Set-cookie' => $c);                                  -expires => '-10y',);
         }          $r->header_out('Set-cookie' => $c);
     }      } elsif (($handle eq '') && ($userdom ne '')) {
     $r->send_http_header;          my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
     return OK if $r->header_only;          foreach my $name (keys(%cookies)) {
               next unless ($name =~ /^lon(|S|Link|Pub)ID$/);
               my $c = new CGI::Cookie(-name    => $name,
 # Are we re-routing?                                      -value   => '',
     my $londocroot = $r->dir_config('lonDocRoot');                                       -expires => '-10y',);
     if (-e "$londocroot/lon-status/reroute.txt") {              $r->headers_out->add('Set-cookie' => $c);
  &Apache::lonauth::reroute($r);          }
  return OK;      }
     }      $r->send_http_header;
       return OK if $r->header_only;
     my $lonhost = $r->dir_config('lonHostID');  
     $env{'form.firsturl'} =~ s/(`)/'/g;  
   # Are we re-routing?
 # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)      my $londocroot = $r->dir_config('lonDocRoot');
       if (-e "$londocroot/lon-status/reroute.txt") {
     my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1);   &Apache::lonauth::reroute($r);
     if ($found_server) {   return OK;
         my $hostname = &Apache::lonnet::hostname($found_server);      }
         if ($hostname ne '') {  
             my $protocol = $Apache::lonnet::protocol{$found_server};      my $lonhost = $r->dir_config('lonHostID');
             $protocol = 'http' if ($protocol ne 'https');  
             my $dest = '/adm/roles';  # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
             if ($env{'form.firsturl'} ne '') {  
                 $dest = $env{'form.firsturl'};      my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1);
             }      if ($found_server) {
             my %info = (          my $hostname = &Apache::lonnet::hostname($found_server);
                          balcookie => $lonhost.':'.$balancer_cookie,          if ($hostname ne '') {
                        );              my $protocol = $Apache::lonnet::protocol{$found_server};
             my $balancer_token = &Apache::lonnet::tmpput(\%info,$found_server);              $protocol = 'http' if ($protocol ne 'https');
             if ($balancer_token) {              my $dest = '/adm/roles';
                 $dest .=  (($dest=~/\?/)?'&;':'?') . 'btoken='.$balancer_token;              if ($env{'form.firsturl'} ne '') {
             }                  if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) {
             my $url = $protocol.'://'.$hostname.$dest;                      $dest = &uri_escape_utf8($env{'form.firsturl'});
             my $start_page =                  } else {
                 &Apache::loncommon::start_page('Switching Server ...',undef,                      $dest = &uri_escape($env{'form.firsturl'});
                                                {'redirect'       => [0,$url],});                  }
             my $end_page   = &Apache::loncommon::end_page();                  $dest = &HTML::Entities::encode($dest,"'");
             $r->print($start_page.$end_page);              }
             return OK;              my %info = (
         }                           balcookie => $lonhost.':'.$balancer_cookie,
     }                         );
               if ($env{'form.ltoken'}) {
 #                  my %link_info = &Apache::lonnet::tmpget($env{'form.ltoken'});
 # Check if a LON-CAPA load balancer sent user here because user's browser sent                  if ($link_info{'linkprot'}) {
 # it a balancer cookie for an active session on this server.                      $info{'linkprot'} = $link_info{'linkprot'};
 #                  }
                   &Apache::lonnet::tmpdel($env{'form.ltoken'});
     my $balcookie;                  delete($env{'form.ltoken'});
     if ($env{'form.btoken'}) {              } elsif ($env{'form.linkkey'}) {
         my %info = &Apache::lonnet::tmpget($env{'form.btoken'});                  $info{'linkkey'} = $env{'form.linkkey'};
         $balcookie = $info{'balcookie'};                  delete($env{'form.linkkey'});
         &Apache::lonnet::tmpdel($env{'form.btoken'});              }
         delete($env{'form.btoken'});              my $balancer_token = &Apache::lonnet::tmpput(\%info,$found_server);
     }              if ($balancer_token) {
                   $dest .=  (($dest=~/\?/)?'&':'?') . 'btoken='.$balancer_token;
 #              }
 # If browser sent an old cookie for which the session file had been removed              unless ($found_server eq $lonhost) {
 # check if configuration for user's domain has a portal URL set.  If so                  my $alias = &Apache::lonnet::use_proxy_alias($r,$found_server);
 # switch user's log-in to the portal.                  $hostname = $alias if ($alias ne '');
 #              }
               my $url = $protocol.'://'.$hostname.$dest;
     if (($handle eq '') && ($userdom ne '')) {              my $start_page =
         my %domdefaults = &Apache::lonnet::get_domain_defaults($userdom);                  &Apache::loncommon::start_page('Switching Server ...',undef,
         if ($domdefaults{'portal_def'} =~ /^https?\:/) {                                                 {'redirect'       => [0,$url],});
             my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,              my $end_page   = &Apache::loncommon::end_page();
                                           {'redirect' => [0,$domdefaults{'portal_def'}],});              $r->print($start_page.$end_page);
             my $end_page   = &Apache::loncommon::end_page();              return OK;
             $r->print($start_page.$end_page);          }
             return OK;      }
         }  
     }  #
   # Check if a LON-CAPA load balancer sent user here because user's browser sent
     $env{'form.firsturl'} =~ s/(`)/'/g;  # it a balancer cookie for an active session on this server.
   #
 # -------------------------------- Prevent users from attempting to login twice  
     if ($handle ne '') {      my ($balcookie,$linkprot,$linkkey);
         &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);      if ($env{'form.btoken'}) {
  my $start_page =           my %info = &Apache::lonnet::tmpget($env{'form.btoken'});
     &Apache::loncommon::start_page('Already logged in');          $balcookie = $info{'balcookie'};
  my $end_page =           if ($balcookie) {
     &Apache::loncommon::end_page();              if ($info{'linkprot'}) {
         my $dest = '/adm/roles';                  $linkprot = $info{'linkprot'};
         if ($env{'form.firsturl'} ne '') {              } elsif ($info{'linkkey'}) {
             $dest = $env{'form.firsturl'};                   $linkkey = $info{'linkkey'};
         }              }
  $r->print(          }    
               $start_page          &Apache::lonnet::tmpdel($env{'form.btoken'});
              .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'          delete($env{'form.btoken'});
              .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',      }
               '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'  
              .$end_page  #
              );  # If browser sent an old cookie for which the session file had been removed
         return OK;  # check if configuration for user's domain has a portal URL set.  If so
     }  # switch user's log-in to the portal.
   #
 # ---------------------------------------------------- No valid token, continue  
       if (($handle eq '') && ($userdom ne '')) {
 # ---------------------------- Not possible to really login to domain "public"          my %domdefaults = &Apache::lonnet::get_domain_defaults($userdom);
     if ($env{'form.domain'} eq 'public') {          if ($domdefaults{'portal_def'} =~ /^https?\:/) {
  $env{'form.domain'}='';              my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
  $env{'form.username'}='';                                            {'redirect' => [0,$domdefaults{'portal_def'}],});
     }              my $end_page   = &Apache::loncommon::end_page();
               $r->print($start_page.$end_page);
 # ------ Is this page requested because /adm/migrateuser detected an IP change?              return OK;
     my %sessiondata;          }
     if ($env{'form.iptoken'}) {      }
         %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});  
         unless ($sessiondata{'sessionserver'}) {  # -------------------------------- Prevent users from attempting to login twice
             my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});      if ($handle ne '') {
             delete($env{'form.iptoken'});          &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
         }   my $start_page =
     }      &Apache::loncommon::start_page('Already logged in');
 # ----------------------------------------------------------- Process Interface   my $end_page =
     $env{'form.interface'}=~s/\W//g;      &Apache::loncommon::end_page();
           my $dest = '/adm/roles';
     (undef,undef,undef,undef,undef,undef,my $clientmobile) =          if ($env{'form.firsturl'} ne '') {
         &Apache::loncommon::decode_user_agent();              if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) {
                   $dest = &uri_escape_utf8($env{'form.firsturl'});
     my $iconpath=               } else {
  &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));                  $dest = &uri_escape($env{'form.firsturl'});
               }
     my $domain = &Apache::lonnet::default_login_domain();              $dest = &HTML::Entities::encode($dest,"'");
     my $defdom = $domain;          }
     if ($lonhost ne '') {          if (($env{'form.ltoken'}) || ($linkprot)) {
         unless ($sessiondata{'sessionserver'}) {              unless ($linkprot) {
             my $redirect = &check_loginvia($domain,$lonhost,$lonidsdir,$balcookie);                  my %info = &Apache::lonnet::tmpget($env{'form.ltoken'});
             if ($redirect) {                  $linkprot = $info{'linkprot'};
                 $r->print($redirect);                  my $delete = &Apache::lonnet::tmpdel($env{'form.ltoken'});
                 return OK;                  delete($env{'form.ltoken'});
             }              }
         }              if ($linkprot) {
     }                  my ($linkprotector,$deeplink) = split(/:/,$linkprot,2);
                   if ($env{'user.linkprotector'}) {
     if (($sessiondata{'domain'}) &&                      my @protectors = split(/,/,$env{'user.linkprotector'});
         (&Apache::lonnet::domain($sessiondata{'domain'},'description'))) {                      unless (grep(/^\Q$linkprotector\E$/,@protectors)) {
         $domain=$sessiondata{'domain'};                          push(@protectors,$linkprotector);
     } elsif (($env{'form.domain'}) &&                           @protectors = sort { $a <=> $b } @protectors;
  (&Apache::lonnet::domain($env{'form.domain'},'description'))) {                          &Apache::lonnet::appenv({'user.linkprotector' => join(',',@protectors)});
  $domain=$env{'form.domain'};                      }
     }                  } else {
                       &Apache::lonnet::appenv({'user.linkprotector' => $linkprotector });
     my $role    = $r->dir_config('lonRole');                  }
     my $loadlim = $r->dir_config('lonLoadLim');                  if ($env{'user.linkproturi'}) {
     my $uloadlim= $r->dir_config('lonUserLoadLim');                      my @proturis = split(/,/,$env{'user.linkproturi'});
     my $servadm = $r->dir_config('lonAdmEMail');                      unless (grep(/^\Q$deeplink\E$/,@proturis)) {
     my $tabdir  = $r->dir_config('lonTabDir');                          push(@proturis,$deeplink);
     my $include = $r->dir_config('lonIncludes');                          @proturis = sort @proturis;
     my $expire  = $r->dir_config('lonExpire');                          &Apache::lonnet::appenv({'user.linkproturi' => join(',',@proturis)});
     my $version = $r->dir_config('lonVersion');                      }
     my $host_name = &Apache::lonnet::hostname($lonhost);                  } else {
                       &Apache::lonnet::appenv({'user.linkproturi' => $deeplink});
 # --------------------------------------------- Default values for login fields                  }
                   }
     my ($authusername,$authdomain);          } elsif (($env{'form.linkkey'}) || ($linkkey)) {
     if ($sessiondata{'username'}) {              if ($env{'form.firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
         $authusername=$sessiondata{'username'};                  if ($linkkey eq '') {
     } else {                      $linkkey = $env{'form.linkkey'};
         $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});                  }
         $authusername=($env{'form.username'}?$env{'form.username'}:'');                  if ($env{'user.deeplinkkey'}) {
     }                      my @linkkeys = split(/,/,$env{'user.deeplinkkey'});
     if ($sessiondata{'domain'}) {                      unless (grep(/^\Q$linkkey\E$/,@linkkeys)) {
         $authdomain=$sessiondata{'domain'};                          push(@linkkeys,$linkkey);
     } else {                          &Apache::lonnet::appenv({'user.deeplinkkey' => join(',',sort(@linkkeys))});  
         $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});                      }
         $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);                  } else {
     }                      &Apache::lonnet::appenv({'user.deeplinkkey' => $linkkey});
                   }
 # ---------------------------------------------------------- Determine own load                  my $deeplink = $env{'form.firsturl'};
     my $loadavg;                  if ($env{'user.keyedlinkuri'}) {
     {                      my @keyeduris = split(/,/,$env{'user.keyedlinkuri'});
  my $loadfile=Apache::File->new('/proc/loadavg');                      unless (grep(/^\Q$deeplink\E$/,@keyeduris)) {
  $loadavg=<$loadfile>;                          push(@keyeduris,$deeplink);
     }                          &Apache::lonnet::appenv({'user.keyedlinkuri' => join(',',sort(@keyeduris))});
     $loadavg =~ s/\s.*//g;                      }
                   } else {
     my ($loadpercent,$userloadpercent);                      &Apache::lonnet::appenv({'user.keyedlinkuri' => $deeplink});
     if ($loadlim) {                  }
         $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);              }
     }          }
     if ($uloadlim) {   $r->print(
         $userloadpercent=&Apache::lonnet::userload();                    $start_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].',
     my $firsturl=                    '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
     ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});                   .$end_page
                    );
 # ----------------------------------------------------------- Get announcements          return OK;
     my $announcements=&Apache::lonnet::getannounce();      }
 # -------------------------------------------------------- Set login parameters  
   # ---------------------------------------------------- No valid token, continue
     my @hexstr=('0','1','2','3','4','5','6','7',  
                 '8','9','a','b','c','d','e','f');  # ---------------------------- Not possible to really login to domain "public"
     my $lkey='';      if ($env{'form.domain'} eq 'public') {
     for (0..7) {   $env{'form.domain'}='';
         $lkey.=$hexstr[rand(15)];   $env{'form.username'}='';
     }      }
   
     my $ukey='';  # ------ Is this page requested because /adm/migrateuser detected an IP change?
     for (0..7) {      my %sessiondata;
         $ukey.=$hexstr[rand(15)];      if ($env{'form.iptoken'}) {
     }          %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});
           unless ($sessiondata{'sessionserver'}) {
     my $lextkey=hex($lkey);              my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});
     if ($lextkey>2147483647) { $lextkey-=4294967296; }              delete($env{'form.iptoken'});
           }
     my $uextkey=hex($ukey);      }
     if ($uextkey>2147483647) { $uextkey-=4294967296; }  # ----------------------------------------------------------- Process Interface
       $env{'form.interface'}=~s/\W//g;
 # -------------------------------------------------------- Store away log token  
     my $tokenextras;      (undef,undef,undef,undef,undef,undef,my $clientmobile) =
     if ($env{'form.role'}) {          &Apache::loncommon::decode_user_agent();
         $tokenextras = '&role='.&escape($env{'form.role'});  
     }      my $iconpath=
     if ($env{'form.symb'}) {   &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
         if (!$tokenextras) {  
             $tokenextras = '&';      my $domain = &Apache::lonnet::default_login_domain();
         }      my $defdom = $domain;
         $tokenextras .= '&symb='.&escape($env{'form.symb'});      if ($lonhost ne '') {
     }          unless ($sessiondata{'sessionserver'}) {
     if ($env{'form.iptoken'}) {              my $redirect = &check_loginvia($domain,$lonhost,$lonidsdir,$balcookie,$linkprot);
         if (!$tokenextras) {              if ($redirect) {
             $tokenextras = '&&';                  $r->print($redirect);
         }                  return OK;
         $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});              }
     }          }
     my $logtoken=Apache::lonnet::reply(      }
        'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,  
        $lonhost);      if (($sessiondata{'domain'}) &&
           (&Apache::lonnet::domain($sessiondata{'domain'},'description'))) {
 # -- If we cannot talk to ourselves, or hostID does not map to a hostname          $domain=$sessiondata{'domain'};
 #    we are in serious trouble      } elsif (($env{'form.domain'}) &&
    (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
     if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {   $domain=$env{'form.domain'};
         if ($logtoken eq 'no_such_host') {      }
             &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');  
         }      my $role    = $r->dir_config('lonRole');
         my $spares='';      my $loadlim = $r->dir_config('lonLoadLim');
         my (@sparehosts,%spareservers);      my $uloadlim= $r->dir_config('lonUserLoadLim');
         my $sparesref = &Apache::lonnet::this_host_spares($defdom);      my $servadm = $r->dir_config('lonAdmEMail');
         if (ref($sparesref) eq 'HASH') {      my $tabdir  = $r->dir_config('lonTabDir');
             foreach my $key (keys(%{$sparesref})) {      my $include = $r->dir_config('lonIncludes');
                 if (ref($sparesref->{$key}) eq 'ARRAY') {      my $expire  = $r->dir_config('lonExpire');
                     my @sorted = sort { &Apache::lonnet::hostname($a) cmp      my $version = $r->dir_config('lonVersion');
                                         &Apache::lonnet::hostname($b);      my $host_name = &Apache::lonnet::hostname($lonhost);
                                       } @{$sparesref->{$key}};  
                     if (@sorted) {  # --------------------------------------------- Default values for login fields
                         if ($key eq 'primary') {     
                             unshift(@sparehosts,@sorted);      my ($authusername,$authdomain);
                         } elsif ($key eq 'default') {      if ($sessiondata{'username'}) {
                             push(@sparehosts,@sorted);          $authusername=$sessiondata{'username'};
                         }      } else {
                     }          $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
                 }          $authusername=($env{'form.username'}?$env{'form.username'}:'');
             }      }
         }      if ($sessiondata{'domain'}) {
         foreach my $hostid (@sparehosts) {          $authdomain=$sessiondata{'domain'};
             next if ($hostid eq $lonhost);      } else {
     my $hostname = &Apache::lonnet::hostname($hostid);          $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
     next if (($hostname eq '') || ($spareservers{$hostname}));          $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
             $spareservers{$hostname} = 1;      }
             my $protocol = $Apache::lonnet::protocol{$hostid};  
             $protocol = 'http' if ($protocol ne 'https');  # ---------------------------------------------------------- Determine own load
             $spares.='<br /><span style="font-size: larger;"><a href="'.$protocol.'://'.      my $loadavg;
                 $hostname.      {
                 '/adm/login?domain='.$authdomain.'">'.   my $loadfile=Apache::File->new('/proc/loadavg');
                 $hostname.'</a>'.   $loadavg=<$loadfile>;
                 ' '.&mt('(preferred)').'</span>'.$/;      }
         }      $loadavg =~ s/\s.*//g;
         if ($spares) {  
             $spares.= '<br />';      my ($loadpercent,$userloadpercent);
         }      if ($loadlim) {
         my %all_hostnames = &Apache::lonnet::all_hostnames();          $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
         foreach my $hostid (sort      }
     {      if ($uloadlim) {
  &Apache::lonnet::hostname($a) cmp          $userloadpercent=&Apache::lonnet::userload();
     &Apache::lonnet::hostname($b);      }
     }  
     keys(%all_hostnames)) {      my $firsturl=
             next if ($hostid eq $lonhost);      ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
             my $hostname = &Apache::lonnet::hostname($hostid);  
             next if (($hostname eq '') || ($spareservers{$hostname}));  # ----------------------------------------------------------- Get announcements
             $spareservers{$hostname} = 1;      my $announcements=&Apache::lonnet::getannounce();
             my $protocol = $Apache::lonnet::protocol{$hostid};  # -------------------------------------------------------- Set login parameters
             $protocol = 'http' if ($protocol ne 'https');  
             $spares.='<br /><a href="'.$protocol.'://'.      my @hexstr=('0','1','2','3','4','5','6','7',
              $hostname.                  '8','9','a','b','c','d','e','f');
              '/adm/login?domain='.$authdomain.'">'.      my $lkey='';
              $hostname.'</a>';      for (0..7) {
          }          $lkey.=$hexstr[rand(15)];
          $r->print(      }
    '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'  
   .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'      my $ukey='';
   .'<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>'      for (0..7) {
   .&mt('The LearningOnline Network with CAPA')          $ukey.=$hexstr[rand(15)];
   .'</title></head>'      }
   .'<body bgcolor="#FFFFFF">'  
   .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'      my $lextkey=hex($lkey);
   .'<img src="/adm/lonKaputt/lonlogo_broken.gif" alt="broken icon" align="right" />'      if ($lextkey>2147483647) { $lextkey-=4294967296; }
   .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');  
         if ($spares) {      my $uextkey=hex($ukey);
             $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')      if ($uextkey>2147483647) { $uextkey-=4294967296; }
                      .'</p>'  
                      .$spares);  # -------------------------------------------------------- Store away log token
         }      my $tokenextras;
         $r->print('</body>'      if ($env{'form.role'}) {
                  .'</html>'          $tokenextras = '&role='.&escape($env{'form.role'});
         );      }
         return OK;      if ($env{'form.symb'}) {
     }          if (!$tokenextras) {
               $tokenextras = '&';
 # ----------------------------------------------- Apparently we are in business          }
     $servadm=~s/\,/\<br \/\>/g;          $tokenextras .= '&symb='.&escape($env{'form.symb'});
       }
 # ----------------------------------------------------------- Front page design      if ($env{'form.iptoken'}) {
     my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);          if (!$tokenextras) {
     my $font=&Apache::loncommon::designparm('login.font',$domain);              $tokenextras = '&&';
     my $link=&Apache::loncommon::designparm('login.link',$domain);          }
     my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);          $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});
     my $alink=&Apache::loncommon::designparm('login.alink',$domain);      }
     my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);      if ($env{'form.ltoken'}) {
     my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);          my %info = &Apache::lonnet::tmpget($env{'form.ltoken'});
     my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);          &Apache::lonnet::tmpdel($env{'form.ltoken'});
     my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);          delete($env{'form.ltoken'});
     my $logo=&Apache::loncommon::designparm('login.logo',$domain);          if ($info{'linkprot'}) {
     my $img=&Apache::loncommon::designparm('login.img',$domain);              if (!$tokenextras) {
     my $domainlogo=&Apache::loncommon::domainlogo($domain);                  $tokenextras = '&&&';
     my $showbanner = 1;              }
     my $showmainlogo = 1;              $tokenextras .= '&linkprot='.&escape($info{'linkprot'});
     if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {          }
         $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);      } elsif ($env{'form.linkkey'}) {
     }          if (!$tokenextras) {
     if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {              $tokenextras = '&&&';
         $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);          }
     }          $tokenextras .= '&linkkey='.&escape($env{'form.linkkey'});
     my $showadminmail;      }
     my @possdoms = &Apache::lonnet::current_machine_domains();      my $logtoken=Apache::lonnet::reply(
     if (grep(/^\Q$domain\E$/,@possdoms)) {         'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
         $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);         $lonhost);
     }  
     my $showcoursecat =  # -- If we cannot talk to ourselves, or hostID does not map to a hostname
         &Apache::loncommon::designparm('login.coursecatalog',$domain);  #    we are in serious trouble
     my $shownewuserlink =   
         &Apache::loncommon::designparm('login.newuser',$domain);      if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
     my $showhelpdesk =          if ($logtoken eq 'no_such_host') {
         &Apache::loncommon::designparm('login.helpdesk',$domain);              &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
     my $now=time;          }
     my $js = (<<ENDSCRIPT);          my $spares='';
           my (@sparehosts,%spareservers);
 <script type="text/javascript" language="JavaScript">          my $sparesref = &Apache::lonnet::this_host_spares($defdom);
 // <![CDATA[          if (ref($sparesref) eq 'HASH') {
 function send()              foreach my $key (keys(%{$sparesref})) {
 {                  if (ref($sparesref->{$key}) eq 'ARRAY') {
 this.document.server.elements.uname.value                      my @sorted = sort { &Apache::lonnet::hostname($a) cmp
 =this.document.client.elements.uname.value;                                          &Apache::lonnet::hostname($b);
                                         } @{$sparesref->{$key}};
 this.document.server.elements.udom.value                      if (@sorted) {
 =this.document.client.elements.udom.value;                          if ($key eq 'primary') {
                               unshift(@sparehosts,@sorted);
 uextkey=this.document.client.elements.uextkey.value;                          } elsif ($key eq 'default') {
 lextkey=this.document.client.elements.lextkey.value;                              push(@sparehosts,@sorted);
 initkeys();                          }
                       }
 this.document.server.elements.upass0.value                  }
     =getCrypted(this.document.client.elements.upass$now.value);              }
           }
 this.document.client.elements.uname.value='';          foreach my $hostid (@sparehosts) {
 this.document.client.elements.upass$now.value='';              next if ($hostid eq $lonhost);
       my $hostname = &Apache::lonnet::hostname($hostid);
 this.document.server.submit();      next if (($hostname eq '') || ($spareservers{$hostname}));
 return false;              $spareservers{$hostname} = 1;
 }              my $protocol = $Apache::lonnet::protocol{$hostid};
               $protocol = 'http' if ($protocol ne 'https');
 function enableInput() {              $spares.='<br /><span style="font-size: larger;"><a href="'.$protocol.'://'.
     this.document.client.elements.upass$now.removeAttribute("readOnly");                  $hostname.
     this.document.client.elements.uname.removeAttribute("readOnly");                  '/adm/login?domain='.$authdomain.'">'.
     this.document.client.elements.udom.removeAttribute("readOnly");                  $hostname.'</a>'.
     return;                  ' '.&mt('(preferred)').'</span>'.$/;
 }          }
           if ($spares) {
 // ]]>              $spares.= '<br />';
 </script>          }
           my %all_hostnames = &Apache::lonnet::all_hostnames();
 ENDSCRIPT          foreach my $hostid (sort
       {
 # --------------------------------------------------- Print login screen header   &Apache::lonnet::hostname($a) cmp
       &Apache::lonnet::hostname($b);
     my %add_entries = (      }
        bgcolor      => "$mainbg",      keys(%all_hostnames)) {
        text         => "$font",              next if ($hostid eq $lonhost);
        link         => "$link",              my $hostname = &Apache::lonnet::hostname($hostid);
        vlink        => "$vlink",              next if (($hostname eq '') || ($spareservers{$hostname}));
        alink        => "$alink",              $spareservers{$hostname} = 1;
                onload       => 'javascript:enableInput();',);              my $protocol = $Apache::lonnet::protocol{$hostid};
               $protocol = 'http' if ($protocol ne 'https');
     my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);              $spares.='<br /><a href="'.$protocol.'://'.
     @hosts = &Apache::lonnet::current_machine_ids();               $hostname.
     $lonhost_in_use = $lonhost;               '/adm/login?domain='.$authdomain.'">'.
     if (@hosts > 1) {               $hostname.'</a>';
         foreach my $hostid (@hosts) {           }
             if (&Apache::lonnet::host_domain($hostid) eq $defdom) {           $r->print(
                 $lonhost_in_use = $hostid;     '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
                 last;    .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'
             }    .'<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>'
         }    .&mt('The LearningOnline Network with CAPA')
     }    .'</title></head>'
     %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);    .'<body bgcolor="#FFFFFF">'
     $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};    .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
     $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};    .'<img src="/adm/lonKaputt/lonlogo_broken.gif" alt="broken icon" align="right" />'
     if ($headextra) {    .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
         my $omitextra;          if ($spares) {
         if ($headextra_exempt ne '') {              $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
             my @exempt = split(',',$headextra_exempt);                       .'</p>'
             my $ip = $ENV{'REMOTE_ADDR'};                       .$spares);
             if (grep(/^\Q$ip\E$/,@exempt)) {          }
                 $omitextra = 1;          $r->print('</body>'
             }                   .'</html>'
         }          );
         unless ($omitextra) {          return OK;
             my $confname = $defdom.'-domainconfig';      }
             if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {  
                 my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));  # ----------------------------------------------- Apparently we are in business
                 unless ($extra eq '-1') {      $servadm=~s/\,/\<br \/\>/g;
                     $js .= "\n".$extra."\n";  
                 }  # ----------------------------------------------------------- Front page design
             }      my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
         }      my $font=&Apache::loncommon::designparm('login.font',$domain);
     }      my $link=&Apache::loncommon::designparm('login.link',$domain);
       my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
     $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,      my $alink=&Apache::loncommon::designparm('login.alink',$domain);
        { 'redirect'       => [$expire,'/adm/roles'],       my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
  'add_entries' => \%add_entries,      my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
  'only_body'   => 1,}));      my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
       my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
 # ----------------------------------------------------------------------- Texts      my $logo=&Apache::loncommon::designparm('login.logo',$domain);
       my $img=&Apache::loncommon::designparm('login.img',$domain);
     my %lt=&Apache::lonlocal::texthash(      my $domainlogo=&Apache::loncommon::domainlogo($domain);
           'un'       => 'Username',      my $showbanner = 1;
           'pw'       => 'Password',      my $showmainlogo = 1;
           'dom'      => 'Domain',      if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
           'perc'     => 'percent',          $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
           'load'     => 'Server Load',      }
           'userload' => 'User Load',      if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
           'catalog'  => 'Course/Community Catalog',          $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
           'log'      => 'Log in',      }
           'help'     => 'Log-in Help',      my $showadminmail;
           'serv'     => 'Server',      my @possdoms = &Apache::lonnet::current_machine_domains();
           'servadm'  => 'Server Administration',      if (grep(/^\Q$domain\E$/,@possdoms)) {
           'helpdesk' => 'Contact Helpdesk',          $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
           'forgotpw' => 'Forgot password?',      }
           'newuser'  => 'New User?',      my $showcoursecat =
        );          &Apache::loncommon::designparm('login.coursecatalog',$domain);
 # -------------------------------------------------- Change password field name      my $shownewuserlink =
           &Apache::loncommon::designparm('login.newuser',$domain);
     my $forgotpw = &forgotpwdisplay(%lt);      my $showhelpdesk =
     $forgotpw .= '<br />' if $forgotpw;          &Apache::loncommon::designparm('login.helpdesk',$domain);
     my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);      my $now=time;
     if ($loginhelp) {      my $js = (<<ENDSCRIPT);
         $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';  
     }  <script type="text/javascript" language="JavaScript">
   // <![CDATA[
 # ---------------------------------------------------- Serve out DES JavaScript  function send()
     {  {
     my $jsh=Apache::File->new($include."/londes.js");  this.document.server.elements.uname.value
     $r->print(<$jsh>);  =this.document.client.elements.uname.value;
     }  
 # ---------------------------------------------------------- Serve rest of page  this.document.server.elements.udom.value
   =this.document.client.elements.udom.value;
     $r->print(  
     '<div class="LC_Box"'  uextkey=this.document.client.elements.uextkey.value;
    .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'  lextkey=this.document.client.elements.lextkey.value;
 );  initkeys();
   
     $r->print(<<ENDSERVERFORM);  if(this.document.server.action.substr(0,5) === 'http:'){
 <form name="server" action="/adm/authenticate" method="post" target="_top">      this.document.server.elements.upass0.value
    <input type="hidden" name="logtoken" value="$logtoken" />          =getCrypted(this.document.client.elements.upass$now.value);
    <input type="hidden" name="serverid" value="$lonhost" />  } else {
    <input type="hidden" name="uname" value="" />      this.document.server.elements.upass0.value
    <input type="hidden" name="upass0" value="" />          =this.document.client.elements.upass$now.value;
    <input type="hidden" name="udom" value="" />  }
    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />  
    <input type="hidden" name="localres" value="$env{'form.localres'}" />  this.document.client.elements.uname.value='';
   </form>  this.document.client.elements.upass$now.value='';
 ENDSERVERFORM  
     my $coursecatalog;  this.document.server.submit();
     if (($showcoursecat eq '') || ($showcoursecat)) {  return false;
         $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';  }
     }  
     my $newuserlink;  function enableInput() {
     if ($shownewuserlink) {      this.document.client.elements.upass$now.removeAttribute("readOnly");
         $newuserlink = &newuser_link($lt{'newuser'}).'<br />';      this.document.client.elements.uname.removeAttribute("readOnly");
     }      this.document.client.elements.udom.removeAttribute("readOnly");
     my $logintitle =      return;
         '<h2 class="LC_hcell"'  }
        .' style="background:'.$loginbox_header_bgcol.';'  
        .' color:'.$loginbox_header_textcol.'">'  // ]]>
        .$lt{'log'}  </script>
        .'</h2>';  
   ENDSCRIPT
     my $noscript_warning='<noscript><span class="LC_warning"><b>'  
                         .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')      my ($lonhost_in_use,@hosts,%defaultdomconf,$saml_prefix,$saml_landing,
                         .'</b></span></noscript>';          $samlssotext,$samlnonsso,$samlssoimg,$samlssoalt,$samlssourl,$samltooltip);
     my $helpdeskscript;      %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
     my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,      @hosts = &Apache::lonnet::current_machine_ids();
                                        $authdomain,\$helpdeskscript,      $lonhost_in_use = $lonhost;
                                        $showhelpdesk,\@possdoms);      if (@hosts > 1) {
           foreach my $hostid (@hosts) {
     my $mobileargs;              if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
     if ($clientmobile) {                  $lonhost_in_use = $hostid;
         $mobileargs = 'autocapitalize="off" autocorrect="off"';                   last;
     }              }
     my $loginform=(<<LFORM);          }
 <form name="client" action="" onsubmit="return(send())">      }
   <input type="hidden" name="lextkey" value="$lextkey" />      $saml_prefix = $defdom.'.login.saml_';
   <input type="hidden" name="uextkey" value="$uextkey" />      if ($defaultdomconf{$saml_prefix.$lonhost_in_use}) {
   <b><label for="uname">$lt{'un'}</label>:</b><br />          $saml_landing = 1;
   <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />          $samlssotext = $defaultdomconf{$saml_prefix.'text_'.$lonhost_in_use};
   <b><label for="upass$now">$lt{'pw'}</label>:</b><br />          $samlnonsso = $defaultdomconf{$saml_prefix.'notsso_'.$lonhost_in_use};
   <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />          $samlssoimg = $defaultdomconf{$saml_prefix.'img_'.$lonhost_in_use};
   <b><label for="udom">$lt{'dom'}</label>:</b><br />          $samlssoalt = $defaultdomconf{$saml_prefix.'alt_'.$lonhost_in_use};
   <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />          $samlssourl = $defaultdomconf{$saml_prefix.'url_'.$lonhost_in_use};
   <input type="submit" value="$lt{'log'}" />          $samltooltip = $defaultdomconf{$saml_prefix.'title_'.$lonhost_in_use};
 </form>      }
 LFORM      if ($saml_landing) {
          if ($samlssotext eq '') {
     if ($showbanner) {             $samlssotext = 'SSO Login';
         $r->print(<<HEADER);         }
 <!-- The LON-CAPA Header -->         if ($samlnonsso eq '') {
 <div style="background:$pgbg;margin:0;width:100%;">             $samlnonsso = 'Non-SSO Login';
   <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />         }
 </div>         $js .= <<"ENDSAMLJS";
 HEADER  
     }  <script type="text/javascript">
     $r->print(<<ENDTOP);  // <![CDATA[
 <div style="float:left;margin-top:0;">  function toggleLClogin() {
 <div class="LC_Box" style="background:$loginbox_bg;">      if (document.getElementById('LC_standard_login')) {
   $logintitle          if (document.getElementById('LC_standard_login').style.display == 'none') {
   $loginform              document.getElementById('LC_standard_login').style.display = 'inline-block';
   $noscript_warning              if (document.getElementById('LC_login_text')) {
 </div>                  document.getElementById('LC_login_text').innerHTML = '$samlnonsso';
                 }
 <div class="LC_Box" style="padding-top: 10px;">              if (document.getElementById('LC_SSO_login')) {
   $loginhelp                  document.getElementById('LC_SSO_login').style.display = 'none';
   $forgotpw              }
   $contactblock          } else {
   $newuserlink              document.getElementById('LC_standard_login').style.display = 'none';
   $coursecatalog              if (document.getElementById('LC_login_text')) {
 </div>                  document.getElementById('LC_login_text').innerHTML = '$samlssotext';
 </div>              }
               if (document.getElementById('LC_SSO_login')) {
 <div>                  document.getElementById('LC_SSO_login').style.display = 'inline-block';
 ENDTOP              }
     if ($showmainlogo) {          }
         $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");      }
     }      return;
 $r->print(<<ENDTOP);  }
 $announcements  
 </div>  // ]]>
 <hr style="clear:both;" />  </script>
 ENDTOP  
     my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);  ENDSAMLJS
     $domainrow = <<"END";      }
       <tr>  
        <td  align="left" valign="top">  # --------------------------------------------------- Print login screen header
         <small><b>$lt{'dom'}:&nbsp;</b></small>  
        </td>      my %add_entries = (
        <td  align="left" valign="top">         bgcolor      => "$mainbg",
         <small><tt>&nbsp;$domain</tt></small>         text         => "$font",
        </td>         link         => "$link",
       </tr>         vlink        => "$vlink",
 END         alink        => "$alink",
     $serverrow = <<"END";                 onload       => 'javascript:enableInput();',);
       <tr>  
        <td  align="left" valign="top">      my ($headextra,$headextra_exempt);
         <small><b>$lt{'serv'}:&nbsp;</b></small>      $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
        </td>      $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
        <td align="left" valign="top">      if ($headextra) {
         <small><tt>&nbsp;$lonhost ($role)</tt></small>          my $omitextra;
        </td>          if ($headextra_exempt ne '') {
       </tr>              my @exempt = split(',',$headextra_exempt);
 END              my $ip = &Apache::lonnet::get_requestor_ip();
     if ($loadlim) {              if (grep(/^\Q$ip\E$/,@exempt)) {
         $loadrow = <<"END";                  $omitextra = 1;
       <tr>              }
        <td align="left" valign="top">          }
         <small><b>$lt{'load'}:&nbsp;</b></small>          unless ($omitextra) {
        </td>              my $confname = $defdom.'-domainconfig';
        <td align="left" valign="top">              if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>                  my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
        </td>                  unless ($extra eq '-1') {
       </tr>                      $js .= "\n".$extra."\n";
 END                  }
     }              }
     if ($uloadlim) {          }
         $userloadrow = <<"END";      }
       <tr>  
        <td align="left" valign="top">      $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
         <small><b>$lt{'userload'}:&nbsp;</b></small>         { 'redirect'       => [$expire,'/adm/roles'],
        </td>   'add_entries' => \%add_entries,
        <td align="left" valign="top">   'only_body'   => 1,}));
         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>  
        </td>  # ----------------------------------------------------------------------- Texts
       </tr>  
 END      my %lt=&Apache::lonlocal::texthash(
     }            'un'       => 'Username',
     if (($version ne '') && ($version ne '<!-- VERSION -->')) {            'pw'       => 'Password',
         $versionrow = <<"END";            'dom'      => 'Domain',
       <tr>            'perc'     => 'percent',
        <td colspan="2" align="left">            'load'     => 'Server Load',
         <small>$version</small>            'userload' => 'User Load',
        </td>            'catalog'  => 'Course/Community Catalog',
       </tr>            'log'      => 'Log in',
 END            'help'     => 'Log-in Help',
     }            'serv'     => 'Server',
             'servadm'  => 'Server Administration',
     $r->print(<<ENDDOCUMENT);            'helpdesk' => 'Contact Helpdesk',
     <div style="float: left;">            'forgotpw' => 'Forgot password?',
      <table border="0" cellspacing="0" cellpadding="0">            'newuser'  => 'New User?',
 $domainrow            'change'   => 'Change?',
 $serverrow         );
 $loadrow      # -------------------------------------------------- Change password field name
 $userloadrow  
 $versionrow      my $forgotpw = &forgotpwdisplay(%lt);
      </table>      $forgotpw .= '<br />' if $forgotpw;
     </div>      my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
     <div style="float: right;">      if ($loginhelp) {
     $domainlogo          $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
     </div>      }
     <br style="clear:both;" />  
  </div>  # ---------------------------------------------------- Serve out DES JavaScript
       {
 <script type="text/javascript">      my $jsh=Apache::File->new($include."/londes.js");
 // <![CDATA[      $r->print(<$jsh>);
 // the if prevents the script error if the browser can not handle this      }
 if ( document.client.uname ) { document.client.uname.focus(); }  # ---------------------------------------------------------- Serve rest of page
 // ]]>  
 </script>      $r->print(
 $helpdeskscript      '<div class="LC_Box"'
      .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
 ENDDOCUMENT  );
     my %endargs = ( 'noredirectlink' => 1, );  
     $r->print(&Apache::loncommon::end_page(\%endargs));      $r->print(<<ENDSERVERFORM);
     return OK;  <form name="server" action="/adm/authenticate" method="post" target="_top">
 }     <input type="hidden" name="logtoken" value="$logtoken" />
      <input type="hidden" name="serverid" value="$lonhost" />
 sub check_loginvia {     <input type="hidden" name="uname" value="" />
     my ($domain,$lonhost,$lonidsdir,$balcookie) = @_;     <input type="hidden" name="upass0" value="" />
     if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {     <input type="hidden" name="udom" value="" />
         return;     <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
     }     <input type="hidden" name="localres" value="$env{'form.localres'}" />
     my %domconfhash = &Apache::loncommon::get_domainconf($domain);    </form>
     my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};  ENDSERVERFORM
     my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};      my $coursecatalog;
     my $output;      if (($showcoursecat eq '') || ($showcoursecat)) {
     if ($loginvia ne '') {          $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
         my $noredirect;      }
         my $ip = $ENV{'REMOTE_ADDR'};      my $newuserlink;
         if ($ip eq '127.0.0.1') {      if ($shownewuserlink) {
             $noredirect = 1;          $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
         } else {      }
             if ($loginvia_exempt ne '') {      my $logintitle =
                 my @exempt = split(',',$loginvia_exempt);          '<h2 class="LC_hcell"'
                 if (grep(/^\Q$ip\E$/,@exempt)) {         .' style="background:'.$loginbox_header_bgcol.';'
                     $noredirect = 1;         .' color:'.$loginbox_header_textcol.'">'
                 }         .$lt{'log'}
             }         .'</h2>';
         }  
         unless ($noredirect) {      my $noscript_warning='<noscript><span class="LC_warning"><b>'
             my ($newhost,$path);                          .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
             if ($loginvia =~ /:/) {                          .'</b></span></noscript>';
                 ($newhost,$path) = split(':',$loginvia);      my $helpdeskscript;
             } else {      my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
                 $newhost = $loginvia;                                         $authdomain,\$helpdeskscript,
             }                                         $showhelpdesk,\@possdoms);
             if ($newhost ne $lonhost) {  
                 if (&Apache::lonnet::hostname($newhost) ne '') {      my $mobileargs;
                     if ($balcookie) {      if ($clientmobile) {
                         my ($balancer,$cookie) = split(/:/,$balcookie);          $mobileargs = 'autocapitalize="off" autocorrect="off"';
                         if ($cookie =~ /^($match_domain)_($match_username)_([a-f0-9]+)$/) {      }
                             my ($udom,$uname,$cookieid) = ($1,$2,$3);      my $loginform=(<<LFORM);
                             unless (&Apache::lonnet::delbalcookie($cookie,$balancer) eq 'ok') {  <form name="client" action="" onsubmit="return(send())" id="lclogin">
                                 if ((-d $lonidsdir) && (opendir(my $dh,$lonidsdir))) {    <input type="hidden" name="lextkey" value="$lextkey" />
                                     while (my $filename=readdir($dh)) {    <input type="hidden" name="uextkey" value="$uextkey" />
                                         if ($filename=~/^(\Q$uname\E_\d+_\Q$udom\E_$match_lonid)\.id$/) {    <b><label for="uname">$lt{'un'}</label>:</b><br />
                                             my $handle = $1;    <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
                                             my %hash =    <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
                                                 &Apache::lonnet::get_sessionfile_vars($handle,$lonidsdir,    <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
                                                                                      ['request.balancercookie',    <b><label for="udom">$lt{'dom'}</label>:</b><br />
                                                                                       'user.linkedenv']);    <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
                                             if ($hash{'request.balancercookie'} eq "$balancer:$cookieid") {    <input type="submit" value="$lt{'log'}" />
                                                 if (unlink("$lonidsdir/$filename")) {  </form>
                                                     if (($hash{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&  LFORM
                                                         (-l "$lonidsdir/$hash{'user.linkedenv'}.id") &&  
                                                         (readlink("$lonidsdir/$hash{'user.linkedenv'}.id") eq "$lonidsdir/$filename")) {      if ($showbanner) {
                                                         unlink("$lonidsdir/$hash{'user.linkedenv'}.id");          $r->print(<<HEADER);
                                                     }  <!-- The LON-CAPA Header -->
                                                 }  <div style="background:$pgbg;margin:0;width:100%;">
                                             }    <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />
                                             last;  </div>
                                         }  HEADER
                                     }      }
                                     closedir($dh);  
                                 }      my $stdauthformstyle = 'inline-block';
                             }      my $ssoauthstyle = 'none';
                         }      my $logintype;
                     }      $r->print('<div style="float:left;margin-top:0;">');
                     $output = &redirect_page($newhost,$path);      if ($saml_landing) {
                 }          $ssoauthstyle = 'inline-block';
             }          $stdauthformstyle = 'none';
         }          $logintype = $samlssotext;
     }          my $ssologin = '/adm/sso';
     return $output;          if ($samlssourl  ne '') {
 }              $ssologin = $samlssourl;
           }
 sub redirect_page {          if ($env{'form.firsturl'} ne '') {
     my ($desthost,$path) = @_;              my $querystring = 'origurl=';
     my $hostname = &Apache::lonnet::hostname($desthost);              if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) {
     my $protocol = $Apache::lonnet::protocol{$desthost};                  $querystring .= &uri_escape_utf8($env{'form.firsturl'});
     $protocol = 'http' if ($protocol ne 'https');              } else {
     unless ($path =~ m{^/}) {                  $querystring .= &uri_escape($env{'form.firsturl'});
         $path = '/'.$path;              }
     }              $querystring = &HTML::Entities::encode($querystring,"'");
     my $url = $protocol.'://'.$hostname.$path;              $ssologin .= (($ssologin=~/\?/)?'&amp;':'?') . $querystring;
     if ($env{'form.firsturl'} ne '') {          }
         $url .='?firsturl='.$env{'form.firsturl'};          my $ssohref;
     }          if ($samlssoimg ne '') {
     my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,              $ssohref = '<a href="'.$ssologin.'" title="'.$samltooltip.'"><img src="'.$samlssoimg.'" alt="'.$samlssoalt.'" /></a>';
                                                     {'redirect' => [0,$url],});          } else {
     my $end_page   = &Apache::loncommon::end_page();              $ssohref = '<a href="'.$ssologin.'">'.$samlssotext.'</a>';
     return $start_page.$end_page;          }
 }          if (($env{'form.saml'} eq 'no') ||
               (($env{'form.username'} ne '') && ($env{'form.domain'} ne ''))) {
 sub contactdisplay {              $ssoauthstyle = 'none';
     my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,              $stdauthformstyle = 'inline-block';
         $possdoms) = @_;              $logintype = $samlnonsso;
     my $contactblock;          }
     my $origmail;          $r->print(<<ENDSAML);
     if (ref($possdoms) eq 'ARRAY') {  <p>
         if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {   Log-in type:
             $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};  <span style="font-weight:bold" id="LC_login_text">$logintype</span><br />
         }  <span><a href="javascript:toggleLClogin();" style="color:#000000">$lt{'change'}</a></span>
     }  </p>
     my $requestmail =   <div style="display:$ssoauthstyle" id="LC_SSO_login">
         &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',  <div class="LC_Box" style="padding-top: 10px;">
                                                  $authdomain,$origmail);  $ssohref
     unless ($showhelpdesk eq '0') {  $noscript_warning
         if ($requestmail =~ m/[^\@]+\@[^\@]+/) {  </div>
             $showhelpdesk = 1;  <div class="LC_Box" style="padding-top: 10px;">
         } else {  $loginhelp
             $showhelpdesk = 0;  $contactblock
         }  $coursecatalog
     }  </div>
     if ($servadm && $showadminmail) {  </div>
         $contactblock .= $$lt{'servadm'}.':<br />'.  ENDSAML
                          '<tt>'.$servadm.'</tt><br />';      }
     }  
     if ($showhelpdesk) {      $r->print(<<ENDLOGIN);
         $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';  <div style="display:$stdauthformstyle;" id="LC_standard_login">
         my $thisurl = &escape('/adm/login');  <div class="LC_Box" style="background:$loginbox_bg;">
         $$helpdeskscript = <<"ENDSCRIPT";    $logintitle
 <script type="text/javascript">    $loginform
 // <![CDATA[    $noscript_warning
 function helpdesk() {  </div>
     var possdom = document.client.udom.value;   
     var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');  <div class="LC_Box" style="padding-top: 10px;">
     if (codedom == '') {    $loginhelp
         codedom = "$authdomain";    $forgotpw
     }    $contactblock
     var querystr = "origurl=$thisurl&codedom="+codedom;    $newuserlink
     document.location.href = "/adm/helpdesk?"+querystr;    $coursecatalog
     return;  </div>
 }  </div>
 // ]]>  
 </script>  ENDLOGIN
 ENDSCRIPT      $r->print('</div><div>'."\n");
     }      if ($showmainlogo) {
     return $contactblock;          $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");
 }      }
   $r->print(<<ENDTOP);
 sub forgotpwdisplay {  $announcements
     my (%lt) = @_;  </div>
     my $prompt_for_resetpw = 1;   <hr style="clear:both;" />
     if ($prompt_for_resetpw) {  ENDTOP
         return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';      my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
     }      $domainrow = <<"END";
     return;        <tr>
 }         <td  align="left" valign="top">
           <small><b>$lt{'dom'}:&nbsp;</b></small>
 sub coursecatalog_link {         </td>
     my ($linkname) = @_;         <td  align="left" valign="top">
     return <<"END";          <small><tt>&nbsp;$domain</tt></small>
       <a href="/adm/coursecatalog">$linkname</a>         </td>
 END        </tr>
 }  END
       $serverrow = <<"END";
 sub newuser_link {        <tr>
     my ($linkname) = @_;         <td  align="left" valign="top">
     return '<a href="/adm/createaccount">'.$linkname.'</a>';          <small><b>$lt{'serv'}:&nbsp;</b></small>
 }         </td>
          <td align="left" valign="top">
 1;          <small><tt>&nbsp;$lonhost ($role)</tt></small>
 __END__         </td>
         </tr>
   END
       if ($loadlim) {
           $loadrow = <<"END";
         <tr>
          <td align="left" valign="top">
           <small><b>$lt{'load'}:&nbsp;</b></small>
          </td>
          <td align="left" valign="top">
           <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
          </td>
         </tr>
   END
       }
       if ($uloadlim) {
           $userloadrow = <<"END";
         <tr>
          <td align="left" valign="top">
           <small><b>$lt{'userload'}:&nbsp;</b></small>
          </td>
          <td align="left" valign="top">
           <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
          </td>
         </tr>
   END
       }
       if (($version ne '') && ($version ne '<!-- VERSION -->')) {
           $versionrow = <<"END";
         <tr>
          <td colspan="2" align="left">
           <small>$version</small>
          </td>
         </tr>
   END
       }
   
       $r->print(<<ENDDOCUMENT);
       <div style="float: left;">
        <table border="0" cellspacing="0" cellpadding="0">
   $domainrow
   $serverrow
   $loadrow    
   $userloadrow
   $versionrow
        </table>
       </div>
       <div style="float: right;">
       $domainlogo
       </div>
       <br style="clear:both;" />
    </div>
   
   <script type="text/javascript">
   // <![CDATA[
   // the if prevents the script error if the browser can not handle this
   if ( document.client.uname ) { document.client.uname.focus(); }
   // ]]>
   </script>
   $helpdeskscript
   
   ENDDOCUMENT
       my %endargs = ( 'noredirectlink' => 1, );
       $r->print(&Apache::loncommon::end_page(\%endargs));
       return OK;
   }
   
   sub check_loginvia {
       my ($domain,$lonhost,$lonidsdir,$balcookie,$linkprot) = @_;
       if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {
           return;
       }
       my %domconfhash = &Apache::loncommon::get_domainconf($domain);
       my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
       my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
       my $output;
       if ($loginvia ne '') {
           my $noredirect;
           my $ip = &Apache::lonnet::get_requestor_ip();  
           if ($ip eq '127.0.0.1') {
               $noredirect = 1;
           } else {
               if ($loginvia_exempt ne '') {
                   my @exempt = split(',',$loginvia_exempt);
                   if (grep(/^\Q$ip\E$/,@exempt)) {
                       $noredirect = 1;
                   }
               }
           }
           unless ($noredirect) {
               my ($newhost,$path);
               if ($loginvia =~ /:/) {
                   ($newhost,$path) = split(':',$loginvia);
               } else {
                   $newhost = $loginvia;
               }
               if ($newhost ne $lonhost) {
                   if (&Apache::lonnet::hostname($newhost) ne '') {
                       if ($balcookie) {
                           my ($balancer,$cookie) = split(/:/,$balcookie);
                           if ($cookie =~ /^($match_domain)_($match_username)_([a-f0-9]+)$/) {
                               my ($udom,$uname,$cookieid) = ($1,$2,$3);
                               unless (&Apache::lonnet::delbalcookie($cookie,$balancer) eq 'ok') {
                                   if ((-d $lonidsdir) && (opendir(my $dh,$lonidsdir))) {
                                       while (my $filename=readdir($dh)) {
                                           if ($filename=~/^(\Q$uname\E_\d+_\Q$udom\E_$match_lonid)\.id$/) {
                                               my $handle = $1;
                                               my %hash =
                                                   &Apache::lonnet::get_sessionfile_vars($handle,$lonidsdir,
                                                                                        ['request.balancercookie',
                                                                                         'user.linkedenv']);
                                               if ($hash{'request.balancercookie'} eq "$balancer:$cookieid") {
                                                   if (unlink("$lonidsdir/$filename")) {
                                                       if (($hash{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&
                                                           (-l "$lonidsdir/$hash{'user.linkedenv'}.id") &&
                                                           (readlink("$lonidsdir/$hash{'user.linkedenv'}.id") eq "$lonidsdir/$filename")) {
                                                           unlink("$lonidsdir/$hash{'user.linkedenv'}.id");
                                                       }
                                                   }
                                               }
                                               last;
                                           }
                                       }
                                       closedir($dh);
                                   }
                               }
                           }
                       }
                       $output = &redirect_page($newhost,$path,$linkprot);
                   }
               }
           }
       }
       return $output;
   }
   
   sub redirect_page {
       my ($desthost,$path,$linkprot) = @_;
       my $hostname = &Apache::lonnet::hostname($desthost);
       my $protocol = $Apache::lonnet::protocol{$desthost};
       $protocol = 'http' if ($protocol ne 'https');
       unless ($path =~ m{^/}) {
           $path = '/'.$path;
       }
       my $url = $protocol.'://'.$hostname.$path;
       if ($env{'form.firsturl'} ne '') {
           my $querystring;
           if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) {
               $querystring = &uri_escape_utf8($env{'form.firsturl'});
           } else {
               $querystring = &uri_escape($env{'form.firsturl'});
           }
           $querystring = &HTML::Entities::encode($querystring,"'");
           $url .='?firsturl='.$querystring
       }
       if ($linkprot) {
           my $ltoken = &Apache::lonnet::tmpput({linkprot => $linkprot},$desthost);
           if ($ltoken) {
               $url .= (($url =~ /\?/) ? '&amp;' : '?').'ltoken='.$ltoken;
           }
       }
       my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
                                                       {'redirect' => [0,$url],});
       my $end_page   = &Apache::loncommon::end_page();
       return $start_page.$end_page;
   }
   
   sub contactdisplay {
       my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
           $possdoms) = @_;
       my $contactblock;
       my $origmail;
       if (ref($possdoms) eq 'ARRAY') {
           if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {
               $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
           }
       }
       my $requestmail =
           &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
                                                    $authdomain,$origmail);
       unless ($showhelpdesk eq '0') {
           if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
               $showhelpdesk = 1;
           } else {
               $showhelpdesk = 0;
           }
       }
       if ($servadm && $showadminmail) {
           $contactblock .= $$lt{'servadm'}.':<br />'.
                            '<tt>'.$servadm.'</tt><br />';
       }
       if ($showhelpdesk) {
           $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
           my $thisurl = &escape('/adm/login');
           $$helpdeskscript = <<"ENDSCRIPT";
   <script type="text/javascript">
   // <![CDATA[
   function helpdesk() {
       var possdom = document.client.udom.value;
       var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
       if (codedom == '') {
           codedom = "$authdomain";
       }
       var querystr = "origurl=$thisurl&codedom="+codedom;
       document.location.href = "/adm/helpdesk?"+querystr;
       return;
   }
   // ]]>
   </script>
   ENDSCRIPT
       }
       return $contactblock;
   }
   
   sub forgotpwdisplay {
       my (%lt) = @_;
       my $prompt_for_resetpw = 1;
       if ($prompt_for_resetpw) {
           return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
       }
       return;
   }
   
   sub coursecatalog_link {
       my ($linkname) = @_;
       return <<"END";
         <a href="/adm/coursecatalog">$linkname</a>
   END
   }
   
   sub newuser_link {
       my ($linkname) = @_;
       return '<a href="/adm/createaccount">'.$linkname.'</a>';
   }
   
   1;
   __END__

Removed from v.1.158.2.9.2.2  
changed lines
  Added in v.1.190


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