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

1.2       harris41    1: <!-- updatequery.piml -->
1.1       harris41    2: 
1.42    ! albertel    3: <!-- $Id: updatequery.piml,v 1.41 2005/08/15 17:53:33 albertel 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.4       harris41   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;
                    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:     }
1.27      albertel  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:     }
1.22      albertel  118:   }
                    119:   elsif ($choice==26) {
                    120:     $lonCluster='rawhide'; $flag=1;
                    121:   }
                    122: }
                    123: }
                    124: </perlscript>
                    125: </file>
                    126: <file>
1.10      harris41  127: <target dist='default'>/home/httpd/lonTabs/hosts.tab</target>
1.1       harris41  128: <perlscript mode='fg'>
1.4       harris41  129: $|=1;
1.20      albertel  130: my $domainDescription;
1.29      albertel  131: my $domainTabExtras;
1.1       harris41  132: unless (-e "<TARGET />") {
                    133:   print(&lt;&lt;END);
                    134:            WELCOME TO LON-CAPA!
                    135: 
                    136: If you have questions, please visit http://install.lon-capa.org
1.32      raeburn   137: or contact helpdesk\@lon-capa.org.
1.1       harris41  138: 
                    139: ===============================================================================
1.4       harris41  140: The following 4 values are needed to configure LON-CAPA:
                    141: * Machine Role
1.8       harris41  142: * LON-CAPA Domain Name
                    143: * LON-CAPA Machine ID Name, and
1.1       harris41  144: * System Administration E-mail Address.
1.32      raeburn   145: ===============================================================================
                    146: 
                    147: In addition, a Support E-mail Address can also be included. If
                    148: an address is included then one of the options in the LON-CAPA 
                    149: help menu will be a link to a form that a user will complete to
                    150: request LON-CAPA help.  
                    151: 
1.1       harris41  152: END
1.3       harris41  153: 
1.4       harris41  154: open(OUT,'&gt;/tmp/loncapa_updatequery.out');
                    155: close(OUT);
                    156: 
1.3       harris41  157: # query for Machine Role
                    158:   print(&lt;&lt;END);
                    159: **** Machine Role ****
                    160: Library server (recommended if first-time installation of LON-CAPA):
                    161:    Servers that are repositories of authoritative educational resources.
                    162:    These servers also provide the construction space by which instructors
                    163:    assemble their classroom online material.
                    164: Access server:
                    165:    Servers that load-balance high-traffic delivery of educational resources
                    166:    over the world-wide web.
1.4       harris41  167: 1) Will this be a library server? (recommended if this is your first install)
1.3       harris41  168: 2) Or, will this be an access server?
                    169: END
1.4       harris41  170: my $flag=0;
                    171: my $r='';
                    172: my $lonRole;
                    173: while (!$flag) {
                    174:   print "ENTER A CHOICE OF 1 or 2:\n";
                    175:   my $choice=&lt;&gt;;
                    176:   chomp($choice);
                    177:   if ($choice==1) {
                    178:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
                    179:     print(OUT 'lonRole'."\t".'library'."\n");
                    180:     close(OUT);
                    181:     $lonRole='library';
                    182:     $r='l';
                    183:     $flag=1;
                    184:   }
                    185:   elsif ($choice==2) {
                    186:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
                    187:     print(OUT 'lonRole'."\t".'access'."\n");
                    188:     close(OUT);
                    189:     $lonRole='access';
                    190:     $r='a';
                    191:     $flag=2;
                    192:   }
                    193:   else {
                    194: 
                    195:   }
                    196: }
1.3       harris41  197: 
                    198: # need to recommend a machine ID name (ipdomain.l.somenumber)
1.36      albertel  199: my $hostname=`hostname -f`; chomp($hostname);
1.4       harris41  200: my $ipdomain='';
                    201: if ($hostname=~/([^\.]*)\.([^\.]*)$/) {
                    202:   $ipdomain=$1;
                    203: }
1.1       harris41  204: 
                    205:   print(&lt;&lt;END);
                    206: 
1.8       harris41  207: **** Domain ****
                    208: [this does NOT need to correspond to internet address domains,
1.37      www       209:  good examples might be "msu" or "bionet" or "vermontcc",
                    210:  bad examples are "physics" (too general)
                    211:    or "michiganstateuniversity" (too long)
                    212:    or "msuedu" (internet domain, just make it "msu")
                    213:    or "msuphysics" (only if there is a good reason to limit)
                    214:    or "mydomain" (what is that?)
                    215:  Please make this name short AND descriptive of your organization.
                    216:  Note that the domain is very hard to change later.
                    217:  Double-check with the LON-CAPA group at MSU if this domain is 
                    218:  going to be part of the main production cluster, since it needs
                    219:  to be unique.]
1.1       harris41  220: END
1.8       harris41  221: 
                    222: # get domain name
