File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.158.2.7: download - view: text, annotated - select for diffs
Tue Sep 4 01:10:29 2018 UTC (5 years, 8 months ago) by raeburn
Branches: version_2_11_X
Diff to branchpoint 1.158: preferred, unified
- For 2.11
  Backport 1.169, 1.170 (modified), 1.171.

    1: # The LearningOnline Network
    2: # Login Screen
    3: #
    4: # $Id: lonlogin.pm,v 1.158.2.7 2018/09/04 01:10:29 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    => 'lonID',
   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: this.document.server.elements.upass0.value
  392:     =getCrypted(this.document.client.elements.upass$now.value);
  393: 
  394: this.document.client.elements.uname.value='';
  395: this.document.client.elements.upass$now.value='';
  396: 
  397: this.document.server.submit();
  398: return false;
  399: }
  400: 
  401: function enableInput() {
  402:     this.document.client.elements.upass$now.removeAttribute("readOnly");
  403:     this.document.client.elements.uname.removeAttribute("readOnly");
  404:     this.document.client.elements.udom.removeAttribute("readOnly");
  405:     return;
  406: }
  407: 
  408: // ]]>
  409: </script>
  410: 
  411: ENDSCRIPT
  412: 
  413: # --------------------------------------------------- Print login screen header
  414: 
  415:     my %add_entries = (
  416: 	       bgcolor      => "$mainbg",
  417: 	       text         => "$font",
  418: 	       link         => "$link",
  419: 	       vlink        => "$vlink",
  420: 	       alink        => "$alink",
  421:                onload       => 'javascript:enableInput();',);
  422: 
  423:     my ($lonhost_in_use,$headextra,$headextra_exempt,@hosts,%defaultdomconf);
  424:     @hosts = &Apache::lonnet::current_machine_ids();
  425:     $lonhost_in_use = $lonhost;
  426:     if (@hosts > 1) {
  427:         foreach my $hostid (@hosts) {
  428:             if (&Apache::lonnet::host_domain($hostid) eq $defdom) {
  429:                 $lonhost_in_use = $hostid;
  430:                 last;
  431:             }
  432:         }
  433:     }
  434:     %defaultdomconf = &Apache::loncommon::get_domainconf($defdom);
  435:     $headextra = $defaultdomconf{$defdom.'.login.headtag_'.$lonhost_in_use};
  436:     $headextra_exempt = $defaultdomconf{$domain.'.login.headtag_exempt_'.$lonhost_in_use};
  437:     if ($headextra) {
  438:         my $omitextra;
  439:         if ($headextra_exempt ne '') {
  440:             my @exempt = split(',',$headextra_exempt);
  441:             my $ip = $ENV{'REMOTE_ADDR'};
  442:             if (grep(/^\Q$ip\E$/,@exempt)) {
  443:                 $omitextra = 1;
  444:             }
  445:         }
  446:         unless ($omitextra) {
  447:             my $confname = $defdom.'-domainconfig';
  448:             if ($headextra =~ m{^\Q/res/$defdom/$confname/login/headtag/$lonhost_in_use/\E}) {
  449:                 my $extra = &Apache::lonnet::getfile(&Apache::lonnet::filelocation("",$headextra));
  450:                 unless ($extra eq '-1') {
  451:                     $js .= "\n".$extra."\n";
  452:                 }
  453:             }
  454:         }
  455:     }
  456: 
  457:     $r->print(&Apache::loncommon::start_page('The LearningOnline Network with CAPA Login',$js,
  458: 			       { 'redirect'       => [$expire,'/adm/roles'], 
  459: 				 'add_entries' => \%add_entries,
  460: 				 'only_body'   => 1,}));
  461: 
  462: # ----------------------------------------------------------------------- Texts
  463: 
  464:     my %lt=&Apache::lonlocal::texthash(
  465:           'un'       => 'Username',
  466:           'pw'       => 'Password',
  467:           'dom'      => 'Domain',
  468:           'perc'     => 'percent',
  469:           'load'     => 'Server Load',
  470:           'userload' => 'User Load',
  471:           'catalog'  => 'Course/Community Catalog',
  472:           'log'      => 'Log in',
  473:           'help'     => 'Log-in Help',
  474:           'serv'     => 'Server',
  475:           'servadm'  => 'Server Administration',
  476:           'helpdesk' => 'Contact Helpdesk',
  477:           'forgotpw' => 'Forgot password?',
  478:           'newuser'  => 'New User?',
  479:        );
  480: # -------------------------------------------------- Change password field name
  481: 
  482:     my $forgotpw = &forgotpwdisplay(%lt);
  483:     $forgotpw .= '<br />' if $forgotpw;
  484:     my $loginhelp = &Apache::lonauth::loginhelpdisplay($authdomain);
  485:     if ($loginhelp) {
  486:         $loginhelp = '<a href="'.$loginhelp.'">'.$lt{'help'}.'</a><br />';
  487:     }
  488: 
  489: # ---------------------------------------------------- Serve out DES JavaScript
  490:     {
  491:     my $jsh=Apache::File->new($include."/londes.js");
  492:     $r->print(<$jsh>);
  493:     }
  494: # ---------------------------------------------------------- Serve rest of page
  495: 
  496:     $r->print(
  497:     '<div class="LC_Box"'
  498:    .' style="margin:0 auto; padding:10px; width:90%; height: auto; background-color:#FFFFFF;">'
  499: );
  500: 
  501:     $r->print(<<ENDSERVERFORM);
  502: <form name="server" action="/adm/authenticate" method="post" target="_top">
  503:    <input type="hidden" name="logtoken" value="$logtoken" />
  504:    <input type="hidden" name="serverid" value="$lonhost" />
  505:    <input type="hidden" name="uname" value="" />
  506:    <input type="hidden" name="upass0" value="" />
  507:    <input type="hidden" name="udom" value="" />
  508:    <input type="hidden" name="localpath" value="$env{'form.localpath'}" />
  509:    <input type="hidden" name="localres" value="$env{'form.localres'}" />
  510:   </form>
  511: ENDSERVERFORM
  512:     my $coursecatalog;
  513:     if (($showcoursecat eq '') || ($showcoursecat)) {
  514:         $coursecatalog = &coursecatalog_link($lt{'catalog'}).'<br />';
  515:     }
  516:     my $newuserlink;
  517:     if ($shownewuserlink) {
  518:         $newuserlink = &newuser_link($lt{'newuser'}).'<br />';
  519:     }
  520:     my $logintitle =
  521:         '<h2 class="LC_hcell"'
  522:        .' style="background:'.$loginbox_header_bgcol.';'
  523:        .' color:'.$loginbox_header_textcol.'">'
  524:        .$lt{'log'}
  525:        .'</h2>';
  526: 
  527:     my $noscript_warning='<noscript><span class="LC_warning"><b>'
  528:                         .&mt('Use of LON-CAPA requires Javascript to be enabled in your web browser.')
  529:                         .'</b></span></noscript>';
  530:     my $helpdeskscript;
  531:     my $contactblock = &contactdisplay(\%lt,$servadm,$showadminmail,
  532:                                        $authdomain,\$helpdeskscript,
  533:                                        $showhelpdesk,\@possdoms);
  534: 
  535:     my $mobileargs;
  536:     if ($clientmobile) {
  537:         $mobileargs = 'autocapitalize="off" autocorrect="off"'; 
  538:     }
  539:     my $loginform=(<<LFORM);
  540: <form name="client" action="" onsubmit="return(send())">
  541:   <input type="hidden" name="lextkey" value="$lextkey" />
  542:   <input type="hidden" name="uextkey" value="$uextkey" />
  543:   <b><label for="uname">$lt{'un'}</label>:</b><br />
  544:   <input type="text" name="uname" id="uname" size="15" value="$authusername" readonly="readonly" $mobileargs /><br />
  545:   <b><label for="upass$now">$lt{'pw'}</label>:</b><br />
  546:   <input type="password" name="upass$now" id="upass$now" size="15" readonly="readonly" /><br />
  547:   <b><label for="udom">$lt{'dom'}</label>:</b><br />
  548:   <input type="text" name="udom" id="udom" size="15" value="$authdomain" readonly="readonly" $mobileargs /><br />
  549:   <input type="submit" value="$lt{'log'}" />
  550: </form>
  551: LFORM
  552: 
  553:     if ($showbanner) {
  554:         $r->print(<<HEADER);
  555: <!-- The LON-CAPA Header -->
  556: <div style="background:$pgbg;margin:0;width:100%;">
  557:   <img src="$img" border="0" alt="The Learning Online Network with CAPA" class="LC_maxwidth" />
  558: </div>
  559: HEADER
  560:     }
  561:     $r->print(<<ENDTOP);
  562: <div style="float:left;margin-top:0;">
  563: <div class="LC_Box" style="background:$loginbox_bg;">
  564:   $logintitle
  565:   $loginform
  566:   $noscript_warning
  567: </div>
  568:   
  569: <div class="LC_Box" style="padding-top: 10px;">
  570:   $loginhelp
  571:   $forgotpw
  572:   $contactblock
  573:   $newuserlink
  574:   $coursecatalog
  575: </div>
  576: </div>
  577: 
  578: <div>
  579: ENDTOP
  580:     if ($showmainlogo) {
  581:         $r->print(' <img src="'.$logo.'" alt="" class="LC_maxwidth" />'."\n");
  582:     }
  583: $r->print(<<ENDTOP);
  584: $announcements
  585: </div>
  586: <hr style="clear:both;" />
  587: ENDTOP
  588:     my ($domainrow,$serverrow,$loadrow,$userloadrow,$versionrow);
  589:     $domainrow = <<"END";
  590:       <tr>
  591:        <td  align="left" valign="top">
  592:         <small><b>$lt{'dom'}:&nbsp;</b></small>
  593:        </td>
  594:        <td  align="left" valign="top">
  595:         <small><tt>&nbsp;$domain</tt></small>
  596:        </td>
  597:       </tr>
  598: END
  599:     $serverrow = <<"END";
  600:       <tr>
  601:        <td  align="left" valign="top">
  602:         <small><b>$lt{'serv'}:&nbsp;</b></small>
  603:        </td>
  604:        <td align="left" valign="top">
  605:         <small><tt>&nbsp;$lonhost ($role)</tt></small>
  606:        </td>
  607:       </tr>
  608: END
  609:     if ($loadlim) {
  610:         $loadrow = <<"END";
  611:       <tr>
  612:        <td align="left" valign="top">
  613:         <small><b>$lt{'load'}:&nbsp;</b></small>
  614:        </td>
  615:        <td align="left" valign="top">
  616:         <small><tt>&nbsp;$loadpercent $lt{'perc'}</tt></small>
  617:        </td>
  618:       </tr>
  619: END
  620:     }
  621:     if ($uloadlim) {
  622:         $userloadrow = <<"END";
  623:       <tr>
  624:        <td align="left" valign="top">
  625:         <small><b>$lt{'userload'}:&nbsp;</b></small>
  626:        </td>
  627:        <td align="left" valign="top">
  628:         <small><tt>&nbsp;$userloadpercent $lt{'perc'}</tt></small>
  629:        </td>
  630:       </tr>
  631: END
  632:     }
  633:     if (($version ne '') && ($version ne '<!-- VERSION -->')) {
  634:         $versionrow = <<"END";
  635:       <tr>
  636:        <td colspan="2" align="left">
  637:         <small>$version</small>
  638:        </td>
  639:       </tr>
  640: END
  641:     }
  642: 
  643:     $r->print(<<ENDDOCUMENT);
  644:     <div style="float: left;">
  645:      <table border="0" cellspacing="0" cellpadding="0">
  646: $domainrow
  647: $serverrow
  648: $loadrow    
  649: $userloadrow
  650: $versionrow
  651:      </table>
  652:     </div>
  653:     <div style="float: right;">
  654:     $domainlogo
  655:     </div>
  656:     <br style="clear:both;" />
  657:  </div>
  658: 
  659: <script type="text/javascript">
  660: // <![CDATA[
  661: // the if prevents the script error if the browser can not handle this
  662: if ( document.client.uname ) { document.client.uname.focus(); }
  663: // ]]>
  664: </script>
  665: $helpdeskscript
  666: 
  667: ENDDOCUMENT
  668:     my %endargs = ( 'noredirectlink' => 1, );
  669:     $r->print(&Apache::loncommon::end_page(\%endargs));
  670:     return OK;
  671: }
  672: 
  673: sub check_loginvia {
  674:     my ($domain,$lonhost) = @_;
  675:     if ($domain eq '' || $lonhost eq '') {
  676:         return;
  677:     }
  678:     my %domconfhash = &Apache::loncommon::get_domainconf($domain);
  679:     my $loginvia = $domconfhash{$domain.'.login.loginvia_'.$lonhost};
  680:     my $loginvia_exempt = $domconfhash{$domain.'.login.loginvia_exempt_'.$lonhost};
  681:     my $output;
  682:     if ($loginvia ne '') {
  683:         my $noredirect;
  684:         my $ip = $ENV{'REMOTE_ADDR'};
  685:         if ($ip eq '127.0.0.1') {
  686:             $noredirect = 1;
  687:         } else {
  688:             if ($loginvia_exempt ne '') {
  689:                 my @exempt = split(',',$loginvia_exempt);
  690:                 if (grep(/^\Q$ip\E$/,@exempt)) {
  691:                     $noredirect = 1;
  692:                 }
  693:             }
  694:         }
  695:         unless ($noredirect) {
  696:             my ($newhost,$path);
  697:             if ($loginvia =~ /:/) {
  698:                 ($newhost,$path) = split(':',$loginvia);
  699:             } else {
  700:                 $newhost = $loginvia;
  701:             }
  702:             if ($newhost ne $lonhost) {
  703:                 if (&Apache::lonnet::hostname($newhost) ne '') {
  704:                     $output = &redirect_page($newhost,$path);
  705:                 }
  706:             }
  707:         }
  708:     }
  709:     return $output;
  710: }
  711: 
  712: sub redirect_page {
  713:     my ($desthost,$path) = @_;
  714:     my $protocol = $Apache::lonnet::protocol{$desthost};
  715:     $protocol = 'http' if ($protocol ne 'https');
  716:     unless ($path =~ m{^/}) {
  717:         $path = '/'.$path;
  718:     }
  719:     my $url = $protocol.'://'.&Apache::lonnet::hostname($desthost).$path;
  720:     if ($env{'form.firsturl'} ne '') {
  721:         $url .='?firsturl='.$env{'form.firsturl'};
  722:     }
  723:     my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
  724:                                                     {'redirect' => [0,$url],});
  725:     my $end_page   = &Apache::loncommon::end_page();
  726:     return $start_page.$end_page;
  727: }
  728: 
  729: sub contactdisplay {
  730:     my ($lt,$servadm,$showadminmail,$authdomain,$helpdeskscript,$showhelpdesk,
  731:         $possdoms) = @_;
  732:     my $contactblock;
  733:     my $origmail;
  734:     if (ref($possdoms) eq 'ARRAY') {
  735:         if (grep(/^\Q$authdomain\E$/,@{$possdoms})) { 
  736:             $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
  737:         }
  738:     }
  739:     my $requestmail = 
  740:         &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
  741:                                                  $authdomain,$origmail);
  742:     unless ($showhelpdesk eq '0') {
  743:         if ($requestmail =~ m/[^\@]+\@[^\@]+/) {
  744:             $showhelpdesk = 1;
  745:         } else {
  746:             $showhelpdesk = 0;
  747:         }
  748:     }
  749:     if ($servadm && $showadminmail) {
  750:         $contactblock .= $$lt{'servadm'}.':<br />'.
  751:                          '<tt>'.$servadm.'</tt><br />';
  752:     }
  753:     if ($showhelpdesk) {
  754:         $contactblock .= '<a href="javascript:helpdesk()">'.$lt->{'helpdesk'}.'</a><br />';
  755:         my $thisurl = &escape('/adm/login');
  756:         $$helpdeskscript = <<"ENDSCRIPT";
  757: <script type="text/javascript">
  758: // <![CDATA[
  759: function helpdesk() {
  760:     var possdom = document.client.udom.value;
  761:     var codedom = possdom.replace( new RegExp("[^A-Za-z0-9.\\-]","g"),'');
  762:     if (codedom == '') {
  763:         codedom = "$authdomain";
  764:     }
  765:     var querystr = "origurl=$thisurl&codedom="+codedom;
  766:     document.location.href = "/adm/helpdesk?"+querystr;
  767:     return;
  768: }
  769: // ]]>
  770: </script>
  771: ENDSCRIPT
  772:     }
  773:     return $contactblock;
  774: }
  775: 
  776: sub forgotpwdisplay {
  777:     my (%lt) = @_;
  778:     my $prompt_for_resetpw = 1; 
  779:     if ($prompt_for_resetpw) {
  780:         return '<a href="/adm/resetpw">'.$lt{'forgotpw'}.'</a>';
  781:     }
  782:     return;
  783: }
  784: 
  785: sub coursecatalog_link {
  786:     my ($linkname) = @_;
  787:     return <<"END";
  788:       <a href="/adm/coursecatalog">$linkname</a>
  789: END
  790: }
  791: 
  792: sub newuser_link {
  793:     my ($linkname) = @_;
  794:     return '<a href="/adm/createaccount">'.$linkname.'</a>';
  795: }
  796: 
  797: 1;
  798: __END__

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