Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.2 and 1.171

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


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