Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.4 and 1.177

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

Removed from v.1.158.2.4  
changed lines
  Added in v.1.177


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