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

1.1       albertel    1: # The LearningOnline Network
                      2: # Login Screen
1.11      www         3: #
1.158.2.13.2.  (raeburn    4:): # $Id: lonlogin.pm,v 1.158.2.13 2021/12/12 11:47:03 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.13  raeburn    41: use URI::Escape;
                     42: use HTML::Entities();
1.158.2.7  raeburn    43: use CGI::Cookie();
1.75      www        44:  
1.1       albertel   45: sub handler {
                     46:     my $r = shift;
1.71      albertel   47: 
                     48:     &Apache::loncommon::get_unprocessed_cgi
1.79      albertel   49: 	(join('&',$ENV{'QUERY_STRING'},$env{'request.querystring'},
                     50: 	      $ENV{'REDIRECT_QUERY_STRING'}),
1.71      albertel   51: 	 ['interface','username','domain','firsturl','localpath','localres',
1.158.2.13.2.  (raeburn   52:): 	  'token','role','symb','iptoken','btoken','ltoken','ttoken','linkkey',
                     53:):           'saml','sso','retry']);
1.71      albertel   54: 
                     55: # -- check if they are a migrating user
                     56:     if (defined($env{'form.token'})) {
                     57: 	return &Apache::migrateuser::handler($r);
                     58:     }
                     59: 
1.158.2.13  raeburn    60:     my $lonhost = $r->dir_config('lonHostID');
1.158.2.13.2.  (raeburn   61:):     if ($env{'form.ttoken'}) {
                     62:):         my %info = &Apache::lonnet::tmpget($env{'form.ttoken'});
                     63:):         &Apache::lonnet::tmpdel($env{'form.ttoken'});
                     64:):         if ($info{'origurl'}) {
                     65:):             $env{'form.firsturl'} = $info{'origurl'};
                     66:):         }
                     67:):         if ($info{'ltoken'}) {
                     68:):             $env{'form.ltoken'} = $info{'ltoken'};
                     69:):         } elsif ($info{'linkprot'}) {
                     70:):             $env{'form.linkprot'} = $info{'linkprot'};
                     71:):         } elsif ($info{'linkkey'} ne '') {
                     72:):             $env{'form.linkkey'} = $info{'linkkey'};
                     73:):         }
                     74:):     } elsif (($env{'form.sso'}) || ($env{'form.retry'})) {
1.158.2.13  raeburn    75:         my $infotoken;
                     76:         if ($env{'form.sso'}) {
                     77:             $infotoken = $env{'form.sso'};
                     78:         } else {
                     79:             $infotoken = $env{'form.retry'};
                     80:         }
                     81:         my $data = &Apache::lonnet::reply('tmpget:'.$infotoken,$lonhost);
                     82:         unless (($data=~/^error/) || ($data eq 'con_lost') ||
                     83:                 ($data eq 'no_such_host')) {
                     84:             my %info = &decode_token($data);
                     85:             foreach my $item (keys(%info)) {
                     86:                 $env{'form.'.$item} = $info{$item};
                     87:             }
                     88:             &Apache::lonnet::tmpdel($infotoken);
                     89:         }
                     90:     } else {
                     91:         if (!defined($env{'form.firsturl'})) {
                     92:             &Apache::lonacc::get_posted_cgi($r,['firsturl']);
                     93:         }
1.158.2.13.2.  (raeburn   94:):         if (!defined($env{'form.firsturl'})) {
                     95:):             if ($ENV{'REDIRECT_URL'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) {
                     96:):                 $env{'form.firsturl'} = $ENV{'REDIRECT_URL'};
                     97:):             }
                     98:):         }
                     99:):         if (($env{'form.firsturl'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) &&
                    100:):             (!$env{'form.ltoken'}) && (!$env{'form.linkprot'}) && (!$env{'form.linkkey'})) {
                    101:):             &Apache::lonacc::get_posted_cgi($r,['linkkey']);
                    102:):         }
1.158.2.13  raeburn   103:         if ($env{'form.firsturl'} eq '/adm/logout') {
                    104:             delete($env{'form.firsturl'});
                    105:         }
                    106:     }
                    107: 
1.158.2.7  raeburn   108: # For "public user" - remove any exising "public" cookie, as user really wants to log-in
                    109:     my ($handle,$lonidsdir,$expirepub,$userdom);
1.158.2.8  raeburn   110:     $lonidsdir=$r->dir_config('lonIDsDir');
1.158.2.7  raeburn   111:     unless ($r->header_only) {
                    112:         $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);
                    113:         if ($handle ne '') {
                    114:             if ($handle=~/^publicuser\_/) {
                    115:                 unlink($r->dir_config('lonIDsDir')."/$handle.id");
                    116:                 undef($handle);
                    117:                 undef($userdom);
                    118:                 $expirepub = 1;
                    119:             }
                    120:         }
                    121:     }
                    122: 
1.53      www       123:     &Apache::loncommon::no_cache($r);
                    124:     &Apache::lonlocal::get_language_handle($r);
1.54      www       125:     &Apache::loncommon::content_type($r,'text/html');
1.158.2.7  raeburn   126:     if ($expirepub) {
1.158.2.9  raeburn   127:         my $c = new CGI::Cookie(-name    => 'lonPubID',
1.158.2.7  raeburn   128:                                 -value   => '',
                    129:                                 -expires => '-10y',);
                    130:         $r->header_out('Set-cookie' => $c);
                    131:     } elsif (($handle eq '') && ($userdom ne '')) {
1.158.2.9  raeburn   132:         my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
                    133:         foreach my $name (keys(%cookies)) {
                    134:             next unless ($name =~ /^lon(|S|Link|Pub)ID$/);
                    135:             my $c = new CGI::Cookie(-name    => $name,
                    136:                                     -value   => '',
                    137:                                     -expires => '-10y',);
                    138:             $r->headers_out->add('Set-cookie' => $c);
                    139:         }
1.158.2.7  raeburn   140:     }
1.1       albertel  141:     $r->send_http_header;
                    142:     return OK if $r->header_only;
                    143: 
1.49      www       144: 
                    145: # Are we re-routing?
1.149     raeburn   146:     my $londocroot = $r->dir_config('lonDocRoot'); 
                    147:     if (-e "$londocroot/lon-status/reroute.txt") {
1.49      www       148: 	&Apache::lonauth::reroute($r);
                    149: 	return OK;
                    150:     }
