Diff for /loncom/auth/lonlogin.pm between versions 1.158.2.6.2.3 and 1.163

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


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