File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.188: download - view: text, annotated - select for diffs
Wed Oct 6 19:28:55 2021 UTC (2 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Use URI::Escape to encode firsturl in query string, and only use
  HTML::Entities for single quotes.

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

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