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

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

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