Diff for /loncom/auth/lonlogin.pm between versions 1.142 and 1.173

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


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