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

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

Removed from v.1.159  
changed lines
  Added in v.1.175


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