Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.7 and 1.163

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


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