Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.13.2.7 and 1.200

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


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