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

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


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