File:  [LON-CAPA] / loncom / auth / lonlogin.pm
Revision 1.158.2.6.2.3: download - view: text, annotated - select for diffs
Wed Feb 6 17:32:59 2019 UTC (5 years, 3 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.172

    1: # The LearningOnline Network
    2: # Login Screen
    3: #
    4: # $Id: lonlogin.pm,v 1.158.2.6.2.3 2019/02/06 17:32:59 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:     if (!defined($env{'form.firsturl'})) {
   55:         if ($ENV{'REDIRECT_URL'} =~ m{^/+tiny/+$LONCAPA::match_domain/+\w+$}) {
   56:             $env{'form.firsturl'} = $ENV{'REDIRECT_URL'};
   57:         }
   58:     }
   59: 
   60: # -- check if they are a migrating user
   61:     if (defined($env{'form.token'})) {
   62: 	return &Apache::migrateuser::handler($r);
   63:     }
   64: 
   65: # For "public user" - remove any exising "public" cookie, as user really wants to log-in
   66:     my ($handle,$lonidsdir,$expirepub,$userdom);
   67:     unless ($r->header_only) {
   68:         $handle = &Apache::lonnet::check_for_valid_session($r,'lonID',undef,\$userdom);
   69:         if ($handle ne '') {
   70:             $lonidsdir=$r->dir_config('lonIDsDir');
   71:             if ($handle=~/^publicuser\_/) {
   72:                 unlink($r->dir_config('lonIDsDir')."/$handle.id");
   73:                 undef($handle);
   74:                 undef($userdom);
   75:                 $expirepub = 1;
   76:             }
   77:         }
   78:     }
   79: 
   80:     &Apache::loncommon::no_cache($r);
   81:     &Apache::lonlocal::get_language_handle($r);
   82:     &Apache::loncommon::content_type($r,'text/html');
   83:     if ($expirepub) {
   84:         my $c = new CGI::Cookie(-name    => 'lonID',
   85:                                 -value   => '',
   86:                                 -expires => '-10y',);
   87:         $r->header_out('Set-cookie' => $c);
   88:     } elsif (($handle eq '') && ($userdom ne '')) {
   89:         my $c = new CGI::Cookie(-name    => 'lonID',
   90:                                 -value   => '',
   91:                                 -expires => '-10y',);
   92:         $r->headers_out->add('Set-cookie' => $c);
   93:     }
   94:     $r->send_http_header;
   95:     return OK if $r->header_only;
   96: 
   97: 
   98: # Are we re-routing?
   99:     my $londocroot = $r->dir_config('lonDocRoot'); 
  100:     if (-e "$londocroot/lon-status/reroute.txt") {
  101: 	&Apache::lonauth::reroute($r);
  102: 	return OK;
  103:     }
  104: 
  105: #
  106: # If browser sent an old cookie for which the session file had been removed
  107: # check if configuration for user's domain has a portal URL set.  If so
  108: # switch user's log-in to the portal.
  109: #
  110: 
  111:     if (($handle eq '') && ($userdom ne '')) {
  112:         my %domdefaults = &Apache::lonnet::get_domain_defaults($userdom);
  113:         if ($domdefaults{'portal_def'} =~ /^https?\:/) {
  114:             my $start_page = &Apache::loncommon::start_page('Switching Server ...',undef,
  115:                                           {'redirect' => [0,$domdefaults{'portal_def'}],});
  116:             my $end_page   = &Apache::loncommon::end_page();
  117:             $r->print($start_page.$end_page);
  118:             return OK;
  119:         }
  120:     }
  121: 
  122:     $env{'form.firsturl'} =~ s/(`)/'/g;
  123: 
  124: # -------------------------------- Prevent users from attempting to login twice
  125:     if ($handle ne '') {
  126:         &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
  127: 	my $start_page = 
  128: 	    &Apache::loncommon::start_page('Already logged in');
  129: 	my $end_page = 
  130: 	    &Apache::loncommon::end_page();
  131:         my $dest = '/adm/roles';
  132:         if ($env{'form.firsturl'} ne '') {
  133:             $dest = $env{'form.firsturl'}; 
  134:         }
  135: 	$r->print(
  136:               $start_page
  137:              .'<p class="LC_warning">'.&mt('You are already logged in!').'</p>'
  138:              .'<p>'.&mt('Please either [_1]continue the current session[_2] or [_3]log out[_4].',
  139:               '<a href="'.$dest.'">','</a>','<a href="/adm/logout">','</a>').'</p>'
  140:              .$end_page
  141:              );
  142:         return OK;
  143:     }
  144: 
  145: # ---------------------------------------------------- No valid token, continue
  146: 
  147: # ---------------------------- Not possible to really login to domain "public"
  148:     if ($env{'form.domain'} eq 'public') {
  149: 	$env{'form.domain'}='';
  150: 	$env{'form.username'}='';
  151:     }
  152: 
  153: # ------ Is this page requested because /adm/migrateuser detected an IP change?
  154:     my %sessiondata;
  155:     if ($env{'form.iptoken'}) {
  156:         %sessiondata = &Apache::lonnet::tmpget($env{'form.iptoken'});
  157:         unless ($sessiondata{'sessionserver'}) {
  158:             my $delete = &Apache::lonnet::tmpdel($env{'form.iptoken'});
  159:             delete($env{'form.iptoken'});
  160:         }
  161:     }
  162: # ----------------------------------------------------------- Process Interface
  163:     $env{'form.interface'}=~s/\W//g;
  164: 
  165:     (undef,undef,undef,undef,undef,undef,my $clientmobile) =
  166:         &Apache::loncommon::decode_user_agent();
  167: 
  168:     my $iconpath= 
  169: 	&Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
  170: 
  171:     my $lonhost = $r->dir_config('lonHostID');
  172:     my $domain = &Apache::lonnet::default_login_domain();
  173:     my $defdom = $domain;
  174:     if ($lonhost ne '') {
  175:         unless ($sessiondata{'sessionserver'}) {
  176:             my $redirect = &check_loginvia($domain,$lonhost);
  177:             if ($redirect) {
  178:                 $r->print($redirect);
  179:                 return OK;
  180:             }
  181:         }
  182:     }
  183: 
  184:     if (($sessiondata{'domain'}) &&
  185:         (&Apache::lonnet::domain($env{'form.domain'},'description'))) {
  186:         $domain=$sessiondata{'domain'};
  187:     } elsif (($env{'form.domain'}) && 
  188: 	(&Apache::lonnet::domain($env{'form.domain'},'description'))) {
  189: 	$domain=$env{'form.domain'};
  190:     }
  191: 
  192:     my $role    = $r->dir_config('lonRole');
  193:     my $loadlim = $r->dir_config('lonLoadLim');
  194:     my $uloadlim= $r->dir_config('lonUserLoadLim');
  195:     my $servadm = $r->dir_config('lonAdmEMail');
  196:     my $tabdir  = $r->dir_config('lonTabDir');
  197:     my $include = $r->dir_config('lonIncludes');
  198:     my $expire  = $r->dir_config('lonExpire');
  199:     my $version = $r->dir_config('lonVersion');
  200:     my $host_name = &Apache::lonnet::hostname($lonhost);
  201: 
  202: # --------------------------------------------- Default values for login fields
  203:     
  204:     my ($authusername,$authdomain);
  205:     if ($sessiondata{'username'}) {
  206:         $authusername=$sessiondata{'username'};
  207:     } else {
  208:         $env{'form.username'} = &Apache::loncommon::cleanup_html($env{'form.username'});
  209:         $authusername=($env{'form.username'}?$env{'form.username'}:'');
  210:     }
  211:     if ($sessiondata{'domain'}) {
  212:         $authdomain=$sessiondata{'domain'};
  213:     } else {
  214:         $env{'form.domain'} = &Apache::loncommon::cleanup_html($env{'form.domain'});
  215:         $authdomain=($env{'form.domain'}?$env{'form.domain'}:$domain);
  216:     }
  217: 
  218: # ---------------------------------------------------------- Determine own load
  219:     my $loadavg;
  220:     {
  221: 	my $loadfile=Apache::File->new('/proc/loadavg');
  222: 	$loadavg=<$loadfile>;
  223:     }
  224:     $loadavg =~ s/\s.*//g;
  225: 
  226:     my ($loadpercent,$userloadpercent);
  227:     if ($loadlim) {
  228:         $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
  229:     }
  230:     if ($uloadlim) {
  231:         $userloadpercent=&Apache::lonnet::userload();
  232:     }
  233: 
  234:     my $firsturl=
  235:     ($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
  236: 
  237: # ----------------------------------------------------------- Get announcements
  238:     my $announcements=&Apache::lonnet::getannounce();
  239: # -------------------------------------------------------- Set login parameters
  240: 
  241:     my @hexstr=('0','1','2','3','4','5','6','7',
  242:                 '8','9','a','b','c','d','e','f');
  243:     my $lkey='';
  244:     for (0..7) {
  245:         $lkey.=$hexstr[rand(15)];
  246:     }
  247: 
  248:     my $ukey='';
  249:     for (0..7) {
  250:         $ukey.=$hexstr[rand(15)];
  251:     }
  252: 
  253:     my $lextkey=hex($lkey);
  254:     if ($lextkey>2147483647) { $lextkey-=4294967296; }
  255: 
  256:     my $uextkey=hex($ukey);
  257:     if ($uextkey>2147483647) { $uextkey-=4294967296; }
  258: 
  259: # -------------------------------------------------------- Store away log token
  260:     my $tokenextras;
  261:     if ($env{'form.role'}) {
  262:         $tokenextras = '&role='.&escape($env{'form.role'});
  263:     }
  264:     if ($env{'form.symb'}) {
  265:         if (!$tokenextras) {
  266:             $tokenextras = '&';
  267:         }
  268:         $tokenextras .= '&symb='.&escape($env{'form.symb'});
  269:     }
  270:     if ($env{'form.iptoken'}) {
  271:         if (!$tokenextras) {
  272:             $tokenextras = '&&';
  273:         }
  274:         $tokenextras .= '&iptoken='.&escape($env{'form.iptoken'});
  275:     }
  276:     my $logtoken=Apache::lonnet::reply(
  277:        'tmpput:'.$ukey.$lkey.'&'.$firsturl.$tokenextras,
  278:        $lonhost);
  279: 
  280: # -- If we cannot talk to ourselves, or hostID does not map to a hostname
  281: #    we are in serious trouble
  282: 
  283:     if (($logtoken eq 'con_lost') || ($logtoken eq 'no_such_host')) {
  284:         if ($logtoken eq 'no_such_host') {
  285:             &Apache::lonnet::logthis('No valid logtoken for log-in page -- unable to determine hostname for hostID: '.$lonhost.'. Check entry in hosts.tab');
  286:         }
  287:         my $spares='';
  288: 	my $last;
  289:         foreach my $hostid (sort
  290: 			    {
  291: 				&Apache::lonnet::hostname($a) cmp
  292: 				    &Apache::lonnet::hostname($b);
  293: 			    }
  294: 			    keys(%Apache::lonnet::spareid)) {
  295:             next if ($hostid eq $lonhost);
  296: 	    my $hostname = &Apache::lonnet::hostname($hostid);
  297: 	    next if (($last eq $hostname) || ($hostname eq ''));
  298:             $spares.='<br /><font size="+1"><a href="http://'.
  299:                 $hostname.
  300:                 '/adm/login?domain='.$authdomain.'">'.
  301:                 $hostname.'</a>'.
  302:                 ' '.&mt('(preferred)').'</font>'.$/;
  303: 	    $last=$hostname;
  304:         }
  305:         if ($spares) {
  306:             $spares.= '<br />';
  307:         }
  308:         my %all_hostnames = &Apache::lonnet::all_hostnames();
  309:         foreach my $hostid (sort
  310: 		    {
  311: 			&Apache::lonnet::hostname($a) cmp
  312: 			    &Apache::lonnet::hostname($b);
  313: 		    }
  314: 		    keys(%all_hostnames)) {
  315:             next if ($hostid eq $lonhost || $Apache::lonnet::spareid{$hostid});
  316:             my $hostname = &Apache::lonnet::hostname($hostid);
  317:             next if (($last eq $hostname) || ($hostname eq ''));
  318:             $spares.='<br /><a href="http://'.
  319: 	             $hostname.
  320: 	             '/adm/login?domain='.$authdomain.'">'.
  321: 	             $hostname.'</a>';
  322:             $last=$hostname;
  323:          }
  324:          $r->print(
  325:    '<html>'
  326:   .'<head><title>'
  327:   .&mt('The LearningOnline Network with CAPA')
  328:   .'</title></head>'
  329:   .'<body bgcolor="#FFFFFF">'
  330:   .'<h1>'.&mt('The LearningOnline Network with CAPA').'</h1>'
  331:   .'<img src="/adm/lonKaputt/lonlogo_broken.gif" align="right" />'
  332:   .'<h3>'.&mt('This LON-CAPA server is temporarily not available for login.').'</h3>');
  333:         if ($spares) {
  334:             $r->print('<p>'.&mt('Please attempt to login to one of the following servers:')
  335:                      .'</p>'
  336:                      .$spares);
  337:         }
  338:         $r->print('</body>'
  339:                  .'</html>'
  340:         );
  341:         return OK;
  342:     }
  343: 
  344: # ----------------------------------------------- Apparently we are in business
  345:     $servadm=~s/\,/\<br \/\>/g;
  346: 
  347: # ----------------------------------------------------------- Front page design
  348:     my $pgbg=&Apache::loncommon::designparm('login.pgbg',$domain);
  349:     my $font=&Apache::loncommon::designparm('login.font',$domain);
  350:     my $link=&Apache::loncommon::designparm('login.link',$domain);
  351:     my $vlink=&Apache::loncommon::designparm('login.vlink',$domain);
  352:     my $alink=&Apache::loncommon::designparm('login.alink',$domain);
  353:     my $mainbg=&Apache::loncommon::designparm('login.mainbg',$domain);
  354:     my $loginbox_bg=&Apache::loncommon::designparm('login.sidebg',$domain);
  355:     my $loginbox_header_bgcol=&Apache::loncommon::designparm('login.bgcol',$domain);
  356:     my $loginbox_header_textcol=&Apache::loncommon::designparm('login.textcol',$domain);
  357:     my $logo=&Apache::loncommon::designparm('login.logo',$domain);
  358:     my $img=&Apache::loncommon::designparm('login.img',$domain);
  359:     my $domainlogo=&Apache::loncommon::domainlogo($domain);
  360:     my $showbanner = 1;
  361:     my $showmainlogo = 1;
  362:     if (defined(&Apache::loncommon::designparm('login.showlogo_img',$domain))) {
  363:         $showbanner = &Apache::loncommon::designparm('login.showlogo_img',$domain);
  364:     }
  365:     if (defined(&Apache::loncommon::designparm('login.showlogo_logo',$domain))) {
  366:         $showmainlogo = &Apache::loncommon::designparm('login.showlogo_logo',$domain);
  367:     }
  368:     my $showadminmail;
  369:     my @possdoms = &Apache::lonnet::current_machine_domains();
  370:     if (grep(/^\Q$domain\E$/,@possdoms)) {
  371:         $showadminmail=&Apache::loncommon::designparm('login.adminmail',$domain);
  372:     }
  373:     my $showcoursecat =
  374:         &Apache::loncommon::designparm('login.coursecatalog',$domain);
  375:     my $shownewuserlink = 
  376:         &Apache::loncommon::designparm('login.newuser',$domain);
  377:     my $showhelpdesk =
  378:         &Apache::loncommon::designparm('login.helpdesk',$domain);
  379:     my $now=time;
  380:     my $js = (<<ENDSCRIPT);
  381: 
  382: <script type="text/javascript" language="JavaScript">
  383: // <![CDATA[
  384: function send()
  385: {
  386: this.document.server.elements.uname.value
  387: =this.document.client.elements.uname.value;
  388: 
  389: this.document.server.elements.udom.value
  390: =this.document.client.elements.udom.value;
  391: 
  392: uextkey=this.document.client.elements.uextkey.value;
  393: lextkey=this.document.client.elements.lextkey.value;
  394: initkeys();
  395: 
  396: this.document.server.elements.upass0.value
  397:     =getCrypted(this.document.client.elements.upass$now.value);
  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>