File:
[LON-CAPA] /
doc /
loncapafiles /
updatequery.piml
Revision
1.18:
download - view:
text,
annotated -
select for diffs
Sat Aug 17 19:05:03 2002 UTC (21 years, 8 months ago) by
harris41
Branches:
MAIN
CVS tags:
HEAD
BUG 649 FIX; This prevents a system administrator from ever specifying
'adm','userfiles','raw','uploaded', or 'priv' to be the lonDefDomain
for the machine. (The goal is to avoid conflicting with namespace
underneath DocumentRoot which is necessary for emerging LON-CAPA
functionality.)
1: <!-- updatequery.piml -->
2: <!-- Scott Harrison -->
3:
4: <!-- $Id: updatequery.piml,v 1.18 2002/08/17 19:05:03 harris41 Exp $ -->
5:
6: <!--
7:
8: This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9:
10: LON-CAPA is free software; you can redistribute it and/or modify
11: it under the terms of the GNU General Public License as published by
12: the Free Software Foundation; either version 2 of the License, or
13: (at your option) any later version.
14:
15: LON-CAPA is distributed in the hope that it will be useful,
16: but WITHOUT ANY WARRANTY; without even the implied warranty of
17: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: GNU General Public License for more details.
19:
20: You should have received a copy of the GNU General Public License
21: along with LON-CAPA; if not, write to the Free Software
22: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23:
24: /home/httpd/html/adm/gpl.txt
25:
26: http://www.lon-capa.org/
27:
28: -->
29:
30: <piml>
31: <targetroot>/</targetroot>
32: <files>
33: <file>
34: <target dist='default'>/</target>
35: <perlscript mode='fg'>
36: $|=1;
37: print(<<END);
38:
39:
40: *********************************************
41: *********************************************
42: **** ****
43: **** LON-CAPA SYSTEM INFORMATION REQUEST ****
44: **** ****
45: **** Please respond to the choices below ****
46: **** ****
47: *********************************************
48: *********************************************
49:
50: END
51: sleep(3);
52: </perlscript>
53: </file>
54: <file>
55: <target dist='default'>/home/httpd/lonTabs/hosts.tab</target>
56: <perlscript mode='fg'>
57: $|=1;
58: unless (-e "<TARGET />") {
59: print(<<END);
60: WELCOME TO LON-CAPA!
61:
62: If you have questions, please visit http://install.lon-capa.org
63: or contact sharrison\@mail.lon-capa.org.
64:
65: ===============================================================================
66: The following 4 values are needed to configure LON-CAPA:
67: * Machine Role
68: * LON-CAPA Domain Name
69: * LON-CAPA Machine ID Name, and
70: * System Administration E-mail Address.
71: END
72:
73: open(OUT,'>/tmp/loncapa_updatequery.out');
74: close(OUT);
75:
76: # query for Machine Role
77: print(<<END);
78: **** Machine Role ****
79: Library server (recommended if first-time installation of LON-CAPA):
80: Servers that are repositories of authoritative educational resources.
81: These servers also provide the construction space by which instructors
82: assemble their classroom online material.
83: Access server:
84: Servers that load-balance high-traffic delivery of educational resources
85: over the world-wide web.
86: 1) Will this be a library server? (recommended if this is your first install)
87: 2) Or, will this be an access server?
88: END
89: my $flag=0;
90: my $r='';
91: my $lonRole;
92: while (!$flag) {
93: print "ENTER A CHOICE OF 1 or 2:\n";
94: my $choice=<>;
95: chomp($choice);
96: if ($choice==1) {
97: open(OUT,'>>/tmp/loncapa_updatequery.out');
98: print(OUT 'lonRole'."\t".'library'."\n");
99: close(OUT);
100: $lonRole='library';
101: $r='l';
102: $flag=1;
103: }
104: elsif ($choice==2) {
105: open(OUT,'>>/tmp/loncapa_updatequery.out');
106: print(OUT 'lonRole'."\t".'access'."\n");
107: close(OUT);
108: $lonRole='access';
109: $r='a';
110: $flag=2;
111: }
112: else {
113:
114: }
115: }
116:
117: # need to recommend a machine ID name (ipdomain.l.somenumber)
118: my $hostname=`hostname`; chomp($hostname);
119: my $ipdomain='';
120: if ($hostname=~/([^\.]*)\.([^\.]*)$/) {
121: $ipdomain=$1;
122: }
123:
124: print(<<END);
125:
126: **** Domain ****
127: [this does NOT need to correspond to internet address domains,
128: examples might be "msu" or "bionet" or "vermontcc"]
129: END
130:
131: # get domain name
132: # accept if valid, if not valid, tell user and repeat
133: $flag=0;
134: my $lonDefDomain;
135: while (!$flag) {
136: if ($ipdomain) {
137: print(<<END);
138: ENTER LONCAPA DOMAIN [$ipdomain]:
139: END
140: }
141: else {
142: print(<<END);
143: ENTER LONCAPA DOMAIN:
144: END
145: }
146: my $choice=<>;
147: chomp($choice);
148: my $bad_domain_flag=0;
149: my @bad_domain_names=('raw','userfiles','priv','adm','uploaded');
150: foreach my $bad (@bad_domain_names) {
151: $bad_domain_flag=1 if $choice eq $bad;
152: }
153: if ($ipdomain and $choice=~/^\s*$/) {
154: $choice=$ipdomain;
155: open(OUT,'>>/tmp/loncapa_updatequery.out');
156: print(OUT 'lonDefDomain'."\t".$choice."\n");
157: close(OUT);
158: $lonDefDomain=$choice;
159: $flag=1;
160: }
161: elsif ($choice!~/\_/ and $choice=~/^\w+$/) {
162: open(OUT,'>>/tmp/loncapa_updatequery.out');
163: print(OUT 'lonDefDomain'."\t".$choice."\n");
164: close(OUT);
165: $lonDefDomain=$choice;
166: $r='l';
167: $flag=1;
168: }
169: elsif ($bad_domain_flag) {
170: print "Invalid input ('$choice' conflicts with LON-CAPA namespace).\n";
171: print "Please try something different than '$choice'\n";
172: }
173: else {
174: print "Invalid input (only alphanumeric characters supported).\n";
175: }
176: }
177:
178: my $lonHostID;
179: if ($lonDefDomain) {
180: $lonHostID=$lonDefDomain.$r.int(1+rand(9)); # should be probably also detect
181: # against the hosts.tab
182: }
183:
184: print(<<END);
185:
186: **** Machine ID Name ****
187: [this does NOT need to correspond to internet address names;
188: this name MUST be unique to the whole LON-CAPA network;
189: we recommend that you use a name based off of your institution;
190: good examples: "msul1" or "bionetl1";
191: bad examples: "loncapabox" or "studentsinside"]
192: END
193: # get machine name
194: # accept if valid, if not valid, tell user and repeat
195: $flag=0;
196: while (!$flag) {
197: if ($ipdomain) {
198: print(<<END);
199: ENTER LONCAPA MACHINE ID [$lonHostID]:
200: END
201: }
202: else {
203: print(<<END);
204: ENTER LONCAPA MACHINE ID:
205: END
206: }
207: my $choice=<>;
208: chomp($choice);
209: if ($lonHostID and $choice=~/^\s*$/) {
210: $choice=$lonHostID;
211: open(OUT,'>>/tmp/loncapa_updatequery.out');
212: print(OUT 'lonHostID'."\t".$choice."\n");
213: close(OUT);
214: $lonHostID=$choice;
215: $flag=1;
216: }
217: elsif ($choice!~/\_/ and $choice=~/^\w+$/) {
218: open(OUT,'>>/tmp/loncapa_updatequery.out');
219: print(OUT 'lonHostID'."\t".$choice."\n");
220: close(OUT);
221: $lonHostID=$choice;
222: $flag=1;
223: }
224: else {
225: print "Invalid input (only alphanumeric characters supported).\n";
226: }
227: }
228:
229: # get e-mail address
230: # accept if valid, if not valid, tell user and repeat
231: $flag=0;
232: my $lonAdmEMail;
233: while (!$flag) {
234: print(<<END);
235:
236: **** System Administrator's E-mail ****
237: E-mail address of the person who will manage this machine
238: [should be in the form somebody\@somewhere]
239: ENTER E-MAIL ADDRESS:
240: END
241:
242: my $choice=<>;
243: chomp($choice);
244: if ($choice=~/\@/) {
245: open(OUT,'>>/tmp/loncapa_updatequery.out');
246: print(OUT 'lonAdmEMail'."\t".$choice."\n");
247: close(OUT);
248: $lonAdmEMail=$choice;
249: $flag=1;
250: }
251: else {
252: print "Invalid input (this needs to look like an e-mail address!).\n";
253: }
254: }
255:
256: # update loncapa.conf
257: my $confdir='/etc/httpd/conf/';
258: #my $confdir='';
259: my $filename='loncapa.conf';
260: my %perlvar;
261: if (-e "$confdir$filename") {
262: open(CONFIG,'<'.$confdir.$filename) or die("Can't read $confdir$filename");
263: while (my $configline=<CONFIG>) {
264: if ($configline =~ /^[^\#]*PerlSetVar/) {
265: my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
266: chomp($varvalue);
267: $perlvar{$varname}=$varvalue if $varvalue!~/^\{\[\[\[\[/;
268: }
269: }
270: close(CONFIG);
271: }
272: $perlvar{'lonHostID'}=$lonHostID;
273: $perlvar{'lonDefDomain'}=$lonDefDomain;
274: $perlvar{'lonAdmEMail'}=$lonAdmEMail;
275: $perlvar{'lonRole'}=$lonRole;
276: unless ($perlvar{'lonLoadLim'} and $perlvar{'lonLoadLim'}!~/\{\[\[\[\[/) {
277: $perlvar{'lonLoadLim'}='2.00';
278: }
279: unless ($perlvar{'lonExpire'} and $perlvar{'lonExpire'}!~/\{\[\[\[\[/) {
280: $perlvar{'lonExpire'}='86400';
281: }
282: unless ($perlvar{'lonReceipt'} and $perlvar{'lonReceipt'}!~/\{\[\[\[\[/) {
283: my $lonReceipt='';
284: srand(time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
285: my @alnum=(0..9,a..z);
286: foreach my $i (1..20) {
287: $lonReceipt.=$alnum[int(rand(36))];
288: }
289: $perlvar{'lonReceipt'}=$lonReceipt;
290: }
291: open(OUT,">$confdir$filename") or
292: die("Cannot output to $confdir$filename\n");
293: foreach my $key (keys %perlvar) {
294: my $value=$perlvar{$key};
295: print(OUT <<END);
296: PerlSetVar $key $value
297: END
298: }
299: close(OUT);
300: }
301: </perlscript>
302: </file>
303: <file>
304: <target dist='default'>/</target>
305: <perlscript mode='fg'>
306: # read values from loncapa.conf
307: my $confdir='/etc/httpd/conf/';
308: my $filename='loncapa.conf';
309: my %perlvar;
310: if (-e "$confdir$filename") {
311: open(CONFIG,'<'.$confdir.$filename) or
312: die("Can't read $confdir$filename");
313: while (my $configline=<CONFIG>) {
314: if ($configline =~ /^[^\#]*PerlSetVar/) {
315: my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
316: chomp($varvalue);
317: $perlvar{$varname}=$varvalue;
318: }
319: }
320: close(CONFIG);
321: }
322: unless ($perlvar{'lonLoadLim'} and $perlvar{'lonLoadLim'}!~/\{\[\[\[\[/) {
323: $perlvar{'lonLoadLim'}='2.00';
324: }
325: unless ($perlvar{'lonExpire'} and $perlvar{'lonExpire'}!~/\{\[\[\[\[/) {
326: $perlvar{'lonExpire'}='86400';
327: }
328: unless ($perlvar{'lonReceipt'} and $perlvar{'lonReceipt'}!~/\{\[\[\[\[/) {
329: my $lonReceipt='';
330: srand(time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
331: my @alnum=(0..9,a..z);
332: foreach my $i (1..20) {
333: $lonReceipt.=$alnum[int(rand(36))];
334: }
335: $perlvar{'lonReceipt'}=$lonReceipt;
336: }
337: my %perlvarstatic;
338: if (-e "${confdir}loncapa_apache.conf") {
339: open(CONFIG,'<'.$confdir.'loncapa_apache.conf') or
340: die("Can't read ${confdir}loncapa_apache.conf");
341: while (my $configline=<CONFIG>) {
342: if ($configline =~ /^[^\#]*PerlSetVar/) {
343: my ($unused,$varname,$varvalue)=split(/\s+/,$configline);
344: chomp($varvalue);
345: $perlvarstatic{$varname}=$varvalue;
346: }
347: }
348: close(CONFIG);
349: }
350: # implement editing logic below, interactively
351: # update loncapa.conf until 7 is entered
352:
353: $flag=0;
354:
355: while (!$flag) {
356: print(<<END);
357:
358: ===============================================================================
359: This is now the current configuration of your machine.
360: 1) Domain Name: $perlvar{'lonDefDomain'}
361: 2) Machine Name: $perlvar{'lonHostID'}
362: 3) System Administrator's E-mail Address: $perlvar{'lonAdmEMail'}
363: 4) Role: $perlvar{'lonRole'}
364: 5) Cache Expiration Time: $perlvar{'lonExpire'}
365: 6) Server Load: $perlvar{'lonLoadLim'}
366: 7) Everything is correct up above
367: END
368: my $hbug=-1;
369: my $dbug=-1;
370: {
371: my $v=$perlvar{'lonHostID'};
372: $hbug=0;
373: $hbug=1 if $v=~/\W/;
374: $hbug=1 if $v=~/\_/;
375: }
376: {
377: my $v=$1;
378: $dbug=0;
379: $dbug=1 if $v=~/\W/;
380: $dbug=1 if $v=~/\_/;
381: }
382:
383: if ($hbug) {
384: print "**** ERROR **** ".
385: "Invalid lonHostID (should only be letters and/or digits)\n";
386: }
387: if ($dbug) {
388: print "**** ERROR **** ".
389: "Invalid lonDefDomain (should only be letters and/or digits)\n";
390: }
391:
392: print(<<END);
393: ENTER A CHOICE OF 1-6 TO CHANGE, otherwise ENTER 7:
394: END
395: my $choice=<>;
396: chomp($choice);
397: if ($choice==1) {
398: print(<<END);
399: 1) Domain Name: $perlvar{'lonDefDomain'}
400: ENTER NEW VALUE:
401: END
402: my $choice2=<>;
403: chomp($choice2);
404: $perlvar{'lonDefDomain'}=$choice2;
405: }
406: elsif ($choice==2) {
407: print(<<END);
408: 2) Machine Name: $perlvar{'lonHostID'}
409: ENTER NEW VALUE:
410: END
411: my $choice2=<>;
412: chomp($choice2);
413: $perlvar{'lonHostID'}=$choice2;
414: }
415: elsif ($choice==3) {
416: print(<<END);
417: 3) System Administrator's E-mail Address: $perlvar{'lonAdmEMail'}
418: ENTER NEW VALUE:
419: END
420: my $choice2=<>;
421: chomp($choice2);
422: $perlvar{'lonAdmEMail'}=$choice2;
423: }
424: elsif ($choice==4) {
425: print(<<END);
426: 4) Role: $perlvar{'lonRole'}
427: ENTER NEW VALUE:
428: END
429: my $choice2=<>;
430: chomp($choice2);
431: $perlvar{'lonRole'}=$choice2;
432: }
433: elsif ($choice==5) {
434: print(<<END);
435: 5) Cache Expiration Time: $perlvar{'lonExpire'}
436: ENTER NEW VALUE:
437: END
438: my $choice2=<>;
439: chomp($choice2);
440: $perlvar{'lonExpire'}=$choice2;
441: }
442: elsif ($choice==6) {
443: print(<<END);
444: 6) Server Load: $perlvar{'lonLoadLim'}
445: ENTER NEW VALUE:
446: END
447: my $choice2=<>;
448: chomp($choice2);
449: $perlvar{'lonLoadLim'}=$choice2;
450: }
451: elsif ($choice==7) {
452: $flag=1;
453: }
454: else {
455:
456: }
457: }
458: open(OUT,">$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 <<END) unless $perlvarstatic{$key};
463: PerlSetVar $key $value
464: END
465: }
466: close(OUT);
467: </perlscript>
468: </file>
469: <file>
470: <target dist='default'>loncom/hosts.tab</target>
471: <perlscript mode='fg'>
472: unless (-l "<TARGET />") {
473: print(<<END);
474:
475: ===============================================================================
476: What hosts.tab would you like to have installed?
477: (hosts.tab is a listing of all other internet machines
478: that a server system considers to be valid server systems
479: on the LON-CAPA network)
480:
481: 1) PRODUCTION - you want to deliver courses today or sometime very soon
482: on this machine
483: 2) STAND-ALONE - you want this machine to run in 'stand-alone' mode and
484: not be connected to other LON-CAPA machines for now
485: 3) DEVELOPMENT - you want to play with or explore LON-CAPA
486: 4) PRESERVE the existing hosts.tab (/home/httpd/lonTabs/hosts.tab)
487:
488: END
489: # Option number 26 will install rawhide_hosts.tab, but
490: # the typical user does not want to be part of an intensive
491: # machine test cluster.
492:
493: # get input
494: # if valid then process, otherwise loop
495: my $hostname=`hostname`;chomp($hostname);
496: my $hostaddress=`hostname -i $hostname`;chomp($hostaddress);
497: $flag=0;
498: while (!$flag) {
499: print "ENTER 1, 2, 3, or 4:\n";
500: my $choice=<>;
501: chomp($choice);
502: $line2insert=<<END;
503: $perlvar{'lonHostID'}:$perlvar{'lonDefDomain'}:$perlvar{'lonRole'}:$hostname:$hostaddress
504: END
505: $date=`date -I`; chomp($date);
506: $lonHostID=$perlvar{'lonHostID'};
507: $lonHostID=~s/\W//g;
508: $lineexistflag=0;
509: $hostidexistflag=0;
510: if ($choice==1) {
511: $lonCluster='production'; $flag=1;
512: }
513: elsif ($choice==2) {
514: $lonCluster='standalone'; $flag=1;
515: open(OUT,'>../'.$lonCluster.'_hosts.tab') or
516: die('file generation error');
517: print(OUT $line2insert);
518: close(OUT);
519: }
520: elsif ($choice==3) {
521: $lonCluster='development'; $flag=1;
522: }
523: elsif ($choice==4) {
524: $lonCluster='existing'; $flag=1;
525: if (-e '/home/httpd/lonTabs/hosts.tab') {
526: `cp /home/httpd/lonTabs/hosts.tab ../existing_hosts.tab`;
527: }
528: else {
529: print <<END;
530: There is no existing /home/httpd/lonTabs/hosts.tab
531: END
532: die('');
533: }
534: }
535: elsif ($choice==26) {
536: $lonCluster='rawhide'; $flag=1;
537: }
538: if ($flag==1) {
539: `rm -f ../hosts.tab`;
540: open(IN,'<../'.$lonCluster.'_hosts.tab');
541: while(<IN>) {
542: if (/^$line2insert$/) {
543: $lineexistflag=1;
544: }
545: if (/^$lonHostID\:/) {
546: $hostidexistflag=1;
547: }
548: }
549: close(IN);
550: if ($hostidexistflag and !$lineexistflag) {
551: print <<END;
552: WARNING: $lonHostID already exists inside
553: loncapa/loncom/${lonCluster}_hosts.tab. The entry inside
554: ${lonCluster}_hosts.tab does not match your settings.
555: The entry inside ${lonCluster}_hosts.tab is being replaced
556: with your new values.
557: END
558: `grep -v "$lonHostID:" ../${lonCluster}_hosts.tab > ../new_${lonCluster}_hosts.tab`;
559: open(OUT,'>>../new_'.$lonCluster.'_hosts.tab') or
560: die("cannot open loncom/${lonCluster}_hosts.tab for output\n");
561: print(OUT $line2insert);
562: close(OUT);
563: `ln -s new_${lonCluster}_hosts.tab ../hosts.tab`;
564: # email appropriate message
565: `echo "REPLACE:$lonCluster:$lonHostID:$date:$line2insert" | mail -s "REPLACE:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
566: }
567: elsif ($hostidexistflag and $lineexistflag) {
568: print <<END;
569: Entry exists in ${lonCluster}_hosts.tab.
570: END
571: `ln -s ${lonCluster}_hosts.tab ../hosts.tab`;
572: # email appropriate message
573: `echo "STABLEUPDATE:$lonCluster:$lonHostID:$date:$line2insert" | mail -s "STABLEUPDATE:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
574: }
575: elsif (!$hostidexistflag and !$lineexistflag) {
576: print <<END;
577: New entry for $lonCluster.
578: END
579: `cat ../${lonCluster}_hosts.tab > ../new_${lonCluster}_hosts.tab`;
580: open(OUT,'>../new_'.$lonCluster.'_hosts.tab') or
581: die("cannot open loncom/${lonCluster}_hosts.tab for output\n");
582: print(OUT $line2insert);
583: close(OUT);
584: `ln -s new_${lonCluster}_hosts.tab ../hosts.tab`;
585: # email appropriate message
586: `echo "INSERT:$lonCluster:$lonHostID:$date:$line2insert" | mail -s "INSERT:$lonCluster:$lonHostID:$date" installrecord\@mail.lon-capa.org`;
587: }
588: }
589: }
590:
591: }
592: </perlscript>
593: </file>
594: </files>
595: </piml>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>