Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.6.2.3 and 1.161

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

Removed from v.1.158.2.6.2.3  
changed lines
  Added in v.1.161


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