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

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


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