1.55      www       151: 
1.158.2.8  raeburn   152: # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
                    153: 
                    154:     my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1);
                    155:     if ($found_server) {
                    156:         my $hostname = &Apache::lonnet::hostname($found_server);
                    157:         if ($hostname ne '') {
                    158:             my $protocol = $Apache::lonnet::protocol{$found_server};
                    159:             $protocol = 'http' if ($protocol ne 'https');
                    160:             my $dest = '/adm/roles';
                    161:             if ($env{'form.firsturl'} ne '') {
1.158.2.13  raeburn   162:                 $dest = &HTML::Entities::encode($env{'form.firsturl'},'\'"<>&');
1.158.2.8  raeburn   163:             }
                    164:             my %info = (
                    165:                          balcookie => $lonhost.':'.$balancer_cookie,
                    166:                        );
1.158.2.13  raeburn   167:             if ($env{'form.role'}) {
                    168:                 $info{'role'} = $env{'form.role'};
                    169:             }
                    170:             if ($env{'form.symb'}) {
                    171:                 $info{'symb'} = $env{'form.symb'};
                    172:             }
1.158.2.8  raeburn   173:             my $balancer_token = &Apache::lonnet::tmpput(\%info,$found_server);
1.158.2.13  raeburn   174:             unless (($balancer_token eq 'con_lost') || ($balancer_token eq 'refused') ||
                    175:                     ($balancer_token eq 'unknown_cmd') || ($balancer_token eq 'no_such_host')) {
                    176:                 $dest .=  (($dest=~/\?/)?'&amp;':'?') . 'btoken='.$balancer_token;
                    177:             }
1.158.2.13.2.  (raeburn  178:):             if ($env{'form.firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
                    179:):                 my %link_info;
                    180:):                 if ($env{'form.ltoken'}) {
                    181:):                     $link_info{'ltoken'} = $env{'form.ltoken'};
                    182:):                 } elsif ($env{'form.linkprot'}) {
                    183:):                     $link_info{'linkprot'} = $env{'form.linkprot'};
                    184:):                 } elsif ($env{'form.linkkey'} ne '') {
                    185:):                     $link_info{'linkkey'} = $env{'form.linkkey'};
                    186:):                 }
                    187:):                 if (keys(%link_info)) {
                    188:):                     $link_info{'origurl'} = $env{'form.firsturl'};
                    189:):                     my $token = &Apache::lonnet::tmpput(\%link_info,$found_server,'link');
                    190:):                     unless (($token eq 'con_lost') || ($token eq 'refused') ||
                    191:):                             ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
                    192:):                         $dest .=  (($dest=~/\?/)?'&amp;':'?') . 'ttoken='.$token;
                    193:):                     }
                    194:):                 }
                    195:):             }
1.158.2.13  raeburn   196:             unless ($found_server eq $lonhost) {
                    197:                 my $alias = &Apache::lonnet::use_proxy_alias($r,$found_server);
                    198:                 $hostname = $alias if ($alias ne '');
1.158.2.8  raeburn   199:             }
                    200:             my $url = $protocol.'://'.$hostname.$dest;
                    201:             my $start_page =
                    202:                 &Apache::loncommon::start_page('Switching Server ...',undef,
                    203:                                                {'redirect'       => [0,$url],});
                    204:             my $end_page   = &Apache::loncommon::end_page();
                    205:             $r->print($start_page.$end_page);
                    206:             return OK;
                    207:         }
                    208:     }
                    209: 
                    210: #
                    211: # Check if a LON-CAPA load balancer sent user here because user's browser sent
                    212: # it a balancer cookie for an active session on this server.
                    213: #
                    214: 
                    215:     my $balcookie;
                    216:     if ($env{'form.btoken'}) {
                    217:         my %info = &Apache::lonnet::tmpget($env{'form.btoken'});
                    218:         $balcookie = $info{'balcookie'};
                    219:         &Apache::lonnet::tmpdel($env{'form.btoken'});
                    220:         delete($env{'form.btoken'});
                    221:     }
                    222: 
1.158.2.7  raeburn   223: #
                    224: # If browser sent an old cookie for which the session file had been removed
                    225: # check if configuration for user's domain has a portal URL set.  If so
                    226: # switch user's log-in to the portal.
                    227: #
                    228: 
                    229:     if (($handle eq '') && ($userdom ne '')) {
                    230:         my %domdefaults = &Apache::lonnet::get_domain_defaults($userdom);
                    231:         if ($domdefaults{'portal_def'} =~ /^https?\:/) {
                    232:             my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
                    233:                                           {'redirect' => [0,$domdefaults{'portal_def'}],});
                    234:             my $end_page   = &Apache::loncommon::end_page();
                    235:             $r->print($start_page.$end_page);
                    236:             return OK;
                    237:         }
                    238:     }
                    239: 
1.55      www       240: # -------------------------------- Prevent users from attempting to login twice
1.135     raeburn   241:     if ($handle ne '') {
1.158.2.7  raeburn   242:         &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
                    243: 	my $start_page = 
                    244: 	    &Apache::loncommon::start_page('Already logged in');
                    245: 	my $end_page = 
                    246: 	    &Apache::loncommon::end_page();
                    247:         my $dest = '/adm/roles';
                    248:         if ($env{'form.firsturl'} ne '') {
1.158.2.13  raeburn   249:             $dest = &HTML::Entities::encode($env{'form.firsturl'},'\'"<>&');
1.158.2.7  raeburn   250:         }
1.158.2.13.2.  (raeburn  251:):         if (($env{'form.ltoken'}) || ($env{'form.linkprot'})) {
                    252:):             my $linkprot;
                    253:):             if ($env{'form.ltoken'}) {
                    254:):                 my %info = &Apache::lonnet::tmpget($env{'form.ltoken'});
                    255:):                 $linkprot = $info{'linkprot'};
                    256:):                 my $delete = &Apache::lonnet::tmpdel($env{'form.ltoken'});
                    257:):             } else {
                    258:):                 $linkprot = $env{'form.linkprot'};
                    259:):             }
                    260:):             if ($linkprot) {
                    261:):                 my ($linkprotector,$deeplink) = split(/:/,$linkprot,2);
                    262:):                 if ($env{'user.linkprotector'}) {
                    263:):                     my @protectors = split(/,/,$env{'user.linkprotector'});
                    264:):                     unless (grep(/^\Q$linkprotector\E$/,@protectors)) {
                    265:):                         push(@protectors,$linkprotector);
                    266:):                         @protectors = sort { $a <=> $b } @protectors;
                    267:):                         &Apache::lonnet::appenv({'user.linkprotector' => join(',',@protectors)});
                    268:):                     }
                    269:):                 } else {
                    270:):                     &Apache::lonnet::appenv({'user.linkprotector' => $linkprotector });
                    271:):                 }
                    272:):                 if ($env{'user.linkproturi'}) {
                    273:):                     my @proturis = split(/,/,$env{'user.linkproturi'});
                    274:):                     unless (grep(/^\Q$deeplink\E$/,@proturis)) {
                    275:):                         push(@proturis,$deeplink);
                    276:):                         @proturis = sort @proturis;
                    277:):                         &Apache::lonnet::appenv({'user.linkproturi' => join(',',@proturis)});
                    278:):                     }
                    279:):                 } else {
                    280:):                     &Apache::lonnet::appenv({'user.linkproturi' => $deeplink});
                    281:):                 }
                    282:):             }
                    283:):         } elsif ($env{'form.linkkey'} ne '') {
                    284:):             if ($env{'form.firsturl'} =~ m{^/tiny/$match_domain/\w+$}) {
                    285:):                 my $linkkey = $env{'form.linkkey'};
                    286:):                 if ($env{'user.deeplinkkey'}) {
                    287:):                     my @linkkeys = split(/,/,$env{'user.deeplinkkey'});
                    288:):                     unless (grep(/^\Q$linkkey\E$/,@linkkeys)) {
                    289:):                         push(@linkkeys,$linkkey);
                    290:):                         &Apache::lonnet::appenv({'user.deeplinkkey' => join(',',sort(@linkkeys))});
                    291:):                     }
                    292:):                 } else {
                    293:):                     &Apache::lonnet::appenv({'user.deeplinkkey' => $linkkey});
                    294:):                 }
                    295:):                 my $deeplink = $env{'form.firsturl'};
                    296:):                 if ($env{'user.keyedlinkuri'}) {
                    297:):                     my @keyeduris = split(/,/,$env{'user.keyedlinkuri'});
                    298:):                     unless (grep(/^\Q$deeplink\E$/,@keyeduris)) {
                    299:):                         push(@keyeduris,$deeplink);
                    300:):                         &Apache::lonnet::appenv({'user.keyedlinkuri' => join(',',sort(@keyeduris))});
                    301:):                     }
                    302:):                 } else {
                    303:):                     &Apache::lonnet::appenv({'user.keyedlinkuri' => $deeplink});
                    304:):                 }
                    305:):             }
                    306:):         }
