Diff for /loncom/auth/lonlogin.pm between versions 1.149 and 1.176

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


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