Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.11 and 1.187

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


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