Diff for /loncom/auth/lonlogin.pm between versions 1.131 and 1.175

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

Removed from v.1.131  
changed lines
  Added in v.1.175


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