Diff for /loncom/auth/lonlogin.pm between versions 1.150 and 1.175

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

Removed from v.1.150  
changed lines
  Added in v.1.175


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