Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.1 and 1.173

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


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