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

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


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