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

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


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