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

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

Removed from v.1.158.2.1  
changed lines
  Added in v.1.174


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