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