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

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


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