File:  [LON-CAPA] / modules / relate / lonlogin.pm
Revision 1.10: download - view: text, annotated - select for diffs
Tue May 1 15:47:14 2012 UTC (12 years ago) by relate
Branches: MAIN
CVS tags: HEAD
- Customization for MITrelate
  - Sign-up for summer course available from log-in page for both
    new users and existing users.

    1: # The LearningOnline Network
    2: # Login Screen
    3: #
    4: # $Id: lonlogin.pm,v 1.10 2012/05/01 15:47:14 relate Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: package Apache::lonlogin;
   30: 
   31: use strict;
   32: use Apache::Constants qw(:common);
   33: use Apache::File ();
   34: use Apache::lonnet;
   35: use Apache::loncommon();
   36: use Apache::lonauth();
   37: use Apache::lonlocal;
   38: use Apache::migrateuser();
   39: use lib '/home/httpd/lib/perl/';
   40: use LONCAPA;
   41: use HTML::Entities();
   42:  
   43: sub handler {
   44:     my $r = shift;
   45: 
   46:     &Apache::loncommon::get_unprocessed_cgi
   47: 	(join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
   48: 	      $ENV{'REDIRECT_QUERY_STRING'}),
   49: 	 ['username','domain','firsturl','localpath','localres',
   50: 	  'token','role','symb']);
   51:     if (!defined($env{'form.firsturl'})) {
   52:         &Apache::lonacc::get_posted_cgi($r,['firsturl']);
   53:     }
   54:     $env{'form.firsturl'} =~ s/(`)/'/g;
   55: 
   56: # -- check if they are a migrating user
   57:     if (defined($env{'form.token'})) {
   58: 	return &Apache::migrateuser::handler($r);
   59:     }
   60: 
   61:     &Apache::loncommon::no_cache($r);
   62:     &Apache::lonlocal::get_language_handle($r);
   63:     &Apache::loncommon::content_type($r,'text/html');
   64:     $r->send_http_header;
   65:     return OK if $r->header_only;
   66: 
   67: # ---------------------------------------------------------  Are we re-routing?
   68:     my $londocroot = $r->dir_config('lonDocRoot'); 
   69:     if (-e "$londocroot/lon-status/reroute.txt") {
   70: 	&Apache::lonauth::reroute($r);
   71: 	return OK;
   72:     }
   73: 
   74: # -------------------------------- Prevent users from attempting to login twice
   75:     my $handle = &Apache::lonnet::check_for_valid_session($r);
   76:     if ($handle ne '') {
   77:         my $lonidsdir=$r->dir_config('lonIDsDir');
   78:         if ($handle=~/^publicuser\_/) {
   79: # For "public user" - remove it, we apparently really want to login
   80: 	    unlink("$lonidsdir/$handle.id");
   81:         } else {
   82: # Indeed, a valid token is found
   83:             &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
   84:             my $start_page =
   85:                 &Apache::loncommon::start_page('Already logged in');
   86:             my $end_page =
   87:                 &Apache::loncommon::end_page();
   88:             my $dest = '/adm/roles';
   89:             if ($env{'form.role'}) {
   90:                 $dest .= '?selectrole=1&'.$env{'form.role'}.'=1';
   91:             }
   92:             if ($env{'form.symb'}) {
   93:                 $dest .= ($dest =~ /\?/) ? '&' : '?';
   94:                 $dest .= 'destinationurl='.
   95:                          &HTML::Entities::encode($env{'form.symb'},'"&<>');
   96:             }
   97:             if ($env{'form.firsturl'} ne '') {
   98:                 $dest = $env{'form.firsturl'};
   99:             }
  100:             $r->print(
  101:                   $start_page.
  102:                   '<h1>'.&mt('You are already logged in!').'</h1>'.
  103:                   '<p>'.
  104:                   &mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
  105:                       '<a href="'.$dest.'">','</a>',
  106:                       '<a href="/adm/logout">','</a>').
  107:                  '</p>'.
  108:                  $end_page
  109:                  );
  110:             return OK;
  111:          }
  112:     }
  113: 
  114: # ---------------------------------------------------- No valid token, continue
  115: 
  116:  # ---------------------------- Not possible to really login to domain "public"
  117:     if ($env{'form.domain'} eq 'public') {
  118: 	$env{'form.domain'}='';
  119: 	$env{'form.username'}='';
  120:     }
  121: # ----------------------------------------------------------- Process Interface
  122:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
  123:     
  124:     my $iconpath= 
  125: 	&Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
  126: 
  127: # ----------------------------------------------------------------  
  128: 
  129:     my $lonhost = $r->dir_config('lonHostID');
  130:     my $domain = &Apache::lonnet::default_login_domain();
  131:     if ($lonhost ne '') {
  132:         my $redirect = &check_loginvia($domain,$lonhost);
  133:         if ($redirect) {
  134:             $r->print($redirect);
  135:             return OK;
  136:         }
  137:     }
  138: 
  139:     if (($env{'form.domain'}) && 
  140: 	(&Apache::lonnet::domain($env{'form.domain'},'description'))) {
  141: 	$domain=$env{'form.domain'};
  142:     }
  143: 
  144:     my $role    = $r->dir_config('lonRole');
  145:     my $loadlim = $r->dir_config('lonLoadLim');
  146:     my $uloadlim= $r->dir_config('lonUserLoadLim');
  147:     my $servadm = $r->dir_config('lonAdmEMail');
  148:     my $tabdir  = $r->dir_config('lonTabDir');
  149:     my $include = $r->dir_config('lonIncludes');
  150:     my $expire  = $r->dir_config('lonExpire');
  151:     my $version = $r->dir_config('lonVersion');
  152:     my $host_name = &Apache::lonnet::hostname($lonhost);
  153: 
  154: # --------------------------------------------- Default values for login fields
  155: 
  156:     my $authusername=($env{'form.username'}?$env{'form.username'}:'');
  157:     my $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
  158: 
  159: # ---------------------------------------------------------- Determine own load
  160:     my $loadavg;
  161:     {
  162: 	my $loadfile=Apache::File->new('/proc/loadavg');
  163: 	$loadavg=<$loadfile>;
  164:     }
  165:     $loadavg =~ s/\s.*//g;
  166: 
  167:     my ($loadpercent,$userloadpercent);
  168:     if ($loadlim) {
  169:         $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
  170:     }
  171:     if ($uloadlim) {
  172:         $userloadpercent=&Apache::lonnet::userload();
  173:     }
  174: 
  175:     my $firsturl=
  176:     ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
  177: 
  178: # ----------------------------------------------------------- Get announcements
  179:     my $announcements=&Apache::lonnet::getannounce();
  180: # -------------------------------------------------------- Set login parameters
  181: 
  182:     my @hexstr=('0','1','2','3','4','5','6','7',
  183:                 '8','9','a','b','c','d','e','f');
  184:     my $lkey='';
  185:     for (0..7) {
  186:         $lkey.=$hexstr[rand(15)];
  187:     }
  188: 
  189:     my $ukey='';
  190:     for (0..7) {
  191:         $ukey.=$hexstr[rand(15)];
  192:     }
  193: 
  194:     my $lextkey=hex($lkey);
  195:     if ($lextkey>2147483647) { $lextkey-=4294967296; }
  196: 
  197:     my $uextkey=hex($ukey);
  198:     if ($uextkey>2147483647) { $uextkey-=4294967296; }
  199: 
  200: # -------------------------------------------------------- Store away log token
  201:     my $tokenextras;
  202:     if ($env{'form.role'}) {
  203:         $tokenextras = '&role='.&escape($env{'form.role'});
  204:     }
  205:     if ($env{'form.symb'}) {
  206:         if (!$tokenextras) {
  207:             $tokenextras = '&';
  208:         }
  209:         $tokenextras .= '&symb='.&escape($env{'form.symb'});
  210:     }
  211:     my $logtoken=Apache::lonnet::reply(
  212:        'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
  213:        $lonhost);
  214: 
  215: # -- If we cannot talk to ourselves, or hostID does not map to a hostname
  216: #    we are in serious trouble
  217: 
  218:     if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
  219:         if ($logtoken eq 'no_such_host') {
  220:             &Apache::lonnet::logthis('No valid logtoken for log-in page -- '.
  221:             'unable to determine hostname for hostID: '.$lonhost.
  222:             '. Check entry in hosts.tab');
  223:         }
  224:         my $spares='';
  225: 	my $last;
  226:         foreach my $hostid (sort
  227: 			    {
  228: 				&Apache::lonnet::hostname($a) cmp
  229: 				    &Apache::lonnet::hostname($b);
  230: 			    }
  231: 			    keys(%Apache::lonnet::spareid)) {
  232:             next if ($hostid eq $lonhost);
  233:             my $hostname = &Apache::lonnet::hostname($hostid);
  234:             next if (($last eq $hostname) || ($hostname eq ''));
  235:             $spares.='<br /><span style="font-size: larger;"><a href="http://'.
  236:                 $hostname.
  237:                 '/adm/login?domain='.$authdomain.'">'.
  238:                 $hostname.'</a>'.
  239:                 ' '.&mt('(preferred)').'</span>'.$/;
  240: 	    $last=$hostname;
  241:         }
  242:         if ($spares) {
  243:             $spares.= '<br />';
  244:         }
  245: 	my %all_hostnames = &Apache::lonnet::all_hostnames();
  246:         foreach my $hostid (sort
  247: 			    {
  248: 				&Apache::lonnet::hostname($a) cmp
  249: 				    &Apache::lonnet::hostname($b);
  250: 			    }
  251: 			    keys(%all_hostnames)) {
  252:             next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
  253: 	    my $hostname = &Apache::lonnet::hostname($hostid);
  254:             next if (($last eq $hostname) || ($hostname eq ''));
  255:             $spares.='<br /><a href="http://'.
  256:                 $hostname.
  257:                 '/adm/login?domain='.$authdomain.'">'.
  258:                 $hostname.'</a>';
  259: 	    $last=$hostname;
  260:         }
  261: 	$r->print(
  262:            '<html>'
  263:           .'<head><title>'
  264:           .&mt('The LearningOnline Network with CAPA')
  265:           .'</title></head>'
  266:           .'<body bgcolor="#FFFFFF">'
  267:           .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
  268:           .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'
  269:           .'<h3>'.&mt("This Mechanics Online course server is temporarily not available for login.").'</h3>'
  270:           .'</body>'
  271:           .'</html>'
  272:         );
  273:         return OK;
  274:     }
  275: 
  276: # ----------------------------------------------- Apparently we are in business
  277:     $servadm=~s/\,/\<br \/\>/g;
  278: 
  279: # ----------------------------------------------------------------------- Texts
  280:     my $pagetitle = 'Mechanics Online Log-in'; # Do not localize.
  281:     my %lt=&Apache::lonlocal::texthash(
  282:           'needu'    => 'You must provide a username',
  283:           'needp'    => 'You must provide a password',
  284:           'un'       => 'Username',
  285:           'pw'       => 'Password',
  286:           'dom'      => 'Domain',
  287:           'perc'     => 'percent',
  288:           'load'     => 'Server Load',
  289:           'userload' => 'User Load',
  290:           'catalog'  => 'Course/Community Catalog',
  291:           'log'      => 'Log-in',
  292:           'help'     => 'Log-in Help',
  293:           'serv'     => 'Server',
  294:           'servadm'  => 'Server Administration',
  295:           'helpdesk' => 'Contact Helpdesk',
  296:           'exist'    => 'Existing user - sign-up with existing username',
  297:           'create'   => 'New user - create username and sign-up',
  298:           'already'  => 'Already signed up?',
  299:           'forgotpw' => 'Forgot your password?',
  300:           'newuser'  => 'New User?',
  301:           'click'   => 'Click here to sign up',
  302:           'plea'    => 'Please log-in',
  303:           'supp'    => 'Support from NSF, NIH, Google',
  304:           'note'    => 'Please Note:',
  305:           'jscr'    => 'Javascript must be enabled in your web browser in order to use this web site.',
  306:        );
  307: # ----------------------------------------------------------- Front page design
  308:     my $font=&Apache::loncommon::designparm('login.font',$domain);
  309:     my $link=&Apache::loncommon::designparm('login.link',$domain);
  310:     my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
  311:     my $alink=&Apache::loncommon::designparm('login.alink',$domain);
  312:     my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
  313:     my $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
  314: 
  315:     my $helpdeskscript;
  316:     my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
  317:                                        $authdomain,\$helpdeskscript);
  318: 
  319: # -------------------------------------------------- Change password field name
  320:     my $now=time;
  321: 
  322: # ---------------------------------------- Assemble Javascript to put in <head>
  323: 
  324: 
  325:     my $js = (<<ENDSCRIPT);
  326: 
  327: <script type="text/javascript" language="JavaScript">
  328: // <![CDATA[
  329: 
  330: function send(caller) {
  331:     if (caller == "newaccount") {
  332:         this.document.signup.submit();
  333:         return false;
  334:     }
  335:     if (document.client.uname.value == "" || !document.client.uname.value) {
  336:         alert("$lt{'needu'}");
  337:         return false;
  338:     }
  339:     if (document.client.upass$now.value == "" || 
  340:         !document.client.upass$now.value) {
  341:        alert("$lt{'needp'}");
  342:        return false;
  343:     }
  344: 
  345:     this.document.server.elements.uname.value
  346:        =this.document.client.elements.uname.value;
  347: 
  348:     this.document.server.elements.udom.value
  349:        =this.document.client.elements.udom.value;
  350: 
  351:     uextkey=this.document.client.elements.uextkey.value;
  352:     lextkey=this.document.client.elements.lextkey.value;
  353:     initkeys();
  354: 
  355:     this.document.server.elements.upass0.value
  356:         =crypted(this.document.client.elements.upass$now.value.substr(0,15));
  357:     this.document.server.elements.upass1.value
  358:         =crypted(this.document.client.elements.upass$now.value.substr(15,15));
  359:     this.document.server.elements.upass2.value
  360:         =crypted(this.document.client.elements.upass$now.value.substr(30,15));
  361: 
  362:     this.document.client.elements.uname.value='';
  363:     this.document.client.elements.upass$now.value='';
  364: 
  365:     this.document.server.submit();
  366:     return false;
  367: }
  368: 
  369: function enableInput() {
  370:     this.document.client.elements.upass$now.removeAttribute("readOnly");
  371:     this.document.client.elements.uname.removeAttribute("readOnly");
  372:     this.document.client.elements.udom.removeAttribute("readOnly");
  373:     return;
  374: }
  375: 
  376: function SubmitSignUp() {
  377:     if (document.signup.usertype[0].checked == true) {
  378:         document.signup.action = '/adm/createaccount';
  379:     }
  380:     if (document.signup.usertype[1].checked == true) {
  381:         document.signup.action = '/adm/selfenroll';
  382:     }
  383:     return true;
  384: }
  385: 
  386: // ]]>
  387: </script>
  388: 
  389: $helpdeskscript
  390: 
  391: ENDSCRIPT
  392: 
  393: # --------------------------------------------------- Print login screen header
  394:     my %add_entries = (
  395:                bgcolor      => "$mainbg",
  396:                text         => "$font",
  397:                link         => "$link",
  398:                vlink        => "$vlink",
  399:                alink        => "$alink",
  400:                onload       => 'javascript:enableInput();',);
  401: 
  402:     my $css_url = "/css/relate/login.css";
  403:     $js .= "\n".'<link type="text/css" rel="stylesheet" href="'.$css_url.'" />'."\n";
  404:     $r->print(&Apache::loncommon::start_page($pagetitle,$js,
  405:                                        {'redirect'   => [$expire,'/adm/roles'], 
  406:                                         'add_entries' => \%add_entries,
  407:                                         'only_body'   => 1,}));
  408: 
  409: # ------------------------------------------------------------ Additional Texts
  410:     $lt{'newto'} = &mt('New to the [_1]Mechanics Online[_2] site?','<i>','</i>');
  411:     $lt{'mech'} = &mt('Mechanics Online is a Newtonian Mechanics course developed by Professor David Pritchard and the RELATE education group at MIT. [_1]Learn more[_2]','<a href="http://relate.mit.edu/physicscourse" style="text-decoration: underline;">','</a>');
  412:     $lt{'runson'} = &mt('Mechanics Online runs on [_1]LON-CAPA[_2] - an open source, freeware, distributed learning content management and assessment system.',
  413:                         '<a href="http://loncapa.org/" style="text-decoration: underline;">',
  414:                         '</a>');
  415:     $lt{'newhere'} = &mt('New to [_1]Mechanics Online[_2]:','<i>','</i>');
  416:     $lt{'browser'} = &mt('Your browser must allow [_1]cookies[_2]',
  417:                          '<a href="http://loncapa.msu.edu/cookies.html" style="color: #ffffff; text-decoration:underline;">','</a>');
  418: 
  419:     my ($contactrow,$domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
  420:     $contactrow = <<"END";
  421:       <tr>
  422:        <td align="left" colspan="2">
  423:        $contactblock
  424:        </td>
  425:       </tr>
  426: END
  427:     $domainrow = <<"END";
  428:       <tr>
  429:        <td align="left" valign="top">
  430:         <small><b>$lt{'dom'}:&nbsp;</b></small>
  431:        </td>
  432:        <td align="left" valign="top">
  433:         <small><tt>&nbsp;$domain</tt></small>
  434:        </td>
  435:       </tr>
  436: END
  437:     $serverrow = <<"END";
  438:       <tr>
  439:        <td align="left" valign="top">
  440:         <small><b>$lt{'serv'}:&nbsp;</b></small>
  441:        </td>
  442:        <td align="left" valign="top">
  443:         <small><tt>&nbsp;$lonhost ($role)</tt></small>
  444:        </td>
  445:       </tr>
  446: END
  447:     if ($loadlim) {
  448:         $loadrow = <<"END";
  449:       <tr>
  450:        <td align="left" valign="top">
  451:         <small><b>$lt{'load'}:&nbsp;</b></small>
  452:        </td>
  453:        <td align="left" valign="top">
  454:         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
  455:        </td>
  456:       </tr>
  457: END
  458:     }
  459:     if ($uloadlim) {
  460:         $userloadrow = <<"END";
  461:       <tr>
  462:        <td align="left" valign="top">
  463:         <small><b>$lt{'userload'}:&nbsp;</b></small>
  464:        </td>
  465:        <td align="left" valign="top">
  466:         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
  467:        </td>
  468:       </tr>
  469: END
  470:     }
  471:     if (($version ne '') && ($version ne '<!-- VERSION -->')) {
  472:         $versionrow = <<"END";
  473:       <tr>
  474:        <td colspan="2" align="left">
  475:         <a href="/adm/about.html">
  476:         <img src="/images/login/lclogosm.gif" width="16" height="14" alt="LC" border="0" />&nbsp;<small>$version</small></a>
  477:        </td>
  478:       </tr>
  479: END
  480:     }
  481: 
  482: # -------------------------------------------- Static cid for prerequisite test
  483:     my $prereqcid = 'relate_2764113e81b9e4f0crelatel1';
  484: 
  485: # ---------------------------------------------------- Warning if no Javascript 
  486:     my $noscript_warning = '<noscript><br /><span class="LC_warning">'.
  487:                            '<b>'.$lt{'note'}.'</b>'.$lt{'jscr'}.
  488:                            '</span></noscript>';
  489: 
  490: # ---------------------------------------------------- Serve out DES JavaScript
  491:     {
  492:         my $jsh=Apache::File->new($include."/londes.js");
  493:         $r->print(<$jsh>);
  494:     }
  495: # ---------------------------------------------------------- Serve rest of page
  496: 
  497:     $r->print(<<"ENDLOGIN");
  498: <br />
  499: <div align="center">
  500: <table class="LC_loginbox">
  501:   <tr>
  502:     <td align="left" valign="top" width="11"><img src="/images/login/tlc_11_ffffff_e2e2e2.gif" width="10" height="10" border="0" alt="" /></td>
  503:     <td width="450" valign="top">
  504:       <table class="LC_loginbox_left">
  505:         <tr>
  506:           <td width="441" align="left"><br />
  507:            <img src="/images/login/LCrelateheader_sm.png" width="441" height="100" alt="Relate @ MIT" align="left" /></td>
  508:         </tr>
  509:         <tr>
  510:          <td>
  511:           <div align="left" style="display:block; margin-top:5px; margin-bottom:5px; margin-left:0px; margin-right:0px; width:440px; height:5px;">
  512:            <div class="divider">
  513:             </div>
  514:           </div>
  515:         </td>
  516:        </tr>
  517:       </table>
  518:       <table class="LC_loginbox_left">
  519:        <tr>
  520:         <td width="10">&nbsp;</td>
  521:         <td valign="top" class="bodyred" width="430" align="left"><br />
  522:          <span style="font-size: 18px; line-height: 22px; ">$lt{'newto'}</span>
  523:          <p class="bodyred">$lt{'mech'}</p>
  524:          <p class="bodyred">$lt{'runson'}</p>
  525:          <fieldset><legend><span style="font-size:larger;">Sign-up for Summer (course begins: June 14th)</span></legend>
  526:          <form name="signup" method="post" action="/adm/createaccount" onsubmit="return SubmitSignUp();">
  527:          <input type="hidden" name="courseid" value="$prereqcid" /> 
  528:          <input type="hidden" name="process" value="signup" />
  529:          <span class="LC_nobreak">
  530:           <label>
  531:            <input type="radio" name="usertype" value="newuser" checked="checked" />$lt{'create'}
  532:           </label></span><br />
  533:           <span class="LC_nobreak"><label>
  534:            <input type="radio" name="usertype" value="existing" />$lt{'exist'}
  535:            </label>
  536:            <input type="hidden" name="phase" value="login" />
  537:          </span><br /><br />
  538:          <input name="signin" type="submit" value="$lt{'click'}" class="buttonred" />
  539:          </form>
  540:          </fieldset>
  541:         </td>
  542:        </tr>
  543:       </table>
  544:      </td>
  545:      <td width="10">&nbsp;</td>
  546:      <td valign="top">
  547:       <form name="client" method="post" onsubmit="return(send());" action="">
  548:       <table class="LC_loginbox_right">
  549:        <tr>
  550:         <td colspan="3" height="23" class="LC_loginbox_strip">&nbsp;</td>
  551:        </tr>
  552:        <tr>
  553:         <td align="left" valign="top" width="11" height="11"><img src="/images/login/tlc_11_993333_ffffff.gif" width="10" height="10" border="0" alt="" /></td>
  554:         <td>&nbsp;</td>
  555:         <td align="right" valign="top" width="11" height="11"><img src="/images/login/tr_11_993333_ffffff.gif" width="11" height="11" border="0" alt="" /></td>
  556:        </tr>
  557:        <tr>
  558:         <td width="10">&nbsp;</td>
  559:         <td>
  560:          <table border="0" cellspacing="0" cellpadding="0">
  561:           <tr>
  562:            <td align="right" class="bodywhite" height="50"><br />
  563:             <span style="font-size: 15px; line-height: 17px; font-weight: bold;">
  564:              $lt{'already'}</span>
  565:              <br />$lt{'plea'}<br />
  566:              <hr class="login" /><br /><br />
  567:             </td>
  568:            </tr>
  569:            <tr>
  570:             <td>
  571:              <table border="0" cellpadding="2" cellspacing="0">
  572:               <tr>
  573:                <td align="right" class="bodywhite"><label>$lt{'un'}</label>:</td>
  574:                <td align="right"><input type="text" name="uname" size="17" value="" /></td>
  575:                </tr>
  576:                <tr>
  577:                 <td align="right" class="bodywhite"><label>$lt{'pw'}</label>:</td>
  578:                 <td align="right"><input name="upass$now" size="17" value="" type="password" /><input type="hidden" name="udom" value="$domain" /></td>
  579:                </tr>
  580:                <tr><td>&nbsp;</td></tr>
  581:                <tr>
  582:                 <td colspan="2" align="right"><input name="signin" type="submit" value="$lt{'log'}" class="buttonwhite" /></td>
  583:                </tr>
  584:               </table>
  585:              </td>
  586:             </tr>
  587:             <tr>
  588:              <td align="right" valign="top" class="bodywhite">
  589:               <br />
  590:               <br />
  591:               <span style="font-size: smaller;">$lt{'browser'}</span><br />
  592:               <hr class="login" />
  593:               <br />
  594:               <a href="/adm/resetpw" style="color: #ffffff; text-decoration:underline;">$lt{'forgotpw'}</a><br />
  595:               <br />
  596:              </td>
  597:             </tr>
  598:            </table>
  599:           </td>
  600:           <td width="9">&nbsp;</td>
  601:         </tr>
  602:         <tr>
  603:           <td align="left" valign="bottom" width="11" height="11"><img src="/images/login/bl_11_993333_ffffff.gif" width="11" height="11" border="0" alt="" /></td>
  604:           <td>&nbsp;</td>
  605:           <td align="right" valign="bottom" width="11" height="11"><img src="/images/login/br_11_993333_ffffff.gif" width="11" height="11" border="0" alt="" /></td>
  606:         </tr>
  607:       </table>
  608:       <input type="hidden" name="lextkey" value="$lextkey" />
  609:       <input type="hidden" name="uextkey" value="$uextkey" />
  610:       </form>
  611:     </td>
  612:     <td align="right" valign="top" width="11"><img src="/images/login/tr_11_ffffff_e2e2e2.gif" width="11" height="11" border="0" alt="" /></td>
  613:   </tr>
  614:   <tr>
  615:    <td width="10">&nbsp;</td>
  616:    <td colspan="3">
  617:     <br />
  618:     $noscript_warning
  619:     <hr style="clear:both;" />
  620:    </td>
  621:    <td width="10">&nbsp;</td>
  622:   </tr>
  623:   <tr>
  624:     <td width="10">&nbsp;</td>
  625:     <td colspan="4">
  626:     <div style="float: left;">
  627:      <table border="0" cellspacing="0" cellpadding="0">
  628: $contactrow
  629: $domainrow
  630: $serverrow
  631: $loadrow
  632: $userloadrow
  633: $versionrow
  634:      </table>
  635:     </div>
  636:     <div style="float: right;">
  637:      <img src="/images/login/sponsors.png" alt="$lt{'supp'}" align="right" />
  638:     <br style="clear:both;" />
  639:     </div>
  640:    </td>
  641:   </tr>
  642:   <tr>
  643:     <td align="left" valign="bottom" width="11"><img src="/images/login/bl_11_ffffff_e2e2e2.gif" width="11" height="11" border="0" alt="" /></td>
  644:     <td colspan="3" width="698">&nbsp;</td>
  645:     <td align="right" valign="bottom" width="11"><img src="/images/login/br_11_ffffff_e2e2e2.gif" width="11" height="11" border="0" alt="" /></td>
  646:   </tr>
  647: </table>
  648: </div>
  649: <p>&nbsp;</p>
  650:   <form name="server" action="/adm/authenticate" method="post" target="_top">
  651:    <input type="hidden" name="logtoken" value="$logtoken" />
  652:    <input type="hidden" name="serverid" value="$lonhost" />
  653:    <input type="hidden" name="uname" value="" />
  654:    <input type="hidden" name="upass0" value="" />
  655:    <input type="hidden" name="upass1" value="" />
  656:    <input type="hidden" name="upass2" value="" />
  657:    <input type="hidden" name="udom" value="" />
  658:    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
  659:    <input type="hidden" name="localres" value="$env{'form.localres'}" />
  660:   </form>
  661: 
  662: <script type="text/javascript">
  663: // <![CDATA[
  664: // the if prevents the script error if the browser can not handle this
  665: if ( document.client.uname ) { document.client.uname.focus(); }
  666: // ]]>
  667: </script>
  668: 
  669: ENDLOGIN
  670: 
  671: # -------------------------------------------------------- Standard page ending 
  672:     my %endargs = ( 'noredirectlink' => 1, );
  673:     $r->print(&Apache::loncommon::end_page(\%endargs));
  674:     return OK;
  675: }
  676: 
  677: sub check_loginvia {
  678:     my ($domain,$lonhost) = @_;
  679:     if ($domain eq '' || $lonhost eq '') {
  680:         return;
  681:     }
  682:     my %domconfhash = &Apache::loncommon::get_domainconf($domain);
  683:     my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
  684:     my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
  685:     my $output;
  686:     if ($loginvia ne '') {
  687:         my $noredirect;
  688:         my $ip = $ENV{'REMOTE_ADDR'};
  689:         if ($ip eq '127.0.0.1') {
  690:             $noredirect = 1;
  691:         } else {
  692:             if ($loginvia_exempt ne '') {
  693:                 my @exempt = split(',',$loginvia_exempt);
  694:                 if (grep(/^\Q$ip\E$/,@exempt)) {
  695:                     $noredirect = 1;
  696:                 }
  697:             }
  698:         }
  699:         unless ($noredirect) {
  700:             my ($newhost,$path);
  701:             if ($loginvia =~ /:/) {
  702:                 ($newhost,$path) = split(':',$loginvia);
  703:             } else {
  704:                 $newhost = $loginvia;
  705:             }
  706:             if ($newhost ne $lonhost) {
  707:                 if (&Apache::lonnet::hostname($newhost) ne '') {
  708:                     $output = &redirect_page($newhost,$path);
  709:                 }
  710:             }
  711:         }
  712:     }
  713:     return $output;
  714: }
  715: 
  716: sub redirect_page {
  717:     my ($desthost,$path) = @_;
  718:     my $protocol = $Apache::lonnet::protocol{$desthost};
  719:     $protocol = 'http' if ($protocol ne 'https');
  720:     unless ($path =~ m{^/}) {
  721:         $path = '/'.$path;
  722:     }
  723:     my $url = $protocol.'://'.&Apache::lonnet::hostname($desthost).$path;
  724:     if ($env{'form.firsturl'} ne '') {
  725:         $url .='?firsturl='.$env{'form.firsturl'};
  726:     }
  727:     my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
  728:                                                     {'redirect' => [0,$url],});
  729:     my $end_page   = &Apache::loncommon::end_page();
  730:     return $start_page.$end_page;
  731: }
  732: 
  733: sub contactdisplay {
  734:     my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript) = @_;
  735:     return unless(ref($lt) eq 'HASH');
  736:     my $contactblock;
  737:     my $showhelpdesk = 0;
  738:     my $requestmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
  739:     if ($requestmail =~ m/^[^\@]+\@[^\@]+$/) {
  740:         $showhelpdesk = 1;
  741:     }
  742:     if ($servadm && $showadminmail) {
  743:         $contactblock .= $lt->{'servadm'}.':<br />'.
  744:                          '<tt>'.$servadm.'</tt><br />';
  745:     }
  746:     if ($showhelpdesk) {
  747:         $contactblock .= '<a href="javascript:helpdesk()" style="text-decoration:underline;">'.$lt->{'helpdesk'}.'</a><br />';
  748:         my $thisurl = &escape('/adm/login');
  749:         $$helpdeskscript = <<"ENDSCRIPT";
  750: <script type="text/javascript">
  751: // <![CDATA[
  752: function helpdesk() {
  753:     var codedom = document.client.udom.value;
  754:     if (codedom == '') {
  755:         codedom = "$authdomain";
  756:     }
  757:     var querystr = "origurl=$thisurl&codedom="+codedom;
  758:     document.location.href = "/adm/helpdesk?"+querystr;
  759:     return;
  760: }
  761: // ]]>
  762: </script>
  763: ENDSCRIPT
  764:     }
  765:     return $contactblock;
  766: }
  767: 
  768: 1;
  769: __END__

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