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

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


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