Diff for /loncom/auth/lonlogin.pm between versions 1.143 and 1.175

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


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