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