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