Diff for /loncom/auth/lonlogin.pm between versions 1.32 and 1.168

version 1.32, 2003/02/17 23:25:59 version 1.168, 2016/05/03 22:33:49
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/
 #  #
 # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,  
 # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9,  package Apache::lonlogin;
 # 1/17/01 Gerd Kortemeyer  
 #  use strict;
 # 2/7/02,2/8,2/12,2/14,2/15,2/19 Josh Brunskole  use Apache::Constants qw(:common);
 #   use Apache::File ();
 # 7/10/02 Jeremy Bowers  use Apache::lonnet;
   use Apache::loncommon();
 package Apache::lonlogin;  use Apache::lonauth();
   use Apache::lonlocal;
 use strict;  use Apache::migrateuser();
 use Apache::Constants qw(:common);  use lib '/home/httpd/lib/perl/';
 use Apache::File ();  use LONCAPA;
 use Apache::lonnet();   
 use Apache::loncommon();  sub handler {
       my $r = shift;
 sub handler {  
     my $r = shift;      &Apache::loncommon::get_unprocessed_cgi
     $r->content_type('text/html');   (join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
     &Apache::loncommon::no_cache($r);        $ENV{'REDIRECT_QUERY_STRING'}),
     $r->send_http_header;   ['interface','username','domain','firsturl','localpath','localres',
     return OK if $r->header_only;    'token','role','symb','iptoken']);
       if (!defined($env{'form.firsturl'})) {
           &Apache::lonacc::get_posted_cgi($r,['firsturl']);
     &Apache::loncommon::get_unprocessed_cgi      }
      ($ENV{'QUERY_STRING'},['interface','username','domain','firsturl']);  
   # -- check if they are a migrating user
 # ----------------------------------------------------------- Process Interface      if (defined($env{'form.token'})) {
     $ENV{'form.interface'}=~s/\W//g;   return &Apache::migrateuser::handler($r);
       }
     my $textbrowsers=$r->dir_config('lonTextBrowsers');  
     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};      &Apache::loncommon::no_cache($r);
           &Apache::lonlocal::get_language_handle($r);
     foreach (split(/\:/,$textbrowsers)) {      &Apache::loncommon::content_type($r,'text/html');
  if ($httpbrowser=~/$_/i) {      $r->send_http_header;
     $ENV{'form.interface'}='textual';      return OK if $r->header_only;
         }  
     }  
   # Are we re-routing?
     my $fullgraph=($ENV{'form.interface'} ne 'textual');      my $londocroot = $r->dir_config('lonDocRoot');
       if (-e "$londocroot/lon-status/reroute.txt") {
     my $iconpath= 'http://'.$ENV{'HTTP_HOST'}.':8080'.   &Apache::lonauth::reroute($r);
                   $r->dir_config('lonIconsURL');   return OK;
     my $domain  = $r->dir_config('lonDefDomain');      }
     my $role    = $r->dir_config('lonRole');  
     my $loadlim = $r->dir_config('lonLoadLim');      $env{'form.firsturl'} =~ s/(`)/'/g;
     my $servadm = $r->dir_config('lonAdmEMail');  
     my $sysadm  = $r->dir_config('lonSysEMail');  # -------------------------------- Prevent users from attempting to login twice
     my $lonhost = $r->dir_config('lonHostID');      my $handle = &Apache::lonnet::check_for_valid_session($r);
     my $tabdir  = $r->dir_config('lonTabDir');      if ($handle ne '') {
     my $include = $r->dir_config('lonIncludes');          my $lonidsdir=$r->dir_config('lonIDsDir');
           if ($handle=~/^publicuser\_/) {
 # --------------------------------------------- Default values for login fields  # For "public user" - remove it, we apparently really want to login
       unlink($r->dir_config('lonIDsDir')."/$handle.id");
     my $authusername=($ENV{'form.username'}?$ENV{'form.username'}:'');          } else {
     my $authdomain=($ENV{'form.domain'}?$ENV{'form.domain'}:$domain);  # Indeed, a valid token is found
               &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
 # ---------------------------------------------------------- Determine own load      my $start_page =
     my $loadavg;          &Apache::loncommon::start_page('Already logged in');
    {      my $end_page =
        my $loadfile=Apache::File->new('/proc/loadavg');          &Apache::loncommon::end_page();
        $loadavg=<$loadfile>;              my $dest = '/adm/roles';
    }              if ($env{'form.firsturl'} ne '') {
     $loadavg =~ s/\s.*//g;                  $dest = $env{'form.firsturl'};
     my $loadpercent=100*$loadavg/$loadlim;              }
       $r->print(
 # ------------------------------------------------------- Do the load balancing                    $start_page
     my $otherserver='http://'.$ENV{'SERVER_NAME'};                   .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
     my $firsturl=                   .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
     ($ENV{'request.firsturl'}?$ENV{'request.firsturl'}:$ENV{'form.firsturl'});                    '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
 # ---------------------------------------- Are we access server and overloaded?                   .$end_page
     if (($role eq 'access') && ($loadpercent>100.0)) {                   );
         $otherserver=Apache::lonnet::spareserver($loadpercent);              return OK;
     }          }
       }
 # -------------------------------------------------------- Set login parameters  
   # ---------------------------------------------------- No valid token, continue
     my @hexstr=('0','1','2','3','4','5','6','7',  
                 '8','9','a','b','c','d','e','f');  # ---------------------------- Not possible to really login to domain "public"
     my $lkey='';      if ($env{'form.domain'} eq 'public') {
     for (0..7) {   $env{'form.domain'}='';
         $lkey.=$hexstr[rand(15)];   $env{'form.username'}='';
     }      }
   
     my $ukey='';  # ------ Is this page requested because /adm/migrateuser detected an IP change?
     for (0..7) {      my %sessiondata;
         $ukey.=$hexstr[rand(15)];      if ($env{'form.iptoken'}) {
     }          %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});
           unless ($sessiondata{'sessionserver'}) {
     my $lextkey=hex($lkey);              my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});
     if ($lextkey>2147483647) { $lextkey-=4294967296; }              delete($env{'form.iptoken'});
           }
     my $uextkey=hex($ukey);      }
     if ($uextkey>2147483647) { $uextkey-=4294967296; }  # ----------------------------------------------------------- Process Interface
       $env{'form.interface'}=~s/\W//g;
 # -------------------------------------------------------- Store away log token  
     my $logtoken=Apache::lonnet::reply(      (undef,undef,undef,undef,undef,undef,my $clientmobile) =
        'tmpput:'.$ukey.$lkey.'&'.$firsturl,          &Apache::loncommon::decode_user_agent();
        $lonhost);  
       my $iconpath=
 # ------------------- If we cannot talk to ourselves, we are in serious trouble   &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
   
     if ($logtoken eq 'con_lost') {      my $lonhost = $r->dir_config('lonHostID');
         my $spares='';      my $domain = &Apache::lonnet::default_login_domain();
         foreach (keys %Apache::lonnet::hostname) {      my $defdom = $domain;
             if ($_ ne $lonhost) {      if ($lonhost ne '') {
                $spares.='<br /><a href="http://'.$Apache::lonnet::hostname{$_}.          unless ($sessiondata{'sessionserver'}) {
  '/adm/login?domain='.$authdomain.'">'.              my $redirect = &check_loginvia($domain,$lonhost);
                  $Apache::lonnet::hostname{$_}.'</a>';              if ($redirect) {
                if ($Apache::lonnet::spareid{$_}) {                  $r->print($redirect);
    $spares.=' (preferred)';                  return OK;
                }              }
    }          }
         }      }
  $r->print(<<ENDTROUBLE);  
 <html>      if (($sessiondata{'domain'}) &&
 <head><title>The LearningOnline Network with CAPA</title></head>          (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
 <body bgcolor="#FFFFFF">          $domain=$sessiondata{'domain'};
 <img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />      } elsif (($env{'form.domain'}) &&
 <h3>This LON-CAPA server is temporarily not available for login</h3>   (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
 <p>Please attempt to login to one of the following servers:</p>$spares   $domain=$env{'form.domain'};
 <p>If the problem persists, please contact <tt>$servadm</tt>.</p>      }
 </body>  
 </html>      my $role    = $r->dir_config('lonRole');
 ENDTROUBLE      my $loadlim = $r->dir_config('lonLoadLim');
         return OK;      my $uloadlim= $r->dir_config('lonUserLoadLim');
     }      my $servadm = $r->dir_config('lonAdmEMail');
       my $tabdir  = $r->dir_config('lonTabDir');
 # ----------------------------------------------- Apparently we are in business      my $include = $r->dir_config('lonIncludes');
       my $expire  = $r->dir_config('lonExpire');
     my $domainlogo=&Apache::loncommon::domainlogo();      my $version = $r->dir_config('lonVersion');
 # --------------------------------------------------- Print login screen header      my $host_name = &Apache::lonnet::hostname($lonhost);
     $r->print(<<ENDHEADER);  
 <html>  # --------------------------------------------- Default values for login fields
 <head>     
 <title>The LearningOnline Network with CAPA Login</title>      my ($authusername,$authdomain);
 </head>      if ($sessiondata{'username'}) {
 ENDHEADER          $authusername=$sessiondata{'username'};
 # ---------------------------------------------------- Serve out DES JavaScript      } else {
     {          $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
  my $jsh=Apache::File->new($include."/londes.js");          $authusername=($env{'form.username'}?$env{'form.username'}:'');
         $r->print(<$jsh>);      }
     }      if ($sessiondata{'domain'}) {
           $authdomain=$sessiondata{'domain'};
 # ----------------------------------------------------------- Front page design      } else {
     my $pgbg=&Apache::loncommon::designparm('login.pgbg');          $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
     my $font=&Apache::loncommon::designparm('login.font');          $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
     my $link=&Apache::loncommon::designparm('login.link');      }
     my $vlink=&Apache::loncommon::designparm('login.vlink');  
     my $alink=&Apache::loncommon::designparm('login.alink');  # ---------------------------------------------------------- Determine own load
     my $mainbg=&Apache::loncommon::designparm('login.mainbg');      my $loadavg;
     my $sidebg=&Apache::loncommon::designparm('login.sidebg');      {
     my $logo=&Apache::loncommon::designparm('login.logo');   my $loadfile=Apache::File->new('/proc/loadavg');
     my $img=&Apache::loncommon::designparm('login.img');   $loadavg=<$loadfile>;
       }
       $loadavg =~ s/\s.*//g;
 # ---------------------------------------------------------- Serve rest of page  
     $r->print(<<ENDSCRIPT);      my ($loadpercent,$userloadpercent);
       if ($loadlim) {
 <body bgcolor="$pgbg" text="$font" link="$link" vlink="$vlink" alink="$alink"          $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
   topmargin=0 leftmargin=0 marginwidth=0 marginheight=0>      }
       if ($uloadlim) {
  <script language="JavaScript">          $userloadpercent=&Apache::lonnet::userload();
     function send()      }
     {  
  this.document.server.elements.uname.value      my $firsturl=
        =this.document.client.elements.uname.value;      ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
   
         this.document.server.elements.udom.value  # ----------------------------------------------------------- Get announcements
        =this.document.client.elements.udom.value;      my $announcements=&Apache::lonnet::getannounce();
   # -------------------------------------------------------- Set login parameters
         uextkey=this.document.client.elements.uextkey.value;  
         lextkey=this.document.client.elements.lextkey.value;      my @hexstr=('0','1','2','3','4','5','6','7',
         initkeys();                  '8','9','a','b','c','d','e','f');
       my $lkey='';
         this.document.server.elements.upass.value      for (0..7) {
     =crypted(this.document.client.elements.upass.value);          $lkey.=$hexstr[rand(15)];
       }
         this.document.server.submit();  
  return false;      my $ukey='';
     }      for (0..7) {
  </script>          $ukey.=$hexstr[rand(15)];
 ENDSCRIPT      }
   
     if ($fullgraph) {      my $lextkey=hex($lkey);
  $r->print(      if ($lextkey>2147483647) { $lextkey-=4294967296; }
   '<table width="100%" cellpadding=0 cellspacing=0 border=0>');  
     }      my $uextkey=hex($ukey);
       if ($uextkey>2147483647) { $uextkey-=4294967296; }
     $r->print(<<ENDSERVERFORM);  
   <form name="server" action="$otherserver/adm/authenticate" method="post" target="_top">  # -------------------------------------------------------- Store away log token
    <input type=hidden name=logtoken value="$logtoken">      my $tokenextras;
    <input type=hidden name=serverid value="$lonhost">      if ($env{'form.role'}) {
    <input type=hidden name=interface value="$ENV{'form.interface'}">          $tokenextras = '&role='.&escape($env{'form.role'});
    <input type=hidden name=uname value="">      }
    <input type=hidden name=upass value="">      if ($env{'form.symb'}) {
    <input type=hidden name=udom value="">          if (!$tokenextras) {
   </form>              $tokenextras = '&';
 ENDSERVERFORM          }
     if ($fullgraph) { $r->print(<<ENDTOP);          $tokenextras .= '&symb='.&escape($env{'form.symb'});
   <!-- The LON-CAPA Header -->      }
   <tr>      if ($env{'form.iptoken'}) {
           if (!$tokenextras) {
    <!-- Row 1 Columns 2-4 -->              $tokenextras = '&&';
    <td width="100%" height=75 colspan=4 align="left" valign="top" bgcolor="$pgbg"><img src="$img" border=0 alt="The Learning Online Network with CAPA" /></td>          }
   </tr>          $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});
       }
   <!-- The gray bar that starts the two table frames -->      my $logtoken=Apache::lonnet::reply(
   <tr>         'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
          $lonhost);
    <!-- Row 2 Column 1 -->  
    <td width=182 height=27 bgcolor="$sidebg">&nbsp;</td>  # -- If we cannot talk to ourselves, or hostID does not map to a hostname
   #    we are in serious trouble
    <!-- Row 2 Column 2 -->  
    <td width=27 height=27 align="left" background="$iconpath/filltop.gif"><img src="$iconpath/upperleft.gif" border=0 alt="" /></td>      if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
           if ($logtoken eq 'no_such_host') {
    <!-- Row 2 Column 3 -->              &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
    <td height=27 background="$iconpath/filltop.gif"><img src="$iconpath/filltop.gif" alt="" /></td>          }
           my $spares='';
    <!-- Row 2 Column 4 -->   my $last;
    <td width=27 height=27 align="right" background="$iconpath/filltop.gif"><img src="$iconpath/upperright.gif" border=0 alt="" /></td>          foreach my $hostid (sort
   </tr>      {
   <tr>   &Apache::lonnet::hostname($a) cmp
          &Apache::lonnet::hostname($b);
    <!-- A cell that will hold the 'access' and 'about' buttons -->      }
    <!-- Row 3 Column 1 -->      keys(%Apache::lonnet::spareid)) {
    <td valign="top" height=60 align="center" bgcolor="$sidebg">              next if ($hostid eq $lonhost);
     <a href="/adm/login?interface=textual"><img src="$iconpath/accessbutton.gif" border=0 alt="Accessibility Options" /></a>      my $hostname = &Apache::lonnet::hostname($hostid);
     <br />      next if (($last eq $hostname) || ($hostname eq ''));
     <a href="/adm/about.html"><img src="$iconpath/aboutlon.gif" border=0 alt="About LON-CAPA" /></a>              $spares.='<br /><font size="+1"><a href="http://'.
    </td>                  $hostname.
                   '/adm/login?domain='.$authdomain.'">'.
    <!-- The shaded space between the two main columns -->                  $hostname.'</a>'.
    <!-- Row 3 Column 2 -->                  ' '.&mt('(preferred)').'</font>'.$/;
    <td width=27 height=60 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>      $last=$hostname;
           }
    <!-- The right main column holding the large LON-CAPA logo-->          if ($spares) {
    <!-- Rows 3-4 Column 3 -->              $spares.= '<br />';
    <td align="center" valign="top" width="100%" height="100%" rowspan=2 bgcolor="$mainbg">          }
     <center>          my %all_hostnames = &Apache::lonnet::all_hostnames();
      <img src="$logo" alt="" />          foreach my $hostid (sort
     </center>      {
    </td>   &Apache::lonnet::hostname($a) cmp
       &Apache::lonnet::hostname($b);
    <!-- Row 3 Column 4 -->      }
    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>      keys(%all_hostnames)) {
   </tr>              next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
   <tr>              my $hostname = &Apache::lonnet::hostname($hostid);
               next if (($last eq $hostname) || ($hostname eq ''));
    <!-- The entry form -->              $spares.='<br /><a href="http://'.
    <!-- Row 4 Column 1 -->               $hostname.
    <td align="center" valign="middle" bgcolor="$sidebg">               '/adm/login?domain='.$authdomain.'">'.
 ENDTOP               $hostname.'</a>';
 } else {              $last=$hostname;
     $r->print('<font color="#FFFFFF"><h1>The Learning<i>Online</i> Network with CAPA</h1><h3>Text-based Interface Login</h3></font>');           }
 }           $r->print(
     $r->print(<<ENDLOGIN);     '<html>'
     <form name="client" onsubmit="return(send())">    .'<head><title>'
      <input type="hidden" name="lextkey" value="$lextkey">    .&mt('The LearningOnline Network with CAPA')
      <input type="hidden" name="uextkey" value="$uextkey">    .'</title></head>'
     .'<body bgcolor="#FFFFFF">'
      <!-- Start the sub-table for text and input alignment -->    .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
      <table border=0 cellspacing=0 cellpadding=0>    .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'
       <tr><td bgcolor="$sidebg" colspan=2><img src="$iconpath/userauthentication.gif" alt="User Authentication" /></td></tr>    .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
       <tr>          if ($spares) {
        <td bgcolor="$mainbg"><br /><font size=-1><b>&nbsp;&nbsp;&nbsp;User Name:</b></font></td>              $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
        <td bgcolor="$mainbg"><br /><input type="text" name="uname" size="10" value="$authusername" /></td>                       .'</p>'
       </tr>                       .$spares);
       <tr>          }
        <td bgcolor="$mainbg"><font size=-1><b>&nbsp;&nbsp;&nbsp;Password:</b></font></td>          $r->print('</body>'
        <td bgcolor="$mainbg"><input type="password" name="upass" size="10" /></td>                   .'</html>'
       </tr>          );
       <tr>          return OK;
        <td bgcolor="$mainbg"><font size=-1><b>&nbsp;&nbsp;&nbsp;Domain:</b></font></td>      }
        <td bgcolor="$mainbg"><input type="text" name="udom" size="10" value="$authdomain" /></td>  
       </tr>  # ----------------------------------------------- Apparently we are in business
       <tr>      $servadm=~s/\,/\<br \/\>/g;
        <td bgcolor="$mainbg">&nbsp;&nbsp;&nbsp;<a href="/adm/loginproblems.html">Help</a></td>  
        <td bgcolor="$mainbg" valign="bottom" align="center">  # ----------------------------------------------------------- Front page design
         <br />      my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
         <input type="submit" value="Log In" />      my $font=&Apache::loncommon::designparm('login.font',$domain);
        </td>      my $link=&Apache::loncommon::designparm('login.link',$domain);
       </tr>      my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
      </table>      my $alink=&Apache::loncommon::designparm('login.alink',$domain);
      <!-- End sub-table -->      my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
     </form>      my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
 ENDLOGIN      my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
     if ($fullgraph) {      my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
  $r->print(<<ENDDOCUMENT);      my $logo=&Apache::loncommon::designparm('login.logo',$domain);
    </td>      my $img=&Apache::loncommon::designparm('login.img',$domain);
       my $domainlogo=&Apache::loncommon::domainlogo($domain);
    <!-- Row 4 Column 2 -->      my $showbanner = 1;
    <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>      my $showmainlogo = 1;
       if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
    <!-- Row 4 Column 4 -->          $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>      }
   </tr>      if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
   <tr>          $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
       }
    <!-- Row 5 Column 1 -->      my $showadminmail;
    <td bgcolor="$sidebg" valign="middle" align="left">      my @possdoms = &Apache::lonnet::current_machine_domains();
      <br />      if (grep(/^\Q$domain\E$/,@possdoms)) {
      <table border=0 cellspacing=0 cellpadding=0>          $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
       <tr>      }
        <td bgcolor="$sidebg" align="left" valign="top">      my $showcoursecat =
         <small><b>&nbsp;&nbsp;&nbsp;Domain:&nbsp;</b></small>          &Apache::loncommon::designparm('login.coursecatalog',$domain);
        </td>      my $shownewuserlink =
        <td bgcolor="$sidebg" align="left" valign="top">          &Apache::loncommon::designparm('login.newuser',$domain);
         <small><tt>&nbsp;$domain</tt></small>      my $showhelpdesk =
        </td>          &Apache::loncommon::designparm('login.helpdesk',$domain);
       </tr>      my $now=time;
       <tr>      my $js = (<<ENDSCRIPT);
        <td bgcolor="$sidebg" align="left" valign="top">  
         <small><b>&nbsp;&nbsp;&nbsp;Server:&nbsp;</b></small>  <script type="text/javascript" language="JavaScript">
        </td>  // <![CDATA[
        <td bgcolor="$sidebg" align="left" valign="top">  function send()
         <small><tt>&nbsp;$lonhost ($role)</tt></small>  {
        </td>  this.document.server.elements.uname.value
       </tr>  =this.document.client.elements.uname.value;
       <tr>  
        <td bgcolor="$sidebg" align="left" valign="top">  this.document.server.elements.udom.value
         <small><b>&nbsp;&nbsp;&nbsp;Load:&nbsp;</b></small>  =this.document.client.elements.udom.value;
        </td>  
        <td bgcolor="$sidebg" align="left" valign="top">  uextkey=this.document.client.elements.uextkey.value;
         <small><tt>&nbsp;$loadpercent percent</tt></small>  lextkey=this.document.client.elements.lextkey.value;
        </td>  initkeys();
       </tr>  
      </table>  if(this.document.server.action.substr(0,5) === 'http:'){
      <br />      this.document.server.elements.upass0.value
     <small>          =getCrypted(this.document.client.elements.upass$now.value);
      <b>&nbsp;&nbsp;&nbsp;System Administration:</b><br />  } else {
      <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sysadm</tt><br />      this.document.server.elements.upass0.value
      <b>&nbsp;&nbsp;&nbsp;Server Administration:</b><br />          =this.document.client.elements.upass$now.value;
      <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$servadm<br />&nbsp;</tt>  }
     </small>  
    </td>  this.document.client.elements.uname.value='';
   this.document.client.elements.upass$now.value='';
    <!-- Row 5 Column 2 -->  
    <td width=27 background="$iconpath/fillleft.gif"><img src="$iconpath/fillleft.gif" alt="" /></td>  this.document.server.submit();
   return false;
    <!-- Row 5 Column 3 -->  }
    <td width="100%" valign="bottom" bgcolor="$mainbg">  
 $domainlogo  function enableInput() {
 </td>      this.document.client.elements.upass$now.removeAttribute("readOnly");
       this.document.client.elements.uname.removeAttribute("readOnly");
    <!-- Row 5 Column 4 -->      this.document.client.elements.udom.removeAttribute("readOnly");
    <td width=27 background="$iconpath/fillright.gif"><img src="$iconpath/fillright.gif" alt="" /></td>      return;
   </tr>  }
   <tr>  
   // ]]>
    <!-- Row 6 Column 1 -->  </script>
    <td bgcolor="$sidebg">&nbsp;</td>  
   ENDSCRIPT
    <!-- Row 6 Column 2 -->  
    <td align="left" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerleft.gif" alt="" /></td>  # --------------------------------------------------- Print login screen header
   
    <!-- Row 6 Column 3 -->      my %add_entries = (
    <td background="$iconpath/fillbottom.gif"><img src="$iconpath/fillbottom.gif" alt="" /></td>         bgcolor      => "$mainbg",
          text         => "$font",
    <!-- Row 6 Column 4 -->         link         => "$link",
    <td align="right" background="$iconpath/fillbottom.gif"><img src="$iconpath/lowerright.gif" alt="" /></td>         vlink        => "$vlink",
   </tr>         alink        => "$alink",
  </table>                 onload       => 'javascript:enableInput();',);
   
 <script>      my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
 // the if prevents the script error if the browser can't handle this      @hosts = &Apache::lonnet::current_machine_ids();
 if ( document.client.uname ) { document.client.uname.focus(); }      $lonhost_in_use = $lonhost;
 </script>      if (@hosts > 1) {
           foreach my $hostid (@hosts) {
 ENDDOCUMENT              if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
 }                  $lonhost_in_use = $hostid;
     $r->print('</body></html>');                  last;
     return OK;              }
 }           }
       }
 1;      %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
 __END__      $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
       $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
       if ($headextra) {
           my $omitextra;
           if ($headextra_exempt ne '') {
               my @exempt = split(',',$headextra_exempt);
               my $ip = $ENV{'REMOTE_ADDR'};
               if (grep(/^\Q$ip\E$/,@exempt)) {
                   $omitextra = 1;
               }
           }
           unless ($omitextra) {
               my $confname = $defdom.'-domainconfig';
               if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
                   my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
                   unless ($extra eq '-1') {
                       $js .= "\n".$extra."\n";
                   }
               }
           }
       }
   
       $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
          { 'redirect'       => [$expire,'/adm/roles'],
    'add_entries' => \%add_entries,
    'only_body'   => 1,}));
   
   # ----------------------------------------------------------------------- Texts
   
       my %lt=&Apache::lonlocal::texthash(
             'un'       => 'Username',
             'pw'       => 'Password',
             'dom'      => 'Domain',
             'perc'     => 'percent',
             'load'     => 'Server Load',
             'userload' => 'User Load',
             'catalog'  => 'Course/Community Catalog',
             'log'      => 'Log in',
             'help'     => 'Log-in Help',
             'serv'     => 'Server',
             'servadm'  => 'Server Administration',
             'helpdesk' => 'Contact Helpdesk',
             'forgotpw' => 'Forgot password?',
             'newuser'  => 'New User?',
          );
   # -------------------------------------------------- Change password field name
   
       my $forgotpw = &forgotpwdisplay(%lt);
       $forgotpw .= '<br />' if $forgotpw;
       my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
       if ($loginhelp) {
           $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
       }
   
   # ---------------------------------------------------- Serve out DES JavaScript
       {
       my $jsh=Apache::File->new($include."/londes.js");
       $r->print(<$jsh>);
       }
   # ---------------------------------------------------------- Serve rest of page
   
       $r->print(
       '<div class="LC_Box"'
      .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
   );
   
       $r->print(<<ENDSERVERFORM);
   <form name="server" action="/adm/authenticate" method="post" target="_top">
      <input type="hidden" name="logtoken" value="$logtoken" />
      <input type="hidden" name="serverid" value="$lonhost" />
      <input type="hidden" name="uname" value="" />
      <input type="hidden" name="upass0" value="" />
      <input type="hidden" name="udom" value="" />
      <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
      <input type="hidden" name="localres" value="$env{'form.localres'}" />
     </form>
   ENDSERVERFORM
       my $coursecatalog;
       if (($showcoursecat eq '') || ($showcoursecat)) {
           $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
       }
       my $newuserlink;
       if ($shownewuserlink) {
           $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
       }
       my $logintitle =
           '<h2 class="LC_hcell"'
          .' style="background:'.$loginbox_header_bgcol.';'
          .' color:'.$loginbox_header_textcol.'">'
          .$lt{'log'}
          .'</h2>';
   
       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>';
       my $helpdeskscript;
       my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
                                          $authdomain,\$helpdeskscript,
                                          $showhelpdesk,\@possdoms);
   
       my $mobileargs;
       if ($clientmobile) {
           $mobileargs = 'autocapitalize="off" autocorrect="off"';
       }
       my $loginform=(<<LFORM);
   <form name="client" action="" onsubmit="return(send())">
     <input type="hidden" name="lextkey" value="$lextkey" />
     <input type="hidden" name="uextkey" value="$uextkey" />
     <b><label for="uname">$lt{'un'}</label>:</b><br />
     <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 />
     <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
     <b><label for="udom">$lt{'dom'}</label>:</b><br />
     <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
     <input type="submit" value="$lt{'log'}" />
   </form>
   LFORM
   
       if ($showbanner) {
           $r->print(<<HEADER);
   <!-- The LON-CAPA Header -->
   <div style="background:$pgbg;margin:0;width:100%;">
     <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />
   </div>
   HEADER
       }
       $r->print(<<ENDTOP);
   <div style="float:left;margin-top:0;">
   <div class="LC_Box" style="background:$loginbox_bg;">
     $logintitle
     $loginform
     $noscript_warning
   </div>
    
   <div class="LC_Box" style="padding-top: 10px;">
     $loginhelp
     $forgotpw
     $contactblock
     $newuserlink
     $coursecatalog
   </div>
   </div>
   
   <div>
   ENDTOP
       if ($showmainlogo) {
           $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");
       }
   $r->print(<<ENDTOP);
   $announcements
   </div>
   <hr style="clear:both;" />
   ENDTOP
       my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
       $domainrow = <<"END";
         <tr>
          <td  align="left" valign="top">
           <small><b>$lt{'dom'}:&nbsp;</b></small>
          </td>
          <td  align="left" valign="top">
           <small><tt>&nbsp;$domain</tt></small>
          </td>
         </tr>
   END
       $serverrow = <<"END";
         <tr>
          <td  align="left" valign="top">
           <small><b>$lt{'serv'}:&nbsp;</b></small>
          </td>
          <td align="left" valign="top">
           <small><tt>&nbsp;$lonhost ($role)</tt></small>
          </td>
         </tr>
   END
       if ($loadlim) {
           $loadrow = <<"END";
         <tr>
          <td align="left" valign="top">
           <small><b>$lt{'load'}:&nbsp;</b></small>
          </td>
          <td align="left" valign="top">
           <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
          </td>
         </tr>
   END
       }
       if ($uloadlim) {
           $userloadrow = <<"END";
         <tr>
          <td align="left" valign="top">
           <small><b>$lt{'userload'}:&nbsp;</b></small>
          </td>
          <td align="left" valign="top">
           <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
          </td>
         </tr>
   END
       }
       if (($version ne '') && ($version ne '<!-- VERSION -->')) {
           $versionrow = <<"END";
         <tr>
          <td colspan="2" align="left">
           <small>$version</small>
          </td>
         </tr>
   END
       }
   
       $r->print(<<ENDDOCUMENT);
       <div style="float: left;">
        <table border="0" cellspacing="0" cellpadding="0">
   $domainrow
   $serverrow
   $loadrow    
   $userloadrow
   $versionrow
        </table>
       </div>
       <div style="float: right;">
       $domainlogo
       </div>
       <br style="clear:both;" />
    </div>
   
   <script type="text/javascript">
   // <![CDATA[
   // the if prevents the script error if the browser can not handle this
   if ( document.client.uname ) { document.client.uname.focus(); }
   // ]]>
   </script>
   $helpdeskscript
   
   ENDDOCUMENT
       my %endargs = ( 'noredirectlink' => 1, );
       $r->print(&Apache::loncommon::end_page(\%endargs));
       return OK;
   }
   
   sub check_loginvia {
       my ($domain,$lonhost) = @_;
       if ($domain eq '' || $lonhost eq '') {
           return;
       }
       my %domconfhash = &Apache::loncommon::get_domainconf($domain);
       my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
       my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
       my $output;
       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.32  
changed lines
  Added in v.1.168


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