Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.2 and 1.174

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


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