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

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


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