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

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


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