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

version 1.153, 2013/01/11 17:35: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',);
                  .'<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;
 # ----------------------------------------------------------- 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;      }
     my @possdoms = &Apache::lonnet::current_machine_domains();  
     if (grep(/^\Q$domain\E$/,@possdoms)) {      my $ukey='';
         $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);      for (0..7) {
     }          $ukey.=$hexstr[rand(15)];
     my $showcoursecat =      }
         &Apache::loncommon::designparm('login.coursecatalog',$domain);  
     my $shownewuserlink =       my $lextkey=hex($lkey);
         &Apache::loncommon::designparm('login.newuser',$domain);      if ($lextkey>2147483647) { $lextkey-=4294967296; }
     my $showhelpdesk =  
         &Apache::loncommon::designparm('login.helpdesk',$domain);      my $uextkey=hex($ukey);
     my $now=time;      if ($uextkey>2147483647) { $uextkey-=4294967296; }
     my $js = (<<ENDSCRIPT);  
   # -------------------------------------------------------- Store away log token
 <script type="text/javascript" language="JavaScript">      my $tokenextras;
 // <![CDATA[      if ($env{'form.role'}) {
 function send()          $tokenextras = '&role='.&escape($env{'form.role'});
 {      }
 this.document.server.elements.uname.value      if ($env{'form.symb'}) {
 =this.document.client.elements.uname.value;          if (!$tokenextras) {
               $tokenextras = '&';
 this.document.server.elements.udom.value          }
 =this.document.client.elements.udom.value;          $tokenextras .= '&symb='.&escape($env{'form.symb'});
       }
 uextkey=this.document.client.elements.uextkey.value;      if ($env{'form.iptoken'}) {
 lextkey=this.document.client.elements.lextkey.value;          if (!$tokenextras) {
 initkeys();              $tokenextras = '&&';
           }
 this.document.server.elements.upass0.value          $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});
     =crypted(this.document.client.elements.upass$now.value.substr(0,15));      }
 this.document.server.elements.upass1.value      my $logtoken=Apache::lonnet::reply(
     =crypted(this.document.client.elements.upass$now.value.substr(15,15));         'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
 this.document.server.elements.upass2.value         $lonhost);
     =crypted(this.document.client.elements.upass$now.value.substr(30,15));  
   # -- If we cannot talk to ourselves, or hostID does not map to a hostname
 this.document.client.elements.uname.value='';  #    we are in serious trouble
 this.document.client.elements.upass$now.value='';  
       if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
 this.document.server.submit();          if ($logtoken eq 'no_such_host') {
 return false;              &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
 }          }
           my $spares='';
 function enableInput() {   my $last;
     this.document.client.elements.upass$now.removeAttribute("readOnly");          foreach my $hostid (sort
     this.document.client.elements.uname.removeAttribute("readOnly");      {
     this.document.client.elements.udom.removeAttribute("readOnly");   &Apache::lonnet::hostname($a) cmp
     return;      &Apache::lonnet::hostname($b);
 }      }
       keys(%Apache::lonnet::spareid)) {
 // ]]>              next if ($hostid eq $lonhost);
 </script>      my $hostname = &Apache::lonnet::hostname($hostid);
       next if (($last eq $hostname) || ($hostname eq ''));
 ENDSCRIPT              $spares.='<br /><font size="+1"><a href="http://'.
                   $hostname.
 # --------------------------------------------------- Print login screen header                  '/adm/login?domain='.$authdomain.'">'.
                   $hostname.'</a>'.
     my %add_entries = (                  ' '.&mt('(preferred)').'</font>'.$/;
        bgcolor      => "$mainbg",      $last=$hostname;
        text         => "$font",          }
        link         => "$link",          if ($spares) {
        vlink        => "$vlink",              $spares.= '<br />';
        alink        => "$alink",          }
                onload       => 'javascript:enableInput();',);          my %all_hostnames = &Apache::lonnet::all_hostnames();
           foreach my $hostid (sort
     $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,      {
        { 'redirect'       => [$expire,'/adm/roles'],    &Apache::lonnet::hostname($a) cmp
  'add_entries' => \%add_entries,      &Apache::lonnet::hostname($b);
  'only_body'   => 1,}));      }
       keys(%all_hostnames)) {
 # ----------------------------------------------------------------------- Texts              next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
               my $hostname = &Apache::lonnet::hostname($hostid);
     my %lt=&Apache::lonlocal::texthash(              next if (($last eq $hostname) || ($hostname eq ''));
           'un'       => 'Username',              $spares.='<br /><a href="http://'.
           'pw'       => 'Password',               $hostname.
           'dom'      => 'Domain',               '/adm/login?domain='.$authdomain.'">'.
           'perc'     => 'percent',               $hostname.'</a>';
           'load'     => 'Server Load',              $last=$hostname;
           'userload' => 'User Load',           }
           'catalog'  => 'Course/Community Catalog',           $r->print(
           'log'      => 'Log in',     '<html>'
           'help'     => 'Log-in Help',    .'<head><title>'
           'serv'     => 'Server',    .&mt('The LearningOnline Network with CAPA')
           'servadm'  => 'Server Administration',    .'</title></head>'
           'helpdesk' => 'Contact Helpdesk',    .'<body bgcolor="#FFFFFF">'
           'forgotpw' => 'Forgot password?',    .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
           'newuser'  => 'New User?',    .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'
        );    .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
 # -------------------------------------------------- Change password field name          if ($spares) {
               $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
     my $forgotpw = &forgotpwdisplay(%lt);                       .'</p>'
     $forgotpw .= '<br />' if $forgotpw;                       .$spares);
     my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);          }
     if ($loginhelp) {          $r->print('</body>'
         $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';                   .'</html>'
     }          );
           return OK;
 # ---------------------------------------------------- Serve out DES JavaScript      }
     {  
     my $jsh=Apache::File->new($include."/londes.js");  # ----------------------------------------------- Apparently we are in business
     $r->print(<$jsh>);      $servadm=~s/\,/\<br \/\>/g;
     }  
 # ---------------------------------------------------------- Serve rest of page  # ----------------------------------------------------------- Front page design
       my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
     $r->print(      my $font=&Apache::loncommon::designparm('login.font',$domain);
     '<div class="LC_Box"'      my $link=&Apache::loncommon::designparm('login.link',$domain);
    .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'      my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
 );      my $alink=&Apache::loncommon::designparm('login.alink',$domain);
       my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
     $r->print(<<ENDSERVERFORM);      my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
 <form name="server" action="/adm/authenticate" method="post" target="_top">      my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
    <input type="hidden" name="logtoken" value="$logtoken" />      my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
    <input type="hidden" name="serverid" value="$lonhost" />      my $logo=&Apache::loncommon::designparm('login.logo',$domain);
    <input type="hidden" name="uname" value="" />      my $img=&Apache::loncommon::designparm('login.img',$domain);
    <input type="hidden" name="upass0" value="" />      my $domainlogo=&Apache::loncommon::domainlogo($domain);
    <input type="hidden" name="upass1" value="" />      my $showbanner = 1;
    <input type="hidden" name="upass2" value="" />      my $showmainlogo = 1;
    <input type="hidden" name="udom" value="" />      if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />          $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
    <input type="hidden" name="localres" value="$env{'form.localres'}" />      }
   </form>      if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
 ENDSERVERFORM          $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
     my $coursecatalog;      }
     if (($showcoursecat eq '') || ($showcoursecat)) {      my $showadminmail;
         $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';      my @possdoms = &Apache::lonnet::current_machine_domains();
     }      if (grep(/^\Q$domain\E$/,@possdoms)) {
     my $newuserlink;          $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
     if ($shownewuserlink) {      }
         $newuserlink = &newuser_link($lt{'newuser'}).'<br />';      my $showcoursecat =
     }          &Apache::loncommon::designparm('login.coursecatalog',$domain);
     my $logintitle =      my $shownewuserlink =
         '<h2 class="LC_hcell"'          &Apache::loncommon::designparm('login.newuser',$domain);
        .' style="background:'.$loginbox_header_bgcol.';'      my $showhelpdesk =
        .' color:'.$loginbox_header_textcol.'">'          &Apache::loncommon::designparm('login.helpdesk',$domain);
        .$lt{'log'}      my $now=time;
        .'</h2>';      my $js = (<<ENDSCRIPT);
   
     my $noscript_warning='<noscript><span class="LC_warning"><b>'  <script type="text/javascript" language="JavaScript">
                         .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')  // <![CDATA[
                         .'</b></span></noscript>';  function send()
     my $helpdeskscript;  {
     my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,  this.document.server.elements.uname.value
                                        $authdomain,\$helpdeskscript,  =this.document.client.elements.uname.value;
                                        $showhelpdesk,\@possdoms);  
   this.document.server.elements.udom.value
     my $loginform=(<<LFORM);  =this.document.client.elements.udom.value;
 <form name="client" action="" onsubmit="return(send())">  
   <input type="hidden" name="lextkey" value="$lextkey" />  uextkey=this.document.client.elements.uextkey.value;
   <input type="hidden" name="uextkey" value="$uextkey" />  lextkey=this.document.client.elements.lextkey.value;
   <b><label for="uname">$lt{'un'}</label>:</b><br />  initkeys();
   <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" /><br />  
   <b><label for="upass$now">$lt{'pw'}</label>:</b><br />  if(this.document.server.action.substr(0,5) === 'http:'){
   <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />      this.document.server.elements.upass0.value
   <b><label for="udom">$lt{'dom'}</label>:</b><br />          =getCrypted(this.document.client.elements.upass$now.value);
   <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" /><br />  } else {
   <input type="submit" value="$lt{'log'}" />      this.document.server.elements.upass0.value
 </form>          =this.document.client.elements.upass$now.value;
 LFORM  }
   
     if ($showbanner) {  this.document.client.elements.uname.value='';
         $r->print(<<HEADER);  this.document.client.elements.upass$now.value='';
 <!-- The LON-CAPA Header -->  
 <div style="background:$pgbg;margin:0;width:100%;">  this.document.server.submit();
   <img src="$img" border="0" alt="The Learning Online Network with CAPA" />  return false;
 </div>  }
 HEADER  
     }  function enableInput() {
     $r->print(<<ENDTOP);      this.document.client.elements.upass$now.removeAttribute("readOnly");
 <div style="float:left;margin-top:0;">      this.document.client.elements.uname.removeAttribute("readOnly");
 <div class="LC_Box" style="background:$loginbox_bg;">      this.document.client.elements.udom.removeAttribute("readOnly");
   $logintitle      return;
   $loginform  }
   $noscript_warning  
 </div>  // ]]>
     </script>
 <div class="LC_Box" style="padding-top: 10px;">  
   $loginhelp  ENDSCRIPT
   $forgotpw  
   $contactblock  # --------------------------------------------------- Print login screen header
   $newuserlink  
   $coursecatalog      my %add_entries = (
 </div>         bgcolor      => "$mainbg",
 </div>         text         => "$font",
          link         => "$link",
 <div>         vlink        => "$vlink",
 ENDTOP         alink        => "$alink",
     if ($showmainlogo) {                 onload       => 'javascript:enableInput();',);
         $r->print(' <img src="'.$logo.'" alt="" />'."\n");  
     }      my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
 $r->print(<<ENDTOP);      @hosts = &Apache::lonnet::current_machine_ids();
 $announcements      $lonhost_in_use = $lonhost;
 </div>      if (@hosts > 1) {
 <hr style="clear:both;" />          foreach my $hostid (@hosts) {
 ENDTOP              if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
     my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);                  $lonhost_in_use = $hostid;
     $domainrow = <<"END";                  last;
       <tr>              }
        <td  align="left" valign="top">          }
         <small><b>$lt{'dom'}:&nbsp;</b></small>      }
        </td>      %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
        <td  align="left" valign="top">      $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
         <small><tt>&nbsp;$domain</tt></small>      $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
        </td>      if ($headextra) {
       </tr>          my $omitextra;
 END          if ($headextra_exempt ne '') {
     $serverrow = <<"END";              my @exempt = split(',',$headextra_exempt);
       <tr>              my $ip = $ENV{'REMOTE_ADDR'};
        <td  align="left" valign="top">              if (grep(/^\Q$ip\E$/,@exempt)) {
         <small><b>$lt{'serv'}:&nbsp;</b></small>                  $omitextra = 1;
        </td>              }
        <td align="left" valign="top">          }
         <small><tt>&nbsp;$lonhost ($role)</tt></small>          unless ($omitextra) {
        </td>              my $confname = $defdom.'-domainconfig';
       </tr>              if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
 END                  my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
     if ($loadlim) {                  unless ($extra eq '-1') {
         $loadrow = <<"END";                      $js .= "\n".$extra."\n";
       <tr>                  }
        <td align="left" valign="top">              }
         <small><b>$lt{'load'}:&nbsp;</b></small>          }
        </td>      }
        <td align="left" valign="top">  
         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>      $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
        </td>         { 'redirect'       => [$expire,'/adm/roles'],
       </tr>   'add_entries' => \%add_entries,
 END   'only_body'   => 1,}));
     }  
     if ($uloadlim) {  # ----------------------------------------------------------------------- Texts
         $userloadrow = <<"END";  
       <tr>      my %lt=&Apache::lonlocal::texthash(
        <td align="left" valign="top">            'un'       => 'Username',
         <small><b>$lt{'userload'}:&nbsp;</b></small>            'pw'       => 'Password',
        </td>            'dom'      => 'Domain',
        <td align="left" valign="top">            'perc'     => 'percent',
         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>            'load'     => 'Server Load',
        </td>            'userload' => 'User Load',
       </tr>            'catalog'  => 'Course/Community Catalog',
 END            'log'      => 'Log in',
     }            'help'     => 'Log-in Help',
     if (($version ne '') && ($version ne '<!-- VERSION -->')) {            'serv'     => 'Server',
         $versionrow = <<"END";            'servadm'  => 'Server Administration',
       <tr>            'helpdesk' => 'Contact Helpdesk',
        <td colspan="2" align="left">            'forgotpw' => 'Forgot password?',
         <small>$version</small>            'newuser'  => 'New User?',
        </td>         );
       </tr>  # -------------------------------------------------- Change password field name
 END  
     }      my $forgotpw = &forgotpwdisplay(%lt);
       $forgotpw .= '<br />' if $forgotpw;
     $r->print(<<ENDDOCUMENT);      my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
     <div style="float: left;">      if ($loginhelp) {
      <table border="0" cellspacing="0" cellpadding="0">          $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
 $domainrow      }
 $serverrow  
 $loadrow      # ---------------------------------------------------- Serve out DES JavaScript
 $userloadrow      {
 $versionrow      my $jsh=Apache::File->new($include."/londes.js");
      </table>      $r->print(<$jsh>);
     </div>      }
     <div style="float: right;">  # ---------------------------------------------------------- Serve rest of page
     $domainlogo  
     </div>      $r->print(
     <br style="clear:both;" />      '<div class="LC_Box"'
  </div>     .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
   );
 <script type="text/javascript">  
 // <![CDATA[      $r->print(<<ENDSERVERFORM);
 // the if prevents the script error if the browser can not handle this  <form name="server" action="/adm/authenticate" method="post" target="_top">
 if ( document.client.uname ) { document.client.uname.focus(); }     <input type="hidden" name="logtoken" value="$logtoken" />
 // ]]>     <input type="hidden" name="serverid" value="$lonhost" />
 </script>     <input type="hidden" name="uname" value="" />
 $helpdeskscript     <input type="hidden" name="upass0" value="" />
      <input type="hidden" name="udom" value="" />
 ENDDOCUMENT     <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
     my %endargs = ( 'noredirectlink' => 1, );     <input type="hidden" name="localres" value="$env{'form.localres'}" />
     $r->print(&Apache::loncommon::end_page(\%endargs));    </form>
     return OK;  ENDSERVERFORM
 }      my $coursecatalog;
       if (($showcoursecat eq '') || ($showcoursecat)) {
 sub check_loginvia {          $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
     my ($domain,$lonhost) = @_;      }
     if ($domain eq '' || $lonhost eq '') {      my $newuserlink;
         return;      if ($shownewuserlink) {
     }          $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
     my %domconfhash = &Apache::loncommon::get_domainconf($domain);      }
     my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};      my $logintitle =
     my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};          '<h2 class="LC_hcell"'
     my $output;         .' style="background:'.$loginbox_header_bgcol.';'
     if ($loginvia ne '') {         .' color:'.$loginbox_header_textcol.'">'
         my $noredirect;         .$lt{'log'}
         my $ip = $ENV{'REMOTE_ADDR'};         .'</h2>';
         if ($ip eq '127.0.0.1') {  
             $noredirect = 1;      my $noscript_warning='<noscript><span class="LC_warning"><b>'
         } else {                          .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
             if ($loginvia_exempt ne '') {                          .'</b></span></noscript>';
                 my @exempt = split(',',$loginvia_exempt);      my $helpdeskscript;
                 if (grep(/^\Q$ip\E$/,@exempt)) {      my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
                     $noredirect = 1;                                         $authdomain,\$helpdeskscript,
                 }                                         $showhelpdesk,\@possdoms);
             }  
         }      my $mobileargs;
         unless ($noredirect) {      if ($clientmobile) {
             my ($newhost,$path);          $mobileargs = 'autocapitalize="off" autocorrect="off"';
             if ($loginvia =~ /:/) {      }
                 ($newhost,$path) = split(':',$loginvia);      my $loginform=(<<LFORM);
             } else {  <form name="client" action="" onsubmit="return(send())">
                 $newhost = $loginvia;    <input type="hidden" name="lextkey" value="$lextkey" />
             }    <input type="hidden" name="uextkey" value="$uextkey" />
             if ($newhost ne $lonhost) {    <b><label for="uname">$lt{'un'}</label>:</b><br />
                 if (&Apache::lonnet::hostname($newhost) ne '') {    <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
                     $output = &redirect_page($newhost,$path);    <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
                 }    <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
             }    <b><label for="udom">$lt{'dom'}</label>:</b><br />
         }    <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
     }    <input type="submit" value="$lt{'log'}" />
     return $output;  </form>
 }  LFORM
   
 sub redirect_page {      if ($showbanner) {
     my ($desthost,$path) = @_;          $r->print(<<HEADER);
     my $protocol = $Apache::lonnet::protocol{$desthost};  <!-- The LON-CAPA Header -->
     $protocol = 'http' if ($protocol ne 'https');  <div style="background:$pgbg;margin:0;width:100%;">
     unless ($path =~ m{^/}) {    <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />
         $path = '/'.$path;  </div>
     }  HEADER
     my $url = $protocol.'://'.&Apache::lonnet::hostname($desthost).$path;      }
     if ($env{'form.firsturl'} ne '') {      $r->print(<<ENDTOP);
         $url .='?firsturl='.$env{'form.firsturl'};  <div style="float:left;margin-top:0;">
     }  <div class="LC_Box" style="background:$loginbox_bg;">
     my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,    $logintitle
                                                     {'redirect' => [0,$url],});    $loginform
     my $end_page   = &Apache::loncommon::end_page();    $noscript_warning
     return $start_page.$end_page;  </div>
 }   
   <div class="LC_Box" style="padding-top: 10px;">
 sub contactdisplay {    $loginhelp
     my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,    $forgotpw
         $possdoms) = @_;    $contactblock
     my $contactblock;    $newuserlink
     my $origmail;    $coursecatalog
     if (ref($possdoms) eq 'ARRAY') {  </div>
         if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {   </div>
             $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};  
         }  <div>
     }  ENDTOP
     my $requestmail =       if ($showmainlogo) {
         &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',          $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");
                                                  $authdomain,$origmail);      }
     if ($showhelpdesk) {  $r->print(<<ENDTOP);
         unless ($requestmail =~ m/[^\@]+\@[^\@]+/) {  $announcements
             $showhelpdesk = 0;  </div>
         }  <hr style="clear:both;" />
     }  ENDTOP
     if ($servadm && $showadminmail) {      my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
         $contactblock .= $$lt{'servadm'}.':<br />'.      $domainrow = <<"END";
                          '<tt>'.$servadm.'</tt><br />';        <tr>
     }         <td  align="left" valign="top">
     if ($showhelpdesk) {          <small><b>$lt{'dom'}:&nbsp;</b></small>
         $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';         </td>
         my $thisurl = &escape('/adm/login');         <td  align="left" valign="top">
         $$helpdeskscript = <<"ENDSCRIPT";          <small><tt>&nbsp;$domain</tt></small>
 <script type="text/javascript">         </td>
 // <![CDATA[        </tr>
 function helpdesk() {  END
     var codedom = document.client.udom.value;      $serverrow = <<"END";
     if (codedom == '') {        <tr>
         codedom = "$authdomain";         <td  align="left" valign="top">
     }          <small><b>$lt{'serv'}:&nbsp;</b></small>
     var querystr = "origurl=$thisurl&codedom="+codedom;         </td>
     document.location.href = "/adm/helpdesk?"+querystr;         <td align="left" valign="top">
     return;          <small><tt>&nbsp;$lonhost ($role)</tt></small>
 }         </td>
 // ]]>        </tr>
 </script>  END
 ENDSCRIPT      if ($loadlim) {
     }          $loadrow = <<"END";
     return $contactblock;        <tr>
 }         <td align="left" valign="top">
           <small><b>$lt{'load'}:&nbsp;</b></small>
 sub forgotpwdisplay {         </td>
     my (%lt) = @_;         <td align="left" valign="top">
     my $prompt_for_resetpw = 1;           <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
     if ($prompt_for_resetpw) {         </td>
         return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';        </tr>
     }  END
     return;      }
 }      if ($uloadlim) {
           $userloadrow = <<"END";
 sub coursecatalog_link {        <tr>
     my ($linkname) = @_;         <td align="left" valign="top">
     return <<"END";          <small><b>$lt{'userload'}:&nbsp;</b></small>
       <a href="/adm/coursecatalog">$linkname</a>         </td>
 END         <td align="left" valign="top">
 }          <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
          </td>
 sub newuser_link {        </tr>
     my ($linkname) = @_;  END
     return '<a href="/adm/createaccount">'.$linkname.'</a>';      }
 }      if (($version ne '') && ($version ne '<!-- VERSION -->')) {
           $versionrow = <<"END";
 1;        <tr>
 __END__         <td colspan="2" align="left">
           <small>$version</small>
          </td>
         </tr>
   END
       }
   
       $r->print(<<ENDDOCUMENT);
       <div style="float: left;">
        <table border="0" cellspacing="0" cellpadding="0">
   $domainrow
   $serverrow
   $loadrow    
   $userloadrow
   $versionrow
        </table>
       </div>
       <div style="float: right;">
       $domainlogo
       </div>
       <br style="clear:both;" />
    </div>
   
   <script type="text/javascript">
   // <![CDATA[
   // the if prevents the script error if the browser can not handle this
   if ( document.client.uname ) { document.client.uname.focus(); }
   // ]]>
   </script>
   $helpdeskscript
   
   ENDDOCUMENT
       my %endargs = ( 'noredirectlink' => 1, );
       $r->print(&Apache::loncommon::end_page(\%endargs));
       return OK;
   }
   
   sub check_loginvia {
       my ($domain,$lonhost,$lonidsdir,$balcookie) = @_;
       if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {
           return;
       }
       my %domconfhash = &Apache::loncommon::get_domainconf($domain);
       my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
       my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
       my $output;
       if ($loginvia ne '') {
           my $noredirect;
           my $ip = $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.153  
changed lines
  Added in v.1.176


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