1.1       harris41  223: # accept if valid, if not valid, tell user and repeat
1.4       harris41  224: $flag=0;
1.8       harris41  225: my $lonDefDomain;
1.4       harris41  226: while (!$flag) {
                    227: if ($ipdomain) {
                    228: print(&lt;&lt;END);
1.8       harris41  229: ENTER LONCAPA DOMAIN [$ipdomain]:
1.4       harris41  230: END
                    231: }
                    232: else {
                    233:   print(&lt;&lt;END);
1.8       harris41  234: ENTER LONCAPA DOMAIN:
1.4       harris41  235: END
                    236: }
                    237:   my $choice=&lt;&gt;;
                    238:   chomp($choice);
1.18      harris41  239:   my $bad_domain_flag=0;
1.41      albertel  240:   my @bad_domain_names=('res','raw','userfiles','priv','adm','uploaded',
                    241: 	'editupload');
1.18      harris41  242:   foreach my $bad (@bad_domain_names) {
                    243:     $bad_domain_flag=1 if $choice eq $bad;
                    244:   }
1.37      www       245:   if ($choice=~/capa/i) {
                    246:      $bad_domain_flag=1;
                    247:   }
1.8       harris41  248:   if ($ipdomain and $choice=~/^\s*$/) {
                    249:     $choice=$ipdomain;
1.4       harris41  250:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
1.8       harris41  251:     print(OUT 'lonDefDomain'."\t".$choice."\n");
1.4       harris41  252:     close(OUT);
1.8       harris41  253:     $lonDefDomain=$choice;
1.4       harris41  254:     $flag=1;
1.37      www       255:   } elsif (length($choice)>12) {
                    256:     print "Name too long\n";
                    257:   } elsif (length($choice)<2) {
                    258:     print "Name too short\n";
1.38      www       259:   } elsif ($bad_domain_flag) {
                    260:     print "Invalid input ('$choice' conflicts with LON-CAPA namespace).\n";
                    261:     print "Please try something different than '$choice'\n";
1.37      www       262:   } elsif ($choice!~/\_/ and $choice=~/^\w+$/) {
1.4       harris41  263:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
1.8       harris41  264:     print(OUT 'lonDefDomain'."\t".$choice."\n");
1.4       harris41  265:     close(OUT);
1.8       harris41  266:     $lonDefDomain=$choice;
                    267:     $r='l';
1.4       harris41  268:     $flag=1;
1.37      www       269:   } else {
1.4       harris41  270:     print "Invalid input (only alphanumeric characters supported).\n";
                    271:   }
                    272: }
1.1       harris41  273: 
1.20      albertel  274: 
                    275: # get domain description
                    276: # accept if valid, if not valid, tell user and repeat
                    277: $flag=0;
                    278: 
                    279: while (!$flag) {
                    280:   print(&lt;&lt;END);
                    281: 
                    282: **** Domain Description ****
                    283: String describing the domain, to be shown to users.
                    284: [Example, msu is Michigan State University]
                    285: ENTER DOMAIN DESCRIPTION:
                    286: END
                    287: 
                    288:   my $choice=&lt;&gt;;
                    289:   chomp($choice);
                    290:   if ($choice!~/:/) {
                    291:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
                    292:     print(OUT 'domainDescription'."\t".$choice."\n");
                    293:     close(OUT);
                    294:     $domainDescription=$choice;
                    295:     $flag=1;
                    296:   }
                    297:   else {
                    298:     print "Invalid input (no ':' allowed).\n";
                    299:   }
                    300: }
                    301: 
1.8       harris41  302: my $lonHostID;
                    303: if ($lonDefDomain) {
                    304:   $lonHostID=$lonDefDomain.$r.int(1+rand(9)); # should be probably also detect
                    305:                                               # against the hosts.tab
                    306: }
                    307: 
1.1       harris41  308:   print(&lt;&lt;END);
                    309: 
1.8       harris41  310: **** Machine ID Name ****
                    311: [this does NOT need to correspond to internet address names;
                    312:  this name MUST be unique to the whole LON-CAPA network;
                    313:  we recommend that you use a name based off of your institution;
1.37      www       314:  good examples: "msul1" or "bioneta2";
                    315:  bad examples: "loncapabox" or "studentsinside".
                    316:  Note that machine names are very hard to change later.]
1.1       harris41  317: END
1.8       harris41  318: # get machine name
1.1       harris41  319: # accept if valid, if not valid, tell user and repeat
1.4       harris41  320: $flag=0;
                    321: while (!$flag) {
                    322: if ($ipdomain) {
                    323: print(&lt;&lt;END);
1.8       harris41  324: ENTER LONCAPA MACHINE ID [$lonHostID]:
1.4       harris41  325: END
                    326: }
                    327: else {
                    328:   print(&lt;&lt;END);
1.8       harris41  329: ENTER LONCAPA MACHINE ID:
1.4       harris41  330: END
                    331: }
                    332:   my $choice=&lt;&gt;;
                    333:   chomp($choice);
1.37      www       334:   if ($choice=~/capa/i) {
                    335:     print "Invalid input (names containing 'capa' are reserved).\n";
                    336:   } elsif ($lonHostID and $choice=~/^\s*$/) {
1.8       harris41  337:     $choice=$lonHostID;
1.4       harris41  338:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
1.8       harris41  339:     print(OUT 'lonHostID'."\t".$choice."\n");
1.4       harris41  340:     close(OUT);
1.8       harris41  341:     $lonHostID=$choice;
1.4       harris41  342:     $flag=1;
1.37      www       343:   } elsif (length($choice)>15) {
                    344:     print "Name too long\n";
                    345:   } elsif (length($choice)<4) {
                    346:     print "Name too short\n";
                    347:   } elsif ($choice!~/\_/ and $choice=~/^\w+$/) {
1.4       harris41  348:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
1.8       harris41  349:     print(OUT 'lonHostID'."\t".$choice."\n");
1.4       harris41  350:     close(OUT);
1.8       harris41  351:     $lonHostID=$choice;
1.4       harris41  352:     $flag=1;
1.37      www       353:   } else {
1.4       harris41  354:     print "Invalid input (only alphanumeric characters supported).\n";
                    355:   }
                    356: }