1.158.2.7  raeburn   307: 	$r->print(
                    308:               $start_page
                    309:              .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
                    310:              .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
                    311:               '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
                    312:              .$end_page
                    313:              );
                    314:         return OK;
1.55      www       315:     }
                    316: 
                    317: # ---------------------------------------------------- No valid token, continue
1.16      www       318: 
1.157     raeburn   319: # ---------------------------- Not possible to really login to domain "public"
1.70      www       320:     if ($env{'form.domain'} eq 'public') {
                    321: 	$env{'form.domain'}='';
                    322: 	$env{'form.username'}='';
                    323:     }
1.157     raeburn   324: 
                    325: # ------ Is this page requested because /adm/migrateuser detected an IP change?
                    326:     my %sessiondata;
                    327:     if ($env{'form.iptoken'}) {
                    328:         %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});
1.158.2.2  raeburn   329:         unless ($sessiondata{'sessionserver'}) {
                    330:             my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});
                    331:             delete($env{'form.iptoken'});
                    332:         }
1.157     raeburn   333:     }
1.32      www       334: # ----------------------------------------------------------- Process Interface
1.63      albertel  335:     $env{'form.interface'}=~s/\W//g;
1.16      www       336: 
1.156     raeburn   337:     (undef,undef,undef,undef,undef,undef,my $clientmobile) =
1.158.2.13  raeburn   338:         &Apache::loncommon::decode_user_agent($r);
1.94      albertel  339: 
                    340:     my $iconpath= 
                    341: 	&Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
                    342: 
1.87      raeburn   343:     my $domain = &Apache::lonnet::default_login_domain();
1.158.2.3  raeburn   344:     my $defdom = $domain;
1.126     raeburn   345:     if ($lonhost ne '') {
1.157     raeburn   346:         unless ($sessiondata{'sessionserver'}) {
1.158.2.8  raeburn   347:             my $redirect = &check_loginvia($domain,$lonhost,$lonidsdir,$balcookie);
1.157     raeburn   348:             if ($redirect) {
                    349:                 $r->print($redirect);
                    350:                 return OK;
                    351:             }
                    352:         }
1.126     raeburn   353:     }
                    354: 
1.157     raeburn   355:     if (($sessiondata{'domain'}) &&
1.158.2.8  raeburn   356:         (&Apache::lonnet::domain($sessiondata{'domain'},'description'))) {
1.157     raeburn   357:         $domain=$sessiondata{'domain'};
                    358:     } elsif (($env{'form.domain'}) && 
1.89      albertel  359: 	(&Apache::lonnet::domain($env{'form.domain'},'description'))) {
1.63      albertel  360: 	$domain=$env{'form.domain'};
1.46      www       361:     }
1.157     raeburn   362: 
1.1       albertel  363:     my $role    = $r->dir_config('lonRole');
                    364:     my $loadlim = $r->dir_config('lonLoadLim');
1.145     www       365:     my $uloadlim= $r->dir_config('lonUserLoadLim');
1.90      raeburn   366:     my $servadm = $r->dir_config('lonAdmEMail');
1.1       albertel  367:     my $tabdir  = $r->dir_config('lonTabDir');
1.6       www       368:     my $include = $r->dir_config('lonIncludes');
1.37      www       369:     my $expire  = $r->dir_config('lonExpire');
1.44      www       370:     my $version = $r->dir_config('lonVersion');
1.88      albertel  371:     my $host_name = &Apache::lonnet::hostname($lonhost);
1.1       albertel  372: 
1.30      www       373: # --------------------------------------------- Default values for login fields
1.157     raeburn   374:     
                    375:     my ($authusername,$authdomain);
                    376:     if ($sessiondata{'username'}) {
                    377:         $authusername=$sessiondata{'username'};
                    378:     } else {
1.158     raeburn   379:         $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
1.157     raeburn   380:         $authusername=($env{'form.username'}?$env{'form.username'}:'');
                    381:     }
                    382:     if ($sessiondata{'domain'}) {
                    383:         $authdomain=$sessiondata{'domain'};
1.158     raeburn   384:     } else {
                    385:         $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
1.157     raeburn   386:         $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
                    387:     }
1.30      www       388: 
                    389: # ---------------------------------------------------------- Determine own load
1.1       albertel  390:     my $loadavg;
1.41      albertel  391:     {
                    392: 	my $loadfile=Apache::File->new('/proc/loadavg');
                    393: 	$loadavg=<$loadfile>;
                    394:     }
1.1       albertel  395:     $loadavg =~ s/\s.*//g;
1.147     raeburn   396: 
                    397:     my ($loadpercent,$userloadpercent);
                    398:     if ($loadlim) {
                    399:         $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
                    400:     }
                    401:     if ($uloadlim) {
                    402:         $userloadpercent=&Apache::lonnet::userload();
                    403:     }
1.1       albertel  404: 
1.31      www       405:     my $firsturl=
1.63      albertel  406:     ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
1.141     raeburn   407: 
1.45      www       408: # ----------------------------------------------------------- Get announcements
                    409:     my $announcements=&Apache::lonnet::getannounce();
1.6       www       410: # -------------------------------------------------------- Set login parameters
                    411: 
                    412:     my @hexstr=('0','1','2','3','4','5','6','7',
                    413:                 '8','9','a','b','c','d','e','f');
                    414:     my $lkey='';
                    415:     for (0..7) {
                    416:         $lkey.=$hexstr[rand(15)];
                    417:     }
                    418: 
                    419:     my $ukey='';
                    420:     for (0..7) {
                    421:         $ukey.=$hexstr[rand(15)];
                    422:     }
                    423: 
                    424:     my $lextkey=hex($lkey);
1.15      www       425:     if ($lextkey>2147483647) { $lextkey-=4294967296; }
                    426: 
1.6       www       427:     my $uextkey=hex($ukey);
1.15      www       428:     if ($uextkey>2147483647) { $uextkey-=4294967296; }
                    429: 
1.31      www       430: # -------------------------------------------------------- Store away log token
1.158.2.13.2.  (raeburn  431:):     my ($tokenextras,$tokentype);
                    432:):     my @names = ('role','symb','iptoken','ltoken','linkprot','linkkey');
1.158.2.13  raeburn   433:     foreach my $name (@names) {
                    434:         if ($env{'form.'.$name} ne '') {
1.158.2.13.2.  (raeburn  435:):             if ($name eq 'ltoken') {
                    436:):                 my %info = &Apache::lonnet::tmpget($env{'form.'.$name});
                    437:):                 if ($info{'linkprot'}) {
                    438:):                     $tokenextras .= '&linkprot='.&escape($info{'linkprot'});
                    439:):                     $tokentype = 'link';
                    440:):                     last;
                    441:):                 }
                    442:):             } else {
                    443:):                 $tokenextras .= '&'.$name.'='.&escape($env{'form.'.$name});
                    444:):                 if (($name eq 'linkkey') || ($name eq 'linkprot')) {
                    445:):                     $tokentype = 'link';
                    446:):                 }
                    447:):             }
