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

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


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