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

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

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


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