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

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


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