File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.158.2.9.2.1: download - view: text, annotated - select for diffs
Wed Jan 22 16:43:52 2020 UTC (4 years, 4 months ago) by raeburn
Branches: version_2_11_3_msu
- For 2.11.3 (modified)
  Include changes in 1.172

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

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