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

version 1.158.2.6.2.2, 2018/09/03 22:20:42 version 1.166, 2016/04/19 18:09:11
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;  if(this.document.server.action.substr(0,5) === 'http:'){
     my $showmainlogo = 1;      this.document.server.elements.upass0.value
     if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {          =getCrypted(this.document.client.elements.upass$now.value);
         $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);  } else {
     }      this.document.server.elements.upass0.value
     if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {          =this.document.client.elements.upass$now.value;
         $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);  
     }  this.document.client.elements.uname.value='';
     my $showadminmail;  this.document.client.elements.upass$now.value='';
     my @possdoms = &Apache::lonnet::current_machine_domains();  
     if (grep(/^\Q$domain\E$/,@possdoms)) {  this.document.server.submit();
         $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);  return false;
     }  }
     my $showcoursecat =  
         &Apache::loncommon::designparm('login.coursecatalog',$domain);  function enableInput() {
     my $shownewuserlink =       this.document.client.elements.upass$now.removeAttribute("readOnly");
         &Apache::loncommon::designparm('login.newuser',$domain);      this.document.client.elements.uname.removeAttribute("readOnly");
     my $showhelpdesk =      this.document.client.elements.udom.removeAttribute("readOnly");
         &Apache::loncommon::designparm('login.helpdesk',$domain);      return;
     my $now=time;  }
     my $js = (<<ENDSCRIPT);  
   // ]]>
 <script type="text/javascript" language="JavaScript">  </script>
 // <![CDATA[  
 function send()  ENDSCRIPT
 {  
 this.document.server.elements.uname.value  # --------------------------------------------------- Print login screen header
 =this.document.client.elements.uname.value;  
       my %add_entries = (
 this.document.server.elements.udom.value         bgcolor      => "$mainbg",
 =this.document.client.elements.udom.value;         text         => "$font",
          link         => "$link",
 uextkey=this.document.client.elements.uextkey.value;         vlink        => "$vlink",
 lextkey=this.document.client.elements.lextkey.value;         alink        => "$alink",
 initkeys();                 onload       => 'javascript:enableInput();',);
   
 this.document.server.elements.upass0.value      my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
     =getCrypted(this.document.client.elements.upass$now.value);      @hosts = &Apache::lonnet::current_machine_ids();
       $lonhost_in_use = $lonhost;
 this.document.client.elements.uname.value='';      if (@hosts > 1) {
 this.document.client.elements.upass$now.value='';          foreach my $hostid (@hosts) {
               if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
 this.document.server.submit();                  $lonhost_in_use = $hostid;
 return false;                  last;
 }              }
           }
 function enableInput() {      }
     this.document.client.elements.upass$now.removeAttribute("readOnly");      %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
     this.document.client.elements.uname.removeAttribute("readOnly");      $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
     this.document.client.elements.udom.removeAttribute("readOnly");      $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
     return;      if ($headextra) {
 }          my $omitextra;
           if ($headextra_exempt ne '') {
 // ]]>              my @exempt = split(',',$headextra_exempt);
 </script>              my $ip = $ENV{'REMOTE_ADDR'};
               if (grep(/^\Q$ip\E$/,@exempt)) {
 ENDSCRIPT                  $omitextra = 1;
               }
 # --------------------------------------------------- Print login screen header          }
           unless ($omitextra) {
     my %add_entries = (              my $confname = $defdom.'-domainconfig';
        bgcolor      => "$mainbg",              if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
        text         => "$font",                  my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
        link         => "$link",                  unless ($extra eq '-1') {
        vlink        => "$vlink",                      $js .= "\n".$extra."\n";
        alink        => "$alink",                  }
                onload       => 'javascript:enableInput();',);              }
           }
     my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);      }
     @hosts = &Apache::lonnet::current_machine_ids();  
     $lonhost_in_use = $lonhost;      $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
     if (@hosts > 1) {         { 'redirect'       => [$expire,'/adm/roles'],
         foreach my $hostid (@hosts) {   'add_entries' => \%add_entries,
             if (&Apache::lonnet::host_domain($hostid) eq $defdom) {   'only_body'   => 1,}));
                 $lonhost_in_use = $hostid;  
                 last;  # ----------------------------------------------------------------------- Texts
             }  
         }      my %lt=&Apache::lonlocal::texthash(
     }            'un'       => 'Username',
     %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);            'pw'       => 'Password',
     $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};            'dom'      => 'Domain',
     $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};            'perc'     => 'percent',
     if ($headextra) {            'load'     => 'Server Load',
         my $omitextra;            'userload' => 'User Load',
         if ($headextra_exempt ne '') {            'catalog'  => 'Course/Community Catalog',
             my @exempt = split(',',$headextra_exempt);            'log'      => 'Log in',
             my $ip = $ENV{'REMOTE_ADDR'};            'help'     => 'Log-in Help',
             if (grep(/^\Q$ip\E$/,@exempt)) {            'serv'     => 'Server',
                 $omitextra = 1;            'servadm'  => 'Server Administration',
             }            'helpdesk' => 'Contact Helpdesk',
         }            'forgotpw' => 'Forgot password?',
         unless ($omitextra) {            'newuser'  => 'New User?',
             my $confname = $defdom.'-domainconfig';         );
             if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {  # -------------------------------------------------- Change password field name
                 my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));  
                 unless ($extra eq '-1') {      my $forgotpw = &forgotpwdisplay(%lt);
                     $js .= "\n".$extra."\n";      $forgotpw .= '<br />' if $forgotpw;
                 }      my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
             }      if ($loginhelp) {
         }          $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
     }      }
   
     $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,  # ---------------------------------------------------- Serve out DES JavaScript
        { 'redirect'       => [$expire,'/adm/roles'],       {
  'add_entries' => \%add_entries,      my $jsh=Apache::File->new($include."/londes.js");
  'only_body'   => 1,}));      $r->print(<$jsh>);
       }
 # ----------------------------------------------------------------------- Texts  # ---------------------------------------------------------- Serve rest of page
   
     my %lt=&Apache::lonlocal::texthash(      $r->print(
           'un'       => 'Username',      '<div class="LC_Box"'
           'pw'       => 'Password',     .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
           'dom'      => 'Domain',  );
           'perc'     => 'percent',  
           'load'     => 'Server Load',      $r->print(<<ENDSERVERFORM);
           'userload' => 'User Load',  <form name="server" action="/adm/authenticate" method="post" target="_top">
           'catalog'  => 'Course/Community Catalog',     <input type="hidden" name="logtoken" value="$logtoken" />
           'log'      => 'Log in',     <input type="hidden" name="serverid" value="$lonhost" />
           'help'     => 'Log-in Help',     <input type="hidden" name="uname" value="" />
           'serv'     => 'Server',     <input type="hidden" name="upass0" value="" />
           'servadm'  => 'Server Administration',     <input type="hidden" name="udom" value="" />
           'helpdesk' => 'Contact Helpdesk',     <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
           'forgotpw' => 'Forgot password?',     <input type="hidden" name="localres" value="$env{'form.localres'}" />
           'newuser'  => 'New User?',    </form>
        );  ENDSERVERFORM
 # -------------------------------------------------- Change password field name      my $coursecatalog;
       if (($showcoursecat eq '') || ($showcoursecat)) {
     my $forgotpw = &forgotpwdisplay(%lt);          $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
     $forgotpw .= '<br />' if $forgotpw;      }
     my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);      my $newuserlink;
     if ($loginhelp) {      if ($shownewuserlink) {
         $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';          $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
     }      }
       my $logintitle =
 # ---------------------------------------------------- Serve out DES JavaScript          '<h2 class="LC_hcell"'
     {         .' style="background:'.$loginbox_header_bgcol.';'
     my $jsh=Apache::File->new($include."/londes.js");         .' color:'.$loginbox_header_textcol.'">'
     $r->print(<$jsh>);         .$lt{'log'}
     }         .'</h2>';
 # ---------------------------------------------------------- Serve rest of page  
       my $noscript_warning='<noscript><span class="LC_warning"><b>'
     $r->print(                          .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
     '<div class="LC_Box"'                          .'</b></span></noscript>';
    .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'      my $helpdeskscript;
 );      my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
                                          $authdomain,\$helpdeskscript,
     $r->print(<<ENDSERVERFORM);                                         $showhelpdesk,\@possdoms);
 <form name="server" action="/adm/authenticate" method="post" target="_top">  
    <input type="hidden" name="logtoken" value="$logtoken" />      my $mobileargs;
    <input type="hidden" name="serverid" value="$lonhost" />      if ($clientmobile) {
    <input type="hidden" name="uname" value="" />          $mobileargs = 'autocapitalize="off" autocorrect="off"';
    <input type="hidden" name="upass0" value="" />      }
    <input type="hidden" name="udom" value="" />      my $loginform=(<<LFORM);
    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />  <form name="client" action="" onsubmit="return(send())">
    <input type="hidden" name="localres" value="$env{'form.localres'}" />    <input type="hidden" name="lextkey" value="$lextkey" />
   </form>    <input type="hidden" name="uextkey" value="$uextkey" />
 ENDSERVERFORM    <b><label for="uname">$lt{'un'}</label>:</b><br />
     my $coursecatalog;    <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
     if (($showcoursecat eq '') || ($showcoursecat)) {    <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
         $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';    <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
     }    <b><label for="udom">$lt{'dom'}</label>:</b><br />
     my $newuserlink;    <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
     if ($shownewuserlink) {    <input type="submit" value="$lt{'log'}" />
         $newuserlink = &newuser_link($lt{'newuser'}).'<br />';  </form>
     }  LFORM
     my $logintitle =  
         '<h2 class="LC_hcell"'      if ($showbanner) {
        .' style="background:'.$loginbox_header_bgcol.';'          $r->print(<<HEADER);
        .' color:'.$loginbox_header_textcol.'">'  <!-- The LON-CAPA Header -->
        .$lt{'log'}  <div style="background:$pgbg;margin:0;width:100%;">
        .'</h2>';    <img src="$img" border="0" alt="The Learning Online Network with CAPA" />
   </div>
     my $noscript_warning='<noscript><span class="LC_warning"><b>'  HEADER
                         .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')      }
                         .'</b></span></noscript>';      $r->print(<<ENDTOP);
     my $helpdeskscript;  <div style="float:left;margin-top:0;">
     my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,  <div class="LC_Box" style="background:$loginbox_bg;">
                                        $authdomain,\$helpdeskscript,    $logintitle
                                        $showhelpdesk,\@possdoms);    $loginform
     $noscript_warning
     my $mobileargs;  </div>
     if ($clientmobile) {   
         $mobileargs = 'autocapitalize="off" autocorrect="off"';   <div class="LC_Box" style="padding-top: 10px;">
     }    $loginhelp
     my $loginform=(<<LFORM);    $forgotpw
 <form name="client" action="" onsubmit="return(send())">    $contactblock
   <input type="hidden" name="lextkey" value="$lextkey" />    $newuserlink
   <input type="hidden" name="uextkey" value="$uextkey" />    $coursecatalog
   <b><label for="uname">$lt{'un'}</label>:</b><br />  </div>
   <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>
   <b><label for="udom">$lt{'dom'}</label>:</b><br />  ENDTOP
   <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />      if ($showmainlogo) {
   <input type="submit" value="$lt{'log'}" />          $r->print(' <img src="'.$logo.'" alt="" />'."\n");
 </form>      }
 LFORM  $r->print(<<ENDTOP);
   $announcements
     if ($showbanner) {  </div>
         $r->print(<<HEADER);  <hr style="clear:both;" />
 <!-- The LON-CAPA Header -->  ENDTOP
 <div style="background:$pgbg;margin:0;width:100%;">      my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
   <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />      $domainrow = <<"END";
 </div>        <tr>
 HEADER         <td  align="left" valign="top">
     }          <small><b>$lt{'dom'}:&nbsp;</b></small>
     $r->print(<<ENDTOP);         </td>
 <div style="float:left;margin-top:0;">         <td  align="left" valign="top">
 <div class="LC_Box" style="background:$loginbox_bg;">          <small><tt>&nbsp;$domain</tt></small>
   $logintitle         </td>
   $loginform        </tr>
   $noscript_warning  END
 </div>      $serverrow = <<"END";
           <tr>
 <div class="LC_Box" style="padding-top: 10px;">         <td  align="left" valign="top">
   $loginhelp          <small><b>$lt{'serv'}:&nbsp;</b></small>
   $forgotpw         </td>
   $contactblock         <td align="left" valign="top">
   $newuserlink          <small><tt>&nbsp;$lonhost ($role)</tt></small>
   $coursecatalog         </td>
 </div>        </tr>
 </div>  END
       if ($loadlim) {
 <div>          $loadrow = <<"END";
 ENDTOP        <tr>
     if ($showmainlogo) {         <td align="left" valign="top">
         $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");          <small><b>$lt{'load'}:&nbsp;</b></small>
     }         </td>
 $r->print(<<ENDTOP);         <td align="left" valign="top">
 $announcements          <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
 </div>         </td>
 <hr style="clear:both;" />        </tr>
 ENDTOP  END
     my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);      }
     $domainrow = <<"END";      if ($uloadlim) {
       <tr>          $userloadrow = <<"END";
        <td  align="left" valign="top">        <tr>
         <small><b>$lt{'dom'}:&nbsp;</b></small>         <td align="left" valign="top">
        </td>          <small><b>$lt{'userload'}:&nbsp;</b></small>
        <td  align="left" valign="top">         </td>
         <small><tt>&nbsp;$domain</tt></small>         <td align="left" valign="top">
        </td>          <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
       </tr>         </td>
 END        </tr>
     $serverrow = <<"END";  END
       <tr>      }
        <td  align="left" valign="top">      if (($version ne '') && ($version ne '<!-- VERSION -->')) {
         <small><b>$lt{'serv'}:&nbsp;</b></small>          $versionrow = <<"END";
        </td>        <tr>
        <td align="left" valign="top">         <td colspan="2" align="left">
         <small><tt>&nbsp;$lonhost ($role)</tt></small>          <small>$version</small>
        </td>         </td>
       </tr>        </tr>
 END  END
     if ($loadlim) {      }
         $loadrow = <<"END";  
       <tr>      $r->print(<<ENDDOCUMENT);
        <td align="left" valign="top">      <div style="float: left;">
         <small><b>$lt{'load'}:&nbsp;</b></small>       <table border="0" cellspacing="0" cellpadding="0">
        </td>  $domainrow
        <td align="left" valign="top">  $serverrow
         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>  $loadrow    
        </td>  $userloadrow
       </tr>  $versionrow
 END       </table>
     }      </div>
     if ($uloadlim) {      <div style="float: right;">
         $userloadrow = <<"END";      $domainlogo
       <tr>      </div>
        <td align="left" valign="top">      <br style="clear:both;" />
         <small><b>$lt{'userload'}:&nbsp;</b></small>   </div>
        </td>  
        <td align="left" valign="top">  <script type="text/javascript">
         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></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>
     if (($version ne '') && ($version ne '<!-- VERSION -->')) {  $helpdeskscript
         $versionrow = <<"END";  
       <tr>  ENDDOCUMENT
        <td colspan="2" align="left">      my %endargs = ( 'noredirectlink' => 1, );
         <small>$version</small>      $r->print(&Apache::loncommon::end_page(\%endargs));
        </td>      return OK;
       </tr>  }
 END  
     }  sub check_loginvia {
       my ($domain,$lonhost) = @_;
     $r->print(<<ENDDOCUMENT);      if ($domain eq '' || $lonhost eq '') {
     <div style="float: left;">          return;
      <table border="0" cellspacing="0" cellpadding="0">      }
 $domainrow      my %domconfhash = &Apache::loncommon::get_domainconf($domain);
 $serverrow      my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
 $loadrow          my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
 $userloadrow      my $output;
 $versionrow      if ($loginvia ne '') {
      </table>          my $noredirect;
     </div>          my $ip = $ENV{'REMOTE_ADDR'};
     <div style="float: right;">          if ($ip eq '127.0.0.1') {
     $domainlogo              $noredirect = 1;
     </div>          } else {
     <br style="clear:both;" />              if ($loginvia_exempt ne '') {
  </div>                  my @exempt = split(',',$loginvia_exempt);
                   if (grep(/^\Q$ip\E$/,@exempt)) {
 <script type="text/javascript">                      $noredirect = 1;
 // <![CDATA[                  }
 // the if prevents the script error if the browser can not handle this              }
 if ( document.client.uname ) { document.client.uname.focus(); }          }
 // ]]>          unless ($noredirect) {
 </script>              my ($newhost,$path);
 $helpdeskscript              if ($loginvia =~ /:/) {
                   ($newhost,$path) = split(':',$loginvia);
 ENDDOCUMENT              } else {
     my %endargs = ( 'noredirectlink' => 1, );                  $newhost = $loginvia;
     $r->print(&Apache::loncommon::end_page(\%endargs));              }
     return OK;              if ($newhost ne $lonhost) {
 }                  if (&Apache::lonnet::hostname($newhost) ne '') {
                       $output = &redirect_page($newhost,$path);
 sub check_loginvia {                  }
     my ($domain,$lonhost) = @_;              }
     if ($domain eq '' || $lonhost eq '') {          }
         return;      }
     }      return $output;
     my %domconfhash = &Apache::loncommon::get_domainconf($domain);  }
     my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};  
     my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};  sub redirect_page {
     my $output;      my ($desthost,$path) = @_;
     if ($loginvia ne '') {      my $protocol = $Apache::lonnet::protocol{$desthost};
         my $noredirect;      $protocol = 'http' if ($protocol ne 'https');
         my $ip = $ENV{'REMOTE_ADDR'};      unless ($path =~ m{^/}) {
         if ($ip eq '127.0.0.1') {          $path = '/'.$path;
             $noredirect = 1;      }
         } else {      my $url = $protocol.'://'.&Apache::lonnet::hostname($desthost).$path;
             if ($loginvia_exempt ne '') {      if ($env{'form.firsturl'} ne '') {
                 my @exempt = split(',',$loginvia_exempt);          $url .='?firsturl='.$env{'form.firsturl'};
                 if (grep(/^\Q$ip\E$/,@exempt)) {      }
                     $noredirect = 1;      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;
         unless ($noredirect) {  }
             my ($newhost,$path);  
             if ($loginvia =~ /:/) {  sub contactdisplay {
                 ($newhost,$path) = split(':',$loginvia);      my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
             } else {          $possdoms) = @_;
                 $newhost = $loginvia;      my $contactblock;
             }      my $origmail;
             if ($newhost ne $lonhost) {      if (ref($possdoms) eq 'ARRAY') {
                 if (&Apache::lonnet::hostname($newhost) ne '') {          if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {
                     $output = &redirect_page($newhost,$path);              $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
                 }          }
             }      }
         }      my $requestmail =
     }          &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
     return $output;                                                   $authdomain,$origmail);
 }      unless ($showhelpdesk eq '0') {
           if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
 sub redirect_page {              $showhelpdesk = 1;
     my ($desthost,$path) = @_;          } else {
     my $protocol = $Apache::lonnet::protocol{$desthost};              $showhelpdesk = 0;
     $protocol = 'http' if ($protocol ne 'https');          }
     unless ($path =~ m{^/}) {      }
         $path = '/'.$path;      if ($servadm && $showadminmail) {
     }          $contactblock .= $$lt{'servadm'}.':<br />'.
     my $url = $protocol.'://'.&Apache::lonnet::hostname($desthost).$path;                           '<tt>'.$servadm.'</tt><br />';
     if ($env{'form.firsturl'} ne '') {      }
         $url .='?firsturl='.$env{'form.firsturl'};      if ($showhelpdesk) {
     }          $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
     my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,          my $thisurl = &escape('/adm/login');
                                                     {'redirect' => [0,$url],});          $$helpdeskscript = <<"ENDSCRIPT";
     my $end_page   = &Apache::loncommon::end_page();  <script type="text/javascript">
     return $start_page.$end_page;  // <![CDATA[
 }  function helpdesk() {
       var possdom = document.client.udom.value;
 sub contactdisplay {      var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
     my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,      if (codedom == '') {
         $possdoms) = @_;          codedom = "$authdomain";
     my $contactblock;      }
     my $origmail;      var querystr = "origurl=$thisurl&codedom="+codedom;
     if (ref($possdoms) eq 'ARRAY') {      document.location.href = "/adm/helpdesk?"+querystr;
         if (grep(/^\Q$authdomain\E$/,@{$possdoms})) {       return;
             $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};  }
         }  // ]]>
     }  </script>
     my $requestmail =   ENDSCRIPT
         &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',      }
                                                  $authdomain,$origmail);      return $contactblock;
     unless ($showhelpdesk eq '0') {  }
         if ($requestmail =~ m/[^\@]+\@[^\@]+/) {  
             $showhelpdesk = 1;  sub forgotpwdisplay {
         } else {      my (%lt) = @_;
             $showhelpdesk = 0;      my $prompt_for_resetpw = 1;
         }      if ($prompt_for_resetpw) {
     }          return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
     if ($servadm && $showadminmail) {      }
         $contactblock .= $$lt{'servadm'}.':<br />'.      return;
                          '<tt>'.$servadm.'</tt><br />';  }
     }  
     if ($showhelpdesk) {  sub coursecatalog_link {
         $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';      my ($linkname) = @_;
         my $thisurl = &escape('/adm/login');      return <<"END";
         $$helpdeskscript = <<"ENDSCRIPT";        <a href="/adm/coursecatalog">$linkname</a>
 <script type="text/javascript">  END
 // <![CDATA[  }
 function helpdesk() {  
     var possdom = document.client.udom.value;  sub newuser_link {
     var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');      my ($linkname) = @_;
     if (codedom == '') {      return '<a href="/adm/createaccount">'.$linkname.'</a>';
         codedom = "$authdomain";  }
     }  
     var querystr = "origurl=$thisurl&codedom="+codedom;  1;
     document.location.href = "/adm/helpdesk?"+querystr;  __END__
     return;  
 }  
 // ]]>  
 </script>  
 ENDSCRIPT  
     }  
     return $contactblock;  
 }  
   
 sub forgotpwdisplay {  
     my (%lt) = @_;  
     my $prompt_for_resetpw = 1;   
     if ($prompt_for_resetpw) {  
         return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';  
     }  
     return;  
 }  
   
 sub coursecatalog_link {  
     my ($linkname) = @_;  
     return <<"END";  
       <a href="/adm/coursecatalog">$linkname</a>  
 END  
 }  
   
 sub newuser_link {  
     my ($linkname) = @_;  
     return '<a href="/adm/createaccount">'.$linkname.'</a>';  
 }  
   
 1;  
 __END__  

Removed from v.1.158.2.6.2.2  
changed lines
  Added in v.1.166


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