Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.6.2.1 and 1.164

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


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