File:  [LON-CAPA] / doc / loncapafiles / updatequery.piml
Revision 1.50: download - view: text, annotated - select for diffs
Thu Sep 28 22:52:43 2006 UTC (17 years, 7 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_2_X, version_2_2_2, HEAD
Some SuSE 10.1 additions.

    1: <!-- updatequery.piml -->
    2: 
    3: <!-- $Id: updatequery.piml,v 1.50 2006/09/28 22:52:43 raeburn Exp $ -->
    4: 
    5: <!--
    6: 
    7: This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    8: 
    9: LON-CAPA is free software; you can redistribute it and/or modify
   10: it under the terms of the GNU General Public License as published by
   11: the Free Software Foundation; either version 2 of the License, or
   12: (at your option) any later version.
   13: 
   14: LON-CAPA is distributed in the hope that it will be useful,
   15: but WITHOUT ANY WARRANTY; without even the implied warranty of
   16: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17: GNU General Public License for more details.
   18: 
   19: You should have received a copy of the GNU General Public License
   20: along with LON-CAPA; if not, write to the Free Software
   21: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   22: 
   23: /home/httpd/html/adm/gpl.txt
   24: 
   25: http://www.lon-capa.org/
   26: 
   27: -->
   28: 
   29: <piml>
   30: <targetroot>/</targetroot>
   31: <files>
   32: <file>
   33: <target dist='default'>/</target>
   34: <perlscript mode='fg'>
   35: $|=1;
   36:   print(&lt;&lt;END);
   37: 
   38: 
   39: *********************************************
   40: *********************************************
   41: ****                                     ****
   42: **** LON-CAPA SYSTEM INFORMATION REQUEST ****
   43: ****                                     ****
   44: **** Please respond to the choices below ****
   45: ****                                     ****
   46: *********************************************
   47: *********************************************
   48: 
   49: END
   50: sleep(3);
   51: </perlscript>
   52: </file>
   53: <file>
   54: <target dist='default'>loncom/hosts.tab</target>
   55: <perlscript mode='fg'>
   56: unless (-l "<TARGET />") {
   57:   print(&lt;&lt;END);
   58: 
   59: ===============================================================================
   60: Which cluster option would you like to have installed?
   61: IMPORTANT: to take advantage of the cluster options 1) and 3),
   62: you must contact lon-capa\@lon-capa.org.
   63: 
   64: 1) PRODUCTION - you want to eventually connect this machine to the
   65:                 LON-CAPA content sharing network. This setting is for
   66:                 schools, colleges, and universities, that currently
   67:                 are running - or in the future will run - courses
   68: 2) STAND-ALONE - you want this machine to run in 'stand-alone' mode and
   69:                  not be connected to other LON-CAPA machines for now
   70: 3) DEVELOPMENT - you want to do software (not content!) development with
   71:                  this workstation and eventually link it with the
   72:                  workstations of other LON-CAPA software developers.
   73: 4) RUNNING YOUR OWN CLUSTER - this machine is not in the standard LON-CAPA
   74:                  clusters and won't be in the future and you want the existing
   75:                  hosts.tab and domain.tab files to be left alone.
   76:                  (This choice is unlikely what you want to select.)
   77: END
   78: # Option number 26 will install rawhide_hosts.tab, but
   79: # the typical user does not want to be part of an intensive
   80: # machine test cluster.
   81: 
   82: # get input
   83: # if valid then process, otherwise loop
   84: $flag=0;
   85: while (!$flag) {
   86:   print "ENTER 1, 2, 3, or 4:\n";
   87:   my $choice=&lt;&gt;;
   88:   chomp($choice);
   89:   if ($choice==1) {
   90:     $lonCluster='production'; $flag=1;
   91:   }
   92:   elsif ($choice==2) {
   93:     $lonCluster='standalone'; $flag=1;
   94:   }
   95:   elsif ($choice==3) {
   96:     $lonCluster='development'; $flag=1;
   97:   }
   98:   elsif ($choice==4) {
   99:     $lonCluster='existing'; $flag=1;
  100:     if (-e '/home/httpd/lonTabs/hosts.tab') {
  101:       `cp /home/httpd/lonTabs/hosts.tab ../existing_hosts.tab`;
  102:     }
  103:     else {
  104:       print &lt;&lt;END;
  105: There is no existing /home/httpd/lonTabs/hosts.tab
  106: END
  107:       die('');
  108:     }
  109:     if (-e '/home/httpd/lonTabs/domain.tab') {
  110:       `cp /home/httpd/lonTabs/domain.tab ../existing_domain.tab`;
  111:     }
  112:     else {
  113:       print &lt;&lt;END;
  114: There is no existing /home/httpd/lonTabs/domain.tab
  115: END
  116:       die('');
  117:     }
  118:   }
  119:   elsif ($choice==26) {
  120:     $lonCluster='rawhide'; $flag=1;
  121:   }
  122: }
  123: }
  124: </perlscript>
  125: </file>
  126: <file>
  127: <target dist='default'>/home/httpd/lonTabs/hosts.tab</target>
  128: <perlscript mode='fg'>
  129: $|=1;
  130: my $domainDescription;
  131: my $domainTabExtras;
  132: my $primaryLibServer;
  133: my @libservers = ();
  134: unless (-e "<TARGET />") {
  135:   print(&lt;&lt;END);
  136:            WELCOME TO LON-CAPA!
  137: 
  138: If you have questions, please visit http://install.lon-capa.org
  139: or contact helpdesk\@lon-capa.org.
  140: 
  141: ===============================================================================
  142: The following 4 values are needed to configure LON-CAPA:
  143: * Machine Role
  144: * LON-CAPA Domain Name
  145: * LON-CAPA Machine ID Name, and
  146: * Server Administration E-mail Address.
  147: ===============================================================================
  148: 
  149: In addition, a Support E-mail Address can also be included. If
  150: an address is included then one of the options in the LON-CAPA 
  151: help menu will be a link to a form that a user will complete to
  152: request LON-CAPA help.  
  153: 
  154: END
  155: 
  156: open(OUT,'&gt;/tmp/loncapa_updatequery.out');
  157: close(OUT);
  158: 
  159: # query for Machine Role
  160:   print(&lt;&lt;END);
  161: **** Machine Role ****
  162: Library server (recommended if first-time installation of LON-CAPA):
  163:    Servers that are repositories of authoritative educational resources.
  164:    These servers also provide the construction space by which instructors
  165:    assemble their classroom online material.
  166: Access server:
  167:    Servers that load-balance high-traffic delivery of educational resources
  168:    over the world-wide web.
  169: 1) Will this be a library server? (recommended if this is your first install)
  170: 2) Or, will this be an access server?
  171: END
  172: my $flag=0;
  173: my $r='';
  174: my $lonRole;
  175: while (!$flag) {
  176:   print "ENTER A CHOICE OF 1 or 2:\n";
  177:   my $choice=&lt;&gt;;
  178:   chomp($choice);
  179:   if ($choice==1) {
  180:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  181:     print(OUT 'lonRole'."\t".'library'."\n");
  182:     close(OUT);
  183:     $lonRole='library';
  184:     $r='l';
  185:     $flag=1;
  186:   }
  187:   elsif ($choice==2) {
  188:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  189:     print(OUT 'lonRole'."\t".'access'."\n");
  190:     close(OUT);
  191:     $lonRole='access';
  192:     $r='a';
  193:     $flag=2;
  194:   }
  195:   else {
  196: 
  197:   }
  198: }
  199: 
  200: # need to recommend a machine ID name (ipdomain.l.somenumber)
  201: my $hostname=`hostname -f`; chomp($hostname);
  202: my $ipdomain='';
  203: if ($hostname=~/([^\.]*)\.([^\.]*)$/) {
  204:   $ipdomain=$1;
  205: }
  206: 
  207:   print(&lt;&lt;END);
  208: 
  209: **** Domain ****
  210: [This does NOT need to correspond to internet address domains.
  211:  Please make this name short AND descriptive of your organization.
  212:  Domain names are close to impossible to change later!!!
  213:  Good examples might be "msu" or "bionet" or "vermontcc".
  214:  Bad examples are "physics" (too general)
  215:    or "michiganstateuniversity" (too long)
  216:    or "msuedu" (internet domain, just make it "msu")
  217:    or "msuphysics" (only if there is a good reason to limit to department
  218:                     - we don't know of one)
  219:    or "mydomain" (what is that?)
  220:  Avoid multiple domains at the same institution, even if it means that you 
  221:  have to actually work together with your colleagues. You can still run
  222:  multiple library servers within the same domain.
  223:  If this domain is eventually going to be part of the main production
  224:  cluster, you MUST contact the LON-CAPA group at MSU (loncapa@loncapa.org)
  225:  to have a domain name assigned, and then use it exactly as given. This is
  226:  also true for test installs that might eventually turn into production setups.
  227:  Stop now if you didn't do so.]
  228: END
  229: 
  230: # get domain name
  231: # accept if valid, if not valid, tell user and repeat
  232: $flag=0;
  233: my $lonDefDomain;
  234: while (!$flag) {
  235: if ($ipdomain) {
  236: print(&lt;&lt;END);
  237: ENTER LONCAPA DOMAIN [$ipdomain]:
  238: END
  239: }
  240: else {
  241:   print(&lt;&lt;END);
  242: ENTER LONCAPA DOMAIN:
  243: END
  244: }
  245:   my $choice=&lt;&gt;;
  246:   chomp($choice);
  247:   my $bad_domain_flag=0;
  248:   my @bad_domain_names=('res','raw','userfiles','priv','adm','uploaded',
  249: 	'editupload');
  250:   foreach my $bad (@bad_domain_names) {
  251:     $bad_domain_flag=1 if $choice eq $bad;
  252:   }
  253:   if ($choice=~/capa/i) {
  254:      $bad_domain_flag=1;
  255:   }
  256:   if ($ipdomain and $choice=~/^\s*$/) {
  257:     $choice=$ipdomain;
  258:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  259:     print(OUT 'lonDefDomain'."\t".$choice."\n");
  260:     close(OUT);
  261:     $lonDefDomain=$choice;
  262:     $flag=1;
  263:   } elsif (length($choice)>12) {
  264:     print "Name too long\n";
  265:   } elsif (length($choice)<2) {
  266:     print "Name too short\n";
  267:   } elsif ($bad_domain_flag) {
  268:     print "Invalid input ('$choice' conflicts with LON-CAPA namespace).\n";
  269:     print "Please try something different than '$choice'\n";
  270:   } elsif ($choice!~/\_/ and $choice=~/^\w+$/) {
  271:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  272:     print(OUT 'lonDefDomain'."\t".$choice."\n");
  273:     close(OUT);
  274:     $lonDefDomain=$choice;
  275:     $r='l';
  276:     $flag=1;
  277:   } else {
  278:     print "Invalid input (only alphanumeric characters supported).\n";
  279:   }
  280: }
  281: 
  282: 
  283: # get domain description
  284: # accept if valid, if not valid, tell user and repeat
  285: $flag=0;
  286: 
  287: while (!$flag) {
  288:   print(&lt;&lt;END);
  289: 
  290: **** Domain Description ****
  291: String describing the domain, to be shown to users.
  292: [Example, msu is Michigan State University]
  293: ENTER DOMAIN DESCRIPTION:
  294: END
  295: 
  296:   my $choice=&lt;&gt;;
  297:   chomp($choice);
  298:   if ($choice!~/:/) {
  299:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  300:     print(OUT 'domainDescription'."\t".$choice."\n");
  301:     close(OUT);
  302:     $domainDescription=$choice;
  303:     $flag=1;
  304:   }
  305:   else {
  306:     print "Invalid input (no ':' allowed).\n";
  307:   }
  308: }
  309: 
  310: my $lonHostID;
  311: if ($lonDefDomain) {
  312:   $lonHostID=$lonDefDomain.$r.int(1+rand(9)); # should be probably also detect
  313:                                               # against the hosts.tab
  314: }
  315: 
  316:   print(&lt;&lt;END);
  317: 
  318: **** Machine ID Name ****
  319: [This does NOT need to correspond to internet address names;
  320:  this name MUST be unique to the whole LON-CAPA network;
  321:  we recommend that you use a name based off of your institution.
  322:  Good examples: "msul1" or "bioneta2".
  323:  Bad examples: "loncapabox" or "studentsinside".
  324:  Note that machine names are very hard to change later.]
  325: END
  326: # get machine name
  327: # accept if valid, if not valid, tell user and repeat
  328: $flag=0;
  329: while (!$flag) {
  330: if ($ipdomain) {
  331: print(&lt;&lt;END);
  332: ENTER LONCAPA MACHINE ID [$lonHostID]:
  333: END
  334: }
  335: else {
  336:   print(&lt;&lt;END);
  337: ENTER LONCAPA MACHINE ID:
  338: END
  339: }
  340:   my $choice=&lt;&gt;;
  341:   chomp($choice);
  342:   if ($choice=~/capa/i) {
  343:     print "Invalid input (names containing 'capa' are reserved).\n";
  344:   } elsif ($lonHostID and $choice=~/^\s*$/) {
  345:     $choice=$lonHostID;
  346:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  347:     print(OUT 'lonHostID'."\t".$choice."\n");
  348:     close(OUT);
  349:     $lonHostID=$choice;
  350:     $flag=1;
  351:   } elsif (length($choice)>15) {
  352:     print "Name too long\n";
  353:   } elsif (length($choice)<4) {
  354:     print "Name too short\n";
  355:   } elsif ($choice!~/\_/ and $choice=~/^\w+$/) {
  356:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  357:     print(OUT 'lonHostID'."\t".$choice."\n");
  358:     close(OUT);
  359:     $lonHostID=$choice;
  360:     $flag=1;
  361:   } else {
  362:     print "Invalid input (only alphanumeric characters supported).\n";
  363:   }
  364: }
  365: 
  366: # get primary library server in domain
  367: if ($lonRole eq 'library') {
  368:     if (!grep/^\Q$lonHostID\E$/,@libservers) {
  369:         push(@libservers,$lonHostID);
  370:     } 
  371:     if (@libservers == 1) {
  372:         $primaryLibServer = $libservers[0];
  373:     }
  374: }
  375: while (!$flag) {
  376:   print(&lt;&lt;END);
  377: **** Domain's Primary Library Server ID ****
  378: This should be the LON-CAPA machine ID of a library server in your 
  379: domain.  If you only have a single library server in your domain, then
  380: the Primary Library server ID will be the machine ID of that server. 
  381: This server will be where domain data which are not associated with any
  382: specific home library server will be stored (e.g., e-mail broadcast by
  383: administrators to users in the domain).
  384: END
  385:     if (defined($primaryLibServer)) {
  386:         print(&lt;&lt;END);
  387: ENTER DOMAIN'S PRIMARY LIBRARY SERVER ID [$primaryLibServer]:
  388: END
  389:     } elsif (@libservers > 0) {
  390:         print(&lt;&lt;END);
  391: ENTER DOMAIN'S PRIMARY LIBRARY SERVER ID [$libservers[0]]
  392: END
  393:     } else {
  394:         print (&lt;&lt;END);
  395: No library servers could be identified for this domain.  If you have already installed LON-CAPA on a different server (designated as a library server) in this domain, please enter the LONCAPA MACHINE ID of that server.  If not, you will need to install a LON-CAPA library server.  Enter the MACHINE ID of the server you plan to designate as a library server.
  396: END
  397:     }
  398: 
  399:     my $choice=&lt;&gt;;
  400:     chomp($choice);
  401:     if ($primaryLibServer and $choice=~/^\s*$/) {
  402:         $choice=$primaryLibServer;
  403:         open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  404:         print(OUT 'primaryLibServer'."\t".$choice."\n");
  405:         close(OUT);
  406:         $flag=1;
  407:     } elsif (length($choice)>15) {
  408:         print "Name too long\n";
  409:     } elsif (length($choice)<4) {
  410:         print "Name too short\n";
  411:     } elsif ($choice!~/\_/ and $choice=~/^\w+$/) {
  412:         open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  413:         print(OUT 'primaryLibServer'."\t".$choice."\n");
  414:         close(OUT);
  415:         $primaryLibServer=$choice;
  416:         $flag=1;
  417:     } else {
  418:         print "Invalid input (only alphanumeric characters supported).\n";
  419:     }
  420: }
  421: 
  422: 
  423: # get admin e-mail address
  424: # accept if valid, if not valid, tell user and repeat
  425: $flag=0;
  426: my $lonAdmEMail;
  427: while (!$flag) {
  428:   print(&lt;&lt;END);
  429: 
  430: **** Server Administrator's E-mail ****
  431: E-mail address of the person who will manage this machine
  432: [should be in the form somebody\@somewhere]
  433: ENTER ADMIN E-MAIL ADDRESS:
  434: END
  435: 
  436:   my $choice=&lt;&gt;;
  437:   chomp($choice);
  438:   if ($choice=~/\@/) {
  439:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  440:     print(OUT 'lonAdmEMail'."\t".$choice."\n");
  441:     close(OUT);
  442:     $lonAdmEMail=$choice;
  443:     $flag=1;
  444:   }
  445:   else {
  446:     print "Invalid input (this needs to look like an e-mail address!).\n";
  447:   }
  448: }
  449: 
  450: 
  451: # get support e-mail address
  452: # accept if valid, if not valid, tell user and repeat
  453: $flag=0;
  454: my $lonSupportEMail;
  455: while (!$flag) {
  456:   print(&lt;&lt;END);
  457: 
  458: **** Support E-mail ****
  459: E-mail address of the person who will receive 
  460: help requests from LON-CAPA users who access 
  461: the system via this server. If the address is left blank,
  462: then a help support form will not be displayed 
  463: as part of the help menu.
  464: [should be in the form somebody\@somewhere]
  465: ENTER SUPPORT E-MAIL ADDRESS:
  466: END
  467: 
  468:   my $choice=&lt;&gt;;
  469:   chomp($choice);
  470:   $choice =~ s/\s//g;
  471:   if ( ($choice=~/\@/) || $choice eq '') {
  472:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
  473:     print(OUT 'lonSupportEMail'."\t".$choice."\n");
  474:     close(OUT);
  475:     $lonSupportEMail=$choice;
  476:     $flag=1;
  477:   }
  478:   else {
  479:     print "Invalid input (this either needs to be blank, or look like an e-mail address!).\n";
  480:   }
  481: }
  482: 
  483: 
  484: # update loncapa.conf
  485: my $confdir = '/etc/httpd/conf/';
  486: if ('<DIST />' eq 'sles10' || '<DIST />' eq 'suse10.1') {
  487:      $confdir = '/etc/apache2/';
  488: }   
  489: my $filename='loncapa.conf';
  490: my %perlvar;
  491:     if (-e "$confdir$filename") {
  492: 	open(CONFIG,'&lt;'.$confdir.$filename) or die("Can't read $confdir$filename");
  493: 	while (my $configline=&lt;CONFIG&gt;) {
  494: 	    if ($configline =~ /^[^\#]*PerlSetVar/) {
  495: 		my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
  496: 		chomp($varvalue);
  497: 		$perlvar{$varname}=$varvalue if $varvalue!~/^\{\[\[\[\[/;
  498: 	    }
  499: 	}
  500: 	close(CONFIG);
  501:     }
  502:     $perlvar{'lonHostID'}=$lonHostID;
  503:     $perlvar{'lonDefDomain'}=$lonDefDomain;
  504:     $perlvar{'lonAdmEMail'}=$lonAdmEMail;
  505:     $perlvar{'lonSupportEMail'}=$lonSupportEMail;
  506:     $perlvar{'lonRole'}=$lonRole;
  507:     unless ($perlvar{'lonLoadLim'} and $perlvar{'lonLoadLim'}!~/\{\[\[\[\[/) {
  508:        $perlvar{'lonLoadLim'}='2.00';
  509:     }
  510:     unless ($perlvar{'lonUserLoadLim'} and $perlvar{'lonUserLoadLim'}!~/\{\[\[\[\[/) {
  511:        $perlvar{'lonUserLoadLim'}='0';
  512:     }
  513:     unless ($perlvar{'lonExpire'} and $perlvar{'lonExpire'}!~/\{\[\[\[\[/) {
  514:        $perlvar{'lonExpire'}='86400';
  515:     }
  516:     unless ($perlvar{'lonReceipt'} and $perlvar{'lonReceipt'}!~/\{\[\[\[\[/) {
  517:        my $lonReceipt='';
  518:        srand(time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
  519:        my @alnum=(0..9,a..z);
  520:        foreach my $i (1..20) {
  521: 	 $lonReceipt.=$alnum[int(rand(36))];
  522:        }
  523:        $perlvar{'lonReceipt'}=$lonReceipt;
  524:     }
  525:     open(OUT,"&gt;$confdir$filename") or
  526:       die("Cannot output to $confdir$filename\n");
  527:     foreach my $key (keys %perlvar) {
  528:       my $value=$perlvar{$key};
  529:       my $line = "PerlSetVar     $key      $value"; 
  530:       if ($value eq '') {
  531:           $line = '#'.$line;
  532:       }
  533:       print(OUT &lt;&lt;END);
  534: $line
  535: END
  536:     }
  537:     close(OUT);
  538: }
  539: </perlscript>
  540: </file>
  541: <file>
  542: <target dist='default'>/etc/httpd/conf/</target>
  543: <target dist='sles10 suse10.1'>/etc/apache2/</target>
  544: <perlscript mode='fg'>
  545: sub securesetting {
  546:     my (%perlvar)=@_;
  547:     my $securestatus='unknown';
  548:     my $securenum='';
  549:     if      ( $perlvar{'loncAllowInsecure'}&&  $perlvar{'londAllowInsecure'}) {
  550: 	$securestatus='no';                  $securenum='4';
  551:     } elsif ( $perlvar{'loncAllowInsecure'}&& !$perlvar{'londAllowInsecure'}) {
  552: 	$securestatus='lond';                $securenum='3';
  553:     } elsif (!$perlvar{'loncAllowInsecure'}&&  $perlvar{'londAllowInsecure'}) {
  554: 	$securestatus='lonc';                $securenum='2';
  555:     } elsif (!$perlvar{'loncAllowInsecure'}&& !$perlvar{'londAllowInsecure'}) {
  556: 	$securestatus='yes (lond and lonc)'; $securenum='1';
  557:     }
  558:     return ($securestatus,$securenum);
  559: }
  560: # read values from loncapa.conf
  561: my $confdir = "<TARGET />";
  562: my $filename='loncapa.conf';
  563: my %perlvar;
  564: my ($securestatus,$securenum);
  565:     if (-e "$confdir$filename") {
  566: 	open(CONFIG,'&lt;'.$confdir.$filename) or 
  567:           die("Can't read $confdir$filename");
  568: 	while (my $configline=&lt;CONFIG&gt;) {
  569: 	    if ($configline =~ /^[^\#]*PerlSetVar/) {
  570: 		my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
  571: 		chomp($varvalue);
  572: 		$perlvar{$varname}=$varvalue;
  573: 	    }
  574: 	}
  575: 	close(CONFIG);
  576:     }
  577:     unless ($perlvar{'lonLoadLim'} and $perlvar{'lonLoadLim'}!~/\{\[\[\[\[/) {
  578:        $perlvar{'lonLoadLim'}='2.00';
  579:     }
  580:     unless ($perlvar{'lonUserLoadLim'} and $perlvar{'lonUserLoadLim'}!~/\{\[\[\[\[/) {
  581:        $perlvar{'lonUserLoadLim'}='0';
  582:     }
  583:     unless ($perlvar{'lonExpire'} and $perlvar{'lonExpire'}!~/\{\[\[\[\[/) {
  584:        $perlvar{'lonExpire'}='86400';
  585:     }
  586:     unless ($perlvar{'londAllowInsecure'} and $perlvar{'londAllowInsecure'}!~/\{\[\[\[\[/) {
  587:        $perlvar{'londAllowInsecure'}='1';
  588:     }
  589:     unless ($perlvar{'loncAllowInsecure'} and $perlvar{'loncAllowInsecure'}!~/\{\[\[\[\[/) {
  590:        $perlvar{'loncAllowInsecure'}='1';
  591:     }
  592:     ($securestatus,$securenum)=&securesetting(%perlvar);
  593:     unless ($perlvar{'lonReceipt'} and $perlvar{'lonReceipt'}!~/\{\[\[\[\[/) {
  594:        my $lonReceipt='';
  595:        srand(time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
  596:        my @alnum=(0..9,a..z);
  597:        foreach my $i (1..20) {
  598: 	 $lonReceipt.=$alnum[int(rand(36))];
  599:        }
  600:        $perlvar{'lonReceipt'}=$lonReceipt;
  601:     }
  602: my %perlvarstatic;
  603:     if (-e "${confdir}loncapa_apache.conf") {
  604: 	open(CONFIG,'&lt;'.$confdir.'loncapa_apache.conf') or 
  605:           die("Can't read ${confdir}loncapa_apache.conf");
  606: 	while (my $configline=&lt;CONFIG&gt;) {
  607: 	    if ($configline =~ /^[^\#]*PerlSetVar/) {
  608: 		my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
  609: 		chomp($varvalue);
  610: 		$perlvarstatic{$varname}=$varvalue;
  611: 	    }
  612: 	}
  613: 	close(CONFIG);
  614:     }
  615:     if (!$domainDescription && $lonCluster ne 'existing') {
  616:        open(IN,'&lt;../'.$lonCluster.'_domain.tab');
  617:        while(&lt;IN&gt;) {
  618:           if (/^$perlvar{'lonDefDomain'}\:/) {
  619: 	     (undef,$domainDescription,$domainTabExtras)=split(/:/,$_,3);
  620: 	     chomp($domainDescription);
  621: 	     chomp($domainTabExtras);
  622: 	     # the remianing field (primary lib server) is handled later
  623: 	     $domainTabExtras = join(':',(split(/:/,$domainTabExtras))[0..5]);
  624:              last;
  625:           }
  626:        }
  627:        close(IN);
  628:     }
  629:     if (!$domainDescription) {
  630:        open(IN,'&lt;/home/httpd/lonTabs/domain.tab');
  631:        while(&lt;IN&gt;) {
  632:           if (/^$perlvar{'lonDefDomain'}\:/) {
  633: 	     (undef,$domainDescription,$domainTabExtras)=split(/:/,$_,3);
  634: 	     chomp($domainDescription);
  635: 	     chomp($domainTabExtras);
  636: 	     # the remianing field (primary lib server) is handled later
  637: 	     $domainTabExtras = join(':',(split(/:/,$domainTabExtras))[0..5]);
  638:              last;
  639:           }
  640:        }
  641:        close(IN);
  642:     }
  643:     if (!$primaryLibServer and $lonCluster ne 'existing') {
  644:         open(IN,'&lt;../'.$lonCluster.'_domain.tab');
  645:         while(&lt;IN&gt;) {
  646:             if (/^$perlvar{'lonDefDomain'}\:/) {
  647:                 (undef,undef,undef,undef,undef,undef,undef,undef,
  648:                                               $primaryLibServer)=split(/:/,$_);
  649:                 chomp($primaryLibServer);
  650:             }
  651:         }
  652:         close(IN);
  653:         if (!$primaryLibServer) {
  654:             open(IN,'&lt;../'.$lonCluster.'_hosts.tab');
  655:             while(&lt;IN&gt;) {
  656:                 if (/^([^\:]+)\:\Q$perlvar{'lonDefDomain'}\E\:library\:/) {
  657:                     push(@libservers,$1);
  658:                 }
  659:             }
  660:             close(IN);
  661:             if (@libservers == 1) {
  662:                 $primaryLibServer = $libservers[0];
  663:             }
  664:         }
  665:     }
  666:     if (!$primaryLibServer) {
  667:         open(IN,'&lt;/home/httpd/lonTabs/domain.tab');
  668:         while(&lt;IN&gt;) {
  669:             if (/^$perlvar{'lonDefDomain'}\:/) {
  670:                 (undef,undef,undef,undef,undef,undef,undef,undef,
  671:                                               $primaryLibServer)=split(/:/,$_);
  672:                 chomp($primaryLibServer);
  673:             }
  674:             close(IN);
  675:         }
  676:         if (!$primaryLibServer) {
  677:             open(IN,'&lt;/home/httpd/lonTabs/hosts.tab');
  678:             while(&lt;IN&gt;) {
  679:                 if (/^([^\:]+)\:\Q$perlvar{'lonDefDomain'}\E\:library\:/) {
  680:                     push(@libservers,$1);
  681:                 }
  682:             }
  683:             close(IN);
  684:             if (@libservers == 1) {
  685:                 $primaryLibServer = $libservers[0];
  686:             }
  687:         }
  688:     }
  689:    
  690: # implement editing logic below, interactively
  691: # update loncapa.conf until 12 is entered
  692: 
  693: $flag=0;
  694: 
  695: while (!$flag) {
  696:   print(&lt;&lt;END);
  697: 
  698: ===============================================================================
  699: This is now the current configuration of your machine.
  700:  1) Domain Name: $perlvar{'lonDefDomain'}
  701:  2) Domain Description: $domainDescription
  702:  3) Machine Name: $perlvar{'lonHostID'}
  703:  4) ID of primary library server for domain: $primaryLibServer
  704:  5) Server Administrator's E-mail Address: $perlvar{'lonAdmEMail'}
  705:  6) Support E-mail Address: $perlvar{'lonSupportEMail'}
  706:  7) Role: $perlvar{'lonRole'}
  707:  8) Cache Expiration Time: $perlvar{'lonExpire'}
  708:  9) Server Load: $perlvar{'lonLoadLim'}
  709: 10) User Load: $perlvar{'lonUserLoadLim'}
  710: 11) Allow only secure connections: $securestatus 
  711: 12) Everything is correct up above
  712: END
  713: 
  714: my $error='';
  715: foreach my $v ($perlvar{'lonDefDomain'},$perlvar{'lonHostID'}) {
  716:    if (length($v)>16) { $error.="\nName $v too long"; }		
  717:    if (length($v)<2) { $error.="\nName $v too short"; }
  718:    if ($v=~/capa/i) {
  719: 	if ($v!~/^oucapa\d+$/ && 
  720: 	    ($v!~/^capa\d+$/ && $perlvar{'lonDefDomain'} eq 'uwsp')) {
  721: 		 $error.="\nName $v contains 'capa'"; 
  722: 	}
  723:    }
  724:    foreach my $bad ('res','raw','userfiles','priv','adm','uploaded',
  725: 	'editupload') {
  726:       $error.="\nName $v reserved." if $v eq $bad;
  727:    }
  728:    if ($v=~/\W/) { $error.="\nName $v contains special characters"; }
  729: }
  730: if ($domainDescription!~/^[\(\)\-\w\s,]+$/) {
  731:    $error.="\nDomain Description contains special characters";
  732: } 
  733: foreach my $v ($perlvar{'lonExpire'},$perlvar{'lonLoadLim'}) {
  734:    unless ($v=~/^[\d+\.]+$/) { $error.="\nNumber expected instead of $v"; }
  735: }
  736: unless (($perlvar{'lonRole'} eq 'library') || ($perlvar{'lonRole'} eq 'access')) {
  737:    $error.="\nInvalid Role";
  738: }
  739: 
  740: if (!defined($primaryLibServer)) {
  741:    if (@libservers > 0) {
  742:        $error .= "No primary library server ID designated. Choose from: ".join(',',sort(@libservers));
  743:    } else {
  744:        $error .= "No library servers in this domain (including current server)";
  745:    }
  746: } else {
  747:    if (length($primaryLibServer)>16) { $error.="\nPrimary Library Server ID:  $primaryLibServer too long"; }
  748:    if (length($primaryLibServer)<2) { $error.="\nPrimary Library Server ID:  $primaryLibServer too short"; }
  749:    if ($primaryLibServer =~/capa/i) {
  750:         if ($primaryLibServer!~/^oucapa\d+$/ &&
  751:             ($primaryLibServer!~/^capa\d+$/ && $perlvar{'lonDefDomain'} eq 'uwsp')) {
  752:                  $error.="\nPrimary library server ID $primaryLibServer contains 'capa'";
  753:         }
  754:    }
  755:    foreach my $bad ('res','raw','userfiles','priv','adm','uploaded',
  756:         'editupload') {
  757:       $error.="\nPrimary library server ID $primaryLibServer reserved." if $primaryLibServer eq $bad;
  758:    }
  759:    if ($primaryLibServer=~/\W/) { $error.="\nPrimary library server ID $primaryLibServer contains special characters"; }
  760: }
  761: 
  762: 
  763: if ($error) { print "\n*** ERRORS: $error\n"; }
  764:   print(&lt;&lt;END);
  765: ENTER A CHOICE OF 1-11 TO CHANGE, otherwise ENTER 12:
  766: END
  767: my $choice=&lt;&gt;;
  768: chomp($choice);
  769:   if ($choice==1) {
  770:   print(&lt;&lt;END);
  771: 1) Domain Name: $perlvar{'lonDefDomain'}
  772: ENTER NEW VALUE (this is an internal value used to identify a group of
  773:                  LON-CAPA machines, it must be alphanumerical, we suggest
  774:                  using a part of your actual DNS domain. For example, for
  775:                  the machine loncapa.msu.edu, we set the Domain to msu):
  776: END
  777:     my $choice2=&lt;&gt;;
  778:     chomp($choice2);
  779:     $perlvar{'lonDefDomain'}=$choice2;
  780:   }
  781:   elsif ($choice==2) {
  782:   print(&lt;&lt;END);
  783: 2) Domain Description: $domainDescription
  784: ENTER NEW VALUE (this should be a string that describes your domain, spaces
  785:                  and punctuation are fine except for ':'):
  786: END
  787:     my $choice2=&lt;&gt;;
  788:     chomp($choice2);
  789:     $domainDescription=$choice2;
  790:   }
  791:   elsif ($choice==3) {
  792:   print(&lt;&lt;END);
  793: 3) Machine Name: $perlvar{'lonHostID'}
  794: ENTER NEW VALUE (this will be the name of the machine in the LON-CAPA network
  795:                  it cannot contain any of '_' '-' '.' or ':'. We suggest that
  796:                  if you are in the domain 'example' and are the first library
  797:                  server you enter 'examplel1') :
  798: END
  799:     my $choice2=&lt;&gt;;
  800:     chomp($choice2);
  801:     $perlvar{'lonHostID'}=$choice2;
  802:   }
  803:   elsif ($choice==4) {
  804:   print(&lt;&lt;END);
  805: 4) ID of primary library server for domain: $primaryLibServer
  806: ENTER NEW VALUE (this will be the LON-CAPA Machine ID of a library server in
  807:                  your domain; it cannot contain any of '_' '-' '.' or ':'. 
  808:                  This server will be where domain data which are not 
  809:                  associated with any specific home library server
  810:                  will be stored (e.g., e-mail broadcast by Domain Coordinators
  811:                  to users in the domain).
  812: END
  813:     my $choice2=&lt;&gt;;
  814:     chomp($choice2);
  815:     $primaryLibServer=$choice2;
  816:   }
  817:   elsif ($choice==5) {
  818:   print(&lt;&lt;END);
  819: 5) Server Administrator's E-mail Address: $perlvar{'lonAdmEMail'}
  820: ENTER NEW VALUE:
  821: END
  822:     my $choice2=&lt;&gt;;
  823:     chomp($choice2);
  824:     $perlvar{'lonAdmEMail'}=$choice2;
  825:   }
  826:   elsif ($choice==6) {
  827:   print(&lt;&lt;END);
  828: 6) Support E-mail Address: $perlvar{'lonSupportEMail'}
  829: ENTER NEW VALUE:
  830: END
  831:     my $choice2=&lt;&gt;;
  832:     chomp($choice2);
  833:     $perlvar{'lonSupportEMail'}=$choice2;
  834:   }
  835:   elsif ($choice==7) {
  836:   print(&lt;&lt;END);
  837: 7) Role: $perlvar{'lonRole'}
  838: ENTER NEW VALUE (this should be either 'access' or 'library' 
  839:                  if in doubt select 'library'):
  840: END
  841:     my $choice2=&lt;&gt;;
  842:     chomp($choice2);
  843:     $perlvar{'lonRole'}=$choice2;
  844:   }
  845:   elsif ($choice==8) {
  846:   print(&lt;&lt;END);
  847: 8) Cache Expiration Time: $perlvar{'lonExpire'}
  848: ENTER NEW VALUE (in seconds, 86400 is a reasonable value):
  849: END
  850:     my $choice2=&lt;&gt;;
  851:     chomp($choice2);
  852:     $perlvar{'lonExpire'}=$choice2;
  853:   }
  854:   elsif ($choice==9) {
  855:   print(&lt;&lt;END);
  856: 9) Server Load: $perlvar{'lonLoadLim'}
  857: ENTER NEW VALUE:
  858: END
  859:     my $choice2=&lt;&gt;;
  860:     chomp($choice2);
  861:     $perlvar{'lonLoadLim'}=$choice2;
  862:   }
  863:   elsif ($choice==10) {
  864:   print(&lt;&lt;END);
  865: 10) User Load: $perlvar{'lonUserLoadLim'}
  866: Numer of users that can login before machine is 'overloaded'
  867: ENTER NEW VALUE (integer value, 0 means there is no limit):
  868: END
  869:     my $choice2=&lt;&gt;;
  870:     chomp($choice2);
  871:     $perlvar{'lonUserLoadLim'}=$choice2;
  872:   }
  873:   elsif ($choice==11) {
  874:   print(&lt;&lt;END);
  875: 11) Allow only secure connections: $securestatus 
  876: The Lon-CAPA communication daemons lonc and lond can be configured to
  877: allow only secure connections by default.
  878: 
  879: POSSIBLE CHOICES:
  880: 1) allow only secure connections and don't connect to machines that
  881:     can not be connected to securely
  882: 2) allow only secure connections but allow this machine to connect to 
  883:     machines that don't support secure connections
  884: 3) allow insecure connections to this machine but only allow connections
  885:     to machines that support secure connections
  886: 4) allow insecure connections
  887: ENTER NEW VALUE (currenly $securenum):
  888: END
  889:     my $choice2=&lt;&gt;;
  890:     chomp($choice2);
  891:     if      ($choice2 eq '1') {
  892: 	$perlvar{'loncAllowInsecure'}=0;$perlvar{'londAllowInsecure'}=0;
  893:     } elsif ($choice2 eq '2') {
  894: 	$perlvar{'loncAllowInsecure'}=0;$perlvar{'londAllowInsecure'}=1;
  895:     } elsif ($choice2 eq '3') {
  896: 	$perlvar{'loncAllowInsecure'}=1;$perlvar{'londAllowInsecure'}=0;
  897:     } elsif ($choice2 eq '4') {
  898: 	$perlvar{'loncAllowInsecure'}=1;$perlvar{'londAllowInsecure'}=1;
  899:     }
  900:     ($securestatus,$securenum)=&securesetting(%perlvar);
  901:   }
  902:   elsif (($choice==12) && (!$error)) {
  903:     $flag=1;
  904:   }
  905:   else {
  906:     print "Invalid input.\n";
  907:   }
  908: }
  909:     open(OUT,"&gt;$confdir$filename") or
  910:       die("Cannot output to $confdir$filename\n");
  911:     foreach my $key (keys %perlvar) {
  912:       my $value=$perlvar{$key};
  913:       my $line = "PerlSetVar     $key      $value";
  914:       if ($value eq '') {
  915:           $line = '#'.$line;
  916:       }
  917:       print(OUT &lt;&lt;END) unless $perlvarstatic{$key};
  918: $line
  919: END
  920:     }
  921:     close(OUT);
  922: </perlscript>
  923: </file>
  924: <file>
  925: <target dist='default'>loncom/hosts.tab</target>
  926: <perlscript mode='fg'>
  927: unless (-l "<TARGET />") {
  928:   my $hostname=`hostname -f`;chomp($hostname);
  929:   $date=`date -I`; chomp($date);
  930:   $lonHostID=$perlvar{'lonHostID'};
  931:   $lonHostID=~s/\W//g;
  932:   $lineexistflag=0;
  933:   $hostidexistflag=0;
  934:   $line2insert=&lt;&lt;END;
  935: $perlvar{'lonHostID'}:$perlvar{'lonDefDomain'}:$perlvar{'lonRole'}:$hostname
  936: END
  937:   $domaininsert="$perlvar{'lonDefDomain'}:$domainDescription:$domainTabExtras:$primaryLibServer\n";
  938:   if ($lonCluster eq 'standalone') {
  939:     open(OUT,'&gt;../'.$lonCluster.'_hosts.tab') or
  940:       die('file generation error');
  941:       print(OUT $line2insert);
  942:     close(OUT);
  943:     open(OUT,'&gt;../'.$lonCluster.'_domain.tab') or
  944:       die('file generation error');
  945:       print(OUT $domaininsert);
  946:     close(OUT);
  947:   }
  948:   if ($flag==1) {
  949:     `rm -f ../hosts.tab`;
  950:     open(IN,'&lt;../'.$lonCluster.'_hosts.tab');
  951:     while(&lt;IN&gt;) {
  952:       if (/^$line2insert$/) {
  953:         $lineexistflag=1;
  954:       }
  955:       if (/^$lonHostID\:/) {
  956:         $hostidexistflag=1;
  957:       }
  958:     }
  959:     close(IN);
  960:     if ($hostidexistflag and !$lineexistflag) {
  961:       print &lt;&lt;END;
  962: WARNING: $lonHostID already exists inside
  963: loncapa/loncom/${lonCluster}_hosts.tab.  The entry inside
  964: ${lonCluster}_hosts.tab does not match your settings.
  965: The entry inside ${lonCluster}_hosts.tab is being replaced
  966: with your new values.
  967: END
  968:       `grep -v "$lonHostID:" ../${lonCluster}_hosts.tab &gt; ../new_${lonCluster}_hosts.tab`;
  969:        open(OUT,'&gt;&gt;../new_'.$lonCluster.'_hosts.tab') or
  970:          die("cannot open loncom/${lonCluster}_hosts.tab for output\n");
  971:          print(OUT $line2insert);
  972:        close(OUT);
  973:       `ln -s new_${lonCluster}_hosts.tab ../hosts.tab`;
  974:       # email appropriate message
  975:       `echo "REPLACE:$lonCluster:$lonHostID:$date:$line2insert" | mail -s "REPLACE:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
  976:     }
  977:     elsif ($hostidexistflag and $lineexistflag) {
  978:       print &lt;&lt;END;
  979: Entry exists in ${lonCluster}_hosts.tab.
  980: END
  981:       `ln -s ${lonCluster}_hosts.tab ../hosts.tab`;
  982:       # email appropriate message
  983:       `echo "STABLEUPDATE:$lonCluster:$lonHostID:$date:$line2insert" | mail -s "STABLEUPDATE:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
  984:     }
  985:     elsif (!$hostidexistflag and !$lineexistflag) {
  986:       print &lt;&lt;END;
  987: New entry for $lonCluster.
  988: END
  989:       `cat ../${lonCluster}_hosts.tab &gt; ../new_${lonCluster}_hosts.tab`;
  990:        open(OUT,'&gt;&gt;../new_'.$lonCluster.'_hosts.tab') or
  991:          die("cannot open loncom/new_${lonCluster}_hosts.tab for output\n");
  992:          print(OUT $line2insert);
  993:        close(OUT);
  994:       `ln -s new_${lonCluster}_hosts.tab ../hosts.tab`;
  995:       # email appropriate message
  996:       `echo "INSERT:$lonCluster:$lonHostID:$date:$line2insert" | mail -s "INSERT:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
  997:     }
  998:   }
  999:   $lineexistflag=0;
 1000:   if ($flag==1) {
 1001:     `rm -f ../domain.tab`;
 1002:     open(IN,'&lt;../'.$lonCluster.'_domain.tab');
 1003:     while(&lt;IN&gt;) {
 1004:       if (/^$domaininsert$/) {
 1005:         $lineexistflag=1;
 1006:       }
 1007:       if (/^$perlvar{'lonDefDomain'}\:/) {
 1008:         $domainexistflag=1;
 1009:       }
 1010:     }
 1011:     close(IN);
 1012:     if ($domainexistflag and !$lineexistflag) {
 1013:       print &lt;&lt;END;
 1014: WARNING: $perlvar{'lonDefDomain'} already exists inside
 1015: loncapa/loncom/${lonCluster}_domain.tab.  The entry inside
 1016: ${lonCluster}_domain.tab does not match your settings.
 1017: The entry inside ${lonCluster}_domain.tab is being replaced
 1018: with your new values.
 1019: END
 1020:       `grep -v "$perlvar{'lonDefDomain'}:" ../${lonCluster}_domain.tab &gt; ../new_${lonCluster}_domain.tab`;
 1021:        open(OUT,'&gt;&gt;../new_'.$lonCluster.'_domain.tab') or
 1022:          die("cannot open loncom/${lonCluster}_domain.tab for output\n");
 1023:          print(OUT $domaininsert);
 1024:        close(OUT);
 1025:       `ln -s new_${lonCluster}_domain.tab ../domain.tab`;
 1026:       # email appropriate message
 1027:       `echo "REPLACEdom:$lonCluster:$lonHostID:$date:$domaninsert" | mail -s "REPLACEdom:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
 1028:     }
 1029:     elsif ($domainexistflag and $lineexistflag) {
 1030:       print &lt;&lt;END;
 1031: Entry exists in ${lonCluster}_domain.tab.
 1032: END
 1033:       `ln -s ${lonCluster}_domain.tab ../domain.tab`;
 1034:       # email appropriate message
 1035:       `echo "STABLEUPDATEdom:$lonCluster:$lonHostID:$date:$domaininsert" | mail -s "STABLEUPDATEdom:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
 1036:     }
 1037:     elsif (!$domainexistflag and !$lineexistflag) {
 1038:       print &lt;&lt;END;
 1039: New entry for $lonCluster.
 1040: END
 1041:       `cat ../${lonCluster}_domain.tab &gt; ../new_${lonCluster}_domain.tab`;
 1042:        open(OUT,'&gt;&gt;../new_'.$lonCluster.'_domain.tab') or
 1043:          die("cannot open loncom/new_${lonCluster}_domain.tab for output\n");
 1044:          print(OUT $domaininsert);
 1045:        close(OUT);
 1046:       `ln -s new_${lonCluster}_domain.tab ../domain.tab`;
 1047:       # email appropriate message
 1048:       `echo "INSERTdom:$lonCluster:$lonHostID:$date:$domaininsert" | mail -s "INSERTdom:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
 1049:     }
 1050:   }
 1051: }
 1052: </perlscript>
 1053: </file>
 1054: </files>
 1055: </piml>

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