Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.4 and 1.172

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


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