File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.171: download - view: text, annotated - select for diffs
Mon Sep 25 00:36:30 2017 UTC (6 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- When browser sends a LON-CAPA cookie for an expired session, redirect user
  to portal URL for user's domain for re-authentication.

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

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