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

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


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