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

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


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