Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.13.2.10 and 1.192

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

Removed from v.1.158.2.13.2.10  
changed lines
  Added in v.1.192


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