Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.14 and 1.182

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


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