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