Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.13.2.2 and 1.175

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


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