1.158.2.2  raeburn   448:         }
                    449:     }
1.158.2.13.2.  (raeburn  450:):     if ($tokentype) {
                    451:):         $tokenextras .= ":$tokentype";
                    452:):     }
1.6       www       453:     my $logtoken=Apache::lonnet::reply(
1.158.2.13  raeburn   454:        'tmpput:'.$ukey.$lkey.'&'.&escape($firsturl).$tokenextras,
1.6       www       455:        $lonhost);
1.31      www       456: 
1.148     raeburn   457: # -- If we cannot talk to ourselves, or hostID does not map to a hostname
                    458: #    we are in serious trouble
1.31      www       459: 
1.148     raeburn   460:     if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
                    461:         if ($logtoken eq 'no_such_host') {
                    462:             &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
                    463:         }
1.158.2.13.2.  (raeburn  464:):         if ($env{'form.ltoken'}) {
                    465:):             &Apache::lonnet::tmpdel($env{'form.ltoken'});
                    466:):             delete($env{'form.ltoken'});
                    467:):         }
1.31      www       468:         my $spares='';
1.158.2.10  raeburn   469:         my (@sparehosts,%spareservers);
                    470:         my $sparesref = &Apache::lonnet::this_host_spares($defdom);
                    471:         if (ref($sparesref) eq 'HASH') {
                    472:             foreach my $key (keys(%{$sparesref})) {
                    473:                 if (ref($sparesref->{$key}) eq 'ARRAY') {
                    474:                     my @sorted = sort { &Apache::lonnet::hostname($a) cmp
                    475:                                         &Apache::lonnet::hostname($b);
                    476:                                       } @{$sparesref->{$key}};
                    477:                     if (@sorted) {
                    478:                         if ($key eq 'primary') {
                    479:                             unshift(@sparehosts,@sorted);
                    480:                         } elsif ($key eq 'default') {
                    481:                             push(@sparehosts,@sorted);
                    482:                         }
                    483:                     }
                    484:                 }
                    485:             }
                    486:         }
                    487:         foreach my $hostid (@sparehosts) {
1.58      matthew   488:             next if ($hostid eq $lonhost);
1.88      albertel  489: 	    my $hostname = &Apache::lonnet::hostname($hostid);
1.158.2.10  raeburn   490: 	    next if (($hostname eq '') || ($spareservers{$hostname}));
                    491:             $spareservers{$hostname} = 1;
                    492:             my $protocol = $Apache::lonnet::protocol{$hostid};
                    493:             $protocol = 'http' if ($protocol ne 'https');
                    494:             $spares.='<br /><span style="font-size: larger;"><a href="'.$protocol.'://'.
1.88      albertel  495:                 $hostname.
1.58      matthew   496:                 '/adm/login?domain='.$authdomain.'">'.
1.88      albertel  497:                 $hostname.'</a>'.
1.158.2.10  raeburn   498:                 ' '.&mt('(preferred)').'</span>'.$/;
1.58      matthew   499:         }
1.148     raeburn   500:         if ($spares) {
                    501:             $spares.= '<br />';
                    502:         }
1.151     raeburn   503:         my %all_hostnames = &Apache::lonnet::all_hostnames();
                    504:         foreach my $hostid (sort
1.107     tempelho  505: 		    {
                    506: 			&Apache::lonnet::hostname($a) cmp
                    507: 			    &Apache::lonnet::hostname($b);
                    508: 		    }
                    509: 		    keys(%all_hostnames)) {
1.158.2.10  raeburn   510:             next if ($hostid eq $lonhost);
1.151     raeburn   511:             my $hostname = &Apache::lonnet::hostname($hostid);
1.158.2.10  raeburn   512:             next if (($hostname eq '') || ($spareservers{$hostname}));
1.158.2.11  raeburn   513:             $spareservers{$hostname} = 1;
1.158.2.10  raeburn   514:             my $protocol = $Apache::lonnet::protocol{$hostid};
                    515:             $protocol = 'http' if ($protocol ne 'https');
                    516:             $spares.='<br /><a href="'.$protocol.'://'.
1.151     raeburn   517: 	             $hostname.
                    518: 	             '/adm/login?domain='.$authdomain.'">'.
                    519: 	             $hostname.'</a>';
                    520:          }
                    521:          $r->print(
1.158.2.10  raeburn   522:    '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
                    523:   .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'
                    524:   .'<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>'
1.107     tempelho  525:   .&mt('The LearningOnline Network with CAPA')
                    526:   .'</title></head>'
                    527:   .'<body bgcolor="#FFFFFF">'
                    528:   .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
1.158.2.10  raeburn   529:   .'<img src="/adm/lonKaputt/lonlogo_broken.gif" alt="broken icon" align="right" />'
1.148     raeburn   530:   .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
1.151     raeburn   531:         if ($spares) {
                    532:             $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
                    533:                      .'</p>'
                    534:                      .$spares);
                    535:         }
                    536:         $r->print('</body>'
                    537:                  .'</html>'
                    538:         );
                    539:         return OK;
                    540:     }
1.31      www       541: 
                    542: # ----------------------------------------------- Apparently we are in business
1.151     raeburn   543:     $servadm=~s/\,/\<br \/\>/g;
1.38      www       544: 
1.21      www       545: # ----------------------------------------------------------- Front page design
1.151     raeburn   546:     my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
                    547:     my $font=&Apache::loncommon::designparm('login.font',$domain);
                    548:     my $link=&Apache::loncommon::designparm('login.link',$domain);
                    549:     my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
                    550:     my $alink=&Apache::loncommon::designparm('login.alink',$domain);
                    551:     my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
                    552:     my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
                    553:     my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
                    554:     my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
                    555:     my $logo=&Apache::loncommon::designparm('login.logo',$domain);
                    556:     my $img=&Apache::loncommon::designparm('login.img',$domain);
                    557:     my $domainlogo=&Apache::loncommon::domainlogo($domain);
                    558:     my $showbanner = 1;
                    559:     my $showmainlogo = 1;
                    560:     if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
                    561:         $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
                    562:     }
                    563:     if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
                    564:         $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
                    565:     }
1.153     raeburn   566:     my $showadminmail;
                    567:     my @possdoms = &Apache::lonnet::current_machine_domains();
                    568:     if (grep(/^\Q$domain\E$/,@possdoms)) {
                    569:         $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
                    570:     }
1.151     raeburn   571:     my $showcoursecat =
                    572:         &Apache::loncommon::designparm('login.coursecatalog',$domain);
                    573:     my $shownewuserlink = 
                    574:         &Apache::loncommon::designparm('login.newuser',$domain);
1.153     raeburn   575:     my $showhelpdesk =
                    576:         &Apache::loncommon::designparm('login.helpdesk',$domain);
1.151     raeburn   577:     my $now=time;
                    578:     my $js = (<<ENDSCRIPT);
1.107     tempelho  579: 
1.116     bisitz    580: <script type="text/javascript" language="JavaScript">
1.122     bisitz    581: // <![CDATA[
1.107     tempelho  582: function send()
                    583: {
                    584: this.document.server.elements.uname.value
                    585: =this.document.client.elements.uname.value;
                    586: 
                    587: this.document.server.elements.udom.value
                    588: =this.document.client.elements.udom.value;
                    589: 
                    590: uextkey=this.document.client.elements.uextkey.value;
                    591: lextkey=this.document.client.elements.lextkey.value;
                    592: initkeys();
                    593: 
                    594: this.document.server.elements.upass0.value
1.158.2.5  raeburn   595:     =getCrypted(this.document.client.elements.upass$now.value);
1.6       www       596: 
1.107     tempelho  597: this.document.client.elements.uname.value='';
                    598: this.document.client.elements.upass$now.value='';
1.6       www       599: 
1.107     tempelho  600: this.document.server.submit();
                    601: return false;
                    602: }
