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

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

Removed from v.1.153  
changed lines
  Added in v.1.171


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