Annotation of doc/loncapafiles/updatequery.piml, revision 1.64

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

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