1.139     raeburn   603: 
                    604: function enableInput() {
1.144     bisitz    605:     this.document.client.elements.upass$now.removeAttribute("readOnly");
                    606:     this.document.client.elements.uname.removeAttribute("readOnly");
                    607:     this.document.client.elements.udom.removeAttribute("readOnly");
1.139     raeburn   608:     return;
                    609: }
                    610: 
1.122     bisitz    611: // ]]>
1.107     tempelho  612: </script>
1.98      raeburn   613: 
1.16      www       614: ENDSCRIPT
1.6       www       615: 
1.158.2.13  raeburn   616:     my ($lonhost_in_use,@hosts,%defaultdomconf,$saml_prefix,$saml_landing,
                    617:         $samlssotext,$samlnonsso,$samlssoimg,$samlssoalt,$samlssourl,$samltooltip);
                    618:     %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
1.158.2.4  raeburn   619:     @hosts = &Apache::lonnet::current_machine_ids();
                    620:     $lonhost_in_use = $lonhost;
                    621:     if (@hosts > 1) {
                    622:         foreach my $hostid (@hosts) {
                    623:             if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
                    624:                 $lonhost_in_use = $hostid;
                    625:                 last;
                    626:             }
                    627:         }
                    628:     }
1.158.2.13  raeburn   629:     $saml_prefix = $defdom.'.login.saml_';
                    630:     if ($defaultdomconf{$saml_prefix.$lonhost_in_use}) {
                    631:         $saml_landing = 1;
                    632:         $samlssotext = $defaultdomconf{$saml_prefix.'text_'.$lonhost_in_use};
                    633:         $samlnonsso = $defaultdomconf{$saml_prefix.'notsso_'.$lonhost_in_use};
                    634:         $samlssoimg = $defaultdomconf{$saml_prefix.'img_'.$lonhost_in_use};
                    635:         $samlssoalt = $defaultdomconf{$saml_prefix.'alt_'.$lonhost_in_use};
                    636:         $samlssourl = $defaultdomconf{$saml_prefix.'url_'.$lonhost_in_use};
                    637:         $samltooltip = $defaultdomconf{$saml_prefix.'title_'.$lonhost_in_use};
                    638:     }
                    639:     if ($saml_landing) {
                    640:        if ($samlssotext eq '') {
                    641:            $samlssotext = 'SSO Login';
                    642:        }
                    643:        if ($samlnonsso eq '') {
                    644:            $samlnonsso = 'Non-SSO Login';
                    645:        }
                    646:        $js .= <<"ENDSAMLJS";
                    647: 
                    648: <script type="text/javascript">
                    649: // <![CDATA[
                    650: function toggleLClogin() {
                    651:     if (document.getElementById('LC_standard_login')) {
                    652:         if (document.getElementById('LC_standard_login').style.display == 'none') {
                    653:             document.getElementById('LC_standard_login').style.display = 'inline-block';
                    654:             if (document.getElementById('LC_login_text')) {
                    655:                 document.getElementById('LC_login_text').innerHTML = '$samlnonsso';
                    656:             }
                    657:             if (document.getElementById('LC_SSO_login')) {
                    658:                 document.getElementById('LC_SSO_login').style.display = 'none';
                    659:             }
                    660:         } else {
                    661:             document.getElementById('LC_standard_login').style.display = 'none';
                    662:             if (document.getElementById('LC_login_text')) {
                    663:                 document.getElementById('LC_login_text').innerHTML = '$samlssotext';
                    664:             }
                    665:             if (document.getElementById('LC_SSO_login')) {
                    666:                 document.getElementById('LC_SSO_login').style.display = 'inline-block';
                    667:             }
                    668:         }
                    669:     }
                    670:     return;
                    671: }
                    672: 
                    673: // ]]>
                    674: </script>
                    675: 
                    676: ENDSAMLJS
                    677:     }
                    678: 
                    679: # --------------------------------------------------- Print login screen header
                    680: 
                    681:     my %add_entries = (
                    682: 	       bgcolor      => "$mainbg",
                    683: 	       text         => "$font",
                    684: 	       link         => "$link",
                    685: 	       vlink        => "$vlink",
                    686: 	       alink        => "$alink",
                    687:                onload       => 'javascript:enableInput();',);
                    688: 
                    689:     my ($headextra,$headextra_exempt);
1.158.2.4  raeburn   690:     $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
                    691:     $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
1.158.2.1  raeburn   692:     if ($headextra) {
                    693:         my $omitextra;
                    694:         if ($headextra_exempt ne '') {
                    695:             my @exempt = split(',',$headextra_exempt);
1.158.2.12  raeburn   696:             my $ip = &Apache::lonnet::get_requestor_ip();
1.158.2.1  raeburn   697:             if (grep(/^\Q$ip\E$/,@exempt)) {
                    698:                 $omitextra = 1;
                    699:             }
                    700:         }
                    701:         unless ($omitextra) {
                    702:             my $confname = $defdom.'-domainconfig';
1.158.2.4  raeburn   703:             if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
1.158.2.1  raeburn   704:                 my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
                    705:                 unless ($extra eq '-1') {
                    706:                     $js .= "\n".$extra."\n";
                    707:                 }
                    708:             }
                    709:         }
                    710:     }
                    711: 
1.151     raeburn   712:     $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
1.107     tempelho  713: 			       { 'redirect'       => [$expire,'/adm/roles'], 
                    714: 				 'add_entries' => \%add_entries,
                    715: 				 'only_body'   => 1,}));
1.98      raeburn   716: 
                    717: # ----------------------------------------------------------------------- Texts
                    718: 
1.151     raeburn   719:     my %lt=&Apache::lonlocal::texthash(
1.129     bisitz    720:           'un'       => 'Username',
                    721:           'pw'       => 'Password',
                    722:           'dom'      => 'Domain',
                    723:           'perc'     => 'percent',
                    724:           'load'     => 'Server Load',
                    725:           'userload' => 'User Load',
                    726:           'catalog'  => 'Course/Community Catalog',
                    727:           'log'      => 'Log in',
                    728:           'help'     => 'Log-in Help',
                    729:           'serv'     => 'Server',
                    730:           'servadm'  => 'Server Administration',
                    731:           'helpdesk' => 'Contact Helpdesk',
                    732:           'forgotpw' => 'Forgot password?',
                    733:           'newuser'  => 'New User?',
1.158.2.13  raeburn   734:           'change'   => 'Change?',
1.129     bisitz    735:        );
1.98      raeburn   736: # -------------------------------------------------- Change password field name
1.131     jms       737: 
1.151     raeburn   738:     my $forgotpw = &forgotpwdisplay(%lt);
                    739:     $forgotpw .= '<br />' if $forgotpw;
1.152     raeburn   740:     my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
                    741:     if ($loginhelp) {
                    742:         $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
                    743:     }
1.98      raeburn   744: 
                    745: # ---------------------------------------------------- Serve out DES JavaScript
