Annotation of loncom/auth/lonlogin.pm, revision 1.158.2.9.2.3

1.1       albertel    1: # The LearningOnline Network
                      2: # Login Screen
1.11      www         3: #
1.158.2.9.2.3! (raeburn    4:: # $Id: lonlogin.pm,v 1.158.2.9.2.2 2020/10/26 02:06:16 raeburn Exp $
1.11      www         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: #
1.14      albertel   28: 
1.1       albertel   29: package Apache::lonlogin;
                     30: 
                     31: use strict;
                     32: use Apache::Constants qw(:common);
                     33: use Apache::File ();
1.63      albertel   34: use Apache::lonnet;
1.12      albertel   35: use Apache::loncommon();
1.49      www        36: use Apache::lonauth();
1.50      www        37: use Apache::lonlocal;
1.71      albertel   38: use Apache::migrateuser();
1.75      www        39: use lib '/home/httpd/lib/perl/';
1.158.2.8  raeburn    40: use LONCAPA qw(:DEFAULT :match);
1.158.2.7  raeburn    41: use CGI::Cookie();
1.75      www        42:  
1.1       albertel   43: sub handler {
                     44:     my $r = shift;
1.71      albertel   45: 
                     46:     &Apache::loncommon::get_unprocessed_cgi
1.79      albertel   47: 	(join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
                     48: 	      $ENV{'REDIRECT_QUERY_STRING'}),
1.71      albertel   49: 	 ['interface','username','domain','firsturl','localpath','localres',
1.158.2.8  raeburn    50: 	  'token','role','symb','iptoken','btoken']);
1.102     raeburn    51:     if (!defined($env{'form.firsturl'})) {
                     52:         &Apache::lonacc::get_posted_cgi($r,['firsturl']);
                     53:     }
1.158.2.9.2.1  (raeburn   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::     }
1.71      albertel   59: 
                     60: # -- check if they are a migrating user
                     61:     if (defined($env{'form.token'})) {
                     62: 	return &Apache::migrateuser::handler($r);
                     63:     }
                     64: 
1.158.2.7  raeburn    65: # For "public user" - remove any exising "public" cookie, as user really wants to log-in
                     66:     my ($handle,$lonidsdir,$expirepub,$userdom);
1.158.2.8  raeburn    67:     $lonidsdir=$r->dir_config('lonIDsDir');
1.158.2.7  raeburn    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: 
1.53      www        80:     &Apache::loncommon::no_cache($r);
                     81:     &Apache::lonlocal::get_language_handle($r);
1.54      www        82:     &Apache::loncommon::content_type($r,'text/html');
1.158.2.7  raeburn    83:     if ($expirepub) {
1.158.2.9  raeburn    84:         my $c = new CGI::Cookie(-name    => 'lonPubID',
1.158.2.7  raeburn    85:                                 -value   => '',
                     86:                                 -expires => '-10y',);
                     87:         $r->header_out('Set-cookie' => $c);
                     88:     } elsif (($handle eq '') && ($userdom ne '')) {
1.158.2.9  raeburn    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:         }
1.158.2.7  raeburn    97:     }
1.1       albertel   98:     $r->send_http_header;
                     99:     return OK if $r->header_only;
                    100: 
1.49      www       101: 
                    102: # Are we re-routing?
1.149     raeburn   103:     my $londocroot = $r->dir_config('lonDocRoot'); 
                    104:     if (-e "$londocroot/lon-status/reroute.txt") {
1.49      www       105: 	&Apache::lonauth::reroute($r);
                    106: 	return OK;
                    107:     }
