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