1.151     raeburn   746:     {
                    747:     my $jsh=Apache::File->new($include."/londes.js");
                    748:     $r->print(<$jsh>);
                    749:     }
1.98      raeburn   750: # ---------------------------------------------------------- Serve rest of page
                    751: 
1.151     raeburn   752:     $r->print(
1.137     bisitz    753:     '<div class="LC_Box"'
                    754:    .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
                    755: );
1.6       www       756: 
1.151     raeburn   757:     $r->print(<<ENDSERVERFORM);
1.140     raeburn   758: <form name="server" action="/adm/authenticate" method="post" target="_top">
1.33      www       759:    <input type="hidden" name="logtoken" value="$logtoken" />
                    760:    <input type="hidden" name="serverid" value="$lonhost" />
                    761:    <input type="hidden" name="uname" value="" />
1.65      www       762:    <input type="hidden" name="upass0" value="" />
1.33      www       763:    <input type="hidden" name="udom" value="" />
1.63      albertel  764:    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
                    765:    <input type="hidden" name="localres" value="$env{'form.localres'}" />
1.14      albertel  766:   </form>
1.16      www       767: ENDSERVERFORM
1.151     raeburn   768:     my $coursecatalog;
                    769:     if (($showcoursecat eq '') || ($showcoursecat)) {
                    770:         $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
                    771:     }
                    772:     my $newuserlink;
                    773:     if ($shownewuserlink) {
                    774:         $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
                    775:     }
                    776:     my $logintitle =
                    777:         '<h2 class="LC_hcell"'
                    778:        .' style="background:'.$loginbox_header_bgcol.';'
                    779:        .' color:'.$loginbox_header_textcol.'">'
                    780:        .$lt{'log'}
                    781:        .'</h2>';
                    782: 
                    783:     my $noscript_warning='<noscript><span class="LC_warning"><b>'
                    784:                         .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
                    785:                         .'</b></span></noscript>';
                    786:     my $helpdeskscript;
                    787:     my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
1.153     raeburn   788:                                        $authdomain,\$helpdeskscript,
                    789:                                        $showhelpdesk,\@possdoms);
1.107     tempelho  790: 
1.156     raeburn   791:     my $mobileargs;
                    792:     if ($clientmobile) {
                    793:         $mobileargs = 'autocapitalize="off" autocorrect="off"'; 
                    794:     }
1.151     raeburn   795:     my $loginform=(<<LFORM);
1.158.2.13  raeburn   796: <form name="client" action="" onsubmit="return(send())" id="lclogin">
1.115     bisitz    797:   <input type="hidden" name="lextkey" value="$lextkey" />
                    798:   <input type="hidden" name="uextkey" value="$uextkey" />
1.108     tempelho  799:   <b><label for="uname">$lt{'un'}</label>:</b><br />
1.156     raeburn   800:   <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
1.108     tempelho  801:   <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
1.139     raeburn   802:   <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
1.108     tempelho  803:   <b><label for="udom">$lt{'dom'}</label>:</b><br />
1.156     raeburn   804:   <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
1.108     tempelho  805:   <input type="submit" value="$lt{'log'}" />
                    806: </form>
                    807: LFORM
                    808: 
1.109     raeburn   809:     if ($showbanner) {
                    810:         $r->print(<<HEADER);
                    811: <!-- The LON-CAPA Header -->
1.132     bisitz    812: <div style="background:$pgbg;margin:0;width:100%;">
1.158.2.6  raeburn   813:   <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />
1.132     bisitz    814: </div>
1.109     raeburn   815: HEADER
                    816:     }
1.158.2.13  raeburn   817: 
                    818:     my $stdauthformstyle = 'inline-block';
                    819:     my $ssoauthstyle = 'none';
                    820:     my $logintype;
                    821:     $r->print('<div style="float:left;margin-top:0;">');
                    822:     if ($saml_landing) {
                    823:         $ssoauthstyle = 'inline-block';
                    824:         $stdauthformstyle = 'none';
                    825:         $logintype = $samlssotext;
                    826:         my $ssologin = '/adm/sso';
                    827:         if ($samlssourl  ne '') {
                    828:             $ssologin = $samlssourl;
                    829:         }
                    830:         if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
                    831:             my $querystring;
                    832:             if ($env{'form.firsturl'} ne '') {
                    833:                 $querystring = 'origurl=';
                    834:                 if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) {
                    835:                     $querystring .= &uri_escape_utf8($env{'form.firsturl'});
                    836:                 } else {
                    837:                     $querystring .= &uri_escape($env{'form.firsturl'});
                    838:                 }
                    839:                 $querystring = &HTML::Entities::encode($querystring,"'");
                    840:             }
1.158.2.13.2.  (raeburn  841:):             if ($env{'form.ltoken'} ne '') {
                    842:):                 $querystring .= (($querystring eq '')?'':'&amp;') . 'ltoken='.
                    843:):                                   &HTML::Entities::encode(&uri_escape($env{'form.ltoken'}));
                    844:):             } elsif ($env{'form.linkkey'}) {
                    845:):                 $querystring .= (($querystring eq '')?'':'&amp;') . 'linkkey='.
                    846:):                                   &HTML::Entities::encode(&uri_escape($env{'form.linkkey'}));
                    847:):             }
1.158.2.13  raeburn   848:             if ($querystring ne '') {
                    849:                 $ssologin .= (($ssologin=~/\?/)?'&amp;':'?') . $querystring;
                    850:             }
                    851:         } elsif ($logtoken ne '') {
                    852:             $ssologin .= (($ssologin=~/\?/)?'&amp;':'?') . 'logtoken='.$logtoken;
                    853:         }
                    854:         my $ssohref;
                    855:         if ($samlssoimg ne '') {
                    856:             $ssohref = '<a href="'.$ssologin.'" title="'.$samltooltip.'"><img src="'.$samlssoimg.'" alt="'.$samlssoalt.'" /></a>';
                    857:         } else {
                    858:             $ssohref = '<a href="'.$ssologin.'">'.$samlssotext.'</a>';
                    859:         }
                    860:         if (($env{'form.saml'} eq 'no') ||
                    861:             (($env{'form.username'} ne '') && ($env{'form.domain'} ne ''))) {
                    862:             $ssoauthstyle = 'none';
                    863:             $stdauthformstyle = 'inline-block';
                    864:             $logintype = $samlnonsso;
                    865:         }
                    866:         $r->print(<<ENDSAML);
                    867: <p>
                    868: Log-in type:
                    869: <span style="font-weight:bold" id="LC_login_text">$logintype</span><br />
                    870: <span><a href="javascript:toggleLClogin();" style="color:#000000">$lt{'change'}</a></span>
                    871: </p>
                    872: <div style="display:$ssoauthstyle" id="LC_SSO_login">
                    873: <div class="LC_Box" style="padding-top: 10px;">
                    874: $ssohref
                    875: $noscript_warning
                    876: </div>
                    877: <div class="LC_Box" style="padding-top: 10px;">
                    878: $loginhelp
                    879: $contactblock
                    880: $coursecatalog
                    881: </div>
                    882: </div>
                    883: ENDSAML
1.158.2.13.2.  (raeburn  884:):     } else {
                    885:):         if ($env{'form.ltoken'}) {
                    886:):             &Apache::lonnet::tmpdel($env{'form.ltoken'});
                    887:):             delete($env{'form.ltoken'});
                    888:):         }