1.1       harris41  357: 
1.32      raeburn   358: # get admin e-mail address
1.4       harris41  359: # accept if valid, if not valid, tell user and repeat
                    360: $flag=0;
1.9       harris41  361: my $lonAdmEMail;
1.4       harris41  362: while (!$flag) {
1.1       harris41  363:   print(&lt;&lt;END);
                    364: 
                    365: **** System Administrator's E-mail ****
                    366: E-mail address of the person who will manage this machine
1.4       harris41  367: [should be in the form somebody\@somewhere]
1.32      raeburn   368: ENTER ADMIN E-MAIL ADDRESS:
1.1       harris41  369: END
                    370: 
1.4       harris41  371:   my $choice=&lt;&gt;;
                    372:   chomp($choice);
                    373:   if ($choice=~/\@/) {
                    374:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
1.9       harris41  375:     print(OUT 'lonAdmEMail'."\t".$choice."\n");
1.4       harris41  376:     close(OUT);
1.9       harris41  377:     $lonAdmEMail=$choice;
1.4       harris41  378:     $flag=1;
                    379:   }
                    380:   else {
                    381:     print "Invalid input (this needs to look like an e-mail address!).\n";
                    382:   }
                    383: }
                    384: 
1.32      raeburn   385: 
                    386: # get support e-mail address
                    387: # accept if valid, if not valid, tell user and repeat
                    388: $flag=0;
                    389: my $lonSupportEMail;
                    390: while (!$flag) {
                    391:   print(&lt;&lt;END);
                    392: 
                    393: **** Support E-mail ****
                    394: E-mail address of the person who will receive 
                    395: help requests from LON-CAPA users who access 
                    396: the system via this server. If the address is left blank,
                    397: then a help support form will not be displayed 
                    398: as part of the help menu.
                    399: [should be in the form somebody\@somewhere]
                    400: ENTER SUPPORT E-MAIL ADDRESS:
                    401: END
                    402: 
                    403:   my $choice=&lt;&gt;;
                    404:   chomp($choice);
                    405:   $choice =~ s/\s//g;
1.33      albertel  406:   if ( ($choice=~/\@/) || $choice eq '') {
1.32      raeburn   407:     open(OUT,'&gt;&gt;/tmp/loncapa_updatequery.out');
                    408:     print(OUT 'lonSupportEMail'."\t".$choice."\n");
                    409:     close(OUT);
                    410:     $lonSupportEMail=$choice;
                    411:     $flag=1;
                    412:   }
                    413:   else {
                    414:     print "Invalid input (this either needs to be blank, or look like an e-mail address!).\n";
                    415:   }
                    416: }
                    417: 
                    418: 
1.1       harris41  419: # update loncapa.conf
1.7       harris41  420: my $confdir='/etc/httpd/conf/';
                    421: #my $confdir='';
