File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.158.2.6.2.1: download - view: text, annotated - select for diffs
Sat Oct 14 20:59:35 2017 UTC (6 years, 7 months ago) by raeburn
Branches: version_2_11_2_msu
Diff to branchpoint 1.158.2.6: preferred, unified
- For 2.11.2 (modified)
  Include changes in 1.169, 1.170 (modified), 1.171.

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

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