Annotation of doc/install/linux/install.pl, revision 1.53
1.1 raeburn 1: #!/usr/bin/perl
2: # The LearningOnline Network
3: # Pre-installation script for LON-CAPA
4: #
5: # Copyright Michigan State University Board of Trustees
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: # http://www.lon-capa.org/
24: #
25:
26: use strict;
27: use File::Copy;
28: use Term::ReadKey;
1.47 raeburn 29: use Socket;
1.46 raeburn 30: use Sys::Hostname::FQDN();
1.1 raeburn 31: use DBI;
1.43 raeburn 32: use Cwd();
33: use File::Basename();
34: use lib File::Basename::dirname(Cwd::abs_path($0));
1.1 raeburn 35: use LCLocalization::localize;
36:
37: # ========================================================= The language handle
38:
39: my %languages = (
40: ar => 'Arabic',
41: de => 'German',
42: en => 'English',
43: es => 'Spanish (Castellan)',
44: fa => 'Persian',
45: fr => 'French',
46: he => 'Hebrew',
47: ja => 'Japanese',
48: pt => 'Portuguese',
49: ru => 'Russian',
50: tr => 'Turkish',
51: zh => 'Chinese Simplified'
52: );
53:
54: use vars qw($lh $lang);
55: $lang = 'en';
56: if (@ARGV > 0) {
57: foreach my $poss (keys(%languages)) {
58: if ($ARGV[0] eq $poss) {
59: $lang = $ARGV[0];
60: }
61: }
62: }
63:
64: &get_language_handle($lang);
65:
66: # Check user has root privs
67: if (0 != $<) {
68: print &mt('This script must be run as root.')."\n".
69: &mt('Stopping execution.')."\n";
70: exit;
71: }
72:
73:
74: # Globals: filehandle LOG is global.
75: if (!open(LOG,">>loncapa_install.log")) {
76: print &mt('Unable to open log file.')."\n".
77: &mt('Stopping execution.')."\n";
78: exit;
79: } else {
1.53 ! raeburn 80: print LOG '$Id: install.pl,v 1.52 2019/02/19 19:22:36 raeburn Exp $'."\n";
1.1 raeburn 81: }
82:
83: #
1.2 raeburn 84: # Helper routines and routines to establish recommended actions
1.1 raeburn 85: #
86:
87: sub get_language_handle {
88: my @languages = @_;
89: $lh=LCLocalization::localize->get_handle(@languages);
90: }
91:
92: sub mt (@) {
93: if ($lh) {
94: if ($_[0] eq '') {
95: if (wantarray) {
96: return @_;
97: } else {
98: return $_[0];
99: }
100: } else {
101: return $lh->maketext(@_);
102: }
103: } else {
104: if (wantarray) {
105: return @_;
106: } else {
107: return $_[0];
108: }
109: }
110: }
111:
112: sub texthash {
113: my (%hash) = @_;
114: foreach (keys(%hash)) {
115: $hash{$_}=&mt($hash{$_});
116: }
117: return %hash;
118: }
119:
120:
121: sub skip_if_nonempty {
122: my ($string,$error)=@_;
123: return if (! defined($error));
124: chomp($string);chomp($error);
125: if ($string ne '') {
126: print_and_log("$error\n".&mt('Stopping execution.')."\n");
127: return 1;
128: }
129: return;
130: }
131:
132: sub writelog {
133: while ($_ = shift) {
134: chomp();
135: print LOG "$_\n";
136: }
137: }
138:
139: sub print_and_log {
140: while ($_=shift) {
141: chomp();
142: print "$_\n";
143: print LOG "$_\n";
144: }
145: }
146:
147: sub get_user_selection {
148: my ($defaultrun) = @_;
149: my $do_action = 0;
150: my $choice = <STDIN>;
151: chomp($choice);
152: $choice =~ s/(^\s+|\s+$)//g;
153: my $yes = &mt('y');
154: if ($defaultrun) {
155: if (($choice eq '') || ($choice =~ /^\Q$yes\E/i)) {
156: $do_action = 1;
157: }
158: } else {
159: if ($choice =~ /^\Q$yes\E/i) {
160: $do_action = 1;
161: }
162: }
163: return $do_action;
164: }
165:
166: sub get_distro {
1.49 raeburn 167: my ($distro,$gotprereqs,$updatecmd,$packagecmd,$installnow,$unknown);
1.1 raeburn 168: $packagecmd = '/bin/rpm -q LONCAPA-prerequisites ';
169: if (-e '/etc/redhat-release') {
170: open(IN,'</etc/redhat-release');
171: my $versionstring=<IN>;
172: chomp($versionstring);
173: close(IN);
174: if ($versionstring =~ /^Red Hat Linux release ([\d\.]+) /) {
175: my $version = $1;
176: if ($version=~/^7\./) {
177: $distro='redhat7';
178: } elsif ($version=~/^8\./) {
179: $distro='redhat8';
180: } elsif ($version=~/^9/) {
181: $distro='redhat9';
182: }
183: } elsif ($versionstring =~ /Fedora( Core)? release ([\d\.]+) /) {
184: my $version=$2;
185: if ($version - int($version) > .9) {
186: $distro = 'fedora'.(int($version)+1);
187: } else {
188: $distro = 'fedora'.int($version);
189: }
190: $updatecmd = 'yum install LONCAPA-prerequisites';
191: $installnow = 'yum -y install LONCAPA-prerequisites';
192: } elsif ($versionstring =~ /Red Hat Enterprise Linux [AE]S release ([\d\.]+) /) {
193: $distro = 'rhes'.$1;
194: $updatecmd = 'up2date -i LONCAPA-prerequisites';
195: } elsif ($versionstring =~ /Red Hat Enterprise Linux Server release (\d+)/) {
196: $distro = 'rhes'.$1;
197: $updatecmd = 'yum install LONCAPA-prerequisites';
198: $installnow = 'yum -y install LONCAPA-prerequisites';
1.21 raeburn 199: } elsif ($versionstring =~ /CentOS(?:| Linux) release (\d+)/) {
1.1 raeburn 200: $distro = 'centos'.$1;
201: $updatecmd = 'yum install LONCAPA-prerequisites';
202: $installnow = 'yum -y install LONCAPA-prerequisites';
1.22 raeburn 203: } elsif ($versionstring =~ /Scientific Linux (?:SL )?release ([\d.]+) /) {
1.1 raeburn 204: my $ver = $1;
205: $ver =~ s/\.\d+$//;
206: $distro = 'scientific'.$ver;
207: $updatecmd = 'yum install LONCAPA-prerequisites';
208: $installnow = 'yum -y install LONCAPA-prerequisites';
209: } else {
210: print &mt('Unable to interpret [_1] to determine system type.',
211: '/etc/redhat-release')."\n";
1.49 raeburn 212: $unknown = 1;
1.1 raeburn 213: }
214: } elsif (-e '/etc/SuSE-release') {
215: open(IN,'</etc/SuSE-release');
216: my $versionstring=<IN>;
217: chomp($versionstring);
218: close(IN);
219: if ($versionstring =~ /^SUSE LINUX Enterprise Server ([\d\.]+) /i) {
220: $distro='sles'.$1;
221: if ($1 >= 10) {
222: $updatecmd = 'zypper install LONCAPA-prerequisites';
223: } else {
224: $updatecmd = 'yast -i LONCAPA-prerequisites';
225: }
226: } elsif ($versionstring =~ /^SuSE Linux ([\d\.]+) /i) {
227: $distro = 'suse'.$1;
1.12 raeburn 228: $updatecmd = 'yast -i LONCAPA-prerequisites';
1.1 raeburn 229: } elsif ($versionstring =~ /^openSUSE ([\d\.]+) /i) {
230: $distro = 'suse'.$1;
231: if ($1 >= 10.3 ) {
232: $updatecmd = 'zypper install LONCAPA-prerequisites';
233: } else {
234: $updatecmd = 'yast -i LONCAPA-prerequisites';
235: }
236: } else {
237: print &mt('Unable to interpret [_1] to determine system type.',
238: '/etc/SuSE-release')."\n";
1.49 raeburn 239: $unknown = 1;
1.1 raeburn 240: }
241: } elsif (-e '/etc/issue') {
242: open(IN,'</etc/issue');
243: my $versionstring=<IN>;
244: chomp($versionstring);
245: close(IN);
246: if ($versionstring =~ /^Ubuntu (\d+)\.\d+/i) {
247: $distro = 'ubuntu'.$1;
248: $updatecmd = 'sudo apt-get install loncapa-prerequisites';
249: } elsif ($versionstring =~ /^Debian\s+GNU\/Linux\s+(\d+)\.\d+/i) {
250: $distro = 'debian'.$1;
1.49 raeburn 251: $updatecmd = 'apt-get install loncapa-prerequisites';
1.1 raeburn 252: } elsif (-e '/etc/debian_version') {
253: open(IN,'</etc/debian_version');
254: my $version=<IN>;
255: chomp($version);
256: close(IN);
257: if ($version =~ /^(\d+)\.\d+\.?\d*/) {
258: $distro='debian'.$1;
1.49 raeburn 259: $updatecmd = 'apt-get install loncapa-prerequisites';
1.1 raeburn 260: } else {
261: print &mt('Unable to interpret [_1] to determine system type.',
262: '/etc/debian_version')."\n";
1.49 raeburn 263: $unknown = 1;
1.1 raeburn 264: }
1.49 raeburn 265: }
266: if ($distro ne '') {
267: $packagecmd = '/usr/bin/dpkg -l loncapa-prerequisites ';
1.1 raeburn 268: }
269: } elsif (-e '/etc/debian_version') {
270: open(IN,'</etc/debian_version');
271: my $version=<IN>;
272: chomp($version);
273: close(IN);
274: if ($version =~ /^(\d+)\.\d+\.?\d*/) {
275: $distro='debian'.$1;
276: $packagecmd = '/usr/bin/dpkg -l loncapa-prerequisites ';
277: $updatecmd = 'apt-get install loncapa-prerequisites';
278: } else {
279: print &mt('Unable to interpret [_1] to determine system type.',
280: '/etc/debian_version')."\n";
1.49 raeburn 281: $unknown = 1;
282: }
283: }
284: if (($distro eq '') && (!$unknown)) {
285: if (-e '/etc/os-release') {
286: if (open(IN,'<','/etc/os-release')) {
287: my ($id,$version);
288: while(<IN>) {
289: chomp();
290: if (/^ID="(\w+)"/) {
291: $id=$1;
292: } elsif (/^VERSION_ID="([\d\.]+)"/) {
293: $version=$1;
294: }
295: }
296: close(IN);
297: if ($id eq 'sles') {
298: my ($major,$minor) = split(/\./,$version);
299: if ($major =~ /^\d+$/) {
300: $distro = $id.$major;
301: $updatecmd = 'zypper install LONCAPA-prerequisites';
302: }
303: }
304: }
305: if ($distro eq '') {
306: print &mt('Unable to interpret [_1] to determine system type.',
307: '/etc/os-release')."\n";
308: $unknown = 1;
309: }
310: } else {
311: print &mt('Unknown installation: expecting a debian, ubuntu, suse, sles, redhat, fedora or scientific linux system.')."\n";
1.1 raeburn 312: }
313: }
314: return ($distro,$packagecmd,$updatecmd,$installnow);
315: }
316:
1.47 raeburn 317: #
318: # get_hostname() prompts the user to provide the server's hostname.
319: #
320: # If invalid input is provided, the routine is called recursively
321: # until, a valid hostname is provided.
322: #
323:
1.46 raeburn 324: sub get_hostname {
325: my $hostname;
326: print &mt('Enter the hostname of this server, e.g., loncapa.somewhere.edu'."\n");
327: my $choice = <STDIN>;
328: chomp($choice);
329: $choice =~ s/(^\s+|\s+$)//g;
330: if ($choice eq '') {
331: print &mt("Hostname you entered was either blank or contanied only white space.\n");
332: } elsif ($choice =~ /^[\w\.\-]+$/) {
333: $hostname = $choice;
334: } else {
335: print &mt("Hostname you entered was invalid -- a hostname may only contain letters, numbers, - and .\n");
336: }
337: while ($hostname eq '') {
338: $hostname = &get_hostname();
339: }
340: print "\n";
341: return $hostname;
342: }
343:
1.47 raeburn 344: #
345: # get_hostname() prompts the user to provide the server's IPv4 IP address
346: #
347: # If invalid input is provided, the routine is called recursively
348: # until, a valid IPv4 address is provided.
349: #
350:
351: sub get_hostip {
352: my $hostip;
353: print &mt('Enter the IP address of this server, e.g., 192.168.10.24'."\n");
354: my $choice = <STDIN>;
355: chomp($choice);
356: $choice =~ s/(^\s+|\s+$)//g;
357: my $badformat = 1;
358: if ($choice eq '') {
359: print &mt("IP address you entered was either blank or contained only white space.\n");
360: } else {
361: if ($choice =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) {
362: if (($1<=255) && ($2<=255) && ($3<=255) && ($4<=255)) {
363: $badformat = 0;
364: }
365: }
366: if ($badformat) {
367: print &mt('Host IP you entered was invalid -- a host IP has the format d.d.d.d where each d is an integer between 0 and 255')."\n";
368: } else {
369: $hostip = $choice;
370: }
371: }
372: while ($hostip eq '') {
373: $hostip = &get_hostip();
374: }
375: print "\n";
376: return $hostip;
377: }
378:
1.1 raeburn 379: sub check_prerequisites {
380: my ($packagecmd,$distro) = @_;
381: my $gotprereqs;
382: if ($packagecmd ne '') {
383: if (open(PIPE,"$packagecmd|")) {
384: if ($distro =~ /^(debian|ubuntu)/) {
385: my @lines = <PIPE>;
386: chomp(@lines);
387: foreach my $line (@lines) {
388: if ($line =~ /^ii\s+loncapa-prerequisites\s+([\w\.]+)/) {
389: $gotprereqs = $1;
390: }
391: }
392: } else {
393: my $line = <PIPE>;
394: chomp($line);
1.8 raeburn 395: if ($line =~ /^LONCAPA\-prerequisites\-([\d\-]+)\.(?:[.\w]+)$/) {
1.1 raeburn 396: $gotprereqs = $1;
397: }
398: }
399: close(PIPE);
400: } else {
401: print &mt('Error: could not determine if LONCAPA-prerequisites package is installed')."\n";
402: }
403: }
404: return $gotprereqs;
405: }
406:
1.6 raeburn 407: sub check_locale {
408: my ($distro) = @_;
1.8 raeburn 409: my ($fh,$langvar,$command);
410: $langvar = 'LANG';
1.6 raeburn 411: if ($distro =~ /^(ubuntu|debian)/) {
412: if (!open($fh,"</etc/default/locale")) {
413: print &mt('Failed to open: [_1], default locale not checked.',
414: '/etc/default/locale');
415: }
1.49 raeburn 416: } elsif ($distro =~ /^(suse|sles)(\d+)/) {
417: if (($1 eq 'sles') && ($2 >= 15)) {
418: if (!open($fh,"</etc/locale.conf")) {
419: print &mt('Failed to open: [_1], default locale not checked.',
420: '/etc/locale.conf');
421: }
422: } else {
423: if (!open($fh,"</etc/sysconfig/language")) {
424: print &mt('Failed to open: [_1], default locale not checked.',
425: '/etc/sysconfig/language');
426: }
427: $langvar = 'RC_LANG';
1.8 raeburn 428: }
1.24 raeburn 429: } elsif ($distro =~ /^fedora(\d+)/) {
430: if ($1 >= 18) {
431: if (!open($fh,"</etc/locale.conf")) {
432: print &mt('Failed to open: [_1], default locale not checked.',
433: '/etc/locale.conf');
434: }
435: } elsif (!open($fh,"</etc/sysconfig/i18n")) {
436: print &mt('Failed to open: [_1], default locale not checked.',
437: '/etc/sysconfig/i18n');
438: }
1.29 raeburn 439: } elsif ($distro =~ /^(?:rhes|centos|scientific)(\d+)/) {
440: if ($1 >= 7) {
441: if (!open($fh,"</etc/locale.conf")) {
442: print &mt('Failed to open: [_1], default locale not checked.',
443: '/etc/locale.conf');
444: }
445: } elsif (!open($fh,"</etc/sysconfig/i18n")) {
446: print &mt('Failed to open: [_1], default locale not checked.',
447: '/etc/sysconfig/i18n');
448: }
1.6 raeburn 449: } else {
450: if (!open($fh,"</etc/sysconfig/i18n")) {
451: print &mt('Failed to open: [_1], default locale not checked.',
452: '/etc/sysconfig/i18n');
453: }
454: }
455: my @data = <$fh>;
456: chomp(@data);
457: foreach my $item (@data) {
1.25 raeburn 458: if ($item =~ /^\Q$langvar\E=\"?([^\"]*)\"?/) {
1.6 raeburn 459: my $default = $1;
460: if ($default ne 'en_US.UTF-8') {
461: if ($distro =~ /^debian/) {
1.25 raeburn 462: $command = 'locale-gen en_US.UTF-8'."\n".
463: 'update-locale LANG=en_US.UTF-8';
1.6 raeburn 464: } elsif ($distro =~ /^ubuntu/) {
1.25 raeburn 465: $command = 'sudo locale-gen en_US.UTF-8'."\n".
466: 'sudo update-locale LANG=en_US.UTF-8';
1.7 raeburn 467: } elsif ($distro =~ /^(suse|sles)/) {
468: $command = 'yast language';
1.6 raeburn 469: } else {
470: $command = 'system-config-language';
471: }
472: }
473: last;
474: }
475: }
476: close($fh);
477: return $command;
478: }
479:
1.1 raeburn 480: sub check_required {
481: my ($instdir,$dsn) = @_;
482: my ($distro,$packagecmd,$updatecmd,$installnow) = &get_distro();
483: if ($distro eq '') {
484: return;
485: }
486: my $gotprereqs = &check_prerequisites($packagecmd,$distro);
487: if ($gotprereqs eq '') {
1.22 raeburn 488: return ($distro,$gotprereqs,'',$packagecmd,$updatecmd);
1.6 raeburn 489: }
490: my $localecmd = &check_locale($distro);
491: unless ($localecmd eq '') {
492: return ($distro,$gotprereqs,$localecmd);
1.1 raeburn 493: }
1.34 raeburn 494: my ($mysqlon,$mysqlsetup,$mysqlrestart,$dbh,$has_pass,$has_lcdb,%recommended,
1.46 raeburn 495: $downloadstatus,$filetouse,$production,$testing,$apachefw,$tostop,
1.47 raeburn 496: $uses_systemctl,$hostname,$hostip);
1.1 raeburn 497: my $wwwuid = &uid_of_www();
498: my $wwwgid = getgrnam('www');
499: if (($wwwuid eq '') || ($wwwgid eq '')) {
500: $recommended{'wwwuser'} = 1;
501: }
502: unless( -e "/usr/local/sbin/pwauth") {
503: $recommended{'pwauth'} = 1;
504: }
1.47 raeburn 505: $hostname = Sys::Hostname::FQDN::fqdn();
1.46 raeburn 506: if ($hostname eq '') {
507: $hostname =&get_hostname();
508: } else {
509: print &mt("Hostname detected: $hostname. Is that correct? ~[Y/n~]");
510: if (!&get_user_selection(1)) {
511: $hostname =&get_hostname();
512: }
513: }
1.47 raeburn 514: $hostip = Socket::inet_ntoa(scalar(gethostbyname($hostname)) || 'localhost');
515: if ($hostip eq '') {
516: $hostip=&get_hostip();
517: } else {
518: print &mt("Host IP address detected: $hostip. Is that correct? ~[Y/n~]");
519: if (!&get_user_selection(1)) {
520: $hostip=&get_hostip();
521: }
522: }
523: print_and_log("\n".&mt('Hostname is [_1] and IP address is [_2]',$hostname,$hostip)."\n");
1.1 raeburn 524: $mysqlon = &check_mysql_running($distro);
525: if ($mysqlon) {
526: my $mysql_has_wwwuser = &check_mysql_wwwuser();
1.34 raeburn 527: ($mysqlsetup,$has_pass,$dbh,$mysql_has_wwwuser) =
528: &check_mysql_setup($instdir,$dsn,$distro,$mysql_has_wwwuser);
529: if ($mysqlsetup eq 'needsrestart') {
530: $mysqlrestart = '';
531: if ($distro eq 'ubuntu') {
532: $mysqlrestart = 'sudo ';
533: }
534: $mysqlrestart .= 'service mysql restart';
535: return ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,$mysqlrestart);
1.1 raeburn 536: } else {
1.34 raeburn 537: if ($mysqlsetup eq 'noroot') {
1.1 raeburn 538: $recommended{'mysqlperms'} = 1;
1.34 raeburn 539: } else {
540: unless ($mysql_has_wwwuser) {
541: $recommended{'mysqlperms'} = 1;
542: }
543: }
544: if ($dbh) {
545: $has_lcdb = &check_loncapa_mysqldb($dbh);
546: }
547: unless ($has_lcdb) {
548: $recommended{'mysql'} = 1;
1.1 raeburn 549: }
550: }
551: }
1.47 raeburn 552: my ($sslhostsfilesref,$has_std,$has_int,$rewritenum,$nochgstd,$nochgint);
1.5 raeburn 553: ($recommended{'firewall'},$apachefw) = &chkfirewall($distro);
1.35 raeburn 554: ($recommended{'runlevels'},$tostop,$uses_systemctl) = &chkconfig($distro,$instdir);
1.1 raeburn 555: $recommended{'apache'} = &chkapache($distro,$instdir);
1.47 raeburn 556: ($recommended{'apachessl'},$sslhostsfilesref,$has_std,$has_int,$rewritenum,
557: $nochgstd,$nochgint) = &chkapachessl($distro,$instdir,$hostname,$hostip);
1.1 raeburn 558: $recommended{'stopsrvcs'} = &chksrvcs($distro,$tostop);
559: ($recommended{'download'},$downloadstatus,$filetouse,$production,$testing)
560: = &need_download();
1.6 raeburn 561: return ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,
1.34 raeburn 562: $mysqlrestart,\%recommended,$dbh,$has_pass,$has_lcdb,$downloadstatus,
1.47 raeburn 563: $filetouse,$production,$testing,$apachefw,$uses_systemctl,$hostname,
564: $hostip,$sslhostsfilesref,$has_std,$has_int,$rewritenum,$nochgstd,
565: $nochgint);
1.1 raeburn 566: }
567:
568: sub check_mysql_running {
569: my ($distro) = @_;
1.23 raeburn 570: my $use_systemctl;
1.1 raeburn 571: my $mysqldaemon ='mysqld';
572: if ($distro =~ /^(suse|sles|debian|ubuntu)/) {
573: $mysqldaemon = 'mysql';
574: }
1.6 raeburn 575: my $process = 'mysqld_safe';
576: my $proc_owner = 'root';
577: if ($distro =~ /^ubuntu(\w+)/) {
578: if ($1 >= 10) {
579: $process = 'mysqld';
580: $proc_owner = 'mysql';
581: }
1.35 raeburn 582: } elsif ($distro =~ /^fedora(\d+)/) {
1.23 raeburn 583: if ($1 >= 16) {
584: $process = 'mysqld';
585: $proc_owner = 'mysql';
586: $use_systemctl = 1;
587: }
1.39 raeburn 588: if ($1 >= 19) {
1.37 raeburn 589: $mysqldaemon ='mariadb';
590: }
1.35 raeburn 591: } elsif ($distro =~ /^(?:centos|rhes|scientific)(\d+)/) {
1.29 raeburn 592: if ($1 >= 7) {
593: $mysqldaemon ='mariadb';
594: $process = 'mysqld';
595: $proc_owner = 'mysql';
596: $use_systemctl = 1;
597: }
1.35 raeburn 598: } elsif ($distro =~ /^sles(\d+)/) {
599: if ($1 >= 12) {
600: $use_systemctl = 1;
1.42 raeburn 601: $proc_owner = 'mysql';
602: $process = 'mysqld';
1.35 raeburn 603: }
1.49 raeburn 604: if ($1 >= 15) {
605: $mysqldaemon ='mariadb';
606: }
1.35 raeburn 607: } elsif ($distro =~ /^suse(\d+)/) {
608: if ($1 >= 13) {
609: $use_systemctl = 1;
610: }
1.29 raeburn 611: }
1.35 raeburn 612: if (open(PIPE,"ps -ef |grep $process |grep ^$proc_owner |grep -v grep 2>&1 |")) {
1.1 raeburn 613: my $status = <PIPE>;
614: close(PIPE);
615: chomp($status);
1.6 raeburn 616: if ($status =~ /^\Q$proc_owner\E\s+\d+\s+/) {
1.1 raeburn 617: print_and_log(&mt('MySQL is running.')."\n");
618: return 1;
619: } else {
1.23 raeburn 620: if ($use_systemctl) {
621: system("/bin/systemctl start $mysqldaemon.service >/dev/null 2>&1 ");
622: } else {
623: system("/etc/init.d/$mysqldaemon start >/dev/null 2>&1 ");
624: }
1.1 raeburn 625: print_and_log(&mt('Waiting for MySQL to start.')."\n");
626: sleep 5;
1.12 raeburn 627: if (open(PIPE,"ps -ef |grep $process |grep -v grep 2>&1 |")) {
628: $status = <PIPE>;
1.1 raeburn 629: close(PIPE);
630: chomp($status);
1.12 raeburn 631: if ($status =~ /^\Q$proc_owner\E\s+\d+\s+/) {
1.1 raeburn 632: print_and_log(&mt('MySQL is running.')."\n");
633: return 1;
634: } else {
1.12 raeburn 635: print_and_log(&mt('Still waiting for MySQL to start.')."\n");
636: sleep 5;
637: if (open(PIPE,"ps -ef |grep $process |grep -v grep 2>&1 |")) {
638: $status = <PIPE>;
639: close(PIPE);
640: chomp($status);
641: if ($status =~ /^\Q$proc_owner\E\s+\d+\s+/) {
642: print_and_log(&mt('MySQL is running.')."\n");
643: return 1;
644: } else {
645: print_and_log(&mt('Given up waiting for MySQL to start.')."\n");
646: }
647: }
1.1 raeburn 648: }
649: }
650: }
651: } else {
652: print &mt('Could not determine if MySQL is running.')."\n";
653: }
654: return;
655: }
656:
657: sub chkconfig {
1.8 raeburn 658: my ($distro,$instdir) = @_;
1.23 raeburn 659: my (%needfix,%tostop,%uses_systemctl);
1.1 raeburn 660: my $checker_bin = '/sbin/chkconfig';
1.23 raeburn 661: my $sysctl_bin = '/bin/systemctl';
1.6 raeburn 662: my %daemon = (
663: mysql => 'mysqld',
664: apache => 'httpd',
665: cups => 'cups',
666: ntp => 'ntpd',
667: memcached => 'memcached',
668: );
1.1 raeburn 669: my @runlevels = qw/3 4 5/;
670: my @norunlevels = qw/0 1 6/;
671: if ($distro =~ /^(suse|sles)/) {
672: @runlevels = qw/3 5/;
673: @norunlevels = qw/0 2 1 6/;
1.6 raeburn 674: $daemon{'mysql'} = 'mysql';
675: $daemon{'apache'} = 'apache2';
1.8 raeburn 676: $daemon{'ntp'} = 'ntp';
1.1 raeburn 677: if ($distro =~ /^(suse|sles)9/) {
1.6 raeburn 678: $daemon{'apache'} = 'apache';
1.1 raeburn 679: }
1.35 raeburn 680: if ($distro =~ /^(suse|sles)([\d\.]+)/) {
681: my $name = $1;
682: my $num = $2;
683: if ($num > 11) {
1.26 raeburn 684: $uses_systemctl{'apache'} = 1;
1.35 raeburn 685: if (($name eq 'sles') || ($name eq 'suse' && $num >= 13.2)) {
686: $uses_systemctl{'mysql'} = 1;
687: $uses_systemctl{'ntp'} = 1;
688: $uses_systemctl{'cups'} = 1;
689: $uses_systemctl{'memcached'} = 1;
1.49 raeburn 690: if (($name eq 'sles') && ($num >= 15)) {
691: $daemon{'ntp'} = 'chronyd';
692: $daemon{'mysql'} = 'mariadb';
693: } else {
694: $daemon{'ntp'} = 'ntpd';
695: }
1.35 raeburn 696: }
1.26 raeburn 697: }
698: }
1.6 raeburn 699: } elsif ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
700: my $version = $1;
1.1 raeburn 701: @runlevels = qw/2 3 4 5/;
702: @norunlevels = qw/0 1 6/;
1.44 raeburn 703: if (($distro =~ /^ubuntu/) && ($version <= 16)) {
704: $checker_bin = '/usr/sbin/sysv-rc-conf';
705: } else {
706: $uses_systemctl{'ntp'} = 1;
707: $uses_systemctl{'mysql'} = 1;
708: $uses_systemctl{'apache'} = 1;
709: $uses_systemctl{'memcached'} = 1;
710: $uses_systemctl{'cups'} = 1;
711: }
1.6 raeburn 712: $daemon{'mysql'} = 'mysql';
713: $daemon{'apache'} = 'apache2';
714: $daemon{'ntp'} = 'ntp';
715: if (($distro =~ /^ubuntu/) && ($version <= 8)) {
716: $daemon{'cups'} = 'cupsys';
717: }
1.26 raeburn 718: } elsif ($distro =~ /^fedora(\d+)/) {
1.23 raeburn 719: my $version = $1;
720: if ($version >= 15) {
721: $uses_systemctl{'ntp'} = 1;
722: }
723: if ($version >= 16) {
724: $uses_systemctl{'mysql'} = 1;
725: $uses_systemctl{'apache'} = 1;
1.35 raeburn 726: $uses_systemctl{'memcached'} = 1;
727: $uses_systemctl{'cups'} = 1;
1.23 raeburn 728: }
1.39 raeburn 729: if ($version >= 19) {
1.37 raeburn 730: $daemon{'mysql'} = 'mariadb';
731: }
1.29 raeburn 732: } elsif ($distro =~ /^(?:centos|rhes|scientific)(\d+)/) {
733: my $version = $1;
734: if ($version >= 7) {
735: $uses_systemctl{'ntp'} = 1;
736: $uses_systemctl{'mysql'} = 1;
737: $uses_systemctl{'apache'} = 1;
1.35 raeburn 738: $uses_systemctl{'memcached'} = 1;
739: $uses_systemctl{'cups'} = 1;
1.30 raeburn 740: $daemon{'mysql'} = 'mariadb';
1.29 raeburn 741: }
1.1 raeburn 742: }
1.23 raeburn 743: my $nocheck;
1.1 raeburn 744: if (! -x $checker_bin) {
1.23 raeburn 745: if ($uses_systemctl{'mysql'} && $uses_systemctl{'apache'}) {
746: if (! -x $sysctl_bin) {
747: $nocheck = 1;
748: }
749: } else {
750: $nocheck = 1;
751: }
752: }
753: if ($nocheck) {
1.6 raeburn 754: print &mt('Could not check runlevel status for MySQL or Apache')."\n";
1.1 raeburn 755: return;
756: }
757: my $rlstr = join('',@runlevels);
758: my $nrlstr = join('',@norunlevels);
1.23 raeburn 759:
1.6 raeburn 760: foreach my $type ('apache','mysql','ntp','cups','memcached') {
761: my $service = $daemon{$type};
1.23 raeburn 762: if ($uses_systemctl{$type}) {
1.35 raeburn 763: if (($type eq 'memcached') || ($type eq 'cups')) {
764: if (-l "/etc/systemd/system/multi-user.target.wants/$service.service") {
765: $tostop{$type} = 1;
766: }
767: } else {
768: if (!-l "/etc/systemd/system/multi-user.target.wants/$service.service") {
769: $needfix{$type} = "systemctl enable $service.service";
770: }
1.23 raeburn 771: }
772: } else {
773: my $command = $checker_bin.' --list '.$service.' 2>/dev/null';
1.35 raeburn 774: if ($type eq 'cups') {
1.23 raeburn 775: if ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
776: my $version = $1;
777: if (($distro =~ /^ubuntu/) && ($version <= 8)) {
778: $command = $checker_bin.' --list cupsys 2>/dev/null';
1.19 raeburn 779: }
780: }
781: }
1.23 raeburn 782: my $results = `$command`;
783: my $tofix;
784: if ($results eq '') {
785: if (($type eq 'apache') || ($type eq 'mysql') || ($type eq 'ntp')) {
786: if ($distro =~ /^(debian|ubuntu)/) {
787: $tofix = "update-rc.d $type defaults";
788: } else {
789: $tofix = "$checker_bin --add $service\n";
790: }
1.6 raeburn 791: }
1.23 raeburn 792: } else {
793: my %curr_runlevels;
794: for (my $rl=0; $rl<=6; $rl++) {
795: if ($results =~ /$rl:on/) { $curr_runlevels{$rl}++; }
796: }
797: if (($type eq 'apache') || ($type eq 'mysql') || ($type eq 'ntp')) {
798: my $warning;
799: foreach my $rl (@runlevels) {
800: if (!exists($curr_runlevels{$rl})) {
801: $warning = 1;
802: }
803: }
804: if ($warning) {
805: $tofix = "$checker_bin --level $rlstr $service on\n";
806: }
807: } elsif (keys(%curr_runlevels) > 0) {
808: $tostop{$type} = 1;
1.1 raeburn 809: }
810: }
1.23 raeburn 811: if ($tofix) {
812: $needfix{$type} = $tofix;
1.1 raeburn 813: }
1.5 raeburn 814: }
1.1 raeburn 815: }
816: if ($distro =~ /^(suse|sles)([\d\.]+)$/) {
817: my $name = $1;
818: my $version = $2;
819: my ($major,$minor);
820: if ($name eq 'suse') {
821: ($major,$minor) = split(/\./,$version);
822: } else {
823: $major = $version;
824: }
1.49 raeburn 825: if (($major > 10) && ($major <= 13)) {
1.8 raeburn 826: if (&check_SuSEfirewall2_setup($instdir)) {
827: $needfix{'insserv'} = 1;
828: }
1.1 raeburn 829: }
830: }
1.35 raeburn 831: return (\%needfix,\%tostop,\%uses_systemctl);
1.1 raeburn 832: }
833:
1.49 raeburn 834: sub uses_firewalld {
835: my ($distro) = @_;
1.53 ! raeburn 836: my ($inuse,$checkfirewalld,$zone);
1.49 raeburn 837: if ($distro =~ /^(suse|sles)([\d\.]+)$/) {
838: if (($1 eq 'sles') && ($2 >= 15)) {
839: $checkfirewalld = 1;
840: }
841: } elsif ($distro =~ /^fedora(\d+)$/) {
842: if ($1 >= 18) {
843: $checkfirewalld = 1;
844: }
845: } elsif ($distro =~ /^(?:centos|rhes|scientific)(\d+)/) {
846: if ($1 >= 7) {
847: $checkfirewalld = 1;
848: }
849: }
850: if ($checkfirewalld) {
851: my ($loaded,$active);
852: if (open(PIPE,"systemctl status firewalld |")) {
853: while (<PIPE>) {
854: chomp();
855: if (/^\s*Loaded:\s+(\w+)/) {
856: $loaded = $1;
857: }
858: if (/^\s*Active\s+(\w+)/) {
859: $active = $1;
860: }
861: }
862: close(PIPE);
863: }
864: if (($loaded eq 'loaded') || ($active eq 'active')) {
865: $inuse = 1;
1.53 ! raeburn 866: my $cmd = 'firewall-cmd --get-default-zone';
! 867: if (open(PIPE,"$cmd |")) {
! 868: my $result = <PIPE>;
! 869: chomp($result);
! 870: close(PIPE);
! 871: if ($result =~ /^\w+$/) {
! 872: $zone = $result;
! 873: }
! 874: }
1.49 raeburn 875: }
876: }
1.53 ! raeburn 877: return ($inuse,$zone);
1.49 raeburn 878: }
879:
1.1 raeburn 880: sub chkfirewall {
1.5 raeburn 881: my ($distro) = @_;
1.1 raeburn 882: my $configfirewall = 1;
883: my %ports = (
884: http => 80,
885: https => 443,
886: );
1.5 raeburn 887: my %activefw;
1.53 ! raeburn 888: my ($firewalld,$zone) = &uses_firewalld($distro);
! 889: if ($firewalld) {
! 890: my %current;
! 891: if (open(PIPE,'firewall-cmd --permanent --zone='.$zone.' --list-services |')) {
! 892: my $svc = <PIPE>;
! 893: close(PIPE);
! 894: chomp($svc);
! 895: map { $current{$_} = 1; } (split(/\s+/,$svc));
! 896: }
! 897: if ($current{'http'} && $current{'https'}) {
! 898: $configfirewall = 0;
! 899: }
! 900: } else {
! 901: if (&firewall_is_active()) {
1.49 raeburn 902: my $iptables = &get_pathto_iptables();
903: if ($iptables eq '') {
904: print &mt('Firewall not checked as path to iptables not determined.')."\n";
905: } else {
906: my @fwchains = &get_fw_chains($iptables,$distro);
907: if (@fwchains) {
908: foreach my $service ('http','https') {
909: foreach my $fwchain (@fwchains) {
910: if (&firewall_is_port_open($iptables,$fwchain,$ports{$service})) {
911: $activefw{$service} = 1;
912: last;
913: }
1.1 raeburn 914: }
915: }
1.49 raeburn 916: if ($activefw{'http'}) {
917: $configfirewall = 0;
918: }
919: } else {
920: print &mt('Firewall not checked as iptables Chains not identified.')."\n";
1.1 raeburn 921: }
922: }
1.53 ! raeburn 923: } else {
! 924: print &mt('Firewall not enabled.')."\n";
1.1 raeburn 925: }
926: }
1.5 raeburn 927: return ($configfirewall,\%activefw);
1.1 raeburn 928: }
929:
930: sub chkapache {
931: my ($distro,$instdir) = @_;
932: my $fixapache = 1;
1.28 raeburn 933: if ($distro =~ /^(debian|ubuntu)(\d+)$/) {
934: my $distname = $1;
935: my $version = $2;
1.33 raeburn 936: my ($stdconf,$stdsite);
937: if (($distname eq 'ubuntu') && ($version > 12)) {
938: $stdconf = "$instdir/debian-ubuntu/ubuntu14/loncapa_conf";
939: $stdsite = "$instdir/debian-ubuntu/ubuntu14/loncapa_sites";
940: } else {
941: $stdconf = "$instdir/debian-ubuntu/loncapa";
942: }
943: if (!-e $stdconf) {
1.1 raeburn 944: $fixapache = 0;
945: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
1.28 raeburn 946: } else {
1.33 raeburn 947: my ($configfile,$sitefile);
1.28 raeburn 948: if (($distname eq 'ubuntu') && ($version > 12)) {
1.33 raeburn 949: $sitefile = '/etc/apache2/sites-available/loncapa';
1.28 raeburn 950: $configfile = "/etc/apache2/conf-available/loncapa";
1.33 raeburn 951: } else {
952: $configfile = "/etc/apache2/sites-available/loncapa";
1.28 raeburn 953: }
1.33 raeburn 954: if (($configfile ne '') && (-e $configfile) && (-e $stdconf)) {
955: if (open(PIPE, "diff --brief $stdconf $configfile |")) {
1.28 raeburn 956: my $diffres = <PIPE>;
957: close(PIPE);
958: chomp($diffres);
959: unless ($diffres) {
960: $fixapache = 0;
961: }
1.1 raeburn 962: }
963: }
1.33 raeburn 964: if ((!$fixapache) && ($distname eq 'ubuntu') && ($version > 12)) {
965: if (($sitefile ne '') && (-e $sitefile) && (-e $stdsite)) {
966: if (open(PIPE, "diff --brief $stdsite $sitefile |")) {
967: my $diffres = <PIPE>;
968: close(PIPE);
969: chomp($diffres);
970: unless ($diffres) {
971: $fixapache = 0;
972: }
973: }
974: }
975: }
1.1 raeburn 976: }
1.6 raeburn 977: if (!$fixapache) {
978: foreach my $module ('headers.load','expires.load') {
979: unless (-l "/etc/apache2/mods-enabled/$module") {
980: $fixapache = 1;
981: }
982: }
983: }
1.49 raeburn 984: } elsif ($distro =~ /^(suse|sles)([\d\.]+)$/) {
985: my ($name,$version) = ($1,$2);
1.1 raeburn 986: my $apache = 'apache';
1.49 raeburn 987: my $conf_file = "$instdir/sles-suse/default-server.conf";
988: if ($version >= 10) {
1.8 raeburn 989: $apache = 'apache2';
1.1 raeburn 990: }
1.49 raeburn 991: if (($name eq 'sles') && ($version >= 12)) {
992: $conf_file = "$instdir/sles-suse/apache2.4/default-server.conf";
993: }
994: if (!-e "$conf_file") {
1.1 raeburn 995: $fixapache = 0;
996: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
1.49 raeburn 997: } elsif (-e "/etc/$apache/default-server.conf") {
998: if (open(PIPE, "diff --brief $conf_file /etc/$apache/default-server.conf |")) {
1.9 raeburn 999: my $diffres = <PIPE>;
1000: close(PIPE);
1001: chomp($diffres);
1002: unless ($diffres) {
1003: $fixapache = 0;
1004: }
1005: }
1006: }
1007: } elsif ($distro eq 'rhes4') {
1008: if (!-e "$instdir/rhes4/httpd.conf") {
1009: $fixapache = 0;
1010: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
1011: } elsif ((-e "/etc/httpd/conf/httpd.conf") && (-e "$instdir/rhes4/httpd.conf")) {
1012: if (open(PIPE, "diff --brief $instdir/rhes4/httpd.conf /etc/httpd/conf/httpd.conf |")) {
1.1 raeburn 1013: my $diffres = <PIPE>;
1014: close(PIPE);
1015: chomp($diffres);
1016: unless ($diffres) {
1017: $fixapache = 0;
1018: }
1019: }
1020: }
1021: } else {
1.14 raeburn 1022: my $configfile = 'httpd.conf';
1023: if ($distro =~ /^(?:centos|rhes|scientific)(\d+)$/) {
1.29 raeburn 1024: if ($1 >= 7) {
1025: $configfile = 'apache2.4/httpd.conf';
1026: } elsif ($1 > 5) {
1.14 raeburn 1027: $configfile = 'new/httpd.conf';
1028: }
1029: } elsif ($distro =~ /^fedora(\d+)$/) {
1.29 raeburn 1030: if ($1 > 17) {
1031: $configfile = 'apache2.4/httpd.conf';
1032: } elsif ($1 > 10) {
1.15 raeburn 1033: $configfile = 'new/httpd.conf';
1.14 raeburn 1034: }
1035: }
1036: if (!-e "$instdir/centos-rhes-fedora-sl/$configfile") {
1.1 raeburn 1037: $fixapache = 0;
1038: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
1.14 raeburn 1039: } elsif ((-e "/etc/httpd/conf/httpd.conf") && (-e "$instdir/centos-rhes-fedora-sl/$configfile")) {
1040: if (open(PIPE, "diff --brief $instdir/centos-rhes-fedora-sl/$configfile /etc/httpd/conf/httpd.conf |")) {
1.1 raeburn 1041: my $diffres = <PIPE>;
1042: close(PIPE);
1043: chomp($diffres);
1044: unless ($diffres) {
1045: $fixapache = 0;
1046: }
1047: }
1048: }
1049: }
1050: return $fixapache;
1051: }
1052:
1.47 raeburn 1053: #
1054: # chkapachessl() determines whether a server's Apache SSL configuration
1055: # needs updating to support LON-CAPA.
1056: #
1057: # LON-CAPA uses VirtualHosts for port 443, and requires that they are
1058: # defined in one Apache configuration file containing two VirtualHost
1059: # blocks, in order:
1060: #
1061: # (1) a block with no ServerName, or with ServerName set to the
1062: # server's hostname. This block should contain:
1063: #
1064: # <IfModule mod_rewrite.c>
1065: # LON-CAPA rewrite rules defined in sslrewrite.conf
1066: # </IfModule>
1067: #
1068: # (2) a block with ServerName set to internal-$hostname
1069: # (where $hostname is server's hostname).
1070: # This block should contain the config and rewrite rules
1071: # found in loncapassl.conf.
1072: #
1073: # chkapachessl() retrieves the names of .conf files in
1074: # the directory appropriate for the particular Linux distro,
1075: # and then checks to see which .conf file is the best candidate as
1076: # the single file containing VirtualHosts definitions and
1077: # <IfModule mod_rewrite.c> </IfModule> rewrite blocks.
1078: #
1079: # The best candidate is the one containing a block:
1080: # <VirtualHost ????? :443>
1081: # (where ????? might be _default_ or * or an IP address)
1082: # <IfModule mod_rewrite.c>
1083: # </IfModule>
1084: # </VirtualHost>
1085: # with the fewest differences between the contents of the
1086: # IfModule block and the expected contents (from sslrewrite.conf)
1087: #
1088: # If there are no files with rewrite blocks, then a candidate file
1089: # is chosen from the .conf files containing VirtualHosts definitions.
1090: #
1091: # If the user includes "Configure SSL for Apache web server" as
1092: # one of the actions to take to prepare the server for LON-CAPA
1093: # installation, then the output from &chkapachessl() will be
1094: # used to determined which file will contain VirtualHost configs.
1095: #
1096: # If there are no files containing VirtualHosts definitions, then
1097: # <VirtualHost *:443> </VirtualHost> blocks will be appended to
1098: # the standard Apache SSL config for the particular distro:
1099: # ssl.conf for RHEL/CentOS/Scientific/Fedora, vhost-ssl.conf
1100: # for SuSE/SLES, and default-ssl.conf for Ubuntu.
1101: #
1102: # Once a file is selected, the contents of sslrewrite.conf and
1103: # loncapassl.conf are compared with appropriate blocks in the file
1104: # and the user will be prompted to agree to insertion of missing
1105: # lines and/or deletion of surplus lines.
1106: #
1107:
1.46 raeburn 1108: sub chkapachessl {
1.47 raeburn 1109: my ($distro,$instdir,$hostname,$hostip) = @_;
1.46 raeburn 1110: my $fixapachessl = 1;
1.47 raeburn 1111: my $sslintconf = "$instdir/loncapassl.conf";
1112: my $sslrewriteconf = "$instdir/sslrewrite.conf";
1113: my (%sslfiles,%rewrites,%vhostonly,$has_std,$has_int,$rewritenum,$nochgint,$nochgstd);
1114: $nochgstd = 0;
1115: $nochgint = 0;
1116: if (!-e $sslintconf) {
1117: $fixapachessl = 0;
1118: print &mt('Warning: LON-CAPA SSL Apache configuration file [_1] needed for installation check.',$sslintconf)."\n";
1119: } elsif (!-e $sslrewriteconf) {
1.46 raeburn 1120: $fixapachessl = 0;
1.47 raeburn 1121: print &mt('Warning: LON-CAPA SSL Apache configuration file [_1] needed for installation check is missing.',$sslrewriteconf)."\n";
1.46 raeburn 1122: } else {
1.47 raeburn 1123: my $ssldir;
1.46 raeburn 1124: if ($distro =~ /^(debian|ubuntu)(\d+)$/) {
1.47 raeburn 1125: $ssldir = '/etc/apache2/sites-available';
1.46 raeburn 1126: } elsif ($distro =~ /(suse|sles)/) {
1.47 raeburn 1127: $ssldir = '/etc/apache2/vhosts.d';
1.46 raeburn 1128: } else {
1.47 raeburn 1129: $ssldir = '/etc/httpd/conf.d';
1130: }
1131: my @rewritessl = ();
1132: if (open(my $fh,'<',$sslrewriteconf)) {
1133: my $skipnext = 0;
1134: while (<$fh>) {
1135: chomp();
1136: s/(^\s+|\s+$)//g;
1137: next if ($_ eq '');
1138: next if ($_ eq '<IfModule mod_rewrite.c>');
1139: next if ($_ eq '</IfModule>');
1140: if ($_ eq 'RewriteCond %{REMOTE_ADDR} {[[[[HostIP]]]]}') {
1141: if (($hostip ne '') && ($hostip ne '127.0.0.1')) {
1142: push(@rewritessl,'RewriteCond %{REMOTE_ADDR} '.$hostip);
1143: next;
1144: } else {
1145: $skipnext = 1;
1146: }
1147: } elsif (($_ eq 'RewriteRule (.*) - [L]') && ($skipnext)) {
1148: $skipnext = 0;
1149: next;
1150: }
1151: push(@rewritessl,$_);
1152: }
1.46 raeburn 1153: }
1.47 raeburn 1154: my @intssl = ();
1155: if (open(my $fh,'<',$sslintconf)) {
1156: while(<$fh>) {
1157: chomp();
1158: s/(^\s+|\s+$)//g;
1159: next if ($_ eq '');
1160: if ($_ eq 'ServerName internal-{[[[[Hostname]]]]}') {
1161: if ($hostname ne '') {
1162: push(@intssl,'ServerName internal-'.$hostname);
1163: next;
1164: }
1165: }
1166: next if ($_ eq '<VirtualHost *:443>');
1167: next if ($_ eq '</VirtualHost>');
1168: push(@intssl,$_);
1169: }
1170: }
1171: if (-d $ssldir) {
1172: my @actualint = ();
1173: if (opendir(my $dir,$ssldir)) {
1174: my @sslconf_files;
1175: foreach my $file (grep(!/^\.+/,readdir($dir))) {
1176: next if (($distro =~ /(suse|sles)/) && ($file =~ /\.template$/));
1177: next if ($file =~ /\.rpmnew$/);
1178: if (open(my $fh,'<',"$ssldir/$file")) {
1179: while (<$fh>) {
1180: if (/^\s*<VirtualHost\s+[^:]*\:443>\s*$/) {
1181: push(@sslconf_files,$file);
1182: last;
1183: }
1184: }
1185: close($fh);
1186: }
1187: }
1188: closedir($dir);
1189: if (@sslconf_files) {
1190: foreach my $file (@sslconf_files) {
1191: if (open(my $fh,'<',"$ssldir/$file")) {
1192: my ($virtualhost,$rewrite,$num) = (0,0,0);
1193: my ($currname,$has_rewrite);
1194: while (<$fh>) {
1195: chomp();
1196: next if (/^\s*$/);
1197: if ($virtualhost) {
1198: if (/^\s*<\/VirtualHost>/) {
1199: if ($currname !~ /^\Qinternal-$hostname\E/) {
1200: if ($has_rewrite) {
1201: delete($vhostonly{$file});
1202: } else {
1203: $vhostonly{$file} = 1;
1204: }
1205: }
1206: $sslfiles{$currname}{$file} = 1;
1207: $virtualhost = 0;
1208: $currname = '';
1209: $has_rewrite = '';
1210: next;
1211: } elsif (/^\s*ServerName\s+([^\s]+)\s*$/) {
1212: $currname = $1;
1213: }
1214: if ($currname =~ /^\Qinternal-$hostname\E/) {
1215: s/(^\s+|\s+$)//g;
1216: push(@actualint,$_);
1217: $has_int = $file;
1218: } else {
1219: if ($rewrite) {
1220: if (/^\s*<\/IfModule>/) {
1221: $rewrite = 0;
1222: $num ++;
1223: } else {
1224: s/(^\s+|\s+$)//g;
1225: push(@{$rewrites{$file}[$num]},$_);
1226: }
1227: } elsif (/^\s*<IfModule\s+mod_rewrite\.c>/) {
1228: $rewrite = 1;
1229: $has_rewrite = 1;
1230: if ($currname eq '') {
1231: $currname = $hostname;
1232: }
1233: $rewrites{$file}[$num] = [];
1234: }
1235: }
1236: } elsif (/^\s*<VirtualHost\s+[^:]*\:443>\s*$/) {
1237: $virtualhost = 1;
1238: }
1239: }
1240: close($fh);
1241: }
1242: }
1243: }
1244: if (keys(%rewrites)) {
1245: my $mindiffsall;
1246: foreach my $file (sort(keys(%rewrites))) {
1247: if (ref($rewrites{$file}) eq 'ARRAY') {
1248: my $mindiffs;
1249: for (my $i=0; $i<@{$rewrites{$file}}; $i++) {
1250: if (ref($rewrites{$file}[$i]) eq 'ARRAY') {
1251: my @diffs = &compare_arrays($rewrites{$file}[$i],\@rewritessl);
1252: if (@diffs == 0) {
1253: $fixapachessl = 0;
1254: $mindiffs = 0;
1255: $rewritenum = 1+$i;
1256: last;
1257: } else {
1258: if ($mindiffs eq '') {
1259: $mindiffs = scalar(@diffs);
1260: $rewritenum = 1+$i;
1261: } elsif (scalar(@diffs) <= $mindiffs) {
1262: $mindiffs = scalar(@diffs);
1263: $rewritenum = 1+$i;
1264: }
1265: }
1266: }
1267: }
1268: if ($mindiffsall eq '') {
1269: $mindiffsall = $mindiffs;
1270: $has_std = $file;
1271: } elsif ($mindiffs <= $mindiffsall) {
1272: $mindiffsall = $mindiffs;
1273: $has_std = $file;
1274: }
1275: if ($mindiffsall == 0) {
1276: $nochgstd = 1;
1277: }
1278: }
1279: }
1280: } elsif (keys(%vhostonly) > 0) {
1281: if (($has_int ne '') && (exists($vhostonly{$has_int}))) {
1282: $has_std = $has_int;
1283: }
1284: }
1285: if (@actualint) {
1286: my @diffs = &compare_arrays(\@actualint,\@intssl);
1287: if (@diffs) {
1288: $fixapachessl = 1;
1289: } else {
1290: $nochgint = 1;
1291: }
1292: } else {
1293: $fixapachessl = 1;
1.46 raeburn 1294: }
1295: }
1296: }
1297: unless ($fixapachessl) {
1298: if ($distro =~ /^(debian|ubuntu)(\d+)$/) {
1.47 raeburn 1299: my $enabled_dir = '/etc/apache2/sites-enabled';
1300: if (keys(%sslfiles)) {
1301: foreach my $key (sort(keys(%sslfiles))) {
1302: if (ref($sslfiles{$key}) eq 'HASH') {
1303: foreach my $file (sort(keys(%{$sslfiles{$key}}))) {
1304: unless ((-l "$enabled_dir/$file") &&
1305: (readlink("$enabled_dir/$file") eq "$ssldir/$file")) {
1306: print_and_log(&mt("Warning, use: 'sudo a2ensite $file' to activate LON-CAPA SSL Apache config\n"));
1307: }
1308: }
1309: }
1310: }
1.46 raeburn 1311: }
1312: }
1313: }
1314: }
1.47 raeburn 1315: return ($fixapachessl,\%sslfiles,$has_std,$has_int,$rewritenum,$nochgstd,$nochgint);
1316: }
1317:
1318: #
1319: # compare_arrays() expects two refs to arrays as args.
1320: #
1321: # The contents of the two arrays are compared, and if they
1322: # are different, and array of the differences is returned.
1323: #
1324:
1325: sub compare_arrays {
1326: my ($arrayref1,$arrayref2) = @_;
1327: my (@difference,%count);
1328: @difference = ();
1329: %count = ();
1330: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
1331: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
1332: foreach my $element (keys(%count)) {
1333: if ($count{$element} == 1) {
1334: push(@difference,$element);
1335: }
1336: }
1337: }
1338: return @difference;
1.46 raeburn 1339: }
1340:
1.1 raeburn 1341: sub chksrvcs {
1342: my ($distro,$tostop) = @_;
1343: my %stopsrvcs;
1344: if (ref($tostop) eq 'HASH') {
1345: %stopsrvcs = %{$tostop};
1346: }
1.6 raeburn 1347: foreach my $service ('cups','memcached') {
1.1 raeburn 1348: next if (exists($stopsrvcs{$service}));
1349: my $daemon = $service;
1350: if ($service eq 'cups') {
1351: $daemon = 'cupsd';
1352: }
1353: my $cmd = "ps -ef |grep '$daemon' |grep -v grep";
1354: if (open(PIPE,'-|',$cmd)) {
1355: my $daemonrunning = <PIPE>;
1356: chomp($daemonrunning);
1357: close(PIPE);
1358: if ($daemonrunning) {
1.12 raeburn 1359: if ($service eq 'memcached') {
1.16 raeburn 1360: my $cmd = '/usr/bin/memcached';
1361: if ($distro =~ /^(suse|sles)/) {
1362: $cmd = '/usr/sbin/memcached';
1363: }
1.12 raeburn 1364: unless ($daemonrunning =~ m{^www[^/]+\Q$cmd -m 400 -v\E$}) {
1.10 raeburn 1365: $stopsrvcs{$service} = 1;
1366: }
1367: } else {
1368: $stopsrvcs{$service} = 1;
1369: }
1.1 raeburn 1370: }
1371: }
1.10 raeburn 1372: }
1.1 raeburn 1373: return \%stopsrvcs;
1374: }
1375:
1376: sub need_download {
1377: my $needs_download = 1;
1378: my ($production,$testing,$stdsizes) = &download_versionslist();
1379: my ($rootdir,$localcurrent,$localtesting,%tarball,%localsize,%bymodtime,
1380: %bysize,$filetouse,$downloadstatus);
1381: $rootdir = '/root';
1382: if (opendir(my $dir,"$rootdir")) {
1383: my (@lcdownloads,$version);
1384: foreach my $file (readdir($dir)) {
1385: if ($file =~ /^loncapa\-([\w\-.]+)\.tar\.gz$/) {
1386: $version = $1;
1387: } else {
1388: next;
1389: }
1390: if (ref($stdsizes) eq 'HASH') {
1391: if ($version eq 'current') {
1392: my @stats = stat("$rootdir/$file");
1393: $localcurrent = $stats[7];
1.4 raeburn 1394: if ($localcurrent == $stdsizes->{$production}) {
1.1 raeburn 1395: $needs_download = 0;
1396: $filetouse = $file;
1397: }
1398: } elsif ($version eq 'testing') {
1399: my @stats = stat("$rootdir/$file");
1400: $localtesting = $stats[7];
1.4 raeburn 1401: if ($localtesting == $stdsizes->{$testing}) {
1.1 raeburn 1402: $needs_download = 0;
1403: $filetouse = $file;
1404: }
1405: }
1406: }
1407: $tarball{$version} = $file;
1408: push(@lcdownloads,$version);
1409: }
1410: if ($needs_download) {
1411: if (@lcdownloads > 0) {
1412: foreach my $version (@lcdownloads) {
1413: my @stats = stat("$rootdir/$tarball{$version}");
1414: my $mtime = $stats[9];
1415: $localsize{$version} = $stats[7];
1416: if ($mtime) {
1417: push(@{$bymodtime{$mtime}},$version);
1418: }
1419: if ($localsize{$version}) {
1420: push(@{$bysize{$localsize{$version}}},$version);
1421: }
1422: }
1423: if ($testing) {
1424: if (exists($localsize{$testing})) {
1425: if ($stdsizes->{$testing} == $localsize{$testing}) {
1426: $needs_download = 0;
1427: $filetouse = 'loncapa-'.$testing.'.tar.gz';
1428: }
1429: }
1430: }
1431: if ($needs_download) {
1432: if ($production) {
1433: if (exists($localsize{$production})) {
1434: if ($stdsizes->{$production} == $localsize{$production}) {
1435: $needs_download = 0;
1436: $filetouse = 'loncapa-'.$production.'.tar.gz';
1437: }
1438: }
1439: }
1440: }
1441: if ($needs_download) {
1442: my @sorted = sort { $b <=> $a } keys(%bymodtime);
1443: my $newest = $sorted[0];
1444: if (ref($bymodtime{$newest}) eq 'ARRAY') {
1445: $downloadstatus =
1446: "Latest LON-CAPA source download in $rootdir is: ".
1447: join(',',@{$bymodtime{$newest}})." (downloaded ".
1448: localtime($newest).")\n";
1449: }
1450: } else {
1451: $downloadstatus =
1452: "The $rootdir directory already contains the latest LON-CAPA version:".
1453: "\n".$filetouse."\n"."which can be used for installation.\n";
1454: }
1455: } else {
1456: $downloadstatus = "The $rootdir directory does not appear to contain any downloaded LON-CAPA source code files which can be used for installation.\n";
1457: }
1458: }
1459: } else {
1460: $downloadstatus = "Could not open $rootdir directory to look for existing downloads of LON-CAPA source code.\n";
1461: }
1462: return ($needs_download,$downloadstatus,$filetouse,$production,$testing);
1463: }
1464:
1465: sub check_mysql_setup {
1.34 raeburn 1466: my ($instdir,$dsn,$distro,$mysql_has_wwwuser) = @_;
1.1 raeburn 1467: my ($mysqlsetup,$has_pass);
1468: my $dbh = DBI->connect($dsn,'root','',{'PrintError'=>0});
1469: if ($dbh) {
1470: $mysqlsetup = 'noroot';
1471: } elsif ($DBI::err =~ /1045/) {
1472: $has_pass = 1;
1.34 raeburn 1473: } elsif ($distro =~ /^ubuntu(\d+)$/) {
1474: my $version = $1;
1475: if ($1 > 12) {
1476: print_and_log(&mt('Restarting mysql, please be patient')."\n");
1477: if (open (PIPE, "service mysql restart 2>&1 |")) {
1478: while (<PIPE>) {
1479: print $_;
1480: }
1481: close(PIPE);
1482: }
1483: unless ($mysql_has_wwwuser) {
1484: $mysql_has_wwwuser = &check_mysql_wwwuser();
1485: }
1486: $dbh = DBI->connect($dsn,'root','',{'PrintError'=>0});
1487: if ($dbh) {
1488: $mysqlsetup = 'noroot';
1489: } elsif ($DBI::err =~ /1045/) {
1490: $has_pass = 1;
1491: } else {
1492: $mysqlsetup = 'needsrestart';
1493: return ($mysqlsetup,$has_pass,$dbh,$mysql_has_wwwuser);
1494: }
1495: }
1.1 raeburn 1496: }
1497: if ($has_pass) {
1498: print &mt('You have already set a root password for the MySQL database.')."\n";
1499: my $currpass = &get_mysql_password(&mt('Please enter the password now'));
1500: $dbh = DBI->connect($dsn,'root',$currpass,{'PrintError'=>0});
1501: if ($dbh) {
1502: $mysqlsetup = 'rootok';
1503: print_and_log(&mt('Password accepted.')."\n");
1504: } else {
1505: $mysqlsetup = 'rootfail';
1506: print_and_log(&mt('Problem accessing MySQL.')."\n");
1507: if ($DBI::err =~ /1045/) {
1508: print_and_log(&mt('Perhaps the password was incorrect?')."\n");
1509: print &mt('Try again?').' ';
1510: $currpass = &get_mysql_password(&mt('Re-enter password now'));
1511: $dbh = DBI->connect($dsn,'root',$currpass,{'PrintError'=>0});
1512: if ($dbh) {
1513: $mysqlsetup = 'rootok';
1514: print_and_log(&mt('Password accepted.')."\n");
1515: } else {
1516: if ($DBI::err =~ /1045/) {
1517: print_and_log(&mt('Incorrect password.')."\n");
1518: }
1519: }
1520: }
1521: }
1.34 raeburn 1522: } elsif ($mysqlsetup ne 'noroot') {
1.1 raeburn 1523: print_and_log(&mt('Problem accessing MySQL.')."\n");
1524: $mysqlsetup = 'rootfail';
1525: }
1.34 raeburn 1526: return ($mysqlsetup,$has_pass,$dbh,$mysql_has_wwwuser);
1.1 raeburn 1527: }
1528:
1529: sub check_mysql_wwwuser {
1530: my $mysql_wwwuser;
1.12 raeburn 1531: my $dbhn = DBI->connect("DBI:mysql:database=information_schema",'www','localhostkey',
1532: {PrintError => +0}) || return;
1.1 raeburn 1533: if ($dbhn) {
1534: $mysql_wwwuser = 1;
1535: $dbhn->disconnect;
1536: }
1537: return $mysql_wwwuser;
1538: }
1539:
1540: sub check_loncapa_mysqldb {
1541: my ($dbh) = @_;
1542: my $has_lcdb;
1543: if (ref($dbh)) {
1544: my $sth = $dbh->prepare("SHOW DATABASES");
1545: $sth->execute();
1546: while (my $dbname = $sth->fetchrow_array) {
1547: if ($dbname eq 'loncapa') {
1548: $has_lcdb = 1;
1549: last;
1550: }
1551: }
1552: $sth->finish();
1553: }
1554: return $has_lcdb;
1555: }
1556:
1557: sub get_pathto_iptables {
1558: my $iptables;
1559: if (-e '/sbin/iptables') {
1560: $iptables = '/sbin/iptables';
1561: } elsif (-e '/usr/sbin/iptables') {
1562: $iptables = '/usr/sbin/iptables';
1563: } else {
1564: print &mt('Unable to find iptables command.')."\n";
1565: }
1566: return $iptables;
1567: }
1568:
1569: sub firewall_is_active {
1570: if (-e '/proc/net/ip_tables_names') {
1.49 raeburn 1571: if (open(PIPE,'cat /proc/net/ip_tables_names |grep filter |')) {
1572: my $status = <PIPE>;
1573: close(PIPE);
1574: chomp($status);
1575: if ($status eq 'filter') {
1576: return 1;
1577: }
1578: }
1.1 raeburn 1579: }
1.49 raeburn 1580: return 0;
1.1 raeburn 1581: }
1582:
1583: sub get_fw_chains {
1.5 raeburn 1584: my ($iptables,$distro) = @_;
1.1 raeburn 1585: my @fw_chains;
1586: my $suse_config = "/etc/sysconfig/SuSEfirewall2";
1587: my $ubuntu_config = "/etc/ufw/ufw.conf";
1588: if (-e $suse_config) {
1589: push(@fw_chains,'input_ext');
1590: } else {
1591: my @posschains;
1592: if (-e $ubuntu_config) {
1593: @posschains = ('ufw-user-input','INPUT');
1.5 raeburn 1594: } elsif ($distro =~ /^debian5/) {
1595: @posschains = ('INPUT');
1.49 raeburn 1596: } elsif ($distro =~ /^(suse|sles)(\d+)/) {
1597: @posschains = ('IN_public');
1.1 raeburn 1598: } else {
1599: @posschains = ('RH-Firewall-1-INPUT','INPUT');
1600: if (!-e '/etc/sysconfig/iptables') {
1601: if (!-e '/var/lib/iptables') {
1602: print &mt('Unable to find iptables file containing static definitions.')."\n";
1603: }
1604: push(@fw_chains,'RH-Firewall-1-INPUT');
1605: }
1606: }
1607: if ($iptables eq '') {
1608: $iptables = &get_pathto_iptables();
1609: }
1610: my %counts;
1611: if (open(PIPE,"$iptables -L -n |")) {
1612: while(<PIPE>) {
1613: foreach my $chain (@posschains) {
1614: if (/(\Q$chain\E)/) {
1615: $counts{$1} ++;
1616: }
1617: }
1618: }
1619: close(PIPE);
1620: }
1621: foreach my $fw_chain (@posschains) {
1622: if ($counts{$fw_chain}) {
1623: unless(grep(/^\Q$fw_chain\E$/,@fw_chains)) {
1624: push(@fw_chains,$fw_chain);
1625: }
1626: }
1627: }
1628: }
1629: return @fw_chains;
1630: }
1631:
1632: sub firewall_is_port_open {
1633: my ($iptables,$fw_chain,$port) = @_;
1634: # returns 1 if the firewall port is open, 0 if not.
1635: #
1636: # check if firewall is active or installed
1637: return if (! &firewall_is_active());
1638: my $count = 0;
1639: if (open(PIPE,"$iptables -L $fw_chain -n |")) {
1640: while(<PIPE>) {
1641: if (/tcp dpt\:\Q$port\E/) {
1642: $count ++;
1643: last;
1644: }
1645: }
1646: close(PIPE);
1647: } else {
1648: print &mt('Firewall status not checked: unable to run [_1].','iptables -L')."\n";
1649: }
1650: return $count;
1651: }
1652:
1653: sub get_mysql_password {
1654: my ($prompt) = @_;
1655: local $| = 1;
1656: print $prompt.': ';
1657: my $newpasswd = '';
1658: ReadMode 'raw';
1659: my $key;
1660: while(ord($key = ReadKey(0)) != 10) {
1661: if(ord($key) == 127 || ord($key) == 8) {
1662: chop($newpasswd);
1663: print "\b \b";
1664: } elsif(!ord($key) < 32) {
1665: $newpasswd .= $key;
1666: print '*';
1667: }
1668: }
1669: ReadMode 'normal';
1670: print "\n";
1671: return $newpasswd;
1672: }
1673:
1674: sub check_SuSEfirewall2_setup {
1675: my ($instdir) = @_;
1676: my $need_override = 1;
1.9 raeburn 1677: if ((-e "/etc/insserv/overrides/SuSEfirewall2_setup") && (-e "$instdir/sles-suse/SuSEfirewall2_setup")) {
1678: if (open(PIPE, "diff --brief $instdir/sles-suse/SuSEfirewall2_setup /etc/insserv/overrides/SuSEfirewall2_setup |")) {
1.1 raeburn 1679: my $diffres = <PIPE>;
1680: close(PIPE);
1681: chomp($diffres);
1682: unless ($diffres) {
1683: $need_override = 0;
1684: }
1685: }
1686: }
1687: return $need_override;
1688: }
1689:
1690: sub download_versionslist {
1691: my ($production,$testing,%sizes);
1692: if (-e "latest.txt") {
1693: unlink("latest.txt");
1694: }
1695: my $rtncode = system("wget http://install.loncapa.org/versions/latest.txt ".
1696: "> /dev/null 2>&1");
1697: if (!$rtncode) {
1698: if (open(my $fh,"<latest.txt")) {
1699: my @info = <$fh>;
1700: close($fh);
1701: foreach my $line (@info) {
1702: chomp();
1703: if ($line =~ /^\QLATEST-IS: \E([\w\-.]+):(\d+)$/) {
1704: $production = $1;
1705: $sizes{$1} = $2;
1706: } elsif ($line =~ /^LATEST-TESTING-IS: \E([\w\-.]+):(\d+)$/) {
1707: $testing = $1;
1708: $sizes{$1} = $2;
1709: }
1710: }
1711: }
1712: }
1713: return ($production,$testing,\%sizes);
1714: }
1715:
1716: #
1717: # End helper routines.
1718: # Main script starts here
1719: #
1720:
1721: print "
1722: ********************************************************************
1723:
1724: ".&mt('Welcome to LON-CAPA')."
1725:
1726: ".&mt('This script will configure your system for installation of LON-CAPA.')."
1727:
1728: ********************************************************************
1729:
1730: ".&mt('The following actions are available:')."
1731:
1.4 raeburn 1732: ".&mt('1.')." ".&mt('Create the www user/group.')."
1.1 raeburn 1733: ".&mt('This is the user/group ownership under which Apache child processes run.')."
1734: ".&mt('It also owns most directories within the /home/httpd directory.')."
1735: ".&mt('This directory is where most LON-CAPA files and directories are stored.')."
1.4 raeburn 1736: ".&mt('2.')." ".&mt('Install the package LON-CAPA uses to authenticate users.')."
1737: ".&mt('3.')." ".&mt('Set-up the MySQL database.')."
1738: ".&mt('4.')." ".&mt('Set-up MySQL permissions.')."
1739: ".&mt('5.')." ".&mt('Configure Apache web server.')."
1.46 raeburn 1740: ".&mt('6.')." ".&mt('Configure SSL for Apache web server.')."
1741: ".&mt('7.')." ".&mt('Configure start-up of services.')."
1742: ".&mt('8.')." ".&mt('Check firewall settings.')."
1743: ".&mt('9.')." ".&mt('Stop services not used by LON-CAPA,')."
1.1 raeburn 1744: ".&mt('i.e., services for a print server: [_1] daemon.',"'cups'")."
1.46 raeburn 1745: ".&mt('10.')." ".&mt('Download LON-CAPA source code in readiness for installation.')."
1.1 raeburn 1746:
1747: ".&mt('Typically, you will run this script only once, when you first install LON-CAPA.')."
1748:
1749: ".&mt('The script will analyze your system to determine which actions are recommended.')."
1750: ".&mt('The script will then prompt you to choose the actions you would like taken.')."
1751:
1752: ".&mt('For each the recommended action will be selected if you hit Enter/Return.')."
1753: ".&mt('To override the default, type the lower case option from the two options listed.')."
1754: ".&mt('So, if the default is "yes", ~[Y/n~] will be shown -- type n to override.')."
1755: ".&mt('Whereas if the default is "no", ~[y/N~] will be shown -- type y to override.')."
1756:
1757: ".&mt('To accept the default, simply hit Enter/Return on your keyboard.')."
1758: ".&mt('Otherwise type: y or n then hit the Enter/Return key.')."
1759:
1760: ".&mt('Once a choice has been entered for all nine actions, required changes will be made.')."
1761: ".&mt('Feedback will be displayed on screen, and also stored in: [_1].','loncapa_install.log')."
1762:
1763: ".&mt('Continue? ~[Y/n~] ');
1764:
1765: my $go_on = &get_user_selection(1);
1766: if (!$go_on) {
1767: exit;
1768: }
1769:
1770: my $instdir = `pwd`;
1771: chomp($instdir);
1772:
1773: my %callsub;
1774: my @actions = ('wwwuser','pwauth','mysql','mysqlperms','apache',
1.46 raeburn 1775: 'apachessl','runlevels','firewall','stopsrvcs','download');
1.1 raeburn 1776: my %prompts = &texthash(
1777: wwwuser => "Create the 'www' user?",
1778: pwauth => 'Install the package LON-CAPA uses to authenticate users?',
1779: mysql => 'Set-up the MySQL database?',
1780: mysqlperms => 'Set-up MySQL permissions?',
1781: apache => 'Configure Apache web server?',
1.46 raeburn 1782: apachessl => 'Configure SSL for Apache web server?',
1.1 raeburn 1783: runlevels => 'Set overrides for start-up order of services?',
1784: firewall => 'Configure firewall settings for Apache',
1785: stopsrvcs => 'Stop extra services not required on a LON-CAPA server?',
1786: download => 'Download LON-CAPA source code in readiness for installation?',
1787: );
1788:
1.46 raeburn 1789: print "\n".&mt('Checking system status ...')."\n\n";
1.1 raeburn 1790:
1791: my $dsn = "DBI:mysql:database=mysql";
1.34 raeburn 1792: my ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,$mysqlrestart,
1793: $recommended,$dbh,$has_pass,$has_lcdb,$downloadstatus,$filetouse,$production,
1.47 raeburn 1794: $testing,$apachefw,$uses_systemctl,$hostname,$hostip,$sslhostsfiles,$has_std,
1795: $has_int,$rewritenum,$nochgstd,$nochgint) = &check_required($instdir,$dsn);
1.1 raeburn 1796: if ($distro eq '') {
1797: print "\n".&mt('Linux distribution could not be verified as a supported distribution.')."\n".
1798: &mt('The following are supported: [_1].',
1799: 'CentOS, RedHat Enterprise, Fedora, Scientific Linux, '.
1800: 'openSuSE, SLES, Ubuntu LTS, Debian')."\n\n".
1801: &mt('Stopping execution.')."\n";
1802: exit;
1803: }
1.34 raeburn 1804: if ($mysqlrestart) {
1805: print "\n".&mt('The mysql daemon needs to be restarted using the following command:')."\n".
1806: $mysqlrestart."\n\n".
1807: &mt('Stopping execution of install.pl script.')."\n".
1808: &mt('Please run the install.pl script again, once you have restarted mysql.')."\n";
1809: exit;
1810: }
1.6 raeburn 1811: if ($localecmd ne '') {
1812: print "\n".&mt('Although the LON-CAPA application itself is localized for a number of different languages, the default locale language for the Linux OS on which it runs should be US English.')."\n";
1813: print "\n".&mt('Run the following command from the command line to set the default language for your OS, and then run this LON-CAPA installation set-up script again.')."\n\n".
1814: $localecmd."\n\n".
1815: &mt('Stopping execution.')."\n";
1816: exit;
1817: }
1.1 raeburn 1818: if (!$gotprereqs) {
1.12 raeburn 1819: print "\n".&mt('The LONCAPA-prerequisites package is not installed.')."\n".
1.1 raeburn 1820: &mt('The following command can be used to install the package (and dependencies):')."\n\n".
1821: $updatecmd."\n\n";
1822: if ($installnow eq '') {
1823: exit;
1824: } else {
1825: print &mt('Run command? ~[Y/n~]');
1826: my $install_prereq = &get_user_selection(1);
1827: if ($install_prereq) {
1828: if (open(PIPE,'|-',$installnow)) {
1829: close(PIPE);
1830: $gotprereqs = &check_prerequisites($packagecmd,$distro);
1831: if (!$gotprereqs) {
1.12 raeburn 1832: print &mt('The LONCAPA-prerequisites package is not installed.')."\n".
1.1 raeburn 1833: &mt('Stopping execution.')."\n";
1834: exit;
1835: } else {
1.6 raeburn 1836: ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,
1.34 raeburn 1837: $mysqlrestart,$recommended,$dbh,$has_pass,$has_lcdb,$downloadstatus,
1.35 raeburn 1838: $filetouse,$production,$testing,$apachefw,$uses_systemctl) =
1.5 raeburn 1839: &check_required($instdir,$dsn);
1.1 raeburn 1840: }
1841: } else {
1.12 raeburn 1842: print &mt('Failed to run command to install LONCAPA-prerequisites')."\n";
1.1 raeburn 1843: exit;
1844: }
1845: } else {
1846: print &mt('Stopping execution.')."\n";
1847: exit;
1848: }
1849: }
1850: }
1851: unless (ref($recommended) eq 'HASH') {
1852: print "\n".&mt('An error occurred determining which actions are recommended.')."\n\n".
1853: &mt('Stopping execution.')."\n";
1854: exit;
1855: }
1856:
1857: print "\n";
1858: my $num = 0;
1859: foreach my $action (@actions) {
1860: $num ++;
1861: my ($yesno,$defaultrun);
1862: if (ref($recommended) eq 'HASH') {
1.4 raeburn 1863: if (($action eq 'runlevels') || ($action eq 'stopsrvcs')) {
1.1 raeburn 1864: $yesno = '[y/N]';
1865: if (ref($recommended->{$action}) eq 'HASH') {
1866: if (keys(%{$recommended->{$action}}) > 0) {
1867: $yesno = &mt('~[Y/n~]');
1868: $defaultrun = 1;
1869: }
1870: }
1871: } else {
1872: if ($action eq 'download') {
1873: if ($downloadstatus) {
1874: print "\n$downloadstatus\n";
1875: }
1876: }
1877: if ($recommended->{$action}) {
1878: $yesno = mt('~[Y/n~]');
1879: $defaultrun = 1;
1880: } else {
1881: $yesno = &mt('~[y/N~]');
1882: }
1883: }
1884: print $num.'. '.$prompts{$action}." $yesno ";
1885: $callsub{$action} = &get_user_selection($defaultrun);
1886: }
1887: }
1888:
1889: my $lctarball = 'loncapa-current.tar.gz';
1890: my $sourcetarball = $lctarball;
1891: if ($callsub{'download'}) {
1892: my ($production,$testing,$sizes) = &download_versionslist();
1893: if ($production && $testing) {
1894: if ($production ne $testing) {
1895: print &mt('Two recent LON-CAPA releases are available: ')."\n".
1.3 raeburn 1896: &mt('1.').' '.&mt('A production release - version: [_1].',$production)."\n".
1897: &mt('2.').' '.&mt('A testing release - version: [_1].',$testing)."\n\n".
1.1 raeburn 1898: &mt('Download the production release? ~[Y/n~]');
1899: if (&get_user_selection(1)) {
1.4 raeburn 1900: $sourcetarball = 'loncapa-'.$production.'.tar.gz';
1.1 raeburn 1901: } else {
1902: print "\n".&mt('Download the testing release? ~[Y/n~]');
1903: if (&get_user_selection(1)) {
1.4 raeburn 1904: $sourcetarball = 'loncapa-'.$testing.'.tar.gz';
1.1 raeburn 1905: }
1906: }
1907: }
1908: } elsif ($production) {
1909: print &mt('The most recent LON-CAPA release is version: [_1].',$production)."\n".
1910: &mt('Download the production release? ~[Y/n~]');
1911: if (&get_user_selection(1)) {
1.20 raeburn 1912: $sourcetarball = 'loncapa-'.$production.'.tar.gz';
1.1 raeburn 1913: }
1914: }
1915: } elsif ($filetouse ne '') {
1916: $sourcetarball = $filetouse;
1917: }
1918:
1919: print_and_log("\n");
1920:
1921: # Each action: report if skipping, or perform action and provide feedback.
1922: if ($callsub{'wwwuser'}) {
1923: &setup_www();
1924: } else {
1925: &print_and_log(&mt('Skipping creation of user [_1].',"'www'")."\n");
1926: }
1927:
1928: if ($callsub{'pwauth'}) {
1.4 raeburn 1929: &build_and_install_mod_auth_external($instdir);
1.1 raeburn 1930: } else {
1931: &print_and_log(&mt('Skipping [_1] installation.',"'pwauth'")."\n");
1932: }
1933:
1934: if ($callsub{'mysql'}) {
1935: if ($dbh) {
1936: &setup_mysql($callsub{'mysqlperms'},$distro,$dbh,$has_pass,$has_lcdb);
1937: } else {
1938: print &mt('Unable to configure MySQL because access is denied.')."\n";
1939: }
1940: } else {
1941: &print_and_log(&mt('Skipping configuration of MySQL.')."\n");
1942: if ($callsub{'mysqlperms'}) {
1943: if ($dbh) {
1944: &setup_mysql_permissions($dbh,$has_pass);
1945: } else {
1946: print &mt('Unable to configure MySQL because access is denied.')."\n";
1947: }
1948: } else {
1949: &print_and_log(&mt('Skipping MySQL permissions setup.')."\n");
1950: }
1951: }
1952:
1953: if ($dbh) {
1954: if (!$dbh->disconnect) {
1955: &print_and_log(&mt('Failed to disconnect from MySQL:')."\n".
1956: $dbh->errstr);
1957: }
1958: }
1959:
1960: if ($callsub{'apache'}) {
1961: if ($distro =~ /^(suse|sles)/) {
1.49 raeburn 1962: ©_apache2_suseconf($instdir,$hostname,$distro);
1.1 raeburn 1963: } elsif ($distro =~ /^(debian|ubuntu)/) {
1.46 raeburn 1964: ©_apache2_debconf($instdir,$distro,$hostname);
1.1 raeburn 1965: } else {
1.46 raeburn 1966: ©_httpd_conf($instdir,$distro,$hostname);
1.1 raeburn 1967: }
1968: } else {
1969: print_and_log(&mt('Skipping configuration of Apache web server.')."\n");
1970: }
1971:
1.46 raeburn 1972: if ($callsub{'apachessl'}) {
1.47 raeburn 1973: my $targetdir = '/etc/httpd/conf.d';
1.46 raeburn 1974: if ($distro =~ /^(suse|sles)/) {
1.47 raeburn 1975: $targetdir = '/etc/apache2/vhosts.d';
1.46 raeburn 1976: } elsif ($distro =~ /^(debian|ubuntu)/) {
1.47 raeburn 1977: $targetdir = '/etc/apache2/sites-available';
1978: }
1979: my ($new_rewrite,$new_int) =
1980: ©_apache_sslconf_files($distro,$hostname,$hostip,$instdir,$targetdir,$sslhostsfiles,
1981: $has_std,$has_int,$rewritenum,$nochgstd,$nochgint);
1982: if ($distro =~ /^(debian|ubuntu)/) {
1983: my $apache2_sites_enabled_dir = '/etc/apache2/sites-enabled';
1984: if (-d $apache2_sites_enabled_dir) {
1985: if ($has_std ne '') {
1986: unless ((-l "$apache2_sites_enabled_dir/$has_std") && (readlink(("$apache2_sites_enabled_dir/$has_std") eq "$targetdir/$has_std"))) {
1987: my $made_symlink = eval { symlink("$targetdir/$has_std","$apache2_sites_enabled_dir/$has_std"); 1};
1988: if ($made_symlink) {
1989: print_and_log(&mt('Enabling "[_1]" Apache SSL configuration.',$has_std)."\n");
1990: }
1991: }
1992: }
1993: if (($has_int ne '') && ($has_int ne $has_std)) {
1994: unless ((-l "$apache2_sites_enabled_dir/$has_int") && (readlink("$apache2_sites_enabled_dir/$has_int") eq "$targetdir/$has_int")) {
1995: my $made_symlink = eval { symlink("$targetdir/$has_int","$apache2_sites_enabled_dir/$has_int"); 1 };
1996: if ($made_symlink) {
1997: print_and_log(&mt('Enabling "[_1]" Apache SSL configuration.',$has_int)."\n");
1998: }
1999: }
1.46 raeburn 2000: }
2001: }
2002: }
2003: print_and_log("\n");
2004: } else {
2005: print_and_log(&mt('Skipping configuration of SSL for Apache web server.')."\n");
2006: }
2007:
1.1 raeburn 2008: if ($callsub{'runlevels'}) {
2009: my $count = 0;
2010: if (ref($recommended) eq 'HASH') {
2011: if (ref($recommended->{'runlevels'}) eq 'HASH') {
2012: foreach my $type (keys(%{$recommended->{'runlevels'}})) {
2013: next if ($type eq 'insserv');
2014: $count ++;
2015: my $command = $recommended->{'runlevels'}{$type};
2016: if ($command ne '') {
2017: print_and_log(&mt('Runlevel update command run: [_1].',$command)."\n");
2018: system($command);
2019: }
2020: }
2021: if (!$count) {
2022: print_and_log(&mt('No runlevel updates required.')."\n");
2023: }
2024: }
2025: }
1.49 raeburn 2026: if ($distro =~ /^(suse|sles)(\d+)/) {
2027: unless(($1 eq 'sles') && ($2 >= 15)) {
2028: &update_SuSEfirewall2_setup($instdir);
2029: }
1.11 raeburn 2030: }
1.1 raeburn 2031: } else {
2032: &print_and_log(&mt('Skipping setting override for start-up order of services.')."\n");
2033: }
2034:
2035: if ($callsub{'firewall'}) {
1.53 ! raeburn 2036: my ($firewalld,$zone) = &uses_firewalld($distro);
! 2037: if ($firewalld) {
1.49 raeburn 2038: my (%current,%added);
1.53 ! raeburn 2039: if (open(PIPE,"firewall-cmd --permanent --zone=$zone --list-services |")) {
1.49 raeburn 2040: my $svc = <PIPE>;
2041: close(PIPE);
2042: chomp($svc);
2043: map { $current{$_} = 1; } (split(/\s+/,$svc));
2044: }
2045: foreach my $service ('http','https') {
2046: unless ($current{$service}) {
1.53 ! raeburn 2047: if (open(PIPE,"firewall-cmd --permanent --zone=$zone --add-service=$service |")) {
1.49 raeburn 2048: my $result = <PIPE>;
2049: if ($result =~ /^success/) {
2050: $added{$service} = 1;
2051: }
2052: }
2053: }
2054: }
2055: if (keys(%added) > 0) {
2056: print &mt('Firewall configured to allow access for: [_1].',
2057: join(', ',sort(keys(%added))))."\n";
2058: }
2059: if ($current{'http'} || $current{'https'}) {
2060: print &mt('Firewall already configured to allow access for:[_1].',
2061: (($current{'http'})? ' http':'').(($current{'https'})? ' https':''))."\n";
2062: }
2063: unless ($current{'ssh'}) {
2064: print &mt('If you would the like to allow access to ssh from outside, use the command[_1].',
1.53 ! raeburn 2065: "firewall-cmd --permanent --zone=$zone --add-service=ssh")."\n";
1.49 raeburn 2066: }
2067: } elsif ($distro =~ /^(suse|sles)/) {
1.5 raeburn 2068: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
2069: 'yast -- Security and Users -> Firewall -> Interfaces',
1.49 raeburn 2070: 'ssh, http, https')."\n";
1.5 raeburn 2071: } elsif ($distro =~ /^(debian|ubuntu)(\d+)/) {
2072: if (($1 eq 'ubuntu') || ($2 > 5)) {
2073: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
2074: 'ufw','ssh, http, https')."\n";
2075: } else {
2076: my $fwadded = &get_iptables_rules($distro,$instdir,$apachefw);
2077: if ($fwadded) {
2078: print &mt('Enable firewall? ~[Y/n~]');
2079: my $enable_iptables = &get_user_selection(1);
2080: if ($enable_iptables) {
2081: system('/etc/network/if-pre-up.d/iptables');
2082: print &mt('Firewall enabled using rules defined in [_1].',
2083: '/etc/iptables.loncapa.rules');
2084: }
2085: }
2086: }
1.11 raeburn 2087: } elsif ($distro =~ /^scientific/) {
2088: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
2089: 'system-config-firewall-tui -- Customize',
2090: 'ssh, http')."\n";
1.1 raeburn 2091: } else {
1.53 ! raeburn 2092: my $version;
! 2093: if ($distro =~ /^(redhat|centos)(\d+)$/) {
! 2094: $version = $1;
! 2095: }
! 2096: if ($version > 5) {
! 2097: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
! 2098: 'system-config-firewall-tui -- Customize',
! 2099: 'ssh, http')."\n";
! 2100: } else {
! 2101: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
! 2102: 'setup -- Firewall configuration -> Customize',
! 2103: 'ssh, http, https')."\n";
! 2104: }
1.1 raeburn 2105: }
2106: } else {
1.5 raeburn 2107: &print_and_log(&mt('Skipping Firewall configuration.')."\n");
1.1 raeburn 2108: }
2109:
2110: if ($callsub{'stopsrvcs'}) {
1.45 raeburn 2111: &kill_extra_services($distro,$recommended->{'stopsrvcs'},$uses_systemctl);
1.1 raeburn 2112: } else {
1.10 raeburn 2113: &print_and_log(&mt('Skipping stopping unnecessary service ([_1] daemons).',"'cups','memcached'")."\n");
1.1 raeburn 2114: }
2115:
2116: my ($have_tarball,$updateshown);
2117: if ($callsub{'download'}) {
2118: ($have_tarball,$updateshown) = &download_loncapa($instdir,$sourcetarball);
2119: } else {
2120: print_and_log(&mt('Skipping download of LON-CAPA tar file.')."\n\n");
2121: print &mt('LON-CAPA is available for download from: [_1]',
2122: 'http://install.loncapa.org/')."\n";
2123: if (!-e '/etc/loncapa-release') {
2124: &print_and_log(&mt('LON-CAPA is not yet installed on your system.').
2125: "\n\n".
2126: &mt('You may retrieve the source for LON-CAPA by executing:')."\n".
2127: "wget http://install.loncapa.org/versions/$lctarball\n");
2128: } else {
2129: my $currentversion;
2130: if (open(my $fh,"</etc/loncapa-release")) {
2131: my $version = <$fh>;
2132: chomp($version);
2133: if ($version =~ /^\QLON-CAPA release \E([\w\-.]+)$/) {
2134: $currentversion = $1;
2135: }
2136: }
2137: if ($currentversion ne '') {
2138: print &mt('Version of LON-CAPA currently installed on this server is: [_1].',
2139: $currentversion),"\n";
2140: if ($production) {
2141: print &mt('The latest production release of LON-CAPA is [_1].',$production)."\n";
2142: }
2143: if ($testing) {
2144: print &mt('The latest testing release of LON-CAPA is [_1].',$testing)."\n";
2145: }
2146: }
2147: }
2148: if ($filetouse ne '') {
2149: $have_tarball = 1;
2150: }
2151: }
2152:
2153: print "\n".&mt('Requested configuration complete.')."\n\n";
2154: my $apachename;
2155: if ($have_tarball && !$updateshown) {
2156: my ($lcdir) = ($sourcetarball =~ /^([\w.\-]+)\.tar.gz$/);
2157: if (!-e '/etc/loncapa-release') {
2158: print &mt('If you are now ready to install LON-CAPA, enter the following commands:')."\n\n";
2159: } else {
2160: print &mt('If you are now ready to update LON-CAPA, enter the following commands:')."\n\n".
2161: "/etc/init.d/loncontrol stop\n";
2162: if ($distro =~ /^(suse|sles|debian|ubuntu)([\d.]+)/) {
2163: if (($1 eq 'suse') && ($2 < 10)) {
2164: $apachename = 'apache';
2165: } else {
2166: $apachename = 'apache2';
2167: }
2168: } else {
2169: $apachename = 'httpd';
2170: }
2171: print "/etc/init.d/$apachename stop\n";
2172: }
2173: print "cd /root\n".
2174: "tar zxf $sourcetarball\n".
2175: "cd $lcdir\n".
2176: "./UPDATE\n";
2177: if (-e '/etc/loncapa-release') {
2178: print "/etc/init.d/loncontrol start\n";
2179: print "/etc/init.d/$apachename start\n";
2180: }
2181: }
2182: exit;
2183:
2184: #
2185: # End main script
2186: #
2187:
2188: #
2189: # Routines for the actions
2190: #
2191:
2192: sub setup_www {
2193: ##
2194: ## Set up www
2195: ##
2196: print_and_log(&mt('Creating user [_1]',"'www'")."\n");
2197: # -- Add group
2198:
2199: my $status = `/usr/sbin/groupadd www`;
2200: if ($status =~ /\QGroup `www' already exists.\E/) {
2201: print &mt('Group [_1] already exists.',"'www'")."\n";
2202: } elsif ($status ne '') {
2203: print &mt('Unable to add group [_1].',"'www'")."\n";
2204: }
2205:
2206: my $gid = getgrnam('www');
2207:
2208: if (open (PIPE, "/usr/sbin/useradd -c LONCAPA -g $gid www 2>&1 |")) {
2209: $status = <PIPE>;
2210: close(PIPE);
2211: chomp($status);
2212: if ($status =~ /\QAccount `www' already exists.\E/) {
2213: print &mt('Account [_1] already exists.',"'www'")."\n";
2214: } elsif ($status ne '') {
2215: print &mt('Unable to add user [_1].',"'www'")."\n";
2216: }
2217: } else {
2218: print &mt('Unable to run command to add user [_1].',"'www'")."\n";
2219: }
2220:
2221: my $uid = &uid_of_www();
2222: if (($gid ne '') && ($uid ne '')) {
2223: if (!-e '/home/www') {
2224: mkdir('/home/www',0755);
2225: system('chown www:www /home/www');
2226: }
2227: }
2228: writelog ($status);
2229: }
2230:
2231: sub uid_of_www {
2232: my ($num) = (getpwnam('www'))[2];
2233: return $num;
2234: }
2235:
2236: sub build_and_install_mod_auth_external {
2237: my ($instdir) = @_;
2238: my $num = &uid_of_www();
2239: # Patch pwauth
2240: print_and_log(&mt('Building authentication system for LON-CAPA users.')."\n");
2241: my $patch = <<"ENDPATCH";
2242: 148c148
2243: < #define SERVER_UIDS 99 /* user "nobody" */
2244: ---
2245: > #define SERVER_UIDS $num /* user "www" */
2246: ENDPATCH
2247:
2248: if (! -e "/usr/bin/patch") {
2249: print_and_log(&mt('You must install the software development tools package: [_1], when installing Linux.',"'patch'")."\n");
2250: print_and_log(&mt('Authentication installation not completed.')."\n");
2251: return;
2252: }
2253: if (&skip_if_nonempty(`cd /tmp; tar zxf $instdir/pwauth-2.2.8.tar.gz`,
2254: &mt('Unable to extract pwauth')."\n")) {
2255: return;
2256: }
2257: my $dir = "/tmp/pwauth-2.2.8";
2258: if (open(PATCH,"| patch $dir/config.h")) {
2259: print PATCH $patch;
2260: close(PATCH);
2261: print_and_log("\n");
2262: ##
2263: ## Compile patched pwauth
2264: ##
2265: print_and_log(&mt('Compiling pwauth')."\n");
1.12 raeburn 2266: my $result = `cd $dir/; make 2>/dev/null `;
1.1 raeburn 2267: my $expected = <<"END";
2268: gcc -g -c -o pwauth.o pwauth.c
2269: gcc -o pwauth -g pwauth.o -lcrypt
2270: END
2271: if ($result eq $expected) {
2272: print_and_log(&mt('Apparent success compiling pwauth:').
2273: "\n".$result );
2274: # Install patched pwauth
2275: print_and_log(&mt('Copying pwauth to [_1]',' /usr/local/sbin')."\n");
2276: if (copy "$dir/pwauth","/usr/local/sbin/pwauth") {
1.5 raeburn 2277: if (chmod(06755, "/usr/local/sbin/pwauth")) {
1.1 raeburn 2278: print_and_log(&mt('[_1] copied successfully',"'pwauth'").
2279: "\n");
2280: } else {
2281: print &mt('Unable to set permissions on [_1].'.
2282: "/usr/local/sbin/pwauth")."\n";
2283: }
2284: } else {
2285: print &mt('Unable to copy [_1] to [_2]',
2286: "'$dir/pwauth'","/usr/local/sbin/pwauth")."\n$!\n";
2287: }
2288: } else {
2289: print &mt('Unable to compile patched [_1].'."'pwauth'")."\n";
2290: }
2291: } else {
2292: print &mt('Unable to start patch for [_1]',"'pwauth'")."\n";
2293: }
2294: print_and_log("\n");
2295: }
2296:
2297: sub kill_extra_services {
1.45 raeburn 2298: my ($distro,$stopsrvcs,$uses_systemctl) = @_;
1.1 raeburn 2299: if (ref($stopsrvcs) eq 'HASH') {
2300: my @stopping = sort(keys(%{$stopsrvcs}));
2301: if (@stopping) {
1.6 raeburn 2302: my $kill_list = join("', '",@stopping);
1.1 raeburn 2303: if ($kill_list) {
2304: $kill_list = "'".$kill_list."'";
1.6 raeburn 2305: &print_and_log("\n".&mt('Killing unnecessary services ([_1] daemon(s)).',$kill_list)."\n");
2306: foreach my $service (@stopping) {
2307: my $daemon = $service;
2308: if ($service eq 'cups') {
2309: $daemon = 'cupsd';
2310: if ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
2311: my $version = $1;
2312: if (($distro =~ /^ubuntu/) && ($version <= 8)) {
2313: $daemon = 'cupsys';
2314: }
1.12 raeburn 2315: } else {
1.8 raeburn 2316: $daemon = 'cups';
1.6 raeburn 2317: }
2318: }
1.12 raeburn 2319: my $cmd = "ps -ef |grep '$daemon' |grep -v grep";
2320: if (open(PIPE,'-|',$cmd)) {
2321: my $daemonrunning = <PIPE>;
2322: chomp($daemonrunning);
2323: close(PIPE);
2324: if ($daemonrunning) {
2325: &print_and_log(`/etc/init.d/$daemon stop`);
2326: }
2327: }
1.1 raeburn 2328: &print_and_log(&mt('Removing [_1] from startup.',$service)."\n");
1.45 raeburn 2329: if ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
2330: my $version = $1;
2331: if (($distro =~ /^ubuntu/) && ($version > 16)) {
2332: if (ref($uses_systemctl) eq 'HASH') {
2333: if ($uses_systemctl->{$service}) {
2334: if (`systemctl is-enabled $service`) {
2335: &print_and_log(`systemctl disable $service`);
2336: }
2337: }
2338: }
2339: } else {
2340: &print_and_log(`update-rc.d -f $daemon remove`);
2341: }
1.1 raeburn 2342: } else {
1.35 raeburn 2343: if (ref($uses_systemctl) eq 'HASH') {
2344: if ($uses_systemctl->{$service}) {
2345: if (`systemctl is-enabled $service`) {
2346: &print_and_log(`systemctl disable $service`);
2347: }
2348: } else {
2349: &print_and_log(`/sbin/chkconfig --del $service`);
2350: }
2351: } else {
2352: &print_and_log(`/sbin/chkconfig --del $service`);
2353: }
1.1 raeburn 2354: }
2355: }
2356: }
2357: }
2358: }
2359: return;
2360: }
2361:
2362: sub setup_mysql {
2363: my ($setup_mysql_permissions,$distro,$dbh,$has_pass,$has_lcdb) = @_;
1.4 raeburn 2364: my @mysql_lc_commands;
1.1 raeburn 2365: unless ($has_lcdb) {
1.4 raeburn 2366: push(@mysql_lc_commands,"CREATE DATABASE loncapa");
1.1 raeburn 2367: }
1.4 raeburn 2368: push(@mysql_lc_commands,"USE loncapa");
2369: push(@mysql_lc_commands,qq{
1.18 raeburn 2370: CREATE TABLE IF NOT EXISTS metadata (title TEXT, author TEXT, subject TEXT, url TEXT, keywords TEXT, version TEXT, notes TEXT, abstract TEXT, mime TEXT, language TEXT, creationdate DATETIME, lastrevisiondate DATETIME, owner TEXT, copyright TEXT, domain TEXT, dependencies TEXT, modifyinguser TEXT, authorspace TEXT, lowestgradelevel TEXT, highestgradelevel TEXT, standards TEXT, count INT, course INT, course_list TEXT, goto INT, goto_list TEXT, comefrom INT, comefrom_list TEXT, sequsage INT, sequsage_list TEXT, stdno INT, stdno_list TEXT, avetries FLOAT, avetries_list TEXT, difficulty FLOAT, difficulty_list TEXT, disc FLOAT, disc_list TEXT, clear FLOAT, technical FLOAT, correct FLOAT, helpful FLOAT, depth FLOAT, hostname TEXT, FULLTEXT idx_title (title), FULLTEXT idx_author (author), FULLTEXT idx_subject (subject), FULLTEXT idx_url (url), FULLTEXT idx_keywords (keywords), FULLTEXT idx_version (version), FULLTEXT idx_notes (notes), FULLTEXT idx_abstract (abstract), FULLTEXT idx_mime (mime), FULLTEXT idx_language (language), FULLTEXT idx_owner (owner), FULLTEXT idx_copyright (copyright)) ENGINE=MYISAM
1.4 raeburn 2371: });
1.1 raeburn 2372: if ($setup_mysql_permissions) {
1.4 raeburn 2373: &setup_mysql_permissions($dbh,$has_pass,@mysql_lc_commands);
1.1 raeburn 2374: } else {
2375: print_and_log(&mt('Skipping MySQL permissions setup.')."\n");
2376: if ($dbh) {
1.4 raeburn 2377: if (@mysql_lc_commands) {
2378: foreach my $lccmd (@mysql_lc_commands) {
2379: $dbh->do($lccmd) || print $dbh->errstr."\n";
2380: }
2381: }
1.1 raeburn 2382: print_and_log(&mt('MySQL database set up complete.')."\n");
2383: } else {
2384: print_and_log(&mt('Problem accessing MySQL.')."\n");
2385: }
2386: }
2387: }
2388:
2389: sub setup_mysql_permissions {
1.4 raeburn 2390: my ($dbh,$has_pass,@mysql_lc_commands) = @_;
1.38 raeburn 2391: my ($mysqlversion,$mysqlsubver,$mysqlname) = &get_mysql_version();
1.50 raeburn 2392: my ($usesauth,$is_mariadb,$hasauthcol,@mysql_commands);
1.38 raeburn 2393: if ($mysqlname =~ /^MariaDB/i) {
1.50 raeburn 2394: $is_mariadb = 1;
1.38 raeburn 2395: if ($mysqlversion >= 10.2) {
2396: $usesauth = 1;
1.42 raeburn 2397: } elsif ($mysqlversion >= 5.5) {
2398: $hasauthcol = 1;
1.38 raeburn 2399: }
2400: } else {
2401: if (($mysqlversion > 5.7) || (($mysqlversion == 5.7) && ($mysqlsubver > 5))) {
2402: $usesauth = 1;
1.42 raeburn 2403: } elsif (($mysqlversion >= 5.6) || (($mysqlversion == 5.5) && ($mysqlsubver >= 7))) {
2404: $hasauthcol = 1;
1.38 raeburn 2405: }
2406: }
2407: if ($usesauth) {
1.50 raeburn 2408: @mysql_commands = ("INSERT user (Host, User, ssl_cipher, x509_issuer, x509_subject, authentication_string) VALUES('localhost','www','','','','')");
2409: if ($is_mariadb) {
1.52 raeburn 2410: push(@mysql_commands,"ALTER USER 'www'\@'localhost' IDENTIFIED BY 'localhostkey'");
1.50 raeburn 2411: } else {
1.52 raeburn 2412: push(@mysql_commands,"ALTER USER 'www'\@'localhost' IDENTIFIED WITH mysql_native_password BY 'localhostkey'");
1.50 raeburn 2413: }
1.42 raeburn 2414: } elsif ($hasauthcol) {
2415: @mysql_commands = ("INSERT user (Host, User, Password, ssl_cipher, x509_issuer, x509_subject, authentication_string) VALUES('localhost','www',password('localhostkey'),'','','','');");
1.36 raeburn 2416: } else {
1.42 raeburn 2417: @mysql_commands = ("INSERT user (Host, User, Password, ssl_cipher, x509_issuer, x509_subject) VALUES('localhost','www',password('localhostkey'),'','','');");
1.36 raeburn 2418: }
1.1 raeburn 2419: if ($mysqlversion < 4) {
1.4 raeburn 2420: push (@mysql_commands,"
2421: INSERT db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv) VALUES('localhost','loncapa','www','Y','Y','Y','Y','Y','Y','N','Y','Y','Y')");
2422: } else {
2423: push (@mysql_commands,"
2424: INSERT db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Create_tmp_table_priv,Lock_tables_priv) VALUES('localhost','loncapa','www','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y')");
1.1 raeburn 2425: }
1.4 raeburn 2426: push(@mysql_commands,"DELETE FROM user WHERE host<>'localhost'");
1.1 raeburn 2427: if ($has_pass) {
2428: if ($dbh) {
1.4 raeburn 2429: push(@mysql_commands,"FLUSH PRIVILEGES");
2430: if (@mysql_commands) {
2431: foreach my $cmd (@mysql_commands) {
2432: $dbh->do($cmd) || print $dbh->errstr."\n";
2433: }
2434: }
2435: if (@mysql_lc_commands) {
2436: foreach my $lccmd (@mysql_lc_commands) {
2437: $dbh->do($lccmd) || print $dbh->errstr."\n";
2438: }
2439: }
1.1 raeburn 2440: print_and_log(&mt('Permissions set for LON-CAPA MySQL user: [_1]',"'www'")."\n");
2441: } else {
2442: print_and_log(&mt('Problem accessing MySQL.')."\n".
2443: &mt('Permissions not set.')."\n");
2444: }
2445: } else {
2446: my ($firstpass,$secondpass,$got_passwd,$newmysqlpass);
2447: print &mt('Please enter a root password for the mysql database.')."\n".
2448: &mt('It does not have to match your root account password, but you will need to remember it.')."\n";
2449: my $maxtries = 10;
2450: my $trial = 0;
2451: while ((!$got_passwd) && ($trial < $maxtries)) {
2452: $firstpass = &get_mysql_password(&mt('Enter password'));
2453: if (length($firstpass) > 5) {
2454: $secondpass = &get_mysql_password(&mt('Enter password a second time'));
2455: if ($firstpass eq $secondpass) {
2456: $got_passwd = 1;
2457: $newmysqlpass = $firstpass;
2458: } else {
2459: print(&mt('Passwords did not match. Please try again.')."\n");
2460: }
2461: $trial ++;
2462: } else {
2463: print(&mt('Password too short.')."\n".
2464: &mt('Please choose a password with at least six characters.')."\n");
2465: }
2466: }
2467: if ($got_passwd) {
1.50 raeburn 2468: my (@newpass_cmds) = &new_mysql_rootpasswd($newmysqlpass,$usesauth,$is_mariadb);
1.4 raeburn 2469: push(@mysql_commands,@newpass_cmds);
1.1 raeburn 2470: } else {
2471: print_and_log(&mt('Failed to get MySQL root password from user input.')."\n");
2472: }
2473: if ($dbh) {
1.4 raeburn 2474: if (@mysql_commands) {
2475: foreach my $cmd (@mysql_commands) {
2476: $dbh->do($cmd) || print $dbh->errstr."\n";
2477: }
2478: }
2479: if (@mysql_lc_commands) {
2480: foreach my $lccmd (@mysql_lc_commands) {
2481: $dbh->do($lccmd) || print $dbh->errstr."\n";
2482: }
2483: }
1.1 raeburn 2484: if ($got_passwd) {
2485: print_and_log(&mt('MySQL root password stored.')."\n".
2486: &mt('Permissions set for LON-CAPA MySQL user: [_1].',"'www'")."\n");
2487: } else {
2488: print_and_log(&mt('Permissions set for LON-CAPA MySQL user: [_1].',"'www'")."\n");
2489: }
2490: } else {
2491: print_and_log(&mt('Problem accessing MySQL.')."\n".
2492: &mt('Permissions not set.')."\n");
2493: }
2494: }
2495: }
2496:
2497: sub new_mysql_rootpasswd {
1.50 raeburn 2498: my ($currmysqlpass,$usesauth,$is_mariadb) = @_;
1.36 raeburn 2499: if ($usesauth) {
1.50 raeburn 2500: if ($is_mariadb) {
1.51 raeburn 2501: return ("ALTER USER 'root'\@'localhost' IDENTIFIED BY '$currmysqlpass'",
1.50 raeburn 2502: "FLUSH PRIVILEGES;");
2503: } else {
1.51 raeburn 2504: return ("ALTER USER 'root'\@'localhost' IDENTIFIED WITH mysql_native_password BY '$currmysqlpass'",
1.50 raeburn 2505: "FLUSH PRIVILEGES;");
2506: }
1.36 raeburn 2507: } else {
2508: return ("SET PASSWORD FOR 'root'\@'localhost'=PASSWORD('$currmysqlpass')",
2509: "FLUSH PRIVILEGES;");
2510: }
1.1 raeburn 2511: }
2512:
2513: sub get_mysql_version {
1.38 raeburn 2514: my ($version,$subversion,$name);
1.1 raeburn 2515: if (open(PIPE," mysql -V |")) {
2516: my $info = <PIPE>;
2517: chomp($info);
2518: close(PIPE);
1.38 raeburn 2519: ($version,$subversion,$name) = ($info =~ /(\d+\.\d+)\.(\d+)\-?(\w*),/);
1.1 raeburn 2520: } else {
2521: print &mt('Could not determine which version of MySQL is installed.').
2522: "\n";
2523: }
1.38 raeburn 2524: return ($version,$subversion,$name);
1.1 raeburn 2525: }
2526:
2527: ###########################################################
2528: ##
2529: ## RHEL/CentOS/Fedora/Scientific Linux
2530: ## Copy LON-CAPA httpd.conf to /etc/httpd/conf
2531: ##
2532: ###########################################################
2533:
2534: sub copy_httpd_conf {
1.46 raeburn 2535: my ($instdir,$distro,$hostname) = @_;
1.14 raeburn 2536: my $configfile = 'httpd.conf';
2537: if ($distro =~ /^(?:centos|rhes|scientific)(\d+)$/) {
1.29 raeburn 2538: if ($1 >= 7) {
2539: $configfile = 'apache2.4/httpd.conf';
2540: } elsif ($1 > 5) {
1.14 raeburn 2541: $configfile = 'new/httpd.conf';
2542: }
2543: } elsif ($distro =~ /^fedora(\d+)$/) {
1.29 raeburn 2544: if ($1 > 17) {
2545: $configfile = 'apache2.4/httpd.conf';
2546: } elsif ($1 > 10) {
1.14 raeburn 2547: $configfile = 'new/httpd.conf';
2548: }
2549: }
1.1 raeburn 2550: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'httpd.conf'",
2551: "'/etc/httpd/conf/httpd.conf'")."\n");
2552: copy "/etc/httpd/conf/httpd.conf","/etc/httpd/conf/httpd.conf.original";
1.14 raeburn 2553: copy "$instdir/centos-rhes-fedora-sl/$configfile","/etc/httpd/conf/httpd.conf";
1.5 raeburn 2554: chmod(0444,"/etc/httpd/conf/httpd.conf");
1.1 raeburn 2555: print_and_log("\n");
2556: }
2557:
1.46 raeburn 2558: ###############################################
2559: ##
1.47 raeburn 2560: ## Copy loncapassl.conf and sslrewrite.conf
1.46 raeburn 2561: ##
2562: ###############################################
2563:
1.47 raeburn 2564: #
2565: # The Apache SSL configuration used by LON-CAPA is contained in
2566: # two files: sslrewrite.conf and loncapassl.conf.
2567: #
2568: # Starting with LON-CAPA 2.12, name-based virtual hosts are used
2569: # with port 443. The default virtual host (i.e., the one listed
2570: # first) is for the server's standard hostname, and that is the one
2571: # which will respond to client browser requests for https:// pages.
2572: #
2573: # Accordingly, a system administrator will need to edit the config
2574: # config file to include paths to a signed SSL certificate (public),
2575: # chain (public) and key (private) pem files. The certificate should
2576: # have been signed by a recognized certificate authority ((e.g.,
2577: # InCommon or Let's Encrypt).
2578: #
2579: # The sslrewrite.conf file contains the rewrite configuration for
2580: # the default virtual host. The rewrite rules defined are used to
2581: # allow internal HEAD requests to /cgi-bin/mimetex.cgi to be served
2582: # http://, in order to support vertical alignment of mimetex images
2583: # (one of the options for rendering Math content); (b) allow requests
2584: # for certain URLs (external resource, and syllabus, if external URL
2585: # used) to be served http:// to accommodate the use of iframes which
2586: # would otherwise result in browser blocking of mixed active content.
2587: #
2588: # The loncapassl.conf file contains the configuration for the
2589: # "internal" virtual host, which will respond to requests for https://
2590: # pages from other LON-CAPA servers in the network to which the node
2591: # belongs. The ServerName is internal-<hostname> where <hostname>
2592: # is the server's hostname. There is no need to create a DNS entry
2593: # for internal-<hostname>, as LON-CAPA 2.12 automatically performs
2594: # the required hostname to IP mapping.
2595: #
2596: # Requests to /raw on the "internal" virtual host require a valid
2597: # SSL client certificate, signed by the certificate authority
2598: # for the LON-CAPA network to which the node belongs.
2599: #
2600: # The configuration file to which the contents of sslrewrite.conf
2601: # and loncapassl.conf will be written will have either been identified
2602: # when &chkapachessl() was run, or if no files were found with
2603: # existing rewrite blocks, then a candidate file will be chosen
2604: # from the .conf files containing VirtualHosts definitions.
2605: # If there is more than one suitable candidate file, the system
2606: # administrator will be prompted to select from the available files.
2607: #
2608: # If there are no files containing VirtualHosts definitions, then
2609: # <VirtualHost *:443> </VirtualHost> blocks will be appended to
2610: # the standard Apache SSL config for the particular distro:
2611: # ssl.conf for RHEL/CentOS/Scientific/Fedora, vhost-ssl.conf
2612: # for SuSE/SLES, and default-ssl.conf for Ubuntu.
2613: #
2614: # Once a file is selected, the contents of sslrewrite.conf and
2615: # loncapassl.conf are compared with appropriate blocks in the file
2616: # and the user will be prompted to agree to insertion of missing lines
2617: # and/or deletion of surplus lines.
2618: #
2619:
2620: sub copy_apache_sslconf_files {
2621: my ($distro,$hostname,$hostip,$instdir,$targetdir,$targetfilesref,
2622: $has_std,$has_int,$rewritenum,$nochgstd,$nochgint) = @_;
2623: my ($new_std,$new_int);
2624: my (@internal,@standard,%int_by_linenum,%int_by_linetext,
2625: %rule_by_linenum,%rule_by_linetext,%foundint);
1.46 raeburn 2626: if (-e "$instdir/loncapassl.conf") {
2627: if (open(my $fh,'<',"$instdir/loncapassl.conf")) {
1.47 raeburn 2628: my $num = 1;
2629: while (<$fh>) {
2630: chomp();
2631: if (/^ServerName/) {
2632: s/(\Qinternal-{[[[[Hostname]]]]}\E)/internal-$hostname/;
2633: }
2634: push(@internal,$_);
2635: $int_by_linenum{$num} = $_;
2636: s/(^\s+|\s+$)//g;
2637: push(@{$int_by_linetext{$_}},$num);
2638: $num ++;
2639: }
2640: close($fh);
2641: }
2642: }
2643: if (-e "$instdir/sslrewrite.conf") {
2644: if (open(my $fh,'<',"$instdir/sslrewrite.conf")) {
2645: my $num = 1;
2646: while (<$fh>) {
2647: chomp();
2648: if (/\Q{[[[[HostIP]]]]}\E/) {
2649: s/(\QRewriteCond %{REMOTE_ADDR} {[[[[HostIP]]]]}\E)/RewriteCond %{REMOTE_ADDR} $hostip/;
2650: }
2651: push(@standard,$_);
2652: $rule_by_linenum{$num} = $_;
2653: s/(^\s+|\s+$)//g;
2654: push(@{$rule_by_linetext{$_}},$num);
2655: $num ++;
2656: }
2657: close($fh);
2658: }
2659: }
2660: if (!$nochgstd) {
2661: if ($has_std eq '') {
2662: my $file;
2663: if ($has_int ne '') {
2664: if (open(my $fh,'<',"$targetdir/$has_int")) {
2665: my @saved = <$fh>;
2666: close($fh);
2667: if (open(my $fhout, '>',"$targetdir/$has_int")) {
2668: print $fhout "<VirtualHost *:443>\n".
2669: "ServerName $hostname\n".
2670: join("\n",@standard)."\n".
2671: "</VirtualHost>\n\n".
2672: join('',@saved);
2673: close($fhout);
2674: $new_int = $has_int;
2675: }
2676: }
2677: }
2678: } else {
2679: if ($rewritenum eq '') {
2680: &append_to_vhost($targetdir,$has_std,$hostname,\%rule_by_linenum,'std');
2681: $new_std = $has_std;
2682: } else {
2683: $new_std = &modify_ssl_config($targetdir,$has_std,$hostname,$rewritenum,
2684: \%rule_by_linetext,\%rule_by_linenum,'std');
2685: }
2686: }
2687: }
2688: if (!$nochgint) {
2689: if ($has_int eq '') {
2690: if ($has_std ne '') {
2691: if (open(my $fhout,'>>',"$targetdir/$has_std")) {
2692: print $fhout "\n".join("\n",@internal)."\n";
2693: close($fhout);
2694: $new_int = $has_std;
2695: }
2696: }
2697: } else {
2698: $new_int = &modify_ssl_config($targetdir,$has_int,$hostname,$rewritenum,\%int_by_linetext,\%int_by_linenum,'int');
2699: }
2700: }
2701: if (($has_std eq '') && ($has_int eq '')) {
2702: my ($file,$numfiles) = &get_sslconf_filename($distro,$targetdir,$targetfilesref);
2703: if ($numfiles == 0) {
2704: if (open(my $fhout, '>>', "$targetdir/$file")) {
2705: print $fhout "<VirtualHost *:443>\n".
2706: "ServerName $hostname\n".
2707: join("\n",@standard)."\n".
2708: "</VirtualHost>\n\n".
2709: join("\n",@internal)."\n";
2710: close($fhout);
2711: $new_std = $file;
2712: $new_int = $file;
2713: }
2714: } elsif ($numfiles == 1) {
2715: &append_to_vhost($targetdir,$file,$hostname,\%rule_by_linenum,'std');
2716: if (open(my $fhout, '>>', "$targetdir/$file")) {
2717: print $fhout "\n".join("\n",@internal)."\n";
2718: close($fhout);
2719: $new_std = $file;
2720: $new_int = $file;
2721: }
2722: } elsif ($numfiles == -1) {
2723: print_and_log(&mt('Failed to copy contents of [_1] or [_2] to a file in [_3]',
2724: "'loncapassl.conf'","'sslrewrite.conf'","'$targetdir'")."\n");
2725: }
2726: }
2727: if ($nochgstd) {
2728: print_and_log(&mt('No change required to file: [_1] in [_2], (no difference between [_3] and rewrite block.)',
2729: "'$has_std'","'$targetdir'","'sslrewrite.conf'"));
2730: }
2731: if ($nochgint) {
2732: print_and_log(&mt('No change required to file: [_1] in [_2], (no difference between [_3] and virtualhost block.)',
2733: "'$has_int'","'$targetdir'","'loncapassl.conf'"));
2734: }
2735: if ($new_int) {
2736: print_and_log(&mt('Successfully copied contents of [_1] to [_2].',"'loncapassl.conf'","'$targetdir/$new_int'")."\n");
2737: chmod(0444,"$targetdir/loncapassl.conf");
2738: }
2739: if ($new_std) {
2740: print_and_log(&mt('Successfully copied contents of [_1] to [_2].',"'sslrewrite.conf'","'$targetdir/$new_std'")."\n");
2741: chmod(0444,"$targetdir/loncapassl.conf");
2742: }
2743: return ($new_int,$new_std);
2744: }
2745:
2746: #
2747: # append_to_vhost() is called to add rewrite rules (in a
2748: # <IfModule +mod_rewrite.c> </IfModule> block), provided
2749: # in the sslrewrite.conf configuration file, to an Apache
2750: # SSL configuration file within a VirtualHost for port 443
2751: # (for server's public-facing hostname).
2752: #
2753: sub append_to_vhost {
2754: my ($targetdir,$filename,$hostname,$by_linenum,$type) = @_;
2755: return unless (ref($by_linenum) eq 'HASH');
2756: my ($startvhost,$endvhost);
2757: if (-e "$targetdir/$filename") {
2758: my (@lines,$currname,$virtualhost,$hasname);
2759: if (open(my $fh,'<',"$targetdir/$filename")) {
2760: my $currline = 0;
2761: while (<$fh>) {
2762: $currline ++;
2763: push(@lines,$_);
2764: chomp();
2765: s/(^\s+|\s+$)//g;
2766: if (/^<VirtualHost\s+[^:]*\:443>/) {
2767: $virtualhost = 1;
2768: unless ($endvhost) {
2769: $startvhost = $currline;
1.46 raeburn 2770: }
2771: }
1.47 raeburn 2772: if ($virtualhost) {
2773: if (/^ServerName\s+([^\s]+)\s*$/) {
2774: $currname = $1;
2775: unless ($endvhost) {
2776: if ((($currname eq '') || ($currname eq $hostname)) && ($type eq 'std')) {
2777: $hasname = 1;
2778: }
2779: }
2780: }
2781: if (/^<\/VirtualHost>/) {
2782: $virtualhost = 0;
2783: unless ($endvhost) {
2784: if (((($currname eq '') || ($currname eq $hostname)) && ($type eq 'std')) ||
2785: (($currname eq 'internal-'.$hostname) && ($type eq 'int'))) {
2786: $endvhost = $currline;
2787: } else {
2788: undef($startvhost);
2789: }
2790: }
2791: }
2792: }
2793: }
2794: close($fh);
2795: }
2796: if ($endvhost) {
2797: if (open(my $fout,'>',"$targetdir/$filename")) {
2798: for (my $i=0; $i<@lines; $i++) {
2799: if ($i == $startvhost) {
2800: unless (($hasname) && ($type eq 'std')) {
2801: print $fout "ServerName $hostname\n";
2802: }
2803: }
2804: if ($i == $endvhost-1) {
2805: foreach my $item (sort { $a <=> $b } keys(%{$by_linenum})) {
2806: print $fout $by_linenum->{$item}."\n";
2807: }
2808: }
2809: print $fout $lines[$i];
2810: }
2811: close($fout);
2812: }
2813: }
2814: }
2815: return $endvhost;
2816: }
2817:
2818: #
2819: # get_sslconf_filename() is called when the Apache SSL configuration
2820: # option has been selected and there are no files containing
2821: # VirtualHost definitions containing rewrite blocks,
2822: #
2823: # In this case get_sslconf_filename() is used to chose from the
2824: # available .conf files containing VirtualHosts definitions. If
2825: # there is ambiguity about which file to use, &apacheconf_choice()
2826: # will be called to prompt the user to choose one of the possible
2827: # files.
2828: #
2829:
2830: sub get_sslconf_filename {
2831: my ($distro,$targetdir,$targetfilesref) = @_;
2832: my ($configfile,$numfiles,@possfiles);
2833: if (ref($targetfilesref) eq 'HASH') {
2834: if (keys(%{$targetfilesref}) > 0) {
2835: foreach my $name (sort(keys(%{$targetfilesref}))) {
2836: if (ref($targetfilesref->{$name}) eq 'HASH') {
2837: foreach my $file (sort(keys(%{$targetfilesref->{$name}}))) {
2838: next if ($file eq '');
2839: next if (!-e "$targetdir/$file");
2840: unless (grep(/^\Q$file\E$/,@possfiles)) {
2841: push(@possfiles,$file);
2842: }
2843: }
2844: }
2845: }
2846: }
2847: if (@possfiles == 0) {
2848: $configfile = 'ssl.conf';
2849: if ($distro =~ /^(suse|sles)/) {
2850: $configfile = 'vhost-ssl.conf';
2851: } elsif ($distro =~ /^(debian|ubuntu)/) {
2852: $configfile = 'default-ssl.conf';
2853: }
2854: $numfiles = 0;
2855: print &mt('No configuration files in [_1] contain a <VirtualHost *:443> </VirtualHost> block which can be used to house Apache rewrite rules from https to http.',$targetdir)."\n\n".
2856: &mt('Accordingly, the contents of sslrewrite.conf will be included in a <VirtualHost *:443> </VirtualHost> block which will be added to a file named: [_1].',$configfile)."\n\n";
2857: } elsif (@possfiles == 1) {
2858: $configfile = $possfiles[0];
2859: $numfiles = 1;
2860: print &mt('A single configuration file in [_1] contains a <VirtualHost *:443> </VirtualHost> block.',$targetdir)."\n".
2861: &mt('The contents of sslrewrite.conf will be added to this block.')."\n\n";
2862: } else {
2863: print &mt('More than one Apache config file contains a <VirtualHost *:443> </VirtualHost> block.')."\n\n".&mt('The possible files are:')."\n";
2864: my $counter = 1;
2865: my $max = scalar(@possfiles);
2866: foreach my $file (@possfiles) {
2867: print "$counter. $file\n";
2868: $counter ++;
2869: }
2870: print "\n".&mt('Enter a number between 1 and [_1] to indicate which file should be modified to include the contents of sslrewrite.conf.',$max)."\n";
2871: my $choice = &apacheconf_choice($max);
2872: if (($choice =~ /^\d+$/) && ($choice >= 1) && ($choice <= $max)) {
2873: $configfile = $possfiles[$choice-1];
2874: $numfiles = 1;
1.46 raeburn 2875: } else {
1.47 raeburn 2876: $numfiles = -1;
1.46 raeburn 2877: }
2878: }
2879: }
1.47 raeburn 2880: return ($configfile,$numfiles);
2881: }
2882:
2883: #
2884: # &apacheconf_choice() prompts a user to choose an integer between 1 and the
2885: # maximum number of available of possible Apache SSL config files found
2886: # at the distros standard location for Apache config files containing
2887: # VirtualHost definitions.
2888: #
2889: # This routine is called recursively until the user enters a valid integer.
2890: #
2891:
2892: sub apacheconf_choice {
2893: my ($max) = @_;
2894: my $choice = <STDIN>;
2895: chomp($choice);
2896: $choice =~ s/(^\s+|\s+$)//g;
2897: my $configfile;
2898: if (($choice =~ /^\d+$/) && ($choice >= 1) && ($choice <= $max)) {
2899: $configfile = $choice;
2900: }
2901: while ($configfile eq '') {
2902: print &mt('Invalid choice. Please enter a number between 1 and [_1].',$max)."\n";
2903: $configfile = &apacheconf_choice($max);
2904: }
2905: print "\n";
2906: return $configfile;
2907: }
2908:
2909: #
2910: # &modify_ssl_config() is called to modify the contents of an Apache SSL config
2911: # file so that it has two <VirtualHost *:443> </VirtualHost> blocks containing
2912: # (a) the default VirtualHost with the <IfModule mod_rewrite.c> </IfModule> block
2913: # provided in sslrewrites.conf, and (b) an "internal" VirtualHost with the
2914: # content provided in loncapassl.conf.
2915: #
2916: # This routine will prompted you to agree to insertion of lines present in the
2917: # shipped conf file, but missing from the local config file, and also for
2918: # deletion of lines present in the local config file, but not required in
2919: # the shipped conf file.
2920: #
2921:
2922: sub modify_ssl_config {
2923: my ($targetdir,$filename,$hostname,$rewritenum,$by_linetext,$by_linenum,$type) = @_;
2924: return unless ((ref($by_linetext) eq 'HASH') && (ref($by_linenum) eq 'HASH'));
2925: if (-e "$targetdir/$filename") {
2926: my (@lines,$virtualhost,$currname,$rewrite);
2927: if (open(my $fh,'<',"$targetdir/$filename")) {
2928: my %found;
2929: my %possible;
2930: my $currline = 0;
2931: my $rewritecount = 0;
2932: while (<$fh>) {
2933: $currline ++;
2934: push(@lines,$_);
2935: chomp();
2936: s/(^\s+|\s+$)//g;
2937: if (/^\s*<VirtualHost\s+[^:]*\:443>\s*$/) {
2938: $virtualhost = 1;
2939: }
2940: if ($virtualhost) {
2941: if ((exists($by_linetext->{$_})) && (ref($by_linetext->{$_}) eq 'ARRAY') &&
2942: (@{$by_linetext->{$_}} > 0)) {
2943: $possible{$currline} = shift(@{$by_linetext->{$_}});
2944: }
2945: if (/^\s*<\/VirtualHost>/) {
2946: if ((($currname eq 'internal-'.$hostname) && ($type eq 'int')) ||
2947: ((($currname eq $hostname) || ($currname eq '')) && ($type eq 'std') &&
2948: ($rewritecount == $rewritenum))) {
2949: %found = (%found,%possible);
2950: } else {
2951: foreach my $line (sort {$b <=> $a } keys(%possible)) {
2952: my $num = $possible{$line};
2953: if (ref($by_linetext->{$by_linenum->{$num}}) eq 'ARRAY') {
2954: unshift(@{$by_linetext->{$by_linenum->{$num}}},$num);
2955: }
2956: }
2957: }
2958: undef(%possible);
2959: $virtualhost = 0;
2960: $currname = '';
2961: } elsif (/^\s*ServerName\s+([^\s]+)\s*$/) {
2962: $currname = $1;
2963: } elsif (/^\s*<IfModule\s+mod_rewrite\.c>/) {
2964: $rewrite = 1;
2965: } elsif (/^\s*<\/IfModule>/) {
2966: $rewritecount ++;
2967: $rewrite = 0;
2968: }
2969: }
2970: }
2971: close($fh);
2972: if (open(my $fout,'>',"$targetdir/$filename")) {
2973: my $currline = 0;
2974: my ($lastfound,$done);
2975: my $numfound = 0;
2976: foreach my $line (@lines) {
2977: $currline ++;
2978: if ($done) {
2979: print $fout $line;
2980: } elsif ($lastfound) {
2981: if ($found{$currline}) {
2982: for (my $i=$lastfound+1; $i<$found{$currline}; $i++) {
2983: print &mt('The following line is missing from the current <VirtualHost *:443> </VirtualHost> block:')."\n".
2984: $by_linenum->{$i}."\n".
2985: &mt('Add this line? ~[Y/n~]');
2986: if (&get_user_selection(1)) {
2987: print $fout $by_linenum->{$i}."\n";
2988: }
2989: }
2990: $numfound ++;
2991: $lastfound = $found{$currline};
2992: print $fout $line;
2993: if ($numfound == scalar(keys(%found))) {
2994: $done = 1;
2995: for (my $i=$found{$currline}+1; $i<=scalar(keys(%{$by_linenum})); $i++) {
2996: print &mt('The following line is missing from the current <VirtualHost *:443> </VirtualHost> block:')."\n".
2997: $by_linenum->{$i}."\n".
2998: &mt('Add this line? ~[Y/n~]');
2999: if (&get_user_selection(1)) {
3000: print $fout $by_linenum->{$i}."\n";
3001: }
3002: }
3003: }
3004: } else {
3005: print &mt('The following line found within a <VirtualHost *:443> </VirtualHost> block does not match that expected by LON-CAPA:')."\n".
3006: $line.
3007: &mt('Delete this line? ~[Y/n~]');
3008: if (!&get_user_selection(1)) {
3009: print $fout $line;
3010: }
3011: }
3012: } elsif ($found{$currline}) {
3013: $numfound ++;
3014: $lastfound = $found{$currline};
3015: for (my $i=1; $i<$found{$currline}; $i++) {
3016: print &mt('The following line is missing from the current <VirtualHost *:443> </VirtualHost> block:')."\n".
3017: $by_linenum->{$i}."\n".
3018: &mt('Add this line? ~[Y/n~]');
3019: if (&get_user_selection(1)) {
3020: print $fout $by_linenum->{$i}."\n";
3021: }
3022: }
3023: print $fout $line;
3024: } else {
3025: print $fout $line;
3026: }
3027: }
3028: close($fout);
3029: }
1.46 raeburn 3030: }
3031: }
1.47 raeburn 3032: return $filename;
1.46 raeburn 3033: }
3034:
1.1 raeburn 3035: #########################################################
3036: ##
1.17 raeburn 3037: ## Ubuntu/Debian -- copy our loncapa configuration file to
1.1 raeburn 3038: ## sites-available and set the symlink from sites-enabled.
3039: ##
3040: #########################################################
3041:
3042: sub copy_apache2_debconf {
1.46 raeburn 3043: my ($instdir,$distro,$hostname) = @_;
1.6 raeburn 3044: my $apache2_mods_enabled_dir = '/etc/apache2/mods-enabled';
3045: my $apache2_mods_available_dir = '/etc/apache2/mods-available';
3046: foreach my $module ('headers.load','expires.load') {
3047: unless (-l "$apache2_mods_enabled_dir/$module") {
3048: symlink("$apache2_mods_available_dir/$module","$apache2_mods_enabled_dir/$module");
3049: print_and_log(&mt('Enabling "[_1]" Apache module.',$module)."\n");
3050: }
3051: }
1.28 raeburn 3052: my $apache2_sites_enabled_dir = '/etc/apache2/sites-enabled';
3053: my $apache2_sites_available_dir = '/etc/apache2/sites-available';
3054: my $defaultconfig = "$apache2_sites_enabled_dir/000-default";
3055: my ($distname,$version);
3056: if ($distro =~ /^(debian|ubuntu)(\d+)$/) {
3057: $distname = $1;
3058: $version = $2;
3059: }
3060: if (($distname eq 'ubuntu') && ($version > 12)) {
3061: $defaultconfig = "$apache2_sites_enabled_dir/000-default.conf";
3062: }
3063: if (-l $defaultconfig) {
3064: unlink($defaultconfig);
3065: }
3066: if (($distname eq 'ubuntu') && ($version > 12)) {
1.32 raeburn 3067: print_and_log(&mt('Copying loncapa [_1] config file to [_2] and pointing [_3] to it from conf-enabled.',"'apache2'","'/etc/apache2/conf-available'","'loncapa.conf symlink'")."\n");
1.28 raeburn 3068: my $apache2_conf_enabled_dir = '/etc/apache2/conf-enabled';
3069: my $apache2_conf_available_dir = '/etc/apache2/conf-available';
3070: if (-e "$apache2_conf_available_dir/loncapa") {
3071: copy("$apache2_conf_available_dir/loncapa","$apache2_conf_available_dir/loncapa.original");
3072: }
1.33 raeburn 3073: my $defaultconf = $apache2_conf_enabled_dir.'/loncapa.conf';
1.32 raeburn 3074: copy("$instdir/debian-ubuntu/ubuntu14/loncapa_conf","$apache2_conf_available_dir/loncapa");
1.28 raeburn 3075: chmod(0444,"$apache2_conf_available_dir/loncapa");
1.32 raeburn 3076: if (-l $defaultconf) {
3077: unlink($defaultconf);
3078: }
3079: symlink("$apache2_conf_available_dir/loncapa","$defaultconf");
3080: print_and_log(&mt('Copying loncapa [_1] site file to [_2] and pointing [_3] to it from sites-enabled.',"'apache2'","'/etc/apache2/sites-available'","'000-default.conf symlink'")."\n");
3081: copy("$instdir/debian-ubuntu/ubuntu14/loncapa_site","$apache2_sites_available_dir/loncapa");
3082: chmod(0444,"$apache2_sites_available_dir/loncapa");
3083: symlink("$apache2_sites_available_dir/loncapa","$defaultconfig");
1.28 raeburn 3084: } else {
3085: print_and_log(&mt('Copying loncapa [_1] config file to [_2] and pointing [_3] to it from sites-enabled.',"'apache2'","'/etc/apache2/sites-available'","'000-default symlink'")."\n");
3086: if (-e "$apache2_sites_available_dir/loncapa") {
3087: copy("$apache2_sites_available_dir/loncapa","$apache2_sites_available_dir/loncapa.original");
3088: }
3089: copy("$instdir/debian-ubuntu/loncapa","$apache2_sites_available_dir/loncapa");
3090: chmod(0444,"$apache2_sites_available_dir/loncapa");
3091: symlink("$apache2_sites_available_dir/loncapa","$apache2_sites_enabled_dir/000-default");
3092: }
1.1 raeburn 3093: print_and_log("\n");
3094: }
3095:
3096: ###########################################################
3097: ##
3098: ## openSuSE/SLES Copy apache2 config files:
3099: ## default-server.conf, uid.conf, /etc/sysconfig/apache2
3100: ## and create symlink from /srv/www/conf to /etc/apache2
3101: ##
3102: ###########################################################
3103:
3104: sub copy_apache2_suseconf {
1.49 raeburn 3105: my ($instdir,$hostname,$distro) = @_;
3106: my ($name,$version) = ($distro =~ /^(suse|sles)([\d\.]+)$/);
3107: my $conf_file = "$instdir/sles-suse/default-server.conf";
3108: if (($name eq 'sles') && ($version >= 12)) {
3109: $conf_file = "$instdir/sles-suse/apache2.4/default-server.conf";
3110: }
1.1 raeburn 3111: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',
3112: "'default-server.conf'",
3113: "'/etc/apache2/default-server.conf'")."\n");
3114: if (!-e "/etc/apache2/default-server.conf.original") {
3115: copy "/etc/apache2/default-server.conf","/etc/apache2/default-server.conf.original";
3116: }
1.49 raeburn 3117: copy $conf_file,"/etc/apache2/default-server.conf";
1.5 raeburn 3118: chmod(0444,"/etc/apache2/default-server.conf");
1.1 raeburn 3119: # Make symlink for conf directory (included in loncapa_apache.conf)
3120: my $can_symlink = (eval { symlink('/etc/apache2','/srv/www/conf'); }, $@ eq '');
3121: if ($can_symlink) {
3122: &print_and_log(&mt('Symlink created for [_1] to [_2].',
3123: "'/srv/www/conf'","'/etc/apache2'")."\n");
3124: } else {
3125: &print_and_log(&mt('Symlink creation failed for [_1] to [_2]. You will need to perform this action from the command line.',"'/srv/www/conf'","'/etc/apache2'")."\n");
3126: }
3127: ©_apache2_conf_files($instdir);
1.49 raeburn 3128: ©_sysconfig_apache2_file($instdir,$name,$version);
1.1 raeburn 3129: print_and_log("\n");
3130: }
3131:
3132: ###############################################
3133: ##
3134: ## Modify uid.conf
3135: ##
3136: ###############################################
3137: sub copy_apache2_conf_files {
3138: my ($instdir) = @_;
3139: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',
3140: "'uid.conf'","'/etc/apache2/uid.conf'")."\n");
3141: if (!-e "/etc/apache2/uid.conf.original") {
3142: copy "/etc/apache2/uid.conf","/etc/apache2/uid.conf.original";
3143: }
1.9 raeburn 3144: copy "$instdir/sles-suse/uid.conf","/etc/apache2/uid.conf";
1.5 raeburn 3145: chmod(0444,"/etc/apache2/uid.conf");
1.1 raeburn 3146: }
3147:
3148: ###############################################
3149: ##
3150: ## Modify /etc/sysconfig/apache2
3151: ##
3152: ###############################################
3153: sub copy_sysconfig_apache2_file {
1.49 raeburn 3154: my ($instdir,$name,$version) = @_;
1.1 raeburn 3155: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'sysconfig/apache2'","'/etc/sysconfig/apache2'")."\n");
3156: if (!-e "/etc/sysconfig/apache2.original") {
3157: copy "/etc/sysconfig/apache2","/etc/sysconfig/apache2.original";
3158: }
1.49 raeburn 3159: my $sysconf_file = "$instdir/sles-suse/sysconfig_apache2";
3160: if (($name eq 'sles') && ($version >= 12)) {
3161: $sysconf_file = "$instdir/sles-suse/apache2.4/sysconfig_apache2";
3162: }
3163: copy "$sysconf_file","/etc/sysconfig/apache2";
1.5 raeburn 3164: chmod(0444,"/etc/sysconfig/apache2");
1.1 raeburn 3165: }
3166:
3167: ###############################################
3168: ##
3169: ## Add/Modify /etc/insserv/overrides
3170: ##
3171: ###############################################
3172:
3173: sub update_SuSEfirewall2_setup {
3174: my ($instdir) = @_;
3175: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'SuSEfirewall2_setup'","'/etc/insserv/overrides/SuSEfirewall2_setup'")."\n");
3176: if (!-e "/etc/insserv/overrides/SuSEfirewall2_setup") {
3177: if (!-d "/etc/insserv") {
3178: mkdir("/etc/insserv",0755);
3179: }
3180: if (!-d "/etc/insserv/overrides") {
3181: mkdir("/etc/insserv/overrides",0755);
3182: }
3183: } elsif (!-e "/etc/insserv/overrides/SuSEfirewall2_setup.original") {
3184: copy "/etc/insserv/overrides/SuSEfirewall2_setup","/etc/insserv/overrides/SuSEfirewall2_setup.original"
3185: }
1.9 raeburn 3186: copy "$instdir/sles-suse/SuSEfirewall2_setup","/etc/insserv/overrides/SuSEfirewall2_setup";
1.5 raeburn 3187: chmod(0444,"/etc/insserv/overrides/SuSEfirewall2_setup");
3188: }
3189:
3190: sub get_iptables_rules {
3191: my ($distro,$instdir,$apachefw) = @_;
3192: my (@fwchains,@ports);
3193: if (&firewall_is_active()) {
3194: my $iptables = &get_pathto_iptables();
3195: if ($iptables ne '') {
3196: @fwchains = &get_fw_chains($iptables,$distro);
3197: }
3198: }
3199: if (ref($apachefw) eq 'HASH') {
3200: foreach my $service ('http','https') {
3201: unless ($apachefw->{$service}) {
3202: push (@ports,$service);
3203: }
3204: }
3205: } else {
3206: @ports = ('http','https');
3207: }
3208: if (@ports == 0) {
3209: return;
3210: }
3211: my $ask_to_enable;
3212: if (-e "/etc/iptables.loncapa.rules") {
1.9 raeburn 3213: if (open(PIPE, "diff --brief $instdir/debian-ubuntu/iptables.loncapa.rules /etc/iptables.loncapa.rules |")) {
1.5 raeburn 3214: my $diffres = <PIPE>;
3215: close(PIPE);
3216: chomp($diffres);
3217: if ($diffres) {
3218: print &mt('Warning: [_1] exists but differs from LON-CAPA supplied file.','/etc/iptables.loncapa.rules')."\n";
3219: }
3220: } else {
3221: print &mt('Error: unable to open [_1] to compare contents with LON-CAPA supplied file.','/etc/iptables.loncapa.rules')."\n";
3222: }
3223: } else {
1.9 raeburn 3224: if (-e "$instdir/debian-ubuntu/iptables.loncapa.rules") {
3225: copy "$instdir/debian-ubuntu/iptables.loncapa.rules","/etc/iptables.loncapa.rules";
1.5 raeburn 3226: chmod(0600,"/etc/iptables.loncapa.rules");
3227: }
3228: }
3229: if (-e "/etc/iptables.loncapa.rules") {
3230: if (-e "/etc/network/if-pre-up.d/iptables") {
1.9 raeburn 3231: if (open(PIPE, "diff --brief $instdir/debian-ubuntu/iptables /etc/network/if-pre-up/iptables |")) {
1.5 raeburn 3232: my $diffres = <PIPE>;
3233: close(PIPE);
3234: chomp($diffres);
3235: if ($diffres) {
3236: print &mt('Warning: [_1] exists but differs from LON-CAPA supplied file.','/etc/network/if-pre-up.d/iptables')."\n";
3237: }
3238: } else {
3239: print &mt('Error: unable to open [_1] to compare contents with LON-CAPA supplied file.','/etc/network/if-pre-up.d/iptables')."\n";
3240: }
3241: } else {
1.9 raeburn 3242: copy "$instdir/debian-ubuntu/iptables","/etc/network/if-pre-up.d/iptables";
1.5 raeburn 3243: chmod(0755,"/etc/network/if-pre-up.d/iptables");
3244: print_and_log(&mt('Installed script "[_1]" to add iptables rules to block all ports except 22, 80, and 443 when network is enabled during boot.','/etc/network/if-pre-up.d/iptables'));
3245: $ask_to_enable = 1;
3246: }
3247: }
3248: return $ask_to_enable;
1.1 raeburn 3249: }
3250:
3251: sub download_loncapa {
3252: my ($instdir,$lctarball) = @_;
3253: my ($have_tarball,$updateshown);
3254: if (! -e "$instdir/$lctarball") {
3255: print_and_log(&mt('Retrieving LON-CAPA source files from: [_1]',
3256: 'http://install.loncapa.org')."\n");
3257: system("wget http://install.loncapa.org/versions/$lctarball ".
3258: "2>/dev/null 1>/dev/null");
3259: if (! -e "./$lctarball") {
3260: print &mt('Unable to retrieve LON-CAPA source files from: [_1].',
3261: "http://install.loncapa.org/versions/$lctarball")."\n";
3262: } else {
3263: $have_tarball = 1;
3264: }
3265: print_and_log("\n");
3266: } else {
3267: $have_tarball = 1;
3268: print_and_log("
3269: ------------------------------------------------------------------------
3270:
3271: ".&mt('You seem to have a version of loncapa-current.tar.gz in [_1]',$instdir)."\n".
3272: &mt('This copy will be used and a new version will NOT be downloaded.')."\n".
3273: &mt('If you wish, you may download a new version by executing:')."
3274:
1.2 raeburn 3275: wget http://install.loncapa.org/versions/loncapa-current.tar.gz
1.1 raeburn 3276:
3277: ------------------------------------------------------------------------
3278: ");
3279: }
3280:
3281: ##
3282: ## untar loncapa.tar.gz
3283: ##
3284: if ($have_tarball) {
3285: print_and_log(&mt('Extracting LON-CAPA source files')."\n");
3286: writelog(`cd ~root; tar zxf $instdir/$lctarball`);
3287: print_and_log("\n");
3288: print &mt('LON-CAPA source files extracted.')."\n".
3289: &mt('It remains for you to execute the following commands:')."
3290:
3291: cd /root/loncapa-N.N (N.N should correspond to a version number like '0.4')
3292: ./UPDATE
3293:
3294: ".&mt('If you have any trouble, please see [_1] and [_2]',
3295: 'http://install.loncapa.org/','http://help.loncapa.org/')."\n";
3296: $updateshown = 1;
3297: }
3298: return ($have_tarball,$updateshown);
3299: }
3300:
3301: close LOG;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>