1.158.2.13  raeburn   889:     }
                    890: 
                    891:     $r->print(<<ENDLOGIN);
                    892: <div style="display:$stdauthformstyle;" id="LC_standard_login">
1.137     bisitz    893: <div class="LC_Box" style="background:$loginbox_bg;">
1.112     muellerd  894:   $logintitle
1.137     bisitz    895:   $loginform
                    896:   $noscript_warning
1.108     tempelho  897: </div>
1.107     tempelho  898:   
1.137     bisitz    899: <div class="LC_Box" style="padding-top: 10px;">
1.132     bisitz    900:   $loginhelp
                    901:   $forgotpw
                    902:   $contactblock
                    903:   $newuserlink
1.130     bisitz    904:   $coursecatalog
1.107     tempelho  905: </div>
1.118     tempelho  906: </div>
1.137     bisitz    907: 
1.158.2.13  raeburn   908: ENDLOGIN
                    909:     $r->print('</div><div>'."\n");
1.118     tempelho  910:     if ($showmainlogo) {
1.158.2.6  raeburn   911:         $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");
1.118     tempelho  912:     }
                    913: $r->print(<<ENDTOP);
                    914: $announcements
1.137     bisitz    915: </div>
                    916: <hr style="clear:both;" />
1.108     tempelho  917: ENDTOP
1.147     raeburn   918:     my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
                    919:     $domainrow = <<"END";
1.14      albertel  920:       <tr>
1.110     muellerd  921:        <td  align="left" valign="top">
1.132     bisitz    922:         <small><b>$lt{'dom'}:&nbsp;</b></small>
1.14      albertel  923:        </td>
1.110     muellerd  924:        <td  align="left" valign="top">
1.14      albertel  925:         <small><tt>&nbsp;$domain</tt></small>
                    926:        </td>
                    927:       </tr>
1.147     raeburn   928: END
                    929:     $serverrow = <<"END";
1.14      albertel  930:       <tr>
1.110     muellerd  931:        <td  align="left" valign="top">
1.132     bisitz    932:         <small><b>$lt{'serv'}:&nbsp;</b></small>
1.14      albertel  933:        </td>
1.110     muellerd  934:        <td align="left" valign="top">
1.14      albertel  935:         <small><tt>&nbsp;$lonhost ($role)</tt></small>
                    936:        </td>
                    937:       </tr>
1.147     raeburn   938: END
                    939:     if ($loadlim) {
                    940:         $loadrow = <<"END";
1.14      albertel  941:       <tr>
1.110     muellerd  942:        <td align="left" valign="top">
1.132     bisitz    943:         <small><b>$lt{'load'}:&nbsp;</b></small>
1.14      albertel  944:        </td>
1.110     muellerd  945:        <td align="left" valign="top">
1.51      www       946:         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
1.42      albertel  947:        </td>
                    948:       </tr>
1.147     raeburn   949: END
                    950:     }
                    951:     if ($uloadlim) {
                    952:         $userloadrow = <<"END";
1.42      albertel  953:       <tr>
1.110     muellerd  954:        <td align="left" valign="top">
1.132     bisitz    955:         <small><b>$lt{'userload'}:&nbsp;</b></small>
1.42      albertel  956:        </td>
1.110     muellerd  957:        <td align="left" valign="top">
1.51      www       958:         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
1.14      albertel  959:        </td>
                    960:       </tr>
1.147     raeburn   961: END
                    962:     }
                    963:     if (($version ne '') && ($version ne '<!-- VERSION -->')) {
                    964:         $versionrow = <<"END";
1.132     bisitz    965:       <tr>
                    966:        <td colspan="2" align="left">
                    967:         <small>$version</small>
                    968:        </td>
                    969:       </tr>
1.147     raeburn   970: END
                    971:     }
                    972: 
1.151     raeburn   973:     $r->print(<<ENDDOCUMENT);
1.147     raeburn   974:     <div style="float: left;">
                    975:      <table border="0" cellspacing="0" cellpadding="0">
                    976: $domainrow
                    977: $serverrow
                    978: $loadrow    
                    979: $userloadrow
                    980: $versionrow
1.14      albertel  981:      </table>
1.141     raeburn   982:     </div>
                    983:     <div style="float: right;">
                    984:     $domainlogo
                    985:     </div>
                    986:     <br style="clear:both;" />
1.107     tempelho  987:  </div>
1.25      bowersj2  988: 
1.59      albertel  989: <script type="text/javascript">
1.122     bisitz    990: // <![CDATA[
1.59      albertel  991: // the if prevents the script error if the browser can not handle this
1.25      bowersj2  992: if ( document.client.uname ) { document.client.uname.focus(); }
1.122     bisitz    993: // ]]>
1.25      bowersj2  994: </script>
1.62      raeburn   995: $helpdeskscript
1.14      albertel  996: 
1.1       albertel  997: ENDDOCUMENT
1.98      raeburn   998:     my %endargs = ( 'noredirectlink' => 1, );
                    999:     $r->print(&Apache::loncommon::end_page(\%endargs));
1.1       albertel 1000:     return OK;
1.60      raeburn  1001: }
                   1002: 
