Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.15 and 1.183

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

Removed from v.1.158.2.15  
changed lines
  Added in v.1.183


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