Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.6.2.2 and 1.160

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


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