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

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

Removed from v.1.148  
changed lines
  Added in v.1.172


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