1.133     raeburn  1003: sub check_loginvia {
1.158.2.8  raeburn  1004:     my ($domain,$lonhost,$lonidsdir,$balcookie) = @_;
                   1005:     if ($domain eq '' || $lonhost eq '' || $lonidsdir eq '') {
1.133     raeburn  1006:         return;
                   1007:     }
                   1008:     my %domconfhash = &Apache::loncommon::get_domainconf($domain);
                   1009:     my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
                   1010:     my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
                   1011:     my $output;
                   1012:     if ($loginvia ne '') {
                   1013:         my $noredirect;
1.158.2.12  raeburn  1014:         my $ip = &Apache::lonnet::get_requestor_ip();
1.133     raeburn  1015:         if ($ip eq '127.0.0.1') {
                   1016:             $noredirect = 1;
                   1017:         } else {
                   1018:             if ($loginvia_exempt ne '') {
                   1019:                 my @exempt = split(',',$loginvia_exempt);
                   1020:                 if (grep(/^\Q$ip\E$/,@exempt)) {
                   1021:                     $noredirect = 1;
                   1022:                 }
                   1023:             }
                   1024:         }
                   1025:         unless ($noredirect) {
                   1026:             my ($newhost,$path);
                   1027:             if ($loginvia =~ /:/) {
                   1028:                 ($newhost,$path) = split(':',$loginvia);
                   1029:             } else {
                   1030:                 $newhost = $loginvia;
                   1031:             }
                   1032:             if ($newhost ne $lonhost) {
                   1033:                 if (&Apache::lonnet::hostname($newhost) ne '') {
1.158.2.8  raeburn  1034:                     if ($balcookie) {
                   1035:                         my ($balancer,$cookie) = split(/:/,$balcookie);
                   1036:                         if ($cookie =~ /^($match_domain)_($match_username)_([a-f0-9]+)$/) {
                   1037:                             my ($udom,$uname,$cookieid) = ($1,$2,$3);
                   1038:                             unless (&Apache::lonnet::delbalcookie($cookie,$balancer) eq 'ok') {
                   1039:                                 if ((-d $lonidsdir) && (opendir(my $dh,$lonidsdir))) {
                   1040:                                     while (my $filename=readdir($dh)) {
                   1041:                                         if ($filename=~/^(\Q$uname\E_\d+_\Q$udom\E_$match_lonid)\.id$/) {
                   1042:                                             my $handle = $1;
                   1043:                                             my %hash =
                   1044:                                                 &Apache::lonnet::get_sessionfile_vars($handle,$lonidsdir,
                   1045:                                                                                      ['request.balancercookie',
                   1046:                                                                                       'user.linkedenv']);
                   1047:                                             if ($hash{'request.balancercookie'} eq "$balancer:$cookieid") {
                   1048:                                                 if (unlink("$lonidsdir/$filename")) {
                   1049:                                                     if (($hash{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&
                   1050:                                                         (-l "$lonidsdir/$hash{'user.linkedenv'}.id") &&
                   1051:                                                         (readlink("$lonidsdir/$hash{'user.linkedenv'}.id") eq "$lonidsdir/$filename")) {
                   1052:                                                         unlink("$lonidsdir/$hash{'user.linkedenv'}.id");
                   1053:                                                     }
                   1054:                                                 }
                   1055:                                             }
                   1056:                                             last;
                   1057:                                         }
                   1058:                                     }
                   1059:                                     closedir($dh);
                   1060:                                 }
                   1061:                             }
                   1062:                         }
                   1063:                     }
1.133     raeburn  1064:                     $output = &redirect_page($newhost,$path);
                   1065:                 }
                   1066:             }
                   1067:         }
                   1068:     }
                   1069:     return $output;
                   1070: }
                   1071: 
1.126     raeburn  1072: sub redirect_page {
1.133     raeburn  1073:     my ($desthost,$path) = @_;
1.158.2.8  raeburn  1074:     my $hostname = &Apache::lonnet::hostname($desthost);
1.126     raeburn  1075:     my $protocol = $Apache::lonnet::protocol{$desthost};
                   1076:     $protocol = 'http' if ($protocol ne 'https');
1.133     raeburn  1077:     unless ($path =~ m{^/}) {
                   1078:         $path = '/'.$path;
                   1079:     }
1.158.2.8  raeburn  1080:     my $url = $protocol.'://'.$hostname.$path;
1.126     raeburn  1081:     if ($env{'form.firsturl'} ne '') {
1.158.2.13  raeburn  1082:         my $querystring;
                   1083:         if ($env{'form.firsturl'} =~ /[^\x00-\xFF]/) {
                   1084:             $querystring = &uri_escape_utf8($env{'form.firsturl'});
                   1085:         } else {
                   1086:             $querystring = &uri_escape($env{'form.firsturl'});
                   1087:         }
                   1088:         $querystring = &HTML::Entities::encode($querystring,"'");
                   1089:         $url .='?firsturl='.$querystring;
1.126     raeburn  1090:     }
1.158.2.13.2.  (raeburn 1091:):     if (($env{'form.ltoken'}) || ($env{'form.linkkey'} ne '')) {
                   1092:):         my %link_info;
                   1093:):         if ($env{'form.ltoken'}) {
                   1094:):             $link_info{'ltoken'} = $env{'form.ltoken'};
                   1095:):         } elsif ($env{'form.linkkey'} ne '') {
                   1096:):             $link_info{'linkkey'} = $env{'form.linkkey'};
                   1097:):         }
                   1098:):         my $token = &Apache::lonnet::tmpput(\%link_info,$desthost,'link');
                   1099:):         unless (($token eq 'con_lost') || ($token eq 'refused') ||
                   1100:):                 ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
                   1101:):             $url .= (($url=~/\?/)?'&amp;':'?') . 'ttoken='.$token;
                   1102:):         }
                   1103:):     }
1.136     raeburn  1104:     my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
1.126     raeburn  1105:                                                     {'redirect' => [0,$url],});
                   1106:     my $end_page   = &Apache::loncommon::end_page();
                   1107:     return $start_page.$end_page;
                   1108: }
                   1109: 
1.60      raeburn  1110: sub contactdisplay {
1.153     raeburn  1111:     my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
                   1112:         $possdoms) = @_;
1.60      raeburn  1113:     my $contactblock;
1.153     raeburn  1114:     my $origmail;
                   1115:     if (ref($possdoms) eq 'ARRAY') {
                   1116:         if (grep(/^\Q$authdomain\E$/,@{$possdoms})) { 
                   1117:             $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   1118:         }
                   1119:     }
                   1120:     my $requestmail = 
                   1121:         &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
                   1122:                                                  $authdomain,$origmail);
1.154     raeburn  1123:     unless ($showhelpdesk eq '0') {
                   1124:         if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
                   1125:             $showhelpdesk = 1;
                   1126:         } else {
1.153     raeburn  1127:             $showhelpdesk = 0;
                   1128:         }
1.62      raeburn  1129:     }
1.90      raeburn  1130:     if ($servadm && $showadminmail) {
1.130     bisitz   1131:         $contactblock .= $$lt{'servadm'}.':<br />'.
                   1132:                          '<tt>'.$servadm.'</tt><br />';
1.90      raeburn  1133:     }
1.60      raeburn  1134:     if ($showhelpdesk) {
1.114     tempelho 1135:         $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
1.75      www      1136:         my $thisurl = &escape('/adm/login');
1.62      raeburn  1137:         $$helpdeskscript = <<"ENDSCRIPT";
                   1138: <script type="text/javascript">
1.122     bisitz   1139: // <![CDATA[
1.62      raeburn  1140: function helpdesk() {
1.155     raeburn  1141:     var possdom = document.client.udom.value;
                   1142:     var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
1.62      raeburn  1143:     if (codedom == '') {
                   1144:         codedom = "$authdomain";
                   1145:     }
                   1146:     var querystr = "origurl=$thisurl&codedom="+codedom;
                   1147:     document.location.href = "/adm/helpdesk?"+querystr;
                   1148:     return;
                   1149: }
1.122     bisitz   1150: // ]]>
1.62      raeburn  1151: </script>
                   1152: ENDSCRIPT
1.60      raeburn  1153:     }
                   1154:     return $contactblock;
                   1155: }
1.83      raeburn  1156: 
                   1157: sub forgotpwdisplay {
1.84      raeburn  1158:     my (%lt) = @_;
1.83      raeburn  1159:     my $prompt_for_resetpw = 1; 
                   1160:     if ($prompt_for_resetpw) {
1.107     tempelho 1161:         return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
1.84      raeburn  1162:     }
                   1163:     return;
                   1164: }
                   1165: 
1.90      raeburn  1166: sub coursecatalog_link {
                   1167:     my ($linkname) = @_;
                   1168:     return <<"END";
1.137     bisitz   1169:       <a href="/adm/coursecatalog">$linkname</a>
1.90      raeburn  1170: END
                   1171: }
                   1172: 
1.101     raeburn  1173: sub newuser_link {
                   1174:     my ($linkname) = @_;
1.130     bisitz   1175:     return '<a href="/adm/createaccount">'.$linkname.'</a>';
1.101     raeburn  1176: }
                   1177: 
1.158.2.13  raeburn  1178: sub decode_token {
                   1179:     my ($info) = @_;
                   1180:     my ($firsturl,@rest)=split(/\&/,$info);
                   1181:     my %form;
                   1182:     if ($firsturl ne '') {
                   1183:         $form{'firsturl'} = &unescape($firsturl);
                   1184:     }
                   1185:     foreach my $item (@rest) {
                   1186:         my ($key,$value) = split(/=/,$item);
                   1187:         $form{$key} = &unescape($value);
                   1188:     }
                   1189:     return %form;
                   1190: }
                   1191: 
1.1       albertel 1192: 1;
                   1193: __END__

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