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

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


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