Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.9.2.1 and 1.167

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


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