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

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

Removed from v.1.157  
changed lines
  Added in v.1.173


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