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

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

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


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