File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.158.2.10: download - view: text, annotated - select for diffs
Sat Oct 24 19:49:06 2020 UTC (3 years, 7 months ago) by raeburn
Branches: version_2_11_X
Diff to branchpoint 1.158: preferred, unified
- For 2.11
  Backport 1.180

    1: # The LearningOnline Network
    2: # Login Screen
    3: #
    4: # $Id: lonlogin.pm,v 1.158.2.10 2020/10/24 19:49:06 raeburn 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 qw(:DEFAULT :match);
   41: use CGI::Cookie();
   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: 	 ['interface','username','domain','firsturl','localpath','localres',
   50: 	  'token','role','symb','iptoken','btoken']);
   51:     if (!defined($env{'form.firsturl'})) {
   52:         &Apache::lonacc::get_posted_cgi($r,['firsturl']);
   53:     }
   54: 
   55: # -- check if they are a migrating user
   56:     if (defined($env{'form.token'})) {
   57: 	return &Apache::migrateuser::handler($r);
   58:     }
   59: 
   60: # For "public user" - remove any exising "public" cookie, as user really wants to log-in
   61:     my ($handle,$lonidsdir,$expirepub,$userdom);
   62:     $lonidsdir=$r->dir_config('lonIDsDir');
   63:     unless ($r->header_only) {
   64:         $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);
   65:         if ($handle ne '') {
   66:             if ($handle=~/^publicuser\_/) {
   67:                 unlink($r->dir_config('lonIDsDir')."/$handle.id");
   68:                 undef($handle);
   69:                 undef($userdom);
   70:                 $expirepub = 1;
   71:             }
   72:         }
   73:     }
   74: 
   75:     &Apache::loncommon::no_cache($r);
   76:     &Apache::lonlocal::get_language_handle($r);
   77:     &Apache::loncommon::content_type($r,'text/html');
   78:     if ($expirepub) {
   79:         my $c = new CGI::Cookie(-name    => 'lonPubID',
   80:                                 -value   => '',
   81:                                 -expires => '-10y',);
   82:         $r->header_out('Set-cookie' => $c);
   83:     } elsif (($handle eq '') && ($userdom ne '')) {
   84:         my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
   85:         foreach my $name (keys(%cookies)) {
   86:             next unless ($name =~ /^lon(|S|Link|Pub)ID$/);
   87:             my $c = new CGI::Cookie(-name    => $name,
   88:                                     -value   => '',
   89:                                     -expires => '-10y',);
   90:             $r->headers_out->add('Set-cookie' => $c);
   91:         }
   92:     }
   93:     $r->send_http_header;
   94:     return OK if $r->header_only;
   95: 
   96: 
   97: # Are we re-routing?
   98:     my $londocroot = $r->dir_config('lonDocRoot'); 
   99:     if (-e "$londocroot/lon-status/reroute.txt") {
  100: 	&Apache::lonauth::reroute($r);
  101: 	return OK;
  102:     }
  103: 
  104:     my $lonhost = $r->dir_config('lonHostID');
  105:     $env{'form.firsturl'} =~ s/(`)/'/g;
  106: 
  107: # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
  108: 
  109:     my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1);
  110:     if ($found_server) {
  111:         my $hostname = &Apache::lonnet::hostname($found_server);
  112:         if ($hostname ne '') {
  113:             my $protocol = $Apache::lonnet::protocol{$found_server};
  114:             $protocol = 'http' if ($protocol ne 'https');
  115:             my $dest = '/adm/roles';
  116:             if ($env{'form.firsturl'} ne '') {
  117:                 $dest = $env{'form.firsturl'};
  118:             }
  119:             my %info = (
  120:                          balcookie => $lonhost.':'.$balancer_cookie,
  121:                        );
  122:             my $balancer_token = &Apache::lonnet::tmpput(\%info,$found_server);
  123:             if ($balancer_token) {
  124:                 $dest .=  (($dest=~/\?/)?'&;':'?') . 'btoken='.$balancer_token;
  125:             }
  126:             my $url = $protocol.'://'.$hostname.$dest;
  127:             my $start_page =
  128:                 &Apache::loncommon::start_page('Switching Server ...',undef,
  129:                                                {'redirect'       => [0,$url],});
  130:             my $end_page   = &Apache::loncommon::end_page();
  131:             $r->print($start_page.$end_page);
  132:             return OK;
  133:         }
  134:     }
  135: 
  136: #
  137: # Check if a LON-CAPA load balancer sent user here because user's browser sent
  138: # it a balancer cookie for an active session on this server.
  139: #
  140: 
  141:     my $balcookie;
  142:     if ($env{'form.btoken'}) {
  143:         my %info = &Apache::lonnet::tmpget($env{'form.btoken'});
  144:         $balcookie = $info{'balcookie'};
  145:         &Apache::lonnet::tmpdel($env{'form.btoken'});
  146:         delete($env{'form.btoken'});
  147:     }
  148: 
  149: #
  150: # If browser sent an old cookie for which the session file had been removed
  151: # check if configuration for user's domain has a portal URL set.  If so
  152: # switch user's log-in to the portal.
  153: #
  154: 
  155:     if (($handle eq '') && ($userdom ne '')) {
  156:         my %domdefaults = &Apache::lonnet::get_domain_defaults($userdom);
  157:         if ($domdefaults{'portal_def'} =~ /^https?\:/) {
  158:             my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
  159:                                           {'redirect' => [0,$domdefaults{'portal_def'}],});
  160:             my $end_page   = &Apache::loncommon::end_page();
  161:             $r->print($start_page.$end_page);
  162:             return OK;
  163:         }
  164:     }
  165: 
  166:     $env{'form.firsturl'} =~ s/(`)/'/g;
  167: 
  168: # -------------------------------- Prevent users from attempting to login twice
  169:     if ($handle ne '') {
  170:         &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
  171: 	my $start_page = 
  172: 	    &Apache::loncommon::start_page('Already logged in');
  173: 	my $end_page = 
  174: 	    &Apache::loncommon::end_page();
  175:         my $dest = '/adm/roles';
  176:         if ($env{'form.firsturl'} ne '') {
  177:             $dest = $env{'form.firsturl'}; 
  178:         }
  179: 	$r->print(
  180:               $start_page
  181:              .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
  182:              .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
  183:               '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
  184:              .$end_page
  185:              );
  186:         return OK;
  187:     }
  188: 
  189: # ---------------------------------------------------- No valid token, continue
  190: 
  191: # ---------------------------- Not possible to really login to domain "public"
  192:     if ($env{'form.domain'} eq 'public') {
  193: 	$env{'form.domain'}='';
  194: 	$env{'form.username'}='';
  195:     }
  196: 
  197: # ------ Is this page requested because /adm/migrateuser detected an IP change?
  198:     my %sessiondata;
  199:     if ($env{'form.iptoken'}) {
  200:         %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});
  201:         unless ($sessiondata{'sessionserver'}) {
  202:             my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});
  203:             delete($env{'form.iptoken'});
  204:         }
  205:     }
  206: # ----------------------------------------------------------- Process Interface
  207:     $env{'form.interface'}=~s/\W//g;
  208: 
  209:     (undef,undef,undef,undef,undef,undef,my $clientmobile) =
  210:         &Apache::loncommon::decode_user_agent();
  211: 
  212:     my $iconpath= 
  213: 	&Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
  214: 
  215:     my $domain = &Apache::lonnet::default_login_domain();
  216:     my $defdom = $domain;
  217:     if ($lonhost ne '') {
  218:         unless ($sessiondata{'sessionserver'}) {
  219:             my $redirect = &check_loginvia($domain,$lonhost,$lonidsdir,$balcookie);
  220:             if ($redirect) {
  221:                 $r->print($redirect);
  222:                 return OK;
  223:             }
  224:         }
  225:     }
  226: 
  227:     if (($sessiondata{'domain'}) &&
  228:         (&Apache::lonnet::domain($sessiondata{'domain'},'description'))) {
  229:         $domain=$sessiondata{'domain'};
  230:     } elsif (($env{'form.domain'}) && 
  231: 	(&Apache::lonnet::domain($env{'form.domain'},'description'))) {
  232: 	$domain=$env{'form.domain'};
  233:     }
  234: 
  235:     my $role    = $r->dir_config('lonRole');
  236:     my $loadlim = $r->dir_config('lonLoadLim');
  237:     my $uloadlim= $r->dir_config('lonUserLoadLim');
  238:     my $servadm = $r->dir_config('lonAdmEMail');
  239:     my $tabdir  = $r->dir_config('lonTabDir');
  240:     my $include = $r->dir_config('lonIncludes');
  241:     my $expire  = $r->dir_config('lonExpire');
  242:     my $version = $r->dir_config('lonVersion');
  243:     my $host_name = &Apache::lonnet::hostname($lonhost);
  244: 
  245: # --------------------------------------------- Default values for login fields
  246:     
  247:     my ($authusername,$authdomain);
  248:     if ($sessiondata{'username'}) {
  249:         $authusername=$sessiondata{'username'};
  250:     } else {
  251:         $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
  252:         $authusername=($env{'form.username'}?$env{'form.username'}:'');
  253:     }
  254:     if ($sessiondata{'domain'}) {
  255:         $authdomain=$sessiondata{'domain'};
  256:     } else {
  257:         $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
  258:         $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
  259:     }
  260: 
  261: # ---------------------------------------------------------- Determine own load
  262:     my $loadavg;
  263:     {
  264: 	my $loadfile=Apache::File->new('/proc/loadavg');
  265: 	$loadavg=<$loadfile>;
  266:     }
  267:     $loadavg =~ s/\s.*//g;
  268: 
  269:     my ($loadpercent,$userloadpercent);
  270:     if ($loadlim) {
  271:         $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
  272:     }
  273:     if ($uloadlim) {
  274:         $userloadpercent=&Apache::lonnet::userload();
  275:     }
  276: 
  277:     my $firsturl=
  278:     ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
  279: 
  280: # ----------------------------------------------------------- Get announcements
  281:     my $announcements=&Apache::lonnet::getannounce();
  282: # -------------------------------------------------------- Set login parameters
  283: 
  284:     my @hexstr=('0','1','2','3','4','5','6','7',
  285:                 '8','9','a','b','c','d','e','f');
  286:     my $lkey='';
  287:     for (0..7) {
  288:         $lkey.=$hexstr[rand(15)];
  289:     }
  290: 
  291:     my $ukey='';
  292:     for (0..7) {
  293:         $ukey.=$hexstr[rand(15)];
  294:     }
  295: 
  296:     my $lextkey=hex($lkey);
  297:     if ($lextkey>2147483647) { $lextkey-=4294967296; }
  298: 
  299:     my $uextkey=hex($ukey);
  300:     if ($uextkey>2147483647) { $uextkey-=4294967296; }
  301: 
  302: # -------------------------------------------------------- Store away log token
  303:     my $tokenextras;
  304:     if ($env{'form.role'}) {
  305:         $tokenextras = '&role='.&escape($env{'form.role'});
  306:     }
  307:     if ($env{'form.symb'}) {
  308:         if (!$tokenextras) {
  309:             $tokenextras = '&';
  310:         }
  311:         $tokenextras .= '&symb='.&escape($env{'form.symb'});
  312:     }
  313:     if ($env{'form.iptoken'}) {
  314:         if (!$tokenextras) {
  315:             $tokenextras = '&&';
  316:         }
  317:         $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});
  318:     }
  319:     my $logtoken=Apache::lonnet::reply(
  320:        'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
  321:        $lonhost);
  322: 
  323: # -- If we cannot talk to ourselves, or hostID does not map to a hostname
  324: #    we are in serious trouble
  325: 
  326:     if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
  327:         if ($logtoken eq 'no_such_host') {
  328:             &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
  329:         }
  330:         my $spares='';
  331:         my (@sparehosts,%spareservers);
  332:         my $sparesref = &Apache::lonnet::this_host_spares($defdom);
  333:         if (ref($sparesref) eq 'HASH') {
  334:             foreach my $key (keys(%{$sparesref})) {
  335:                 if (ref($sparesref->{$key}) eq 'ARRAY') {
  336:                     my @sorted = sort { &Apache::lonnet::hostname($a) cmp
  337:                                         &Apache::lonnet::hostname($b);
  338:                                       } @{$sparesref->{$key}};
  339:                     if (@sorted) {
  340:                         if ($key eq 'primary') {
  341:                             unshift(@sparehosts,@sorted);
  342:                         } elsif ($key eq 'default') {
  343:                             push(@sparehosts,@sorted);
  344:                         }
  345:                     }
  346:                 }
  347:             }
  348:         }
  349:         foreach my $hostid (@sparehosts) {
  350:             next if ($hostid eq $lonhost);
  351: 	    my $hostname = &Apache::lonnet::hostname($hostid);
  352: 	    next if (($hostname eq '') || ($spareservers{$hostname}));
  353:             $spareservers{$hostname} = 1;
  354:             my $protocol = $Apache::lonnet::protocol{$hostid};
  355:             $protocol = 'http' if ($protocol ne 'https');
  356:             $spares.='<br /><span style="font-size: larger;"><a href="'.$protocol.'://'.
  357:                 $hostname.
  358:                 '/adm/login?domain='.$authdomain.'">'.
  359:                 $hostname.'</a>'.
  360:                 ' '.&mt('(preferred)').'</span>'.$/;
  361:         }
  362:         if ($spares) {
  363:             $spares.= '<br />';
  364:         }
  365:         my %all_hostnames = &Apache::lonnet::all_hostnames();
  366:         foreach my $hostid (sort
  367: 		    {
  368: 			&Apache::lonnet::hostname($a) cmp
  369: 			    &Apache::lonnet::hostname($b);
  370: 		    }
  371: 		    keys(%all_hostnames)) {
  372:             next if ($hostid eq $lonhost);
  373:             my $hostname = &Apache::lonnet::hostname($hostid);
  374:             next if (($hostname eq '') || ($spareservers{$hostname}));
  375:             my $protocol = $Apache::lonnet::protocol{$hostid};
  376:             $protocol = 'http' if ($protocol ne 'https');
  377:             $spares.='<br /><a href="'.$protocol.'://'.
  378: 	             $hostname.
  379: 	             '/adm/login?domain='.$authdomain.'">'.
  380: 	             $hostname.'</a>';
  381:          }
  382:          $r->print(
  383:    '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
  384:   .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'
  385:   .'<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>'
  386:   .&mt('The LearningOnline Network with CAPA')
  387:   .'</title></head>'
  388:   .'<body bgcolor="#FFFFFF">'
  389:   .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
  390:   .'<img src="/adm/lonKaputt/lonlogo_broken.gif" alt="broken icon" align="right" />'
  391:   .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
  392:         if ($spares) {
  393:             $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
  394:                      .'</p>'
  395:                      .$spares);
  396:         }
  397:         $r->print('</body>'
  398:                  .'</html>'
  399:         );
  400:         return OK;
  401:     }
  402: 
  403: # ----------------------------------------------- Apparently we are in business
  404:     $servadm=~s/\,/\<br \/\>/g;
  405: 
  406: # ----------------------------------------------------------- Front page design
  407:     my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
  408:     my $font=&Apache::loncommon::designparm('login.font',$domain);
  409:     my $link=&Apache::loncommon::designparm('login.link',$domain);
  410:     my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
  411:     my $alink=&Apache::loncommon::designparm('login.alink',$domain);
  412:     my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
  413:     my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
  414:     my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
  415:     my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
  416:     my $logo=&Apache::loncommon::designparm('login.logo',$domain);
  417:     my $img=&Apache::loncommon::designparm('login.img',$domain);
  418:     my $domainlogo=&Apache::loncommon::domainlogo($domain);
  419:     my $showbanner = 1;
  420:     my $showmainlogo = 1;
  421:     if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
  422:         $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
  423:     }
  424:     if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
  425:         $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
  426:     }
  427:     my $showadminmail;
  428:     my @possdoms = &Apache::lonnet::current_machine_domains();
  429:     if (grep(/^\Q$domain\E$/,@possdoms)) {
  430:         $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
  431:     }
  432:     my $showcoursecat =
  433:         &Apache::loncommon::designparm('login.coursecatalog',$domain);
  434:     my $shownewuserlink = 
  435:         &Apache::loncommon::designparm('login.newuser',$domain);
  436:     my $showhelpdesk =
  437:         &Apache::loncommon::designparm('login.helpdesk',$domain);
  438:     my $now=time;
  439:     my $js = (<<ENDSCRIPT);
  440: 
  441: <script type="text/javascript" language="JavaScript">
  442: // <![CDATA[
  443: function send()
  444: {
  445: this.document.server.elements.uname.value
  446: =this.document.client.elements.uname.value;
  447: 
  448: this.document.server.elements.udom.value
  449: =this.document.client.elements.udom.value;
  450: 
  451: uextkey=this.document.client.elements.uextkey.value;
  452: lextkey=this.document.client.elements.lextkey.value;
  453: initkeys();
  454: 
  455: this.document.server.elements.upass0.value
  456:     =getCrypted(this.document.client.elements.upass$now.value);
  457: 
  458: this.document.client.elements.uname.value='';
  459: this.document.client.elements.upass$now.value='';
  460: 
  461: this.document.server.submit();
  462: return false;
  463: }
  464: 
  465: function enableInput() {
  466:     this.document.client.elements.upass$now.removeAttribute("readOnly");
  467:     this.document.client.elements.uname.removeAttribute("readOnly");
  468:     this.document.client.elements.udom.removeAttribute("readOnly");
  469:     return;
  470: }
  471: 
  472: // ]]>
  473: </script>
  474: 
  475: ENDSCRIPT
  476: 
  477: # --------------------------------------------------- Print login screen header
  478: 
  479:     my %add_entries = (
  480: 	       bgcolor      => "$mainbg",
  481: 	       text         => "$font",
  482: 	       link         => "$link",
  483: 	       vlink        => "$vlink",
  484: 	       alink        => "$alink",
  485:                onload       => 'javascript:enableInput();',);
  486: 
  487:     my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
  488:     @hosts = &Apache::lonnet::current_machine_ids();
  489:     $lonhost_in_use = $lonhost;
  490:     if (@hosts > 1) {
  491:         foreach my $hostid (@hosts) {
  492:             if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
  493:                 $lonhost_in_use = $hostid;
  494:                 last;
  495:             }
  496:         }
  497:     }
  498:     %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
  499:     $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
  500:     $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
  501:     if ($headextra) {
  502:         my $omitextra;
  503:         if ($headextra_exempt ne '') {
  504:             my @exempt = split(',',$headextra_exempt);
  505:             my $ip = $ENV{'REMOTE_ADDR'};
  506:             if (grep(/^\Q$ip\E$/,@exempt)) {
  507:                 $omitextra = 1;
  508:             }
  509:         }
  510:         unless ($omitextra) {
  511:             my $confname = $defdom.'-domainconfig';
  512:             if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
  513:                 my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
  514:                 unless ($extra eq '-1') {
  515:                     $js .= "\n".$extra."\n";
  516:                 }
  517:             }
  518:         }
  519:     }
  520: 
  521:     $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
  522: 			       { 'redirect'       => [$expire,'/adm/roles'], 
  523: 				 'add_entries' => \%add_entries,
  524: 				 'only_body'   => 1,}));
  525: 
  526: # ----------------------------------------------------------------------- Texts
  527: 
  528:     my %lt=&Apache::lonlocal::texthash(
  529:           'un'       => 'Username',
  530:           'pw'       => 'Password',
  531:           'dom'      => 'Domain',
  532:           'perc'     => 'percent',
  533:           'load'     => 'Server Load',
  534:           'userload' => 'User Load',
  535:           'catalog'  => 'Course/Community Catalog',
  536:           'log'      => 'Log in',
  537:           'help'     => 'Log-in Help',
  538:           'serv'     => 'Server',
  539:           'servadm'  => 'Server Administration',
  540:           'helpdesk' => 'Contact Helpdesk',
  541:           'forgotpw' => 'Forgot password?',
  542:           'newuser'  => 'New User?',
  543:        );
  544: # -------------------------------------------------- Change password field name
  545: 
  546:     my $forgotpw = &forgotpwdisplay(%lt);
  547:     $forgotpw .= '<br />' if $forgotpw;
  548:     my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
  549:     if ($loginhelp) {
  550:         $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
  551:     }
  552: 
  553: # ---------------------------------------------------- Serve out DES JavaScript
  554:     {
  555:     my $jsh=Apache::File->new($include."/londes.js");
  556:     $r->print(<$jsh>);
  557:     }
  558: # ---------------------------------------------------------- Serve rest of page
  559: 
  560:     $r->print(
  561:     '<div class="LC_Box"'
  562:    .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
  563: );
  564: 
  565:     $r->print(<<ENDSERVERFORM);
  566: <form name="server" action="/adm/authenticate" method="post" target="_top">
  567:    <input type="hidden" name="logtoken" value="$logtoken" />
  568:    <input type="hidden" name="serverid" value="$lonhost" />
  569:    <input type="hidden" name="uname" value="" />
  570:    <input type="hidden" name="upass0" value="" />
  571:    <input type="hidden" name="udom" value="" />
  572:    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
  573:    <input type="hidden" name="localres" value="$env{'form.localres'}" />
  574:   </form>
  575: ENDSERVERFORM
  576:     my $coursecatalog;
  577:     if (($showcoursecat eq '') || ($showcoursecat)) {
  578:         $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
  579:     }
  580:     my $newuserlink;
  581:     if ($shownewuserlink) {
  582:         $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
  583:     }
  584:     my $logintitle =
  585:         '<h2 class="LC_hcell"'
  586:        .' style="background:'.$loginbox_header_bgcol.';'
  587:        .' color:'.$loginbox_header_textcol.'">'
  588:        .$lt{'log'}
  589:        .'</h2>';
  590: 
  591:     my $noscript_warning='<noscript><span class="LC_warning"><b>'
  592:                         .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
  593:                         .'</b></span></noscript>';
  594:     my $helpdeskscript;
  595:     my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
  596:                                        $authdomain,\$helpdeskscript,
  597:                                        $showhelpdesk,\@possdoms);
  598: 
  599:     my $mobileargs;
  600:     if ($clientmobile) {
  601:         $mobileargs = 'autocapitalize="off" autocorrect="off"'; 
  602:     }
  603:     my $loginform=(<<LFORM);
  604: <form name="client" action="" onsubmit="return(send())">
  605:   <input type="hidden" name="lextkey" value="$lextkey" />
  606:   <input type="hidden" name="uextkey" value="$uextkey" />
  607:   <b><label for="uname">$lt{'un'}</label>:</b><br />
  608:   <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
  609:   <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
  610:   <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
  611:   <b><label for="udom">$lt{'dom'}</label>:</b><br />
  612:   <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
  613:   <input type="submit" value="$lt{'log'}" />
  614: </form>
  615: LFORM
  616: 
  617:     if ($showbanner) {
  618:         $r->print(<<HEADER);
  619: <!-- The LON-CAPA Header -->
  620: <div style="background:$pgbg;margin:0;width:100%;">
  621:   <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />
  622: </div>
  623: HEADER
  624:     }
  625:     $r->print(<<ENDTOP);
  626: <div style="float:left;margin-top:0;">
  627: <div class="LC_Box" style="background:$loginbox_bg;">
  628:   $logintitle
  629:   $loginform
  630:   $noscript_warning
  631: </div>
  632:   
  633: <div class="LC_Box" style="padding-top: 10px;">
  634:   $loginhelp
  635:   $forgotpw
  636:   $contactblock
  637:   $newuserlink
  638:   $coursecatalog
  639: </div>
  640: </div>
  641: 
  642: <div>
  643: ENDTOP
  644:     if ($showmainlogo) {
  645:         $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");
  646:     }
  647: $r->print(<<ENDTOP);
  648: $announcements
  649: </div>
  650: <hr style="clear:both;" />
  651: ENDTOP
  652:     my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
  653:     $domainrow = <<"END";
  654:       <tr>
  655:        <td  align="left" valign="top">
  656:         <small><b>$lt{'dom'}:&nbsp;</b></small>
  657:        </td>
  658:        <td  align="left" valign="top">
  659:         <small><tt>&nbsp;$domain</tt></small>
  660:        </td>
  661:       </tr>
  662: END
  663:     $serverrow = <<"END";
  664:       <tr>
  665:        <td  align="left" valign="top">
  666:         <small><b>$lt{'serv'}:&nbsp;</b></small>
  667:        </td>
  668:        <td align="left" valign="top">
  669:         <small><tt>&nbsp;$lonhost ($role)</tt></small>
  670:        </td>
  671:       </tr>
  672: END
  673:     if ($loadlim) {
  674:         $loadrow = <<"END";
  675:       <tr>
  676:        <td align="left" valign="top">
  677:         <small><b>$lt{'load'}:&nbsp;</b></small>
  678:        </td>
  679:        <td align="left" valign="top">
  680:         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
  681:        </td>
  682:       </tr>
  683: END
  684:     }
  685:     if ($uloadlim) {
  686:         $userloadrow = <<"END";
  687:       <tr>
  688:        <td align="left" valign="top">
  689:         <small><b>$lt{'userload'}:&nbsp;</b></small>
  690:        </td>
  691:        <td align="left" valign="top">
  692:         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
  693:        </td>
  694:       </tr>
  695: END
  696:     }
  697:     if (($version ne '') && ($version ne '<!-- VERSION -->')) {
  698:         $versionrow = <<"END";
  699:       <tr>
  700:        <td colspan="2" align="left">
  701:         <small>$version</small>
  702:        </td>
  703:       </tr>
  704: END
  705:     }
  706: 
  707:     $r->print(<<ENDDOCUMENT);
  708:     <div style="float: left;">
  709:      <table border="0" cellspacing="0" cellpadding="0">
  710: $domainrow
  711: $serverrow
  712: $loadrow    
  713: $userloadrow
  714: $versionrow
  715:      </table>
  716:     </div>
  717:     <div style="float: right;">
  718:     $domainlogo
  719:     </div>
  720:     <br style="clear:both;" />
  721:  </div>
  722: 
  723: <script type="text/javascript">
  724: // <![CDATA[
  725: // the if prevents the script error if the browser can not handle this
  726: if ( document.client.uname ) { document.client.uname.focus(); }
  727: // ]]>
  728: </script>
  729: $helpdeskscript
  730: 
  731: ENDDOCUMENT
  732:     my %endargs = ( 'noredirectlink' => 1, );
  733:     $r->print(&Apache::loncommon::end_page(\%endargs));
  734:     return OK;
  735: }
  736: 
  737: sub check_loginvia {
  738:     my ($domain,$lonhost,$lonidsdir,$balcookie) = @_;
  739:     if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {
  740:         return;
  741:     }
  742:     my %domconfhash = &Apache::loncommon::get_domainconf($domain);
  743:     my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
  744:     my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
  745:     my $output;
  746:     if ($loginvia ne '') {
  747:         my $noredirect;
  748:         my $ip = $ENV{'REMOTE_ADDR'};
  749:         if ($ip eq '127.0.0.1') {
  750:             $noredirect = 1;
  751:         } else {
  752:             if ($loginvia_exempt ne '') {
  753:                 my @exempt = split(',',$loginvia_exempt);
  754:                 if (grep(/^\Q$ip\E$/,@exempt)) {
  755:                     $noredirect = 1;
  756:                 }
  757:             }
  758:         }
  759:         unless ($noredirect) {
  760:             my ($newhost,$path);
  761:             if ($loginvia =~ /:/) {
  762:                 ($newhost,$path) = split(':',$loginvia);
  763:             } else {
  764:                 $newhost = $loginvia;
  765:             }
  766:             if ($newhost ne $lonhost) {
  767:                 if (&Apache::lonnet::hostname($newhost) ne '') {
  768:                     if ($balcookie) {
  769:                         my ($balancer,$cookie) = split(/:/,$balcookie);
  770:                         if ($cookie =~ /^($match_domain)_($match_username)_([a-f0-9]+)$/) {
  771:                             my ($udom,$uname,$cookieid) = ($1,$2,$3);
  772:                             unless (&Apache::lonnet::delbalcookie($cookie,$balancer) eq 'ok') {
  773:                                 if ((-d $lonidsdir) && (opendir(my $dh,$lonidsdir))) {
  774:                                     while (my $filename=readdir($dh)) {
  775:                                         if ($filename=~/^(\Q$uname\E_\d+_\Q$udom\E_$match_lonid)\.id$/) {
  776:                                             my $handle = $1;
  777:                                             my %hash =
  778:                                                 &Apache::lonnet::get_sessionfile_vars($handle,$lonidsdir,
  779:                                                                                      ['request.balancercookie',
  780:                                                                                       'user.linkedenv']);
  781:                                             if ($hash{'request.balancercookie'} eq "$balancer:$cookieid") {
  782:                                                 if (unlink("$lonidsdir/$filename")) {
  783:                                                     if (($hash{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&
  784:                                                         (-l "$lonidsdir/$hash{'user.linkedenv'}.id") &&
  785:                                                         (readlink("$lonidsdir/$hash{'user.linkedenv'}.id") eq "$lonidsdir/$filename")) {
  786:                                                         unlink("$lonidsdir/$hash{'user.linkedenv'}.id");
  787:                                                     }
  788:                                                 }
  789:                                             }
  790:                                             last;
  791:                                         }
  792:                                     }
  793:                                     closedir($dh);
  794:                                 }
  795:                             }
  796:                         }
  797:                     }
  798:                     $output = &redirect_page($newhost,$path);
  799:                 }
  800:             }
  801:         }
  802:     }
  803:     return $output;
  804: }
  805: 
  806: sub redirect_page {
  807:     my ($desthost,$path) = @_;
  808:     my $hostname = &Apache::lonnet::hostname($desthost);
  809:     my $protocol = $Apache::lonnet::protocol{$desthost};
  810:     $protocol = 'http' if ($protocol ne 'https');
  811:     unless ($path =~ m{^/}) {
  812:         $path = '/'.$path;
  813:     }
  814:     my $url = $protocol.'://'.$hostname.$path;
  815:     if ($env{'form.firsturl'} ne '') {
  816:         $url .='?firsturl='.$env{'form.firsturl'};
  817:     }
  818:     my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
  819:                                                     {'redirect' => [0,$url],});
  820:     my $end_page   = &Apache::loncommon::end_page();
  821:     return $start_page.$end_page;
  822: }
  823: 
  824: sub contactdisplay {
  825:     my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
  826:         $possdoms) = @_;
  827:     my $contactblock;
  828:     my $origmail;
  829:     if (ref($possdoms) eq 'ARRAY') {
  830:         if (grep(/^\Q$authdomain\E$/,@{$possdoms})) { 
  831:             $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
  832:         }
  833:     }
  834:     my $requestmail = 
  835:         &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
  836:                                                  $authdomain,$origmail);
  837:     unless ($showhelpdesk eq '0') {
  838:         if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
  839:             $showhelpdesk = 1;
  840:         } else {
  841:             $showhelpdesk = 0;
  842:         }
  843:     }
  844:     if ($servadm && $showadminmail) {
  845:         $contactblock .= $$lt{'servadm'}.':<br />'.
  846:                          '<tt>'.$servadm.'</tt><br />';
  847:     }
  848:     if ($showhelpdesk) {
  849:         $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
  850:         my $thisurl = &escape('/adm/login');
  851:         $$helpdeskscript = <<"ENDSCRIPT";
  852: <script type="text/javascript">
  853: // <![CDATA[
  854: function helpdesk() {
  855:     var possdom = document.client.udom.value;
  856:     var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
  857:     if (codedom == '') {
  858:         codedom = "$authdomain";
  859:     }
  860:     var querystr = "origurl=$thisurl&codedom="+codedom;
  861:     document.location.href = "/adm/helpdesk?"+querystr;
  862:     return;
  863: }
  864: // ]]>
  865: </script>
  866: ENDSCRIPT
  867:     }
  868:     return $contactblock;
  869: }
  870: 
  871: sub forgotpwdisplay {
  872:     my (%lt) = @_;
  873:     my $prompt_for_resetpw = 1; 
  874:     if ($prompt_for_resetpw) {
  875:         return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
  876:     }
  877:     return;
  878: }
  879: 
  880: sub coursecatalog_link {
  881:     my ($linkname) = @_;
  882:     return <<"END";
  883:       <a href="/adm/coursecatalog">$linkname</a>
  884: END
  885: }
  886: 
  887: sub newuser_link {
  888:     my ($linkname) = @_;
  889:     return '<a href="/adm/createaccount">'.$linkname.'</a>';
  890: }
  891: 
  892: 1;
  893: __END__

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