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

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


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