Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.13.2.4 and 1.203

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

Removed from v.1.158.2.13.2.4  
changed lines
  Added in v.1.203


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