Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.6.2.2 and 1.194

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


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