1.5       harris41  422: my $filename='loncapa.conf';
                    423: my %perlvar;
                    424:     if (-e "$confdir$filename") {
                    425: 	open(CONFIG,'&lt;'.$confdir.$filename) or die("Can't read $confdir$filename");
                    426: 	while (my $configline=&lt;CONFIG&gt;) {
                    427: 	    if ($configline =~ /^[^\#]*PerlSetVar/) {
                    428: 		my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
                    429: 		chomp($varvalue);
1.12      harris41  430: 		$perlvar{$varname}=$varvalue if $varvalue!~/^\{\[\[\[\[/;
1.5       harris41  431: 	    }
                    432: 	}
                    433: 	close(CONFIG);
                    434:     }
                    435:     $perlvar{'lonHostID'}=$lonHostID;
                    436:     $perlvar{'lonDefDomain'}=$lonDefDomain;
1.9       harris41  437:     $perlvar{'lonAdmEMail'}=$lonAdmEMail;
1.32      raeburn   438:     $perlvar{'lonSupportEMail'}=$lonSupportEMail;
1.5       harris41  439:     $perlvar{'lonRole'}=$lonRole;
1.16      harris41  440:     unless ($perlvar{'lonLoadLim'} and $perlvar{'lonLoadLim'}!~/\{\[\[\[\[/) {
1.5       harris41  441:        $perlvar{'lonLoadLim'}='2.00';
                    442:     }
1.25      albertel  443:     unless ($perlvar{'lonUserLoadLim'} and $perlvar{'lonUserLoadLim'}!~/\{\[\[\[\[/) {
                    444:        $perlvar{'lonUserLoadLim'}='0';
                    445:     }
1.16      harris41  446:     unless ($perlvar{'lonExpire'} and $perlvar{'lonExpire'}!~/\{\[\[\[\[/) {
1.5       harris41  447:        $perlvar{'lonExpire'}='86400';
                    448:     }
1.16      harris41  449:     unless ($perlvar{'lonReceipt'} and $perlvar{'lonReceipt'}!~/\{\[\[\[\[/) {
1.5       harris41  450:        my $lonReceipt='';
1.11      harris41  451:        srand(time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
1.5       harris41  452:        my @alnum=(0..9,a..z);
                    453:        foreach my $i (1..20) {
                    454: 	 $lonReceipt.=$alnum[int(rand(36))];
                    455:        }
                    456:        $perlvar{'lonReceipt'}=$lonReceipt;
                    457:     }
                    458:     open(OUT,"&gt;$confdir$filename") or
                    459:       die("Cannot output to $confdir$filename\n");
                    460:     foreach my $key (keys %perlvar) {
                    461:       my $value=$perlvar{$key};
                    462:       print(OUT &lt;&lt;END);
                    463: PerlSetVar     $key      $value
                    464: END
                    465:     }
                    466:     close(OUT);
1.1       harris41  467: }
                    468: </perlscript>
                    469: </file>
                    470: <file>
1.5       harris41  471: <target dist='default'>/</target>
1.1       harris41  472: <perlscript mode='fg'>
1.31      albertel  473: sub securesetting {
                    474:     my (%perlvar)=@_;
                    475:     my $securestatus='unknown';
                    476:     my $securenum='';
                    477:     if      ( $perlvar{'loncAllowInsecure'}&&  $perlvar{'londAllowInsecure'}) {
                    478: 	$securestatus='no';                  $securenum='4';
                    479:     } elsif ( $perlvar{'loncAllowInsecure'}&& !$perlvar{'londAllowInsecure'}) {
                    480: 	$securestatus='lond';                $securenum='3';
                    481:     } elsif (!$perlvar{'loncAllowInsecure'}&&  $perlvar{'londAllowInsecure'}) {
                    482: 	$securestatus='lonc';                $securenum='2';
                    483:     } elsif (!$perlvar{'loncAllowInsecure'}&& !$perlvar{'londAllowInsecure'}) {
                    484: 	$securestatus='yes (lond and lonc)'; $securenum='1';
                    485:     }
                    486:     return ($securestatus,$securenum);
                    487: }
1.1       harris41  488: # read values from loncapa.conf
1.7       harris41  489: my $confdir='/etc/httpd/conf/';
1.5       harris41  490: my $filename='loncapa.conf';
                    491: my %perlvar;
1.31      albertel  492: my ($securestatus,$securenum);
1.5       harris41  493:     if (-e "$confdir$filename") {
                    494: 	open(CONFIG,'&lt;'.$confdir.$filename) or 
                    495:           die("Can't read $confdir$filename");
                    496: 	while (my $configline=&lt;CONFIG&gt;) {
                    497: 	    if ($configline =~ /^[^\#]*PerlSetVar/) {
                    498: 		my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
                    499: 		chomp($varvalue);
                    500: 		$perlvar{$varname}=$varvalue;
                    501: 	    }
                    502: 	}
                    503: 	close(CONFIG);
                    504:     }
1.16      harris41  505:     unless ($perlvar{'lonLoadLim'} and $perlvar{'lonLoadLim'}!~/\{\[\[\[\[/) {
                    506:        $perlvar{'lonLoadLim'}='2.00';
                    507:     }
1.25      albertel  508:     unless ($perlvar{'lonUserLoadLim'} and $perlvar{'lonUserLoadLim'}!~/\{\[\[\[\[/) {
                    509:        $perlvar{'lonUserLoadLim'}='0';
                    510:     }
1.16      harris41  511:     unless ($perlvar{'lonExpire'} and $perlvar{'lonExpire'}!~/\{\[\[\[\[/) {
                    512:        $perlvar{'lonExpire'}='86400';
                    513:     }
1.31      albertel  514:     unless ($perlvar{'londAllowInsecure'} and $perlvar{'londAllowInsecure'}!~/\{\[\[\[\[/) {
                    515:        $perlvar{'londAllowInsecure'}='1';
                    516:     }
                    517:     unless ($perlvar{'loncAllowInsecure'} and $perlvar{'loncAllowInsecure'}!~/\{\[\[\[\[/) {
                    518:        $perlvar{'loncAllowInsecure'}='1';
                    519:     }
                    520:     ($securestatus,$securenum)=&securesetting(%perlvar);
1.16      harris41  521:     unless ($perlvar{'lonReceipt'} and $perlvar{'lonReceipt'}!~/\{\[\[\[\[/) {
                    522:        my $lonReceipt='';
                    523:        srand(time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
                    524:        my @alnum=(0..9,a..z);
                    525:        foreach my $i (1..20) {
                    526: 	 $lonReceipt.=$alnum[int(rand(36))];
                    527:        }
                    528:        $perlvar{'lonReceipt'}=$lonReceipt;
                    529:     }
1.7       harris41  530: my %perlvarstatic;
                    531:     if (-e "${confdir}loncapa_apache.conf") {
                    532: 	open(CONFIG,'&lt;'.$confdir.'loncapa_apache.conf') or 
                    533:           die("Can't read ${confdir}loncapa_apache.conf");
                    534: 	while (my $configline=&lt;CONFIG&gt;) {
                    535: 	    if ($configline =~ /^[^\#]*PerlSetVar/) {
                    536: 		my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
                    537: 		chomp($varvalue);
                    538: 		$perlvarstatic{$varname}=$varvalue;
                    539: 	    }
                    540: 	}
                    541: 	close(CONFIG);
                    542:     }
1.23      albertel  543:     if (!$domainDescription && $lonCluster ne 'existing') {
1.27      albertel  544:        open(IN,'&lt;../'.$lonCluster.'_domain.tab');
1.22      albertel  545:        while(&lt;IN&gt;) {
1.27      albertel  546:           if (/^$perlvar{'lonDefDomain'}\:/) {
1.29      albertel  547: 	     (undef,$domainDescription,$domainTabExtras)=split(/:/,$_,3);
1.22      albertel  548: 	     chomp($domainDescription);
1.29      albertel  549: 	     chomp($domainTabExtras);
1.22      albertel  550:              last;
                    551:           }
                    552:        }
1.23      albertel  553:        close(IN);
1.22      albertel  554:     }
1.23      albertel  555:     if (!$domainDescription) {
1.27      albertel  556:        open(IN,'&lt;/home/httpd/lonTabs/domain.tab');
1.23      albertel  557:        while(&lt;IN&gt;) {
1.27      albertel  558:           if (/^$perlvar{'lonDefDomain'}\:/) {
1.29      albertel  559: 	     (undef,$domainDescription,$domainTabExtras)=split(/:/,$_,3);
1.23      albertel  560: 	     chomp($domainDescription);
1.29      albertel  561: 	     chomp($domainTabExtras);
1.23      albertel  562:              last;
                    563:           }
                    564:        }
                    565:        close(IN);
                    566:     }
                    567:    
1.6       harris41  568: # implement editing logic below, interactively
1.22      albertel  569: # update loncapa.conf until 8 is entered
1.6       harris41  570: 
                    571: $flag=0;
1.17      harris41  572: 
1.6       harris41  573: while (!$flag) {
1.1       harris41  574:   print(&lt;&lt;END);
                    575: 
                    576: ===============================================================================
                    577: This is now the current configuration of your machine.
1.31      albertel  578:  1) Domain Name: $perlvar{'lonDefDomain'}
                    579:  2) Domain Description: $domainDescription
                    580:  3) Machine Name: $perlvar{'lonHostID'}
                    581:  4) System Administrator's E-mail Address: $perlvar{'lonAdmEMail'}
1.33      albertel  582:  5) Support E-mail Address: $perlvar{'lonSupportEMail'}
1.32      raeburn   583:  6) Role: $perlvar{'lonRole'}
                    584:  7) Cache Expiration Time: $perlvar{'lonExpire'}
                    585:  8) Server Load: $perlvar{'lonLoadLim'}
                    586:  9) User Load: $perlvar{'lonUserLoadLim'}
                    587: 10) Allow only secure connections: $securestatus 
                    588: 11) Everything is correct up above
1.6       harris41  589: END
1.38      www       590: 
                    591: my $error='';
                    592: foreach my $v ($perlvar{'lonDefDomain'},$perlvar{'lonHostID'}) {
                    593:    if (length($v)>16) { $error.="\nName $v too long"; }		
                    594:    if (length($v)<2) { $error.="\nName $v too short"; }
1.39      albertel  595:    if ($v=~/capa/i) {
                    596: 	if ($v!~/^oucapa\d+$/ && 
                    597: 	    ($v!~/^capa\d+$/ && $perlvar{'lonDefDomain'} eq 'uwsp')) {
                    598: 		 $error.="\nName $v contains 'capa'"; 
                    599: 	}
                    600:    }
1.41      albertel  601:    foreach my $bad ('res','raw','userfiles','priv','adm','uploaded',
                    602: 	'editupload') {
1.38      www       603:       $error.="\nName $v reserved." if $v eq $bad;
                    604:    }
                    605:    if ($v=~/\W/) { $error.="\nName $v contains special characters"; }
                    606: }
1.42    ! albertel  607: if ($domainDescription!~/^[\(\)\-\w\s,]+$/) {
1.38      www       608:    $error.="\nDomain Description contains special characters";
                    609: } 
                    610: foreach my $v ($perlvar{'lonExpire'},$perlvar{'lonLoadLim'}) {
                    611:    unless ($v=~/^[\d+\.]+$/) { $error.="\nNumber expected instead of $v"; }
                    612: }
                    613: unless (($perlvar{'lonRole'} eq 'library') || ($perlvar{'lonRole'} eq 'access')) {
                    614:    $error.="\nInvalid Role";
1.17      harris41  615: }
1.38      www       616: if ($error) { print "\n*** ERRORS: $error\n"; }
1.6       harris41  617:   print(&lt;&lt;END);
1.32      raeburn   618: ENTER A CHOICE OF 1-10 TO CHANGE, otherwise ENTER 11:
1.1       harris41  619: END
1.5       harris41  620: my $choice=&lt;&gt;;
                    621: chomp($choice);
1.6       harris41  622:   if ($choice==1) {
                    623:   print(&lt;&lt;END);
1.16      harris41  624: 1) Domain Name: $perlvar{'lonDefDomain'}
1.20      albertel  625: ENTER NEW VALUE (this is an internal value used to identify a group of
                    626:                  LON-CAPA machines, it must be alphanumerical, we suggest
                    627:                  using a part of your actual DNS domain. For example, for
                    628:                  the machine loncapa.msu.edu, we set the Domain to msu):
1.6       harris41  629: END
                    630:     my $choice2=&lt;&gt;;
                    631:     chomp($choice2);
1.8       harris41  632:     $perlvar{'lonDefDomain'}=$choice2;
1.6       harris41  633:   }
                    634:   elsif ($choice==2) {
                    635:   print(&lt;&lt;END);
1.20      albertel  636: 2) Domain Description: $domainDescription
                    637: ENTER NEW VALUE (this should be a string that describes your domain, spaces
                    638:                  and punctuation are fine except for ':'):
                    639: END
                    640:     my $choice2=&lt;&gt;;
                    641:     chomp($choice2);
                    642:     $domainDescription=$choice2;
                    643:   }
                    644:   elsif ($choice==3) {
                    645:   print(&lt;&lt;END);
                    646: 3) Machine Name: $perlvar{'lonHostID'}
                    647: ENTER NEW VALUE (this will be the name of the machine in the LON-CAPA network
                    648:                  it cannot contain any of '_' '-' '.' or ':'. We suggest that
                    649:                  if you are in the domain 'example' and are the first library
                    650:                  server you enter 'examplel1') :
1.6       harris41  651: END
                    652:     my $choice2=&lt;&gt;;
                    653:     chomp($choice2);
1.8       harris41  654:     $perlvar{'lonHostID'}=$choice2;
1.6       harris41  655:   }
1.20      albertel  656:   elsif ($choice==4) {
1.6       harris41  657:   print(&lt;&lt;END);
1.20      albertel  658: 4) System Administrator's E-mail Address: $perlvar{'lonAdmEMail'}
1.6       harris41  659: ENTER NEW VALUE:
                    660: END
                    661:     my $choice2=&lt;&gt;;
                    662:     chomp($choice2);
1.9       harris41  663:     $perlvar{'lonAdmEMail'}=$choice2;
1.6       harris41  664:   }
1.20      albertel  665:   elsif ($choice==5) {
1.6       harris41  666:   print(&lt;&lt;END);
1.32      raeburn   667: 5) Support E-mail Address: $perlvar{'lonSupportEMail'}
                    668: ENTER NEW VALUE:
                    669: END
                    670:     my $choice2=&lt;&gt;;
                    671:     chomp($choice2);
                    672:     $perlvar{'lonSupportEMail'}=$choice2;
                    673:   }
                    674:   elsif ($choice==6) {
                    675:   print(&lt;&lt;END);
                    676: 6) Role: $perlvar{'lonRole'}
1.20      albertel  677: ENTER NEW VALUE (this should be either 'access' or 'library' 
                    678:                  if in doubt select 'library'):
1.6       harris41  679: END
                    680:     my $choice2=&lt;&gt;;
                    681:     chomp($choice2);
                    682:     $perlvar{'lonRole'}=$choice2;
                    683:   }
1.32      raeburn   684:   elsif ($choice==7) {
1.6       harris41  685:   print(&lt;&lt;END);
1.32      raeburn   686: 7) Cache Expiration Time: $perlvar{'lonExpire'}
1.20      albertel  687: ENTER NEW VALUE (in seconds, 86400 is a reasonable value):
1.6       harris41  688: END
                    689:     my $choice2=&lt;&gt;;
                    690:     chomp($choice2);
                    691:     $perlvar{'lonExpire'}=$choice2;
                    692:   }
1.32      raeburn   693:   elsif ($choice==8) {
1.6       harris41  694:   print(&lt;&lt;END);
1.32      raeburn   695: 8) Server Load: $perlvar{'lonLoadLim'}
1.6       harris41  696: ENTER NEW VALUE:
                    697: END
                    698:     my $choice2=&lt;&gt;;
                    699:     chomp($choice2);
                    700:     $perlvar{'lonLoadLim'}=$choice2;
                    701:   }
1.32      raeburn   702:   elsif ($choice==9) {
1.25      albertel  703:   print(&lt;&lt;END);
1.32      raeburn   704: 9) User Load: $perlvar{'lonUserLoadLim'}
1.25      albertel  705: Numer of users that can login before machine is 'overloaded'
1.26      albertel  706: ENTER NEW VALUE (integer value, 0 means there is no limit):
1.25      albertel  707: END
                    708:     my $choice2=&lt;&gt;;
                    709:     chomp($choice2);
                    710:     $perlvar{'lonUserLoadLim'}=$choice2;
                    711:   }
1.32      raeburn   712:   elsif ($choice==10) {
1.31      albertel  713:   print(&lt;&lt;END);
1.32      raeburn   714: 10) Allow only secure connections: $securestatus 
1.31      albertel  715: The Lon-CAPA communication daemons lonc and lond can be configured to
                    716: allow only secure connections by default.
                    717: 
                    718: POSSIBLE CHOICES:
                    719: 1) allow only secure connections and don't connect to machines that
                    720:     can not be connected to securely
                    721: 2) allow only secure connections but allow this machine to connect to 
                    722:     machines that don't support secure connections
                    723: 3) allow insecure connections to this machine but only allow connections
                    724:     to machines that support secure connections
                    725: 4) allow insecure connections
                    726: ENTER NEW VALUE (currenly $securenum):
                    727: END
                    728:     my $choice2=&lt;&gt;;
                    729:     chomp($choice2);
                    730:     if      ($choice2 eq '1') {
                    731: 	$perlvar{'loncAllowInsecure'}=0;$perlvar{'londAllowInsecure'}=0;
                    732:     } elsif ($choice2 eq '2') {
                    733: 	$perlvar{'loncAllowInsecure'}=0;$perlvar{'londAllowInsecure'}=1;
                    734:     } elsif ($choice2 eq '3') {
                    735: 	$perlvar{'loncAllowInsecure'}=1;$perlvar{'londAllowInsecure'}=0;
                    736:     } elsif ($choice2 eq '4') {
                    737: 	$perlvar{'loncAllowInsecure'}=1;$perlvar{'londAllowInsecure'}=1;
                    738:     }
                    739:     ($securestatus,$securenum)=&securesetting(%perlvar);
                    740:   }
1.38      www       741:   elsif (($choice==11) && (!$error)) {
1.6       harris41  742:     $flag=1;
                    743:   }
                    744:   else {
1.38      www       745:     print "Invalid input.\n";
1.6       harris41  746:   }
                    747: }
1.7       harris41  748:     open(OUT,"&gt;$confdir$filename") or
                    749:       die("Cannot output to $confdir$filename\n");
                    750:     foreach my $key (keys %perlvar) {
                    751:       my $value=$perlvar{$key};
1.8       harris41  752:       print(OUT &lt;&lt;END) unless $perlvarstatic{$key};
1.7       harris41  753: PerlSetVar     $key      $value
                    754: END
                    755:     }
                    756:     close(OUT);
1.1       harris41  757: </perlscript>
                    758: </file>
                    759: <file>
                    760: <target dist='default'>loncom/hosts.tab</target>
                    761: <perlscript mode='fg'>
                    762: unless (-l "<TARGET />") {
1.36      albertel  763:   my $hostname=`hostname -f`;chomp($hostname);
1.15      harris41  764:   $date=`date -I`; chomp($date);
                    765:   $lonHostID=$perlvar{'lonHostID'};
                    766:   $lonHostID=~s/\W//g;
                    767:   $lineexistflag=0;
                    768:   $hostidexistflag=0;
1.22      albertel  769:   $line2insert=&lt;&lt;END;
1.35      albertel  770: $perlvar{'lonHostID'}:$perlvar{'lonDefDomain'}:$perlvar{'lonRole'}:$hostname
1.15      harris41  771: END
1.29      albertel  772:   $domaininsert="$perlvar{'lonDefDomain'}:$domainDescription:$domainTabExtras\n";
1.23      albertel  773:   if ($lonCluster eq 'standalone') {
                    774:     open(OUT,'&gt;../'.$lonCluster.'_hosts.tab') or
                    775:       die('file generation error');
                    776:       print(OUT $line2insert);
                    777:     close(OUT);
1.27      albertel  778:     open(OUT,'&gt;../'.$lonCluster.'_domain.tab') or
                    779:       die('file generation error');
                    780:       print(OUT $domaininsert);
                    781:     close(OUT);
1.23      albertel  782:   }
1.15      harris41  783:   if ($flag==1) {
1.6       harris41  784:     `rm -f ../hosts.tab`;
1.15      harris41  785:     open(IN,'&lt;../'.$lonCluster.'_hosts.tab');
1.13      harris41  786:     while(&lt;IN&gt;) {
                    787:       if (/^$line2insert$/) {
                    788:         $lineexistflag=1;
                    789:       }
1.15      harris41  790:       if (/^$lonHostID\:/) {
1.13      harris41  791:         $hostidexistflag=1;
                    792:       }
                    793:     }
                    794:     close(IN);
                    795:     if ($hostidexistflag and !$lineexistflag) {
                    796:       print &lt;&lt;END;
                    797: WARNING: $lonHostID already exists inside
1.15      harris41  798: loncapa/loncom/${lonCluster}_hosts.tab.  The entry inside
                    799: ${lonCluster}_hosts.tab does not match your settings.
                    800: The entry inside ${lonCluster}_hosts.tab is being replaced
1.13      harris41  801: with your new values.
                    802: END
1.15      harris41  803:       `grep -v "$lonHostID:" ../${lonCluster}_hosts.tab &gt; ../new_${lonCluster}_hosts.tab`;
                    804:        open(OUT,'&gt;&gt;../new_'.$lonCluster.'_hosts.tab') or
                    805:          die("cannot open loncom/${lonCluster}_hosts.tab for output\n");
1.14      harris41  806:          print(OUT $line2insert);
1.13      harris41  807:        close(OUT);
1.15      harris41  808:       `ln -s new_${lonCluster}_hosts.tab ../hosts.tab`;
1.13      harris41  809:       # email appropriate message
1.34      albertel  810:       `echo "REPLACE:$lonCluster:$lonHostID:$date:$line2insert" | mail -s "REPLACE:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
1.13      harris41  811:     }
                    812:     elsif ($hostidexistflag and $lineexistflag) {
1.15      harris41  813:       print &lt;&lt;END;
                    814: Entry exists in ${lonCluster}_hosts.tab.
                    815: END
                    816:       `ln -s ${lonCluster}_hosts.tab ../hosts.tab`;
                    817:       # email appropriate message
                    818:       `echo "STABLEUPDATE:$lonCluster:$lonHostID:$date:$line2insert" | mail -s "STABLEUPDATE:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
1.13      harris41  819:     }
1.15      harris41  820:     elsif (!$hostidexistflag and !$lineexistflag) {
                    821:       print &lt;&lt;END;
                    822: New entry for $lonCluster.
1.6       harris41  823: END
1.15      harris41  824:       `cat ../${lonCluster}_hosts.tab &gt; ../new_${lonCluster}_hosts.tab`;
1.21      albertel  825:        open(OUT,'&gt;&gt;../new_'.$lonCluster.'_hosts.tab') or
                    826:          die("cannot open loncom/new_${lonCluster}_hosts.tab for output\n");
1.15      harris41  827:          print(OUT $line2insert);
                    828:        close(OUT);
                    829:       `ln -s new_${lonCluster}_hosts.tab ../hosts.tab`;
                    830:       # email appropriate message
                    831:       `echo "INSERT:$lonCluster:$lonHostID:$date:$line2insert" | mail -s "INSERT:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
1.27      albertel  832:     }
                    833:   }
                    834:   $lineexistflag=0;
                    835:   if ($flag==1) {
                    836:     `rm -f ../domain.tab`;
                    837:     open(IN,'&lt;../'.$lonCluster.'_domain.tab');
                    838:     while(&lt;IN&gt;) {
                    839:       if (/^$domaininsert$/) {
                    840:         $lineexistflag=1;
                    841:       }
                    842:       if (/^$perlvar{'lonDefDomain'}\:/) {
                    843:         $domainexistflag=1;
                    844:       }
                    845:     }
                    846:     close(IN);
                    847:     if ($domainexistflag and !$lineexistflag) {
                    848:       print &lt;&lt;END;
                    849: WARNING: $perlvar{'lonDefDomain'} already exists inside
                    850: loncapa/loncom/${lonCluster}_domain.tab.  The entry inside
                    851: ${lonCluster}_domain.tab does not match your settings.
                    852: The entry inside ${lonCluster}_domain.tab is being replaced
                    853: with your new values.
                    854: END
                    855:       `grep -v "$perlvar{'lonDefDomain'}:" ../${lonCluster}_domain.tab &gt; ../new_${lonCluster}_domain.tab`;
                    856:        open(OUT,'&gt;&gt;../new_'.$lonCluster.'_domain.tab') or
                    857:          die("cannot open loncom/${lonCluster}_domain.tab for output\n");
                    858:          print(OUT $domaininsert);
                    859:        close(OUT);
                    860:       `ln -s new_${lonCluster}_domain.tab ../domain.tab`;
                    861:       # email appropriate message
1.34      albertel  862:       `echo "REPLACEdom:$lonCluster:$lonHostID:$date:$domaninsert" | mail -s "REPLACEdom:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
1.27      albertel  863:     }
                    864:     elsif ($domainexistflag and $lineexistflag) {
                    865:       print &lt;&lt;END;
                    866: Entry exists in ${lonCluster}_domain.tab.
                    867: END
                    868:       `ln -s ${lonCluster}_domain.tab ../domain.tab`;
                    869:       # email appropriate message
                    870:       `echo "STABLEUPDATEdom:$lonCluster:$lonHostID:$date:$domaininsert" | mail -s "STABLEUPDATEdom:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
                    871:     }
                    872:     elsif (!$domainexistflag and !$lineexistflag) {
                    873:       print &lt;&lt;END;
                    874: New entry for $lonCluster.
                    875: END
                    876:       `cat ../${lonCluster}_domain.tab &gt; ../new_${lonCluster}_domain.tab`;
                    877:        open(OUT,'&gt;&gt;../new_'.$lonCluster.'_domain.tab') or
                    878:          die("cannot open loncom/new_${lonCluster}_domain.tab for output\n");
                    879:          print(OUT $domaininsert);
                    880:        close(OUT);
                    881:       `ln -s new_${lonCluster}_domain.tab ../domain.tab`;
                    882:       # email appropriate message
                    883:       `echo "INSERTdom:$lonCluster:$lonHostID:$date:$domaininsert" | mail -s "INSERTdom:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
1.6       harris41  884:     }
                    885:   }
1.1       harris41  886: }
                    887: </perlscript>
                    888: </file>
                    889: </files>
                    890: </piml>

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