Diff for /loncom/auth/lonlogin.pm between versions 1.147 and 1.171

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


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