Diff for /loncom/auth/lonlogin.pm between versions 1.154 and 1.177

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


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