Diff for /loncom/auth/lonlogin.pm between versions 1.158 and 1.170

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


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