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

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

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


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