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

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


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