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

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

Removed from v.1.158.2.6.2.3  
changed lines
  Added in v.1.170


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