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

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


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