Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.13.2.5 and 1.172

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


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.