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

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


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