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

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


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