1.55      www       108: 
1.158.2.8  raeburn   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: 
1.158.2.7  raeburn   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: 
1.143     raeburn   171:     $env{'form.firsturl'} =~ s/(`)/'/g;
1.71      albertel  172: 
1.55      www       173: # -------------------------------- Prevent users from attempting to login twice
1.135     raeburn   174:     if ($handle ne '') {
1.158.2.7  raeburn   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;
1.55      www       192:     }
                    193: 
                    194: # ---------------------------------------------------- No valid token, continue
1.16      www       195: 
1.157     raeburn   196: # ---------------------------- Not possible to really login to domain "public"
1.70      www       197:     if ($env{'form.domain'} eq 'public') {
                    198: 	$env{'form.domain'}='';
                    199: 	$env{'form.username'}='';
                    200:     }
1.157     raeburn   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'});
1.158.2.2  raeburn   206:         unless ($sessiondata{'sessionserver'}) {
                    207:             my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});
                    208:             delete($env{'form.iptoken'});
                    209:         }
1.157     raeburn   210:     }
1.32      www       211: # ----------------------------------------------------------- Process Interface
1.63      albertel  212:     $env{'form.interface'}=~s/\W//g;
1.16      www       213: 
1.156     raeburn   214:     (undef,undef,undef,undef,undef,undef,my $clientmobile) =
                    215:         &Apache::loncommon::decode_user_agent();
1.94      albertel  216: 
                    217:     my $iconpath= 
                    218: 	&Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
                    219: 
1.87      raeburn   220:     my $domain = &Apache::lonnet::default_login_domain();
1.158.2.3  raeburn   221:     my $defdom = $domain;
1.126     raeburn   222:     if ($lonhost ne '') {
1.157     raeburn   223:         unless ($sessiondata{'sessionserver'}) {
1.158.2.8  raeburn   224:             my $redirect = &check_loginvia($domain,$lonhost,$lonidsdir,$balcookie);
1.157     raeburn   225:             if ($redirect) {
                    226:                 $r->print($redirect);
                    227:                 return OK;
                    228:             }
                    229:         }
1.126     raeburn   230:     }
                    231: 
1.157     raeburn   232:     if (($sessiondata{'domain'}) &&
1.158.2.8  raeburn   233:         (&Apache::lonnet::domain($sessiondata{'domain'},'description'))) {
1.157     raeburn   234:         $domain=$sessiondata{'domain'};
                    235:     } elsif (($env{'form.domain'}) && 
1.89      albertel  236: 	(&Apache::lonnet::domain($env{'form.domain'},'description'))) {
1.63      albertel  237: 	$domain=$env{'form.domain'};
1.46      www       238:     }
1.157     raeburn   239: 
1.1       albertel  240:     my $role    = $r->dir_config('lonRole');
                    241:     my $loadlim = $r->dir_config('lonLoadLim');
1.145     www       242:     my $uloadlim= $r->dir_config('lonUserLoadLim');
1.90      raeburn   243:     my $servadm = $r->dir_config('lonAdmEMail');
1.1       albertel  244:     my $tabdir  = $r->dir_config('lonTabDir');
1.6       www       245:     my $include = $r->dir_config('lonIncludes');
1.37      www       246:     my $expire  = $r->dir_config('lonExpire');
1.44      www       247:     my $version = $r->dir_config('lonVersion');
1.88      albertel  248:     my $host_name = &Apache::lonnet::hostname($lonhost);
1.1       albertel  249: 
1.30      www       250: # --------------------------------------------- Default values for login fields
1.157     raeburn   251:     
                    252:     my ($authusername,$authdomain);
                    253:     if ($sessiondata{'username'}) {
                    254:         $authusername=$sessiondata{'username'};
                    255:     } else {
1.158     raeburn   256:         $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
1.157     raeburn   257:         $authusername=($env{'form.username'}?$env{'form.username'}:'');
                    258:     }
                    259:     if ($sessiondata{'domain'}) {
                    260:         $authdomain=$sessiondata{'domain'};
1.158     raeburn   261:     } else {
                    262:         $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
1.157     raeburn   263:         $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
                    264:     }
1.30      www       265: 
                    266: # ---------------------------------------------------------- Determine own load
1.1       albertel  267:     my $loadavg;
1.41      albertel  268:     {
                    269: 	my $loadfile=Apache::File->new('/proc/loadavg');
                    270: 	$loadavg=<$loadfile>;
                    271:     }
1.1       albertel  272:     $loadavg =~ s/\s.*//g;
1.147     raeburn   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:     }
1.1       albertel  281: 
1.31      www       282:     my $firsturl=
1.63      albertel  283:     ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
1.141     raeburn   284: 
1.45      www       285: # ----------------------------------------------------------- Get announcements
                    286:     my $announcements=&Apache::lonnet::getannounce();
1.6       www       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);
1.15      www       302:     if ($lextkey>2147483647) { $lextkey-=4294967296; }
                    303: 
1.6       www       304:     my $uextkey=hex($ukey);
1.15      www       305:     if ($uextkey>2147483647) { $uextkey-=4294967296; }
                    306: 
1.31      www       307: # -------------------------------------------------------- Store away log token
1.123     raeburn   308:     my $tokenextras;
                    309:     if ($env{'form.role'}) {
                    310:         $tokenextras = '&role='.&escape($env{'form.role'});
                    311:     }
                    312:     if ($env{'form.symb'}) {
1.124     raeburn   313:         if (!$tokenextras) {
                    314:             $tokenextras = '&';
                    315:         }
1.123     raeburn   316:         $tokenextras .= '&symb='.&escape($env{'form.symb'});
                    317:     }
1.158.2.2  raeburn   318:     if ($env{'form.iptoken'}) {
                    319:         if (!$tokenextras) {
                    320:             $tokenextras = '&&';
                    321:         }
                    322:         $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});
                    323:     }
1.6       www       324:     my $logtoken=Apache::lonnet::reply(
1.123     raeburn   325:        'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
1.6       www       326:        $lonhost);
1.31      www       327: 
1.148     raeburn   328: # -- If we cannot talk to ourselves, or hostID does not map to a hostname
                    329: #    we are in serious trouble
1.31      www       330: 
1.148     raeburn   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:         }
1.31      www       335:         my $spares='';
1.158.2.9.2.2  (raeburn  336::         my (@sparehosts,%spareservers);
                    337::         my $sparesref = &Apache::lonnet::this_host_spares($defdom);
                    338::         if (ref($sparesref) eq 'HASH') {
                    339::             foreach my $key (keys(%{$sparesref})) {
                    340::                 if (ref($sparesref->{$key}) eq 'ARRAY') {
                    341::                     my @sorted = sort { &Apache::lonnet::hostname($a) cmp
                    342::                                         &Apache::lonnet::hostname($b);
                    343::                                       } @{$sparesref->{$key}};
                    344::                     if (@sorted) {
                    345::                         if ($key eq 'primary') {
                    346::                             unshift(@sparehosts,@sorted);
                    347::                         } elsif ($key eq 'default') {
                    348::                             push(@sparehosts,@sorted);
                    349::                         }
                    350::                     }
                    351::                 }
                    352::             }
                    353::         }
                    354::         foreach my $hostid (@sparehosts) {
1.58      matthew   355:             next if ($hostid eq $lonhost);
1.88      albertel  356: 	    my $hostname = &Apache::lonnet::hostname($hostid);
1.158.2.9.2.2  (raeburn  357:: 	    next if (($hostname eq '') || ($spareservers{$hostname}));
                    358::             $spareservers{$hostname} = 1;
                    359::             my $protocol = $Apache::lonnet::protocol{$hostid};
                    360::             $protocol = 'http' if ($protocol ne 'https');
                    361::             $spares.='<br /><span style="font-size: larger;"><a href="'.$protocol.'://'.
1.88      albertel  362:                 $hostname.
1.58      matthew   363:                 '/adm/login?domain='.$authdomain.'">'.
1.88      albertel  364:                 $hostname.'</a>'.
1.158.2.9.2.2  (raeburn  365::                 ' '.&mt('(preferred)').'</span>'.$/;
1.58      matthew   366:         }
1.148     raeburn   367:         if ($spares) {
                    368:             $spares.= '<br />';
                    369:         }
1.151     raeburn   370:         my %all_hostnames = &Apache::lonnet::all_hostnames();
                    371:         foreach my $hostid (sort
1.107     tempelho  372: 		    {
                    373: 			&Apache::lonnet::hostname($a) cmp
                    374: 			    &Apache::lonnet::hostname($b);
                    375: 		    }
                    376: 		    keys(%all_hostnames)) {
1.158.2.9.2.2  (raeburn  377::             next if ($hostid eq $lonhost);
1.151     raeburn   378:             my $hostname = &Apache::lonnet::hostname($hostid);
1.158.2.9.2.2  (raeburn  379::             next if (($hostname eq '') || ($spareservers{$hostname}));
                    380::             $spareservers{$hostname} = 1;
                    381::             my $protocol = $Apache::lonnet::protocol{$hostid};
                    382::             $protocol = 'http' if ($protocol ne 'https');
                    383::             $spares.='<br /><a href="'.$protocol.'://'.
1.151     raeburn   384: 	             $hostname.
                    385: 	             '/adm/login?domain='.$authdomain.'">'.
                    386: 	             $hostname.'</a>';
                    387:          }
                    388:          $r->print(
1.158.2.9.2.2  (raeburn  389::    '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
                    390::   .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'
                    391::   .'<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>'
1.107     tempelho  392:   .&mt('The LearningOnline Network with CAPA')
                    393:   .'</title></head>'
                    394:   .'<body bgcolor="#FFFFFF">'
                    395:   .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
1.158.2.9.2.2  (raeburn  396::   .'<img src="/adm/lonKaputt/lonlogo_broken.gif" alt="broken icon" align="right" />'
1.148     raeburn   397:   .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
1.151     raeburn   398:         if ($spares) {
                    399:             $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
                    400:                      .'</p>'
                    401:                      .$spares);
                    402:         }
                    403:         $r->print('</body>'
                    404:                  .'</html>'
                    405:         );
                    406:         return OK;
                    407:     }
1.31      www       408: 
                    409: # ----------------------------------------------- Apparently we are in business
1.151     raeburn   410:     $servadm=~s/\,/\<br \/\>/g;
1.38      www       411: 
1.21      www       412: # ----------------------------------------------------------- Front page design
1.151     raeburn   413:     my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
                    414:     my $font=&Apache::loncommon::designparm('login.font',$domain);
                    415:     my $link=&Apache::loncommon::designparm('login.link',$domain);
                    416:     my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
                    417:     my $alink=&Apache::loncommon::designparm('login.alink',$domain);
                    418:     my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
                    419:     my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
                    420:     my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
                    421:     my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
                    422:     my $logo=&Apache::loncommon::designparm('login.logo',$domain);
                    423:     my $img=&Apache::loncommon::designparm('login.img',$domain);
                    424:     my $domainlogo=&Apache::loncommon::domainlogo($domain);
                    425:     my $showbanner = 1;
                    426:     my $showmainlogo = 1;
                    427:     if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
                    428:         $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
                    429:     }
                    430:     if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
                    431:         $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
                    432:     }
1.153     raeburn   433:     my $showadminmail;
                    434:     my @possdoms = &Apache::lonnet::current_machine_domains();
                    435:     if (grep(/^\Q$domain\E$/,@possdoms)) {
                    436:         $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
                    437:     }
1.151     raeburn   438:     my $showcoursecat =
                    439:         &Apache::loncommon::designparm('login.coursecatalog',$domain);
                    440:     my $shownewuserlink = 
                    441:         &Apache::loncommon::designparm('login.newuser',$domain);
1.153     raeburn   442:     my $showhelpdesk =
                    443:         &Apache::loncommon::designparm('login.helpdesk',$domain);
1.151     raeburn   444:     my $now=time;
                    445:     my $js = (<<ENDSCRIPT);
1.107     tempelho  446: 
1.116     bisitz    447: <script type="text/javascript" language="JavaScript">
1.122     bisitz    448: // <![CDATA[
1.107     tempelho  449: function send()
                    450: {
                    451: this.document.server.elements.uname.value
                    452: =this.document.client.elements.uname.value;
                    453: 
                    454: this.document.server.elements.udom.value
                    455: =this.document.client.elements.udom.value;
                    456: 
                    457: uextkey=this.document.client.elements.uextkey.value;
                    458: lextkey=this.document.client.elements.lextkey.value;
                    459: initkeys();
                    460: 
                    461: this.document.server.elements.upass0.value
1.158.2.5  raeburn   462:     =getCrypted(this.document.client.elements.upass$now.value);
1.6       www       463: 
1.107     tempelho  464: this.document.client.elements.uname.value='';
                    465: this.document.client.elements.upass$now.value='';
1.6       www       466: 
1.107     tempelho  467: this.document.server.submit();
                    468: return false;
                    469: }
1.139     raeburn   470: 
                    471: function enableInput() {
1.144     bisitz    472:     this.document.client.elements.upass$now.removeAttribute("readOnly");
                    473:     this.document.client.elements.uname.removeAttribute("readOnly");
                    474:     this.document.client.elements.udom.removeAttribute("readOnly");
1.139     raeburn   475:     return;
                    476: }
                    477: 
1.122     bisitz    478: // ]]>
1.107     tempelho  479: </script>
1.98      raeburn   480: 
1.16      www       481: ENDSCRIPT
1.6       www       482: 
1.98      raeburn   483: # --------------------------------------------------- Print login screen header
                    484: 
1.151     raeburn   485:     my %add_entries = (
1.108     tempelho  486: 	       bgcolor      => "$mainbg",
1.107     tempelho  487: 	       text         => "$font",
                    488: 	       link         => "$link",
                    489: 	       vlink        => "$vlink",
1.139     raeburn   490: 	       alink        => "$alink",
                    491:                onload       => 'javascript:enableInput();',);
1.107     tempelho  492: 
1.158.2.4  raeburn   493:     my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
                    494:     @hosts = &Apache::lonnet::current_machine_ids();
                    495:     $lonhost_in_use = $lonhost;
                    496:     if (@hosts > 1) {
                    497:         foreach my $hostid (@hosts) {
                    498:             if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
                    499:                 $lonhost_in_use = $hostid;
                    500:                 last;
                    501:             }
                    502:         }
                    503:     }
                    504:     %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
                    505:     $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
                    506:     $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
1.158.2.1  raeburn   507:     if ($headextra) {
                    508:         my $omitextra;
                    509:         if ($headextra_exempt ne '') {
                    510:             my @exempt = split(',',$headextra_exempt);
1.158.2.9.2.3! (raeburn  511::             my $ip = &Apache::lonnet::get_requestor_ip();
1.158.2.1  raeburn   512:             if (grep(/^\Q$ip\E$/,@exempt)) {
                    513:                 $omitextra = 1;
                    514:             }
                    515:         }
                    516:         unless ($omitextra) {
                    517:             my $confname = $defdom.'-domainconfig';
1.158.2.4  raeburn   518:             if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
1.158.2.1  raeburn   519:                 my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
                    520:                 unless ($extra eq '-1') {
                    521:                     $js .= "\n".$extra."\n";
                    522:                 }
                    523:             }
                    524:         }
                    525:     }
                    526: 
1.151     raeburn   527:     $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
1.107     tempelho  528: 			       { 'redirect'       => [$expire,'/adm/roles'], 
                    529: 				 'add_entries' => \%add_entries,
                    530: 				 'only_body'   => 1,}));
1.98      raeburn   531: 
                    532: # ----------------------------------------------------------------------- Texts
                    533: 
1.151     raeburn   534:     my %lt=&Apache::lonlocal::texthash(
1.129     bisitz    535:           'un'       => 'Username',
                    536:           'pw'       => 'Password',
                    537:           'dom'      => 'Domain',
                    538:           'perc'     => 'percent',
                    539:           'load'     => 'Server Load',
                    540:           'userload' => 'User Load',
                    541:           'catalog'  => 'Course/Community Catalog',
                    542:           'log'      => 'Log in',
                    543:           'help'     => 'Log-in Help',
                    544:           'serv'     => 'Server',
                    545:           'servadm'  => 'Server Administration',
                    546:           'helpdesk' => 'Contact Helpdesk',
                    547:           'forgotpw' => 'Forgot password?',
                    548:           'newuser'  => 'New User?',
                    549:        );
1.98      raeburn   550: # -------------------------------------------------- Change password field name
1.131     jms       551: 
1.151     raeburn   552:     my $forgotpw = &forgotpwdisplay(%lt);
                    553:     $forgotpw .= '<br />' if $forgotpw;
1.152     raeburn   554:     my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
                    555:     if ($loginhelp) {
                    556:         $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
                    557:     }
1.98      raeburn   558: 
                    559: # ---------------------------------------------------- Serve out DES JavaScript
1.151     raeburn   560:     {
                    561:     my $jsh=Apache::File->new($include."/londes.js");
                    562:     $r->print(<$jsh>);
                    563:     }
1.98      raeburn   564: # ---------------------------------------------------------- Serve rest of page
                    565: 
1.151     raeburn   566:     $r->print(
1.137     bisitz    567:     '<div class="LC_Box"'
                    568:    .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
                    569: );
1.6       www       570: 
1.151     raeburn   571:     $r->print(<<ENDSERVERFORM);
1.140     raeburn   572: <form name="server" action="/adm/authenticate" method="post" target="_top">
1.33      www       573:    <input type="hidden" name="logtoken" value="$logtoken" />
                    574:    <input type="hidden" name="serverid" value="$lonhost" />
                    575:    <input type="hidden" name="uname" value="" />
1.65      www       576:    <input type="hidden" name="upass0" value="" />
1.33      www       577:    <input type="hidden" name="udom" value="" />
1.63      albertel  578:    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
                    579:    <input type="hidden" name="localres" value="$env{'form.localres'}" />
1.14      albertel  580:   </form>
1.16      www       581: ENDSERVERFORM
1.151     raeburn   582:     my $coursecatalog;
                    583:     if (($showcoursecat eq '') || ($showcoursecat)) {
                    584:         $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
                    585:     }
                    586:     my $newuserlink;
                    587:     if ($shownewuserlink) {
                    588:         $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
                    589:     }
                    590:     my $logintitle =
                    591:         '<h2 class="LC_hcell"'
                    592:        .' style="background:'.$loginbox_header_bgcol.';'
                    593:        .' color:'.$loginbox_header_textcol.'">'
                    594:        .$lt{'log'}
                    595:        .'</h2>';
                    596: 
                    597:     my $noscript_warning='<noscript><span class="LC_warning"><b>'
                    598:                         .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
                    599:                         .'</b></span></noscript>';
                    600:     my $helpdeskscript;
                    601:     my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
1.153     raeburn   602:                                        $authdomain,\$helpdeskscript,
                    603:                                        $showhelpdesk,\@possdoms);
1.107     tempelho  604: 
1.156     raeburn   605:     my $mobileargs;
                    606:     if ($clientmobile) {
                    607:         $mobileargs = 'autocapitalize="off" autocorrect="off"'; 
                    608:     }
1.151     raeburn   609:     my $loginform=(<<LFORM);
1.122     bisitz    610: <form name="client" action="" onsubmit="return(send())">
1.115     bisitz    611:   <input type="hidden" name="lextkey" value="$lextkey" />
                    612:   <input type="hidden" name="uextkey" value="$uextkey" />
1.108     tempelho  613:   <b><label for="uname">$lt{'un'}</label>:</b><br />
1.156     raeburn   614:   <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
1.108     tempelho  615:   <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
1.139     raeburn   616:   <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
1.108     tempelho  617:   <b><label for="udom">$lt{'dom'}</label>:</b><br />
1.156     raeburn   618:   <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
1.108     tempelho  619:   <input type="submit" value="$lt{'log'}" />
                    620: </form>
                    621: LFORM
                    622: 
1.109     raeburn   623:     if ($showbanner) {
                    624:         $r->print(<<HEADER);
                    625: <!-- The LON-CAPA Header -->
1.132     bisitz    626: <div style="background:$pgbg;margin:0;width:100%;">
1.158.2.6  raeburn   627:   <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />
1.132     bisitz    628: </div>
1.109     raeburn   629: HEADER
                    630:     }
                    631:     $r->print(<<ENDTOP);
1.146     bisitz    632: <div style="float:left;margin-top:0;">
1.137     bisitz    633: <div class="LC_Box" style="background:$loginbox_bg;">
1.112     muellerd  634:   $logintitle
1.137     bisitz    635:   $loginform
                    636:   $noscript_warning
1.108     tempelho  637: </div>
1.107     tempelho  638:   
1.137     bisitz    639: <div class="LC_Box" style="padding-top: 10px;">
1.132     bisitz    640:   $loginhelp
                    641:   $forgotpw
                    642:   $contactblock
                    643:   $newuserlink
1.130     bisitz    644:   $coursecatalog
1.107     tempelho  645: </div>
1.118     tempelho  646: </div>
1.137     bisitz    647: 
                    648: <div>
1.118     tempelho  649: ENDTOP
                    650:     if ($showmainlogo) {
1.158.2.6  raeburn   651:         $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");
1.118     tempelho  652:     }
                    653: $r->print(<<ENDTOP);
                    654: $announcements
1.137     bisitz    655: </div>
                    656: <hr style="clear:both;" />
1.108     tempelho  657: ENDTOP
1.147     raeburn   658:     my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
                    659:     $domainrow = <<"END";
1.14      albertel  660:       <tr>
1.110     muellerd  661:        <td  align="left" valign="top">
1.132     bisitz    662:         <small><b>$lt{'dom'}:&nbsp;</b></small>
1.14      albertel  663:        </td>
1.110     muellerd  664:        <td  align="left" valign="top">
1.14      albertel  665:         <small><tt>&nbsp;$domain</tt></small>
                    666:        </td>
                    667:       </tr>
1.147     raeburn   668: END
                    669:     $serverrow = <<"END";
1.14      albertel  670:       <tr>
1.110     muellerd  671:        <td  align="left" valign="top">
1.132     bisitz    672:         <small><b>$lt{'serv'}:&nbsp;</b></small>
1.14      albertel  673:        </td>
1.110     muellerd  674:        <td align="left" valign="top">
1.14      albertel  675:         <small><tt>&nbsp;$lonhost ($role)</tt></small>
                    676:        </td>
                    677:       </tr>
1.147     raeburn   678: END
                    679:     if ($loadlim) {
                    680:         $loadrow = <<"END";
1.14      albertel  681:       <tr>
1.110     muellerd  682:        <td align="left" valign="top">
1.132     bisitz    683:         <small><b>$lt{'load'}:&nbsp;</b></small>
1.14      albertel  684:        </td>
1.110     muellerd  685:        <td align="left" valign="top">
1.51      www       686:         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
1.42      albertel  687:        </td>
                    688:       </tr>
1.147     raeburn   689: END
                    690:     }
                    691:     if ($uloadlim) {
                    692:         $userloadrow = <<"END";
1.42      albertel  693:       <tr>
1.110     muellerd  694:        <td align="left" valign="top">
1.132     bisitz    695:         <small><b>$lt{'userload'}:&nbsp;</b></small>
1.42      albertel  696:        </td>
1.110     muellerd  697:        <td align="left" valign="top">
1.51      www       698:         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
1.14      albertel  699:        </td>
                    700:       </tr>
1.147     raeburn   701: END
                    702:     }
                    703:     if (($version ne '') && ($version ne '<!-- VERSION -->')) {
                    704:         $versionrow = <<"END";
1.132     bisitz    705:       <tr>
                    706:        <td colspan="2" align="left">
                    707:         <small>$version</small>
                    708:        </td>
                    709:       </tr>
1.147     raeburn   710: END
                    711:     }
                    712: 
1.151     raeburn   713:     $r->print(<<ENDDOCUMENT);
1.147     raeburn   714:     <div style="float: left;">
                    715:      <table border="0" cellspacing="0" cellpadding="0">
                    716: $domainrow
                    717: $serverrow
                    718: $loadrow    
                    719: $userloadrow
                    720: $versionrow
1.14      albertel  721:      </table>
1.141     raeburn   722:     </div>
                    723:     <div style="float: right;">
                    724:     $domainlogo
                    725:     </div>
                    726:     <br style="clear:both;" />
1.107     tempelho  727:  </div>
1.25      bowersj2  728: 
1.59      albertel  729: <script type="text/javascript">
1.122     bisitz    730: // <![CDATA[
1.59      albertel  731: // the if prevents the script error if the browser can not handle this
1.25      bowersj2  732: if ( document.client.uname ) { document.client.uname.focus(); }
1.122     bisitz    733: // ]]>
1.25      bowersj2  734: </script>
1.62      raeburn   735: $helpdeskscript
1.14      albertel  736: 
1.1       albertel  737: ENDDOCUMENT
1.98      raeburn   738:     my %endargs = ( 'noredirectlink' => 1, );
                    739:     $r->print(&Apache::loncommon::end_page(\%endargs));
1.1       albertel  740:     return OK;
1.60      raeburn   741: }
                    742: 
1.133     raeburn   743: sub check_loginvia {
1.158.2.8  raeburn   744:     my ($domain,$lonhost,$lonidsdir,$balcookie) = @_;
                    745:     if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {
1.133     raeburn   746:         return;
                    747:     }
                    748:     my %domconfhash = &Apache::loncommon::get_domainconf($domain);
                    749:     my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
                    750:     my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
                    751:     my $output;
                    752:     if ($loginvia ne '') {
                    753:         my $noredirect;
1.158.2.9.2.3! (raeburn  754::         my $ip = &Apache::lonnet::get_requestor_ip();
1.133     raeburn   755:         if ($ip eq '127.0.0.1') {
                    756:             $noredirect = 1;
                    757:         } else {
                    758:             if ($loginvia_exempt ne '') {
                    759:                 my @exempt = split(',',$loginvia_exempt);
                    760:                 if (grep(/^\Q$ip\E$/,@exempt)) {
                    761:                     $noredirect = 1;
                    762:                 }
                    763:             }
                    764:         }
                    765:         unless ($noredirect) {
                    766:             my ($newhost,$path);
                    767:             if ($loginvia =~ /:/) {
                    768:                 ($newhost,$path) = split(':',$loginvia);
                    769:             } else {
                    770:                 $newhost = $loginvia;
                    771:             }
                    772:             if ($newhost ne $lonhost) {
                    773:                 if (&Apache::lonnet::hostname($newhost) ne '') {
1.158.2.8  raeburn   774:                     if ($balcookie) {
                    775:                         my ($balancer,$cookie) = split(/:/,$balcookie);
                    776:                         if ($cookie =~ /^($match_domain)_($match_username)_([a-f0-9]+)$/) {
                    777:                             my ($udom,$uname,$cookieid) = ($1,$2,$3);
                    778:                             unless (&Apache::lonnet::delbalcookie($cookie,$balancer) eq 'ok') {
                    779:                                 if ((-d $lonidsdir) && (opendir(my $dh,$lonidsdir))) {
                    780:                                     while (my $filename=readdir($dh)) {
                    781:                                         if ($filename=~/^(\Q$uname\E_\d+_\Q$udom\E_$match_lonid)\.id$/) {
                    782:                                             my $handle = $1;
                    783:                                             my %hash =
                    784:                                                 &Apache::lonnet::get_sessionfile_vars($handle,$lonidsdir,
                    785:                                                                                      ['request.balancercookie',
                    786:                                                                                       'user.linkedenv']);
                    787:                                             if ($hash{'request.balancercookie'} eq "$balancer:$cookieid") {
                    788:                                                 if (unlink("$lonidsdir/$filename")) {
                    789:                                                     if (($hash{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&
                    790:                                                         (-l "$lonidsdir/$hash{'user.linkedenv'}.id") &&
                    791:                                                         (readlink("$lonidsdir/$hash{'user.linkedenv'}.id") eq "$lonidsdir/$filename")) {
                    792:                                                         unlink("$lonidsdir/$hash{'user.linkedenv'}.id");
                    793:                                                     }
                    794:                                                 }
                    795:                                             }
                    796:                                             last;
                    797:                                         }
                    798:                                     }
                    799:                                     closedir($dh);
                    800:                                 }
                    801:                             }
                    802:                         }
                    803:                     }
1.133     raeburn   804:                     $output = &redirect_page($newhost,$path);
                    805:                 }
                    806:             }
                    807:         }
                    808:     }
                    809:     return $output;
                    810: }
                    811: 
1.126     raeburn   812: sub redirect_page {
1.133     raeburn   813:     my ($desthost,$path) = @_;
1.158.2.8  raeburn   814:     my $hostname = &Apache::lonnet::hostname($desthost);
1.126     raeburn   815:     my $protocol = $Apache::lonnet::protocol{$desthost};
                    816:     $protocol = 'http' if ($protocol ne 'https');
1.133     raeburn   817:     unless ($path =~ m{^/}) {
                    818:         $path = '/'.$path;
                    819:     }
1.158.2.8  raeburn   820:     my $url = $protocol.'://'.$hostname.$path;
1.126     raeburn   821:     if ($env{'form.firsturl'} ne '') {
                    822:         $url .='?firsturl='.$env{'form.firsturl'};
                    823:     }
1.136     raeburn   824:     my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
1.126     raeburn   825:                                                     {'redirect' => [0,$url],});
                    826:     my $end_page   = &Apache::loncommon::end_page();
                    827:     return $start_page.$end_page;
                    828: }
                    829: 
1.60      raeburn   830: sub contactdisplay {
1.153     raeburn   831:     my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
                    832:         $possdoms) = @_;
1.60      raeburn   833:     my $contactblock;
1.153     raeburn   834:     my $origmail;
                    835:     if (ref($possdoms) eq 'ARRAY') {
                    836:         if (grep(/^\Q$authdomain\E$/,@{$possdoms})) { 
                    837:             $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
                    838:         }
                    839:     }
                    840:     my $requestmail = 
                    841:         &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
                    842:                                                  $authdomain,$origmail);
1.154     raeburn   843:     unless ($showhelpdesk eq '0') {
                    844:         if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
                    845:             $showhelpdesk = 1;
                    846:         } else {
1.153     raeburn   847:             $showhelpdesk = 0;
                    848:         }
1.62      raeburn   849:     }
1.90      raeburn   850:     if ($servadm && $showadminmail) {
1.130     bisitz    851:         $contactblock .= $$lt{'servadm'}.':<br />'.
                    852:                          '<tt>'.$servadm.'</tt><br />';
1.90      raeburn   853:     }
1.60      raeburn   854:     if ($showhelpdesk) {
1.114     tempelho  855:         $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
1.75      www       856:         my $thisurl = &escape('/adm/login');
1.62      raeburn   857:         $$helpdeskscript = <<"ENDSCRIPT";
                    858: <script type="text/javascript">
1.122     bisitz    859: // <![CDATA[
1.62      raeburn   860: function helpdesk() {
1.155     raeburn   861:     var possdom = document.client.udom.value;
                    862:     var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
1.62      raeburn   863:     if (codedom == '') {
                    864:         codedom = "$authdomain";
                    865:     }
                    866:     var querystr = "origurl=$thisurl&codedom="+codedom;
                    867:     document.location.href = "/adm/helpdesk?"+querystr;
                    868:     return;
                    869: }
1.122     bisitz    870: // ]]>
1.62      raeburn   871: </script>
                    872: ENDSCRIPT
1.60      raeburn   873:     }
                    874:     return $contactblock;
                    875: }
1.83      raeburn   876: 
                    877: sub forgotpwdisplay {
1.84      raeburn   878:     my (%lt) = @_;
1.83      raeburn   879:     my $prompt_for_resetpw = 1; 
                    880:     if ($prompt_for_resetpw) {
1.107     tempelho  881:         return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
1.84      raeburn   882:     }
                    883:     return;
                    884: }
                    885: 
1.90      raeburn   886: sub coursecatalog_link {
                    887:     my ($linkname) = @_;
                    888:     return <<"END";
1.137     bisitz    889:       <a href="/adm/coursecatalog">$linkname</a>
1.90      raeburn   890: END
                    891: }
                    892: 
1.101     raeburn   893: sub newuser_link {
                    894:     my ($linkname) = @_;
1.130     bisitz    895:     return '<a href="/adm/createaccount">'.$linkname.'</a>';
1.101     raeburn   896: }
                    897: 
1.1       albertel  898: 1;
                    899: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.