Annotation of doc/install/linux/install.pl, revision 1.69
1.1 raeburn 1: #!/usr/bin/perl
2: # The LearningOnline Network
3: # Pre-installation script for LON-CAPA
4: #
5: # Copyright Michigan State University Board of Trustees
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # http://www.lon-capa.org/
24: #
25:
26: use strict;
27: use File::Copy;
28: use Term::ReadKey;
1.47 raeburn 29: use Socket;
1.46 raeburn 30: use Sys::Hostname::FQDN();
1.1 raeburn 31: use DBI;
1.43 raeburn 32: use Cwd();
33: use File::Basename();
34: use lib File::Basename::dirname(Cwd::abs_path($0));
1.1 raeburn 35: use LCLocalization::localize;
36:
37: # ========================================================= The language handle
38:
39: my %languages = (
40: ar => 'Arabic',
41: de => 'German',
42: en => 'English',
43: es => 'Spanish (Castellan)',
44: fa => 'Persian',
45: fr => 'French',
46: he => 'Hebrew',
47: ja => 'Japanese',
48: pt => 'Portuguese',
49: ru => 'Russian',
50: tr => 'Turkish',
51: zh => 'Chinese Simplified'
52: );
53:
54: use vars qw($lh $lang);
55: $lang = 'en';
56: if (@ARGV > 0) {
57: foreach my $poss (keys(%languages)) {
58: if ($ARGV[0] eq $poss) {
59: $lang = $ARGV[0];
60: }
61: }
62: }
63:
64: &get_language_handle($lang);
65:
66: # Check user has root privs
67: if (0 != $<) {
68: print &mt('This script must be run as root.')."\n".
69: &mt('Stopping execution.')."\n";
70: exit;
71: }
72:
73:
74: # Globals: filehandle LOG is global.
75: if (!open(LOG,">>loncapa_install.log")) {
76: print &mt('Unable to open log file.')."\n".
77: &mt('Stopping execution.')."\n";
78: exit;
79: } else {
1.69 ! raeburn 80: print LOG '$Id: install.pl,v 1.68 2020/11/11 20:58:37 raeburn Exp $'."\n";
1.1 raeburn 81: }
82:
83: #
1.2 raeburn 84: # Helper routines and routines to establish recommended actions
1.1 raeburn 85: #
86:
87: sub get_language_handle {
88: my @languages = @_;
89: $lh=LCLocalization::localize->get_handle(@languages);
90: }
91:
92: sub mt (@) {
93: if ($lh) {
94: if ($_[0] eq '') {
95: if (wantarray) {
96: return @_;
97: } else {
98: return $_[0];
99: }
100: } else {
101: return $lh->maketext(@_);
102: }
103: } else {
104: if (wantarray) {
105: return @_;
106: } else {
107: return $_[0];
108: }
109: }
110: }
111:
112: sub texthash {
113: my (%hash) = @_;
114: foreach (keys(%hash)) {
115: $hash{$_}=&mt($hash{$_});
116: }
117: return %hash;
118: }
119:
120:
121: sub skip_if_nonempty {
122: my ($string,$error)=@_;
123: return if (! defined($error));
124: chomp($string);chomp($error);
125: if ($string ne '') {
126: print_and_log("$error\n".&mt('Stopping execution.')."\n");
127: return 1;
128: }
129: return;
130: }
131:
132: sub writelog {
133: while ($_ = shift) {
134: chomp();
135: print LOG "$_\n";
136: }
137: }
138:
139: sub print_and_log {
140: while ($_=shift) {
141: chomp();
142: print "$_\n";
143: print LOG "$_\n";
144: }
145: }
146:
147: sub get_user_selection {
148: my ($defaultrun) = @_;
149: my $do_action = 0;
150: my $choice = <STDIN>;
151: chomp($choice);
152: $choice =~ s/(^\s+|\s+$)//g;
153: my $yes = &mt('y');
154: if ($defaultrun) {
155: if (($choice eq '') || ($choice =~ /^\Q$yes\E/i)) {
156: $do_action = 1;
157: }
158: } else {
159: if ($choice =~ /^\Q$yes\E/i) {
160: $do_action = 1;
161: }
162: }
163: return $do_action;
164: }
165:
166: sub get_distro {
1.49 raeburn 167: my ($distro,$gotprereqs,$updatecmd,$packagecmd,$installnow,$unknown);
1.1 raeburn 168: $packagecmd = '/bin/rpm -q LONCAPA-prerequisites ';
1.55 raeburn 169: if (-e '/etc/oracle-release') {
170: open(IN,'</etc/oracle-release');
171: my $versionstring=<IN>;
172: chomp($versionstring);
173: close(IN);
174: if ($versionstring =~ /^Oracle Linux Server release (\d+)/) {
175: my $version = $1;
176: $distro = 'oracle'.$1;
177: $updatecmd = 'yum install LONCAPA-prerequisites';
178: $installnow = 'yum -y install LONCAPA-prerequisites';
179: }
180: } elsif (-e '/etc/redhat-release') {
1.1 raeburn 181: open(IN,'</etc/redhat-release');
182: my $versionstring=<IN>;
183: chomp($versionstring);
184: close(IN);
185: if ($versionstring =~ /^Red Hat Linux release ([\d\.]+) /) {
186: my $version = $1;
187: if ($version=~/^7\./) {
188: $distro='redhat7';
189: } elsif ($version=~/^8\./) {
190: $distro='redhat8';
191: } elsif ($version=~/^9/) {
192: $distro='redhat9';
193: }
194: } elsif ($versionstring =~ /Fedora( Core)? release ([\d\.]+) /) {
195: my $version=$2;
196: if ($version - int($version) > .9) {
197: $distro = 'fedora'.(int($version)+1);
198: } else {
199: $distro = 'fedora'.int($version);
200: }
201: $updatecmd = 'yum install LONCAPA-prerequisites';
202: $installnow = 'yum -y install LONCAPA-prerequisites';
203: } elsif ($versionstring =~ /Red Hat Enterprise Linux [AE]S release ([\d\.]+) /) {
204: $distro = 'rhes'.$1;
205: $updatecmd = 'up2date -i LONCAPA-prerequisites';
206: } elsif ($versionstring =~ /Red Hat Enterprise Linux Server release (\d+)/) {
207: $distro = 'rhes'.$1;
208: $updatecmd = 'yum install LONCAPA-prerequisites';
209: $installnow = 'yum -y install LONCAPA-prerequisites';
1.54 raeburn 210: } elsif ($versionstring =~ /Red Hat Enterprise Linux release (\d+)/) {
211: $distro = 'rhes'.$1;
212: $updatecmd = 'dnf install LONCAPA-prerequisites';
213: $installnow = 'dnf -y install LONCAPA-prerequisites';
1.21 raeburn 214: } elsif ($versionstring =~ /CentOS(?:| Linux) release (\d+)/) {
1.1 raeburn 215: $distro = 'centos'.$1;
216: $updatecmd = 'yum install LONCAPA-prerequisites';
217: $installnow = 'yum -y install LONCAPA-prerequisites';
1.22 raeburn 218: } elsif ($versionstring =~ /Scientific Linux (?:SL )?release ([\d.]+) /) {
1.1 raeburn 219: my $ver = $1;
220: $ver =~ s/\.\d+$//;
221: $distro = 'scientific'.$ver;
222: $updatecmd = 'yum install LONCAPA-prerequisites';
223: $installnow = 'yum -y install LONCAPA-prerequisites';
224: } else {
225: print &mt('Unable to interpret [_1] to determine system type.',
226: '/etc/redhat-release')."\n";
1.49 raeburn 227: $unknown = 1;
1.1 raeburn 228: }
229: } elsif (-e '/etc/SuSE-release') {
230: open(IN,'</etc/SuSE-release');
231: my $versionstring=<IN>;
232: chomp($versionstring);
233: close(IN);
234: if ($versionstring =~ /^SUSE LINUX Enterprise Server ([\d\.]+) /i) {
235: $distro='sles'.$1;
236: if ($1 >= 10) {
237: $updatecmd = 'zypper install LONCAPA-prerequisites';
238: } else {
239: $updatecmd = 'yast -i LONCAPA-prerequisites';
240: }
241: } elsif ($versionstring =~ /^SuSE Linux ([\d\.]+) /i) {
242: $distro = 'suse'.$1;
1.12 raeburn 243: $updatecmd = 'yast -i LONCAPA-prerequisites';
1.1 raeburn 244: } elsif ($versionstring =~ /^openSUSE ([\d\.]+) /i) {
245: $distro = 'suse'.$1;
246: if ($1 >= 10.3 ) {
247: $updatecmd = 'zypper install LONCAPA-prerequisites';
248: } else {
249: $updatecmd = 'yast -i LONCAPA-prerequisites';
250: }
251: } else {
252: print &mt('Unable to interpret [_1] to determine system type.',
253: '/etc/SuSE-release')."\n";
1.49 raeburn 254: $unknown = 1;
1.1 raeburn 255: }
256: } elsif (-e '/etc/issue') {
257: open(IN,'</etc/issue');
258: my $versionstring=<IN>;
259: chomp($versionstring);
260: close(IN);
261: if ($versionstring =~ /^Ubuntu (\d+)\.\d+/i) {
262: $distro = 'ubuntu'.$1;
263: $updatecmd = 'sudo apt-get install loncapa-prerequisites';
264: } elsif ($versionstring =~ /^Debian\s+GNU\/Linux\s+(\d+)\.\d+/i) {
265: $distro = 'debian'.$1;
1.49 raeburn 266: $updatecmd = 'apt-get install loncapa-prerequisites';
1.1 raeburn 267: } elsif (-e '/etc/debian_version') {
268: open(IN,'</etc/debian_version');
269: my $version=<IN>;
270: chomp($version);
271: close(IN);
272: if ($version =~ /^(\d+)\.\d+\.?\d*/) {
273: $distro='debian'.$1;
1.49 raeburn 274: $updatecmd = 'apt-get install loncapa-prerequisites';
1.1 raeburn 275: } else {
276: print &mt('Unable to interpret [_1] to determine system type.',
277: '/etc/debian_version')."\n";
1.49 raeburn 278: $unknown = 1;
1.1 raeburn 279: }
1.49 raeburn 280: }
281: if ($distro ne '') {
282: $packagecmd = '/usr/bin/dpkg -l loncapa-prerequisites ';
1.1 raeburn 283: }
284: } elsif (-e '/etc/debian_version') {
285: open(IN,'</etc/debian_version');
286: my $version=<IN>;
287: chomp($version);
288: close(IN);
289: if ($version =~ /^(\d+)\.\d+\.?\d*/) {
290: $distro='debian'.$1;
291: $packagecmd = '/usr/bin/dpkg -l loncapa-prerequisites ';
292: $updatecmd = 'apt-get install loncapa-prerequisites';
293: } else {
294: print &mt('Unable to interpret [_1] to determine system type.',
295: '/etc/debian_version')."\n";
1.49 raeburn 296: $unknown = 1;
297: }
298: }
299: if (($distro eq '') && (!$unknown)) {
300: if (-e '/etc/os-release') {
301: if (open(IN,'<','/etc/os-release')) {
302: my ($id,$version);
303: while(<IN>) {
304: chomp();
305: if (/^ID="(\w+)"/) {
306: $id=$1;
307: } elsif (/^VERSION_ID="([\d\.]+)"/) {
308: $version=$1;
309: }
310: }
311: close(IN);
312: if ($id eq 'sles') {
313: my ($major,$minor) = split(/\./,$version);
314: if ($major =~ /^\d+$/) {
315: $distro = $id.$major;
316: $updatecmd = 'zypper install LONCAPA-prerequisites';
317: }
318: }
319: }
320: if ($distro eq '') {
321: print &mt('Unable to interpret [_1] to determine system type.',
322: '/etc/os-release')."\n";
323: $unknown = 1;
324: }
325: } else {
1.55 raeburn 326: print &mt('Unknown installation: expecting a debian, ubuntu, suse, sles, redhat, fedora, scientific linux, or oracle linux system.')."\n";
1.1 raeburn 327: }
328: }
329: return ($distro,$packagecmd,$updatecmd,$installnow);
330: }
331:
1.47 raeburn 332: #
333: # get_hostname() prompts the user to provide the server's hostname.
334: #
335: # If invalid input is provided, the routine is called recursively
336: # until, a valid hostname is provided.
337: #
338:
1.46 raeburn 339: sub get_hostname {
340: my $hostname;
341: print &mt('Enter the hostname of this server, e.g., loncapa.somewhere.edu'."\n");
342: my $choice = <STDIN>;
343: chomp($choice);
344: $choice =~ s/(^\s+|\s+$)//g;
345: if ($choice eq '') {
346: print &mt("Hostname you entered was either blank or contanied only white space.\n");
347: } elsif ($choice =~ /^[\w\.\-]+$/) {
348: $hostname = $choice;
349: } else {
350: print &mt("Hostname you entered was invalid -- a hostname may only contain letters, numbers, - and .\n");
351: }
352: while ($hostname eq '') {
353: $hostname = &get_hostname();
354: }
355: print "\n";
356: return $hostname;
357: }
358:
1.47 raeburn 359: #
1.62 raeburn 360: # get_hostip() prompts the user to provide the server's IPv4 IP address
1.47 raeburn 361: #
362: # If invalid input is provided, the routine is called recursively
363: # until, a valid IPv4 address is provided.
364: #
365:
366: sub get_hostip {
367: my $hostip;
368: print &mt('Enter the IP address of this server, e.g., 192.168.10.24'."\n");
369: my $choice = <STDIN>;
370: chomp($choice);
371: $choice =~ s/(^\s+|\s+$)//g;
372: my $badformat = 1;
373: if ($choice eq '') {
374: print &mt("IP address you entered was either blank or contained only white space.\n");
375: } else {
376: if ($choice =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) {
377: if (($1<=255) && ($2<=255) && ($3<=255) && ($4<=255)) {
378: $badformat = 0;
379: }
380: }
381: if ($badformat) {
382: print &mt('Host IP you entered was invalid -- a host IP has the format d.d.d.d where each d is an integer between 0 and 255')."\n";
383: } else {
384: $hostip = $choice;
385: }
386: }
387: while ($hostip eq '') {
388: $hostip = &get_hostip();
389: }
390: print "\n";
391: return $hostip;
392: }
393:
1.1 raeburn 394: sub check_prerequisites {
395: my ($packagecmd,$distro) = @_;
396: my $gotprereqs;
397: if ($packagecmd ne '') {
398: if (open(PIPE,"$packagecmd|")) {
399: if ($distro =~ /^(debian|ubuntu)/) {
400: my @lines = <PIPE>;
401: chomp(@lines);
402: foreach my $line (@lines) {
403: if ($line =~ /^ii\s+loncapa-prerequisites\s+([\w\.]+)/) {
404: $gotprereqs = $1;
405: }
406: }
407: } else {
408: my $line = <PIPE>;
409: chomp($line);
1.8 raeburn 410: if ($line =~ /^LONCAPA\-prerequisites\-([\d\-]+)\.(?:[.\w]+)$/) {
1.1 raeburn 411: $gotprereqs = $1;
412: }
413: }
414: close(PIPE);
415: } else {
416: print &mt('Error: could not determine if LONCAPA-prerequisites package is installed')."\n";
417: }
418: }
419: return $gotprereqs;
420: }
421:
1.6 raeburn 422: sub check_locale {
423: my ($distro) = @_;
1.63 raeburn 424: my ($fh,$langvar,$command,$earlyout);
1.8 raeburn 425: $langvar = 'LANG';
1.6 raeburn 426: if ($distro =~ /^(ubuntu|debian)/) {
427: if (!open($fh,"</etc/default/locale")) {
428: print &mt('Failed to open: [_1], default locale not checked.',
429: '/etc/default/locale');
1.63 raeburn 430: $earlyout = 1;
1.6 raeburn 431: }
1.49 raeburn 432: } elsif ($distro =~ /^(suse|sles)(\d+)/) {
433: if (($1 eq 'sles') && ($2 >= 15)) {
434: if (!open($fh,"</etc/locale.conf")) {
435: print &mt('Failed to open: [_1], default locale not checked.',
436: '/etc/locale.conf');
1.63 raeburn 437: $earlyout = 1;
1.49 raeburn 438: }
439: } else {
440: if (!open($fh,"</etc/sysconfig/language")) {
441: print &mt('Failed to open: [_1], default locale not checked.',
442: '/etc/sysconfig/language');
1.63 raeburn 443: $earlyout = 1;
1.49 raeburn 444: }
445: $langvar = 'RC_LANG';
1.8 raeburn 446: }
1.24 raeburn 447: } elsif ($distro =~ /^fedora(\d+)/) {
448: if ($1 >= 18) {
449: if (!open($fh,"</etc/locale.conf")) {
450: print &mt('Failed to open: [_1], default locale not checked.',
451: '/etc/locale.conf');
1.63 raeburn 452: $earlyout = 1;
1.24 raeburn 453: }
454: } elsif (!open($fh,"</etc/sysconfig/i18n")) {
455: print &mt('Failed to open: [_1], default locale not checked.',
456: '/etc/sysconfig/i18n');
1.66 raeburn 457: $earlyout = 1;
1.24 raeburn 458: }
1.56 raeburn 459: } elsif ($distro =~ /^(?:rhes|centos|scientific|oracle)(\d+)/) {
1.29 raeburn 460: if ($1 >= 7) {
461: if (!open($fh,"</etc/locale.conf")) {
462: print &mt('Failed to open: [_1], default locale not checked.',
463: '/etc/locale.conf');
1.63 raeburn 464: $earlyout = 1;
1.29 raeburn 465: }
466: } elsif (!open($fh,"</etc/sysconfig/i18n")) {
467: print &mt('Failed to open: [_1], default locale not checked.',
468: '/etc/sysconfig/i18n');
1.63 raeburn 469: $earlyout = 1;
1.29 raeburn 470: }
1.6 raeburn 471: } else {
472: if (!open($fh,"</etc/sysconfig/i18n")) {
473: print &mt('Failed to open: [_1], default locale not checked.',
474: '/etc/sysconfig/i18n');
1.63 raeburn 475: $earlyout = 1;
1.6 raeburn 476: }
477: }
1.63 raeburn 478: return if ($earlyout);
1.6 raeburn 479: my @data = <$fh>;
480: chomp(@data);
481: foreach my $item (@data) {
1.25 raeburn 482: if ($item =~ /^\Q$langvar\E=\"?([^\"]*)\"?/) {
1.6 raeburn 483: my $default = $1;
484: if ($default ne 'en_US.UTF-8') {
485: if ($distro =~ /^debian/) {
1.25 raeburn 486: $command = 'locale-gen en_US.UTF-8'."\n".
487: 'update-locale LANG=en_US.UTF-8';
1.6 raeburn 488: } elsif ($distro =~ /^ubuntu/) {
1.25 raeburn 489: $command = 'sudo locale-gen en_US.UTF-8'."\n".
490: 'sudo update-locale LANG=en_US.UTF-8';
1.7 raeburn 491: } elsif ($distro =~ /^(suse|sles)/) {
1.57 raeburn 492: $command = 'yast language';
1.54 raeburn 493: } elsif (-e '/usr/bin/system-config-language') {
494: $command = 'system-config-language';
495: } elsif (-e '/usr/bin/localectl') {
1.58 raeburn 496: $command = '/usr/bin/localectl set-locale LANG=en_US.UTF-8';
1.6 raeburn 497: } else {
1.54 raeburn 498: $command = 'No standard command found';
1.6 raeburn 499: }
500: }
501: last;
502: }
503: }
504: close($fh);
505: return $command;
506: }
507:
1.1 raeburn 508: sub check_required {
509: my ($instdir,$dsn) = @_;
510: my ($distro,$packagecmd,$updatecmd,$installnow) = &get_distro();
511: if ($distro eq '') {
512: return;
513: }
514: my $gotprereqs = &check_prerequisites($packagecmd,$distro);
515: if ($gotprereqs eq '') {
1.22 raeburn 516: return ($distro,$gotprereqs,'',$packagecmd,$updatecmd);
1.6 raeburn 517: }
518: my $localecmd = &check_locale($distro);
519: unless ($localecmd eq '') {
520: return ($distro,$gotprereqs,$localecmd);
1.1 raeburn 521: }
1.68 raeburn 522: my ($mysqlon,$mysqlsetup,$mysqlrestart,$dbh,$has_pass,$mysql_unix_socket,$has_lcdb,
523: %recommended,$downloadstatus,$filetouse,$production,$testing,$apachefw,
524: $tostop,$uses_systemctl,$hostname,$hostip);
1.1 raeburn 525: my $wwwuid = &uid_of_www();
526: my $wwwgid = getgrnam('www');
527: if (($wwwuid eq '') || ($wwwgid eq '')) {
528: $recommended{'wwwuser'} = 1;
529: }
530: unless( -e "/usr/local/sbin/pwauth") {
531: $recommended{'pwauth'} = 1;
532: }
1.47 raeburn 533: $hostname = Sys::Hostname::FQDN::fqdn();
1.46 raeburn 534: if ($hostname eq '') {
535: $hostname =&get_hostname();
536: } else {
537: print &mt("Hostname detected: $hostname. Is that correct? ~[Y/n~]");
538: if (!&get_user_selection(1)) {
539: $hostname =&get_hostname();
540: }
541: }
1.47 raeburn 542: $hostip = Socket::inet_ntoa(scalar(gethostbyname($hostname)) || 'localhost');
543: if ($hostip eq '') {
544: $hostip=&get_hostip();
545: } else {
546: print &mt("Host IP address detected: $hostip. Is that correct? ~[Y/n~]");
547: if (!&get_user_selection(1)) {
548: $hostip=&get_hostip();
549: }
550: }
551: print_and_log("\n".&mt('Hostname is [_1] and IP address is [_2]',$hostname,$hostip)."\n");
1.1 raeburn 552: $mysqlon = &check_mysql_running($distro);
553: if ($mysqlon) {
554: my $mysql_has_wwwuser = &check_mysql_wwwuser();
1.68 raeburn 555: ($mysqlsetup,$has_pass,$dbh,$mysql_has_wwwuser,$mysql_unix_socket) =
1.34 raeburn 556: &check_mysql_setup($instdir,$dsn,$distro,$mysql_has_wwwuser);
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);
889: if (open(PIPE,"systemctl status firewalld |")) {
890: while (<PIPE>) {
891: chomp();
892: if (/^\s*Loaded:\s+(\w+)/) {
893: $loaded = $1;
894: }
895: if (/^\s*Active\s+(\w+)/) {
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.34 raeburn 1532: my ($instdir,$dsn,$distro,$mysql_has_wwwuser) = @_;
1.68 raeburn 1533: my ($mysqlsetup,$has_pass,$mysql_unix_socket);
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';
1550: $mysql_unix_socket = 1;
1551: unless ($mysql_has_wwwuser) {
1552: $mysql_has_wwwuser = &check_mysql_wwwuser();
1553: }
1554: return ($mysqlsetup,$has_pass,$dbh,$mysql_has_wwwuser,$mysql_unix_socket);
1555: }
1556: }
1557: }
1.1 raeburn 1558: if ($dbh) {
1559: $mysqlsetup = 'noroot';
1560: } elsif ($DBI::err =~ /1045/) {
1561: $has_pass = 1;
1.34 raeburn 1562: } elsif ($distro =~ /^ubuntu(\d+)$/) {
1563: my $version = $1;
1564: if ($1 > 12) {
1565: print_and_log(&mt('Restarting mysql, please be patient')."\n");
1566: if (open (PIPE, "service mysql restart 2>&1 |")) {
1567: while (<PIPE>) {
1568: print $_;
1569: }
1570: close(PIPE);
1571: }
1572: unless ($mysql_has_wwwuser) {
1573: $mysql_has_wwwuser = &check_mysql_wwwuser();
1574: }
1575: $dbh = DBI->connect($dsn,'root','',{'PrintError'=>0});
1576: if ($dbh) {
1577: $mysqlsetup = 'noroot';
1578: } elsif ($DBI::err =~ /1045/) {
1579: $has_pass = 1;
1580: } else {
1581: $mysqlsetup = 'needsrestart';
1582: return ($mysqlsetup,$has_pass,$dbh,$mysql_has_wwwuser);
1583: }
1584: }
1.1 raeburn 1585: }
1586: if ($has_pass) {
1587: print &mt('You have already set a root password for the MySQL database.')."\n";
1588: my $currpass = &get_mysql_password(&mt('Please enter the password now'));
1589: $dbh = DBI->connect($dsn,'root',$currpass,{'PrintError'=>0});
1590: if ($dbh) {
1591: $mysqlsetup = 'rootok';
1592: print_and_log(&mt('Password accepted.')."\n");
1593: } else {
1594: $mysqlsetup = 'rootfail';
1595: print_and_log(&mt('Problem accessing MySQL.')."\n");
1596: if ($DBI::err =~ /1045/) {
1597: print_and_log(&mt('Perhaps the password was incorrect?')."\n");
1598: print &mt('Try again?').' ';
1599: $currpass = &get_mysql_password(&mt('Re-enter password now'));
1600: $dbh = DBI->connect($dsn,'root',$currpass,{'PrintError'=>0});
1601: if ($dbh) {
1602: $mysqlsetup = 'rootok';
1603: print_and_log(&mt('Password accepted.')."\n");
1604: } else {
1605: if ($DBI::err =~ /1045/) {
1606: print_and_log(&mt('Incorrect password.')."\n");
1607: }
1608: }
1609: }
1610: }
1.34 raeburn 1611: } elsif ($mysqlsetup ne 'noroot') {
1.1 raeburn 1612: print_and_log(&mt('Problem accessing MySQL.')."\n");
1613: $mysqlsetup = 'rootfail';
1614: }
1.34 raeburn 1615: return ($mysqlsetup,$has_pass,$dbh,$mysql_has_wwwuser);
1.1 raeburn 1616: }
1617:
1618: sub check_mysql_wwwuser {
1619: my $mysql_wwwuser;
1.12 raeburn 1620: my $dbhn = DBI->connect("DBI:mysql:database=information_schema",'www','localhostkey',
1621: {PrintError => +0}) || return;
1.1 raeburn 1622: if ($dbhn) {
1623: $mysql_wwwuser = 1;
1624: $dbhn->disconnect;
1625: }
1626: return $mysql_wwwuser;
1627: }
1628:
1629: sub check_loncapa_mysqldb {
1630: my ($dbh) = @_;
1631: my $has_lcdb;
1632: if (ref($dbh)) {
1633: my $sth = $dbh->prepare("SHOW DATABASES");
1634: $sth->execute();
1635: while (my $dbname = $sth->fetchrow_array) {
1636: if ($dbname eq 'loncapa') {
1637: $has_lcdb = 1;
1638: last;
1639: }
1640: }
1641: $sth->finish();
1642: }
1643: return $has_lcdb;
1644: }
1645:
1646: sub get_pathto_iptables {
1647: my $iptables;
1648: if (-e '/sbin/iptables') {
1649: $iptables = '/sbin/iptables';
1650: } elsif (-e '/usr/sbin/iptables') {
1651: $iptables = '/usr/sbin/iptables';
1652: } else {
1653: print &mt('Unable to find iptables command.')."\n";
1654: }
1655: return $iptables;
1656: }
1657:
1658: sub firewall_is_active {
1659: if (-e '/proc/net/ip_tables_names') {
1.49 raeburn 1660: if (open(PIPE,'cat /proc/net/ip_tables_names |grep filter |')) {
1661: my $status = <PIPE>;
1662: close(PIPE);
1663: chomp($status);
1664: if ($status eq 'filter') {
1665: return 1;
1666: }
1667: }
1.1 raeburn 1668: }
1.49 raeburn 1669: return 0;
1.1 raeburn 1670: }
1671:
1672: sub get_fw_chains {
1.5 raeburn 1673: my ($iptables,$distro) = @_;
1.1 raeburn 1674: my @fw_chains;
1675: my $suse_config = "/etc/sysconfig/SuSEfirewall2";
1676: my $ubuntu_config = "/etc/ufw/ufw.conf";
1677: if (-e $suse_config) {
1678: push(@fw_chains,'input_ext');
1679: } else {
1680: my @posschains;
1681: if (-e $ubuntu_config) {
1682: @posschains = ('ufw-user-input','INPUT');
1.5 raeburn 1683: } elsif ($distro =~ /^debian5/) {
1684: @posschains = ('INPUT');
1.49 raeburn 1685: } elsif ($distro =~ /^(suse|sles)(\d+)/) {
1686: @posschains = ('IN_public');
1.1 raeburn 1687: } else {
1688: @posschains = ('RH-Firewall-1-INPUT','INPUT');
1689: if (!-e '/etc/sysconfig/iptables') {
1690: if (!-e '/var/lib/iptables') {
1691: print &mt('Unable to find iptables file containing static definitions.')."\n";
1692: }
1693: push(@fw_chains,'RH-Firewall-1-INPUT');
1694: }
1695: }
1696: if ($iptables eq '') {
1697: $iptables = &get_pathto_iptables();
1698: }
1699: my %counts;
1700: if (open(PIPE,"$iptables -L -n |")) {
1701: while(<PIPE>) {
1702: foreach my $chain (@posschains) {
1703: if (/(\Q$chain\E)/) {
1704: $counts{$1} ++;
1705: }
1706: }
1707: }
1708: close(PIPE);
1709: }
1710: foreach my $fw_chain (@posschains) {
1711: if ($counts{$fw_chain}) {
1712: unless(grep(/^\Q$fw_chain\E$/,@fw_chains)) {
1713: push(@fw_chains,$fw_chain);
1714: }
1715: }
1716: }
1717: }
1718: return @fw_chains;
1719: }
1720:
1721: sub firewall_is_port_open {
1722: my ($iptables,$fw_chain,$port) = @_;
1723: # returns 1 if the firewall port is open, 0 if not.
1724: #
1725: # check if firewall is active or installed
1726: return if (! &firewall_is_active());
1727: my $count = 0;
1728: if (open(PIPE,"$iptables -L $fw_chain -n |")) {
1729: while(<PIPE>) {
1730: if (/tcp dpt\:\Q$port\E/) {
1731: $count ++;
1732: last;
1733: }
1734: }
1735: close(PIPE);
1736: } else {
1737: print &mt('Firewall status not checked: unable to run [_1].','iptables -L')."\n";
1738: }
1739: return $count;
1740: }
1741:
1742: sub get_mysql_password {
1743: my ($prompt) = @_;
1744: local $| = 1;
1745: print $prompt.': ';
1746: my $newpasswd = '';
1747: ReadMode 'raw';
1748: my $key;
1749: while(ord($key = ReadKey(0)) != 10) {
1750: if(ord($key) == 127 || ord($key) == 8) {
1751: chop($newpasswd);
1752: print "\b \b";
1753: } elsif(!ord($key) < 32) {
1754: $newpasswd .= $key;
1755: print '*';
1756: }
1757: }
1758: ReadMode 'normal';
1759: print "\n";
1760: return $newpasswd;
1761: }
1762:
1763: sub check_SuSEfirewall2_setup {
1764: my ($instdir) = @_;
1765: my $need_override = 1;
1.9 raeburn 1766: if ((-e "/etc/insserv/overrides/SuSEfirewall2_setup") && (-e "$instdir/sles-suse/SuSEfirewall2_setup")) {
1767: if (open(PIPE, "diff --brief $instdir/sles-suse/SuSEfirewall2_setup /etc/insserv/overrides/SuSEfirewall2_setup |")) {
1.1 raeburn 1768: my $diffres = <PIPE>;
1769: close(PIPE);
1770: chomp($diffres);
1771: unless ($diffres) {
1772: $need_override = 0;
1773: }
1774: }
1775: }
1776: return $need_override;
1777: }
1778:
1779: sub download_versionslist {
1780: my ($production,$testing,%sizes);
1781: if (-e "latest.txt") {
1782: unlink("latest.txt");
1783: }
1784: my $rtncode = system("wget http://install.loncapa.org/versions/latest.txt ".
1785: "> /dev/null 2>&1");
1786: if (!$rtncode) {
1787: if (open(my $fh,"<latest.txt")) {
1788: my @info = <$fh>;
1789: close($fh);
1790: foreach my $line (@info) {
1791: chomp();
1792: if ($line =~ /^\QLATEST-IS: \E([\w\-.]+):(\d+)$/) {
1793: $production = $1;
1794: $sizes{$1} = $2;
1795: } elsif ($line =~ /^LATEST-TESTING-IS: \E([\w\-.]+):(\d+)$/) {
1796: $testing = $1;
1797: $sizes{$1} = $2;
1798: }
1799: }
1800: }
1801: }
1802: return ($production,$testing,\%sizes);
1803: }
1804:
1805: #
1806: # End helper routines.
1807: # Main script starts here
1808: #
1809:
1810: print "
1811: ********************************************************************
1812:
1813: ".&mt('Welcome to LON-CAPA')."
1814:
1815: ".&mt('This script will configure your system for installation of LON-CAPA.')."
1816:
1817: ********************************************************************
1818:
1819: ".&mt('The following actions are available:')."
1820:
1.4 raeburn 1821: ".&mt('1.')." ".&mt('Create the www user/group.')."
1.1 raeburn 1822: ".&mt('This is the user/group ownership under which Apache child processes run.')."
1823: ".&mt('It also owns most directories within the /home/httpd directory.')."
1824: ".&mt('This directory is where most LON-CAPA files and directories are stored.')."
1.4 raeburn 1825: ".&mt('2.')." ".&mt('Install the package LON-CAPA uses to authenticate users.')."
1826: ".&mt('3.')." ".&mt('Set-up the MySQL database.')."
1827: ".&mt('4.')." ".&mt('Set-up MySQL permissions.')."
1828: ".&mt('5.')." ".&mt('Configure Apache web server.')."
1.46 raeburn 1829: ".&mt('6.')." ".&mt('Configure SSL for Apache web server.')."
1830: ".&mt('7.')." ".&mt('Configure start-up of services.')."
1831: ".&mt('8.')." ".&mt('Check firewall settings.')."
1832: ".&mt('9.')." ".&mt('Stop services not used by LON-CAPA,')."
1.1 raeburn 1833: ".&mt('i.e., services for a print server: [_1] daemon.',"'cups'")."
1.46 raeburn 1834: ".&mt('10.')." ".&mt('Download LON-CAPA source code in readiness for installation.')."
1.1 raeburn 1835:
1836: ".&mt('Typically, you will run this script only once, when you first install LON-CAPA.')."
1837:
1838: ".&mt('The script will analyze your system to determine which actions are recommended.')."
1839: ".&mt('The script will then prompt you to choose the actions you would like taken.')."
1840:
1841: ".&mt('For each the recommended action will be selected if you hit Enter/Return.')."
1842: ".&mt('To override the default, type the lower case option from the two options listed.')."
1843: ".&mt('So, if the default is "yes", ~[Y/n~] will be shown -- type n to override.')."
1844: ".&mt('Whereas if the default is "no", ~[y/N~] will be shown -- type y to override.')."
1845:
1846: ".&mt('To accept the default, simply hit Enter/Return on your keyboard.')."
1847: ".&mt('Otherwise type: y or n then hit the Enter/Return key.')."
1848:
1849: ".&mt('Once a choice has been entered for all nine actions, required changes will be made.')."
1850: ".&mt('Feedback will be displayed on screen, and also stored in: [_1].','loncapa_install.log')."
1851:
1852: ".&mt('Continue? ~[Y/n~] ');
1853:
1854: my $go_on = &get_user_selection(1);
1855: if (!$go_on) {
1856: exit;
1857: }
1858:
1859: my $instdir = `pwd`;
1860: chomp($instdir);
1861:
1862: my %callsub;
1863: my @actions = ('wwwuser','pwauth','mysql','mysqlperms','apache',
1.46 raeburn 1864: 'apachessl','runlevels','firewall','stopsrvcs','download');
1.1 raeburn 1865: my %prompts = &texthash(
1866: wwwuser => "Create the 'www' user?",
1867: pwauth => 'Install the package LON-CAPA uses to authenticate users?',
1868: mysql => 'Set-up the MySQL database?',
1869: mysqlperms => 'Set-up MySQL permissions?',
1870: apache => 'Configure Apache web server?',
1.46 raeburn 1871: apachessl => 'Configure SSL for Apache web server?',
1.1 raeburn 1872: runlevels => 'Set overrides for start-up order of services?',
1873: firewall => 'Configure firewall settings for Apache',
1874: stopsrvcs => 'Stop extra services not required on a LON-CAPA server?',
1875: download => 'Download LON-CAPA source code in readiness for installation?',
1876: );
1877:
1.46 raeburn 1878: print "\n".&mt('Checking system status ...')."\n\n";
1.1 raeburn 1879:
1880: my $dsn = "DBI:mysql:database=mysql";
1.34 raeburn 1881: my ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,$mysqlrestart,
1.68 raeburn 1882: $recommended,$dbh,$has_pass,$mysql_unix_socket,$has_lcdb,$downloadstatus,
1883: $filetouse,$production,$testing,$apachefw,$uses_systemctl,$hostname,$hostip,
1884: $sslhostsfiles,$has_std,$has_int,$rewritenum,$nochgstd,$nochgint) =
1885: &check_required($instdir,$dsn);
1.1 raeburn 1886: if ($distro eq '') {
1887: print "\n".&mt('Linux distribution could not be verified as a supported distribution.')."\n".
1888: &mt('The following are supported: [_1].',
1889: 'CentOS, RedHat Enterprise, Fedora, Scientific Linux, '.
1.56 raeburn 1890: 'Oracle Linux, openSuSE, SLES, Ubuntu LTS, Debian')."\n\n".
1.1 raeburn 1891: &mt('Stopping execution.')."\n";
1892: exit;
1893: }
1.34 raeburn 1894: if ($mysqlrestart) {
1895: print "\n".&mt('The mysql daemon needs to be restarted using the following command:')."\n".
1896: $mysqlrestart."\n\n".
1897: &mt('Stopping execution of install.pl script.')."\n".
1898: &mt('Please run the install.pl script again, once you have restarted mysql.')."\n";
1899: exit;
1900: }
1.6 raeburn 1901: if ($localecmd ne '') {
1902: 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";
1903: 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".
1904: $localecmd."\n\n".
1905: &mt('Stopping execution.')."\n";
1906: exit;
1907: }
1.1 raeburn 1908: if (!$gotprereqs) {
1.12 raeburn 1909: print "\n".&mt('The LONCAPA-prerequisites package is not installed.')."\n".
1.1 raeburn 1910: &mt('The following command can be used to install the package (and dependencies):')."\n\n".
1911: $updatecmd."\n\n";
1912: if ($installnow eq '') {
1913: exit;
1914: } else {
1915: print &mt('Run command? ~[Y/n~]');
1916: my $install_prereq = &get_user_selection(1);
1917: if ($install_prereq) {
1918: if (open(PIPE,'|-',$installnow)) {
1919: close(PIPE);
1920: $gotprereqs = &check_prerequisites($packagecmd,$distro);
1921: if (!$gotprereqs) {
1.12 raeburn 1922: print &mt('The LONCAPA-prerequisites package is not installed.')."\n".
1.1 raeburn 1923: &mt('Stopping execution.')."\n";
1924: exit;
1925: } else {
1.6 raeburn 1926: ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,
1.68 raeburn 1927: $mysqlrestart,$recommended,$dbh,$has_pass,$mysql_unix_socket,
1928: $has_lcdb,$downloadstatus,$filetouse,$production,$testing,$apachefw,
1929: $uses_systemctl,$hostname,$hostip,$sslhostsfiles,$has_std,$has_int,
1930: $rewritenum,$nochgstd,$nochgint) = &check_required($instdir,$dsn);
1.1 raeburn 1931: }
1932: } else {
1.12 raeburn 1933: print &mt('Failed to run command to install LONCAPA-prerequisites')."\n";
1.1 raeburn 1934: exit;
1935: }
1936: } else {
1937: print &mt('Stopping execution.')."\n";
1938: exit;
1939: }
1940: }
1941: }
1942: unless (ref($recommended) eq 'HASH') {
1943: print "\n".&mt('An error occurred determining which actions are recommended.')."\n\n".
1944: &mt('Stopping execution.')."\n";
1945: exit;
1946: }
1947:
1948: print "\n";
1949: my $num = 0;
1950: foreach my $action (@actions) {
1951: $num ++;
1952: my ($yesno,$defaultrun);
1953: if (ref($recommended) eq 'HASH') {
1.4 raeburn 1954: if (($action eq 'runlevels') || ($action eq 'stopsrvcs')) {
1.1 raeburn 1955: $yesno = '[y/N]';
1956: if (ref($recommended->{$action}) eq 'HASH') {
1957: if (keys(%{$recommended->{$action}}) > 0) {
1958: $yesno = &mt('~[Y/n~]');
1959: $defaultrun = 1;
1960: }
1961: }
1962: } else {
1963: if ($action eq 'download') {
1964: if ($downloadstatus) {
1965: print "\n$downloadstatus\n";
1966: }
1967: }
1968: if ($recommended->{$action}) {
1969: $yesno = mt('~[Y/n~]');
1970: $defaultrun = 1;
1971: } else {
1972: $yesno = &mt('~[y/N~]');
1973: }
1974: }
1975: print $num.'. '.$prompts{$action}." $yesno ";
1976: $callsub{$action} = &get_user_selection($defaultrun);
1977: }
1978: }
1979:
1980: my $lctarball = 'loncapa-current.tar.gz';
1981: my $sourcetarball = $lctarball;
1982: if ($callsub{'download'}) {
1983: my ($production,$testing,$sizes) = &download_versionslist();
1984: if ($production && $testing) {
1985: if ($production ne $testing) {
1986: print &mt('Two recent LON-CAPA releases are available: ')."\n".
1.3 raeburn 1987: &mt('1.').' '.&mt('A production release - version: [_1].',$production)."\n".
1988: &mt('2.').' '.&mt('A testing release - version: [_1].',$testing)."\n\n".
1.1 raeburn 1989: &mt('Download the production release? ~[Y/n~]');
1990: if (&get_user_selection(1)) {
1.4 raeburn 1991: $sourcetarball = 'loncapa-'.$production.'.tar.gz';
1.1 raeburn 1992: } else {
1993: print "\n".&mt('Download the testing release? ~[Y/n~]');
1994: if (&get_user_selection(1)) {
1.4 raeburn 1995: $sourcetarball = 'loncapa-'.$testing.'.tar.gz';
1.1 raeburn 1996: }
1997: }
1998: }
1999: } elsif ($production) {
2000: print &mt('The most recent LON-CAPA release is version: [_1].',$production)."\n".
2001: &mt('Download the production release? ~[Y/n~]');
2002: if (&get_user_selection(1)) {
1.20 raeburn 2003: $sourcetarball = 'loncapa-'.$production.'.tar.gz';
1.1 raeburn 2004: }
2005: }
2006: } elsif ($filetouse ne '') {
2007: $sourcetarball = $filetouse;
2008: }
2009:
2010: print_and_log("\n");
2011:
2012: # Each action: report if skipping, or perform action and provide feedback.
2013: if ($callsub{'wwwuser'}) {
2014: &setup_www();
2015: } else {
2016: &print_and_log(&mt('Skipping creation of user [_1].',"'www'")."\n");
2017: }
2018:
2019: if ($callsub{'pwauth'}) {
1.4 raeburn 2020: &build_and_install_mod_auth_external($instdir);
1.1 raeburn 2021: } else {
2022: &print_and_log(&mt('Skipping [_1] installation.',"'pwauth'")."\n");
2023: }
2024:
2025: if ($callsub{'mysql'}) {
2026: if ($dbh) {
1.68 raeburn 2027: &setup_mysql($callsub{'mysqlperms'},$dbh,$has_pass,
2028: $mysql_unix_socket,$has_lcdb);
1.1 raeburn 2029: } else {
2030: print &mt('Unable to configure MySQL because access is denied.')."\n";
2031: }
2032: } else {
2033: &print_and_log(&mt('Skipping configuration of MySQL.')."\n");
2034: if ($callsub{'mysqlperms'}) {
2035: if ($dbh) {
1.68 raeburn 2036: &setup_mysql_permissions($dbh,$has_pass,$mysql_unix_socket);
1.1 raeburn 2037: } else {
2038: print &mt('Unable to configure MySQL because access is denied.')."\n";
2039: }
2040: } else {
2041: &print_and_log(&mt('Skipping MySQL permissions setup.')."\n");
2042: }
2043: }
2044:
2045: if ($dbh) {
2046: if (!$dbh->disconnect) {
2047: &print_and_log(&mt('Failed to disconnect from MySQL:')."\n".
2048: $dbh->errstr);
2049: }
2050: }
2051:
2052: if ($callsub{'apache'}) {
2053: if ($distro =~ /^(suse|sles)/) {
1.49 raeburn 2054: ©_apache2_suseconf($instdir,$hostname,$distro);
1.1 raeburn 2055: } elsif ($distro =~ /^(debian|ubuntu)/) {
1.46 raeburn 2056: ©_apache2_debconf($instdir,$distro,$hostname);
1.1 raeburn 2057: } else {
1.46 raeburn 2058: ©_httpd_conf($instdir,$distro,$hostname);
1.59 raeburn 2059: ©_mpm_conf($instdir,$distro);
1.1 raeburn 2060: }
2061: } else {
2062: print_and_log(&mt('Skipping configuration of Apache web server.')."\n");
2063: }
2064:
1.46 raeburn 2065: if ($callsub{'apachessl'}) {
1.47 raeburn 2066: my $targetdir = '/etc/httpd/conf.d';
1.46 raeburn 2067: if ($distro =~ /^(suse|sles)/) {
1.47 raeburn 2068: $targetdir = '/etc/apache2/vhosts.d';
1.46 raeburn 2069: } elsif ($distro =~ /^(debian|ubuntu)/) {
1.47 raeburn 2070: $targetdir = '/etc/apache2/sites-available';
2071: }
2072: my ($new_rewrite,$new_int) =
2073: ©_apache_sslconf_files($distro,$hostname,$hostip,$instdir,$targetdir,$sslhostsfiles,
2074: $has_std,$has_int,$rewritenum,$nochgstd,$nochgint);
2075: if ($distro =~ /^(debian|ubuntu)/) {
2076: my $apache2_sites_enabled_dir = '/etc/apache2/sites-enabled';
2077: if (-d $apache2_sites_enabled_dir) {
2078: if ($has_std ne '') {
2079: unless ((-l "$apache2_sites_enabled_dir/$has_std") && (readlink(("$apache2_sites_enabled_dir/$has_std") eq "$targetdir/$has_std"))) {
2080: my $made_symlink = eval { symlink("$targetdir/$has_std","$apache2_sites_enabled_dir/$has_std"); 1};
2081: if ($made_symlink) {
2082: print_and_log(&mt('Enabling "[_1]" Apache SSL configuration.',$has_std)."\n");
2083: }
2084: }
2085: }
2086: if (($has_int ne '') && ($has_int ne $has_std)) {
2087: unless ((-l "$apache2_sites_enabled_dir/$has_int") && (readlink("$apache2_sites_enabled_dir/$has_int") eq "$targetdir/$has_int")) {
2088: my $made_symlink = eval { symlink("$targetdir/$has_int","$apache2_sites_enabled_dir/$has_int"); 1 };
2089: if ($made_symlink) {
2090: print_and_log(&mt('Enabling "[_1]" Apache SSL configuration.',$has_int)."\n");
2091: }
2092: }
1.46 raeburn 2093: }
2094: }
2095: }
2096: print_and_log("\n");
2097: } else {
2098: print_and_log(&mt('Skipping configuration of SSL for Apache web server.')."\n");
2099: }
2100:
1.1 raeburn 2101: if ($callsub{'runlevels'}) {
2102: my $count = 0;
2103: if (ref($recommended) eq 'HASH') {
2104: if (ref($recommended->{'runlevels'}) eq 'HASH') {
2105: foreach my $type (keys(%{$recommended->{'runlevels'}})) {
2106: next if ($type eq 'insserv');
2107: $count ++;
2108: my $command = $recommended->{'runlevels'}{$type};
2109: if ($command ne '') {
2110: print_and_log(&mt('Runlevel update command run: [_1].',$command)."\n");
2111: system($command);
2112: }
2113: }
2114: if (!$count) {
2115: print_and_log(&mt('No runlevel updates required.')."\n");
2116: }
2117: }
2118: }
1.49 raeburn 2119: if ($distro =~ /^(suse|sles)(\d+)/) {
2120: unless(($1 eq 'sles') && ($2 >= 15)) {
2121: &update_SuSEfirewall2_setup($instdir);
2122: }
1.11 raeburn 2123: }
1.1 raeburn 2124: } else {
2125: &print_and_log(&mt('Skipping setting override for start-up order of services.')."\n");
2126: }
2127:
2128: if ($callsub{'firewall'}) {
1.53 raeburn 2129: my ($firewalld,$zone) = &uses_firewalld($distro);
2130: if ($firewalld) {
1.49 raeburn 2131: my (%current,%added);
1.53 raeburn 2132: if (open(PIPE,"firewall-cmd --permanent --zone=$zone --list-services |")) {
1.49 raeburn 2133: my $svc = <PIPE>;
2134: close(PIPE);
2135: chomp($svc);
2136: map { $current{$_} = 1; } (split(/\s+/,$svc));
2137: }
2138: foreach my $service ('http','https') {
2139: unless ($current{$service}) {
1.53 raeburn 2140: if (open(PIPE,"firewall-cmd --permanent --zone=$zone --add-service=$service |")) {
1.49 raeburn 2141: my $result = <PIPE>;
2142: if ($result =~ /^success/) {
2143: $added{$service} = 1;
2144: }
2145: }
2146: }
2147: }
2148: if (keys(%added) > 0) {
2149: print &mt('Firewall configured to allow access for: [_1].',
2150: join(', ',sort(keys(%added))))."\n";
2151: }
2152: if ($current{'http'} || $current{'https'}) {
2153: print &mt('Firewall already configured to allow access for:[_1].',
2154: (($current{'http'})? ' http':'').(($current{'https'})? ' https':''))."\n";
2155: }
2156: unless ($current{'ssh'}) {
2157: print &mt('If you would the like to allow access to ssh from outside, use the command[_1].',
1.53 raeburn 2158: "firewall-cmd --permanent --zone=$zone --add-service=ssh")."\n";
1.49 raeburn 2159: }
2160: } elsif ($distro =~ /^(suse|sles)/) {
1.5 raeburn 2161: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
2162: 'yast -- Security and Users -> Firewall -> Interfaces',
1.49 raeburn 2163: 'ssh, http, https')."\n";
1.5 raeburn 2164: } elsif ($distro =~ /^(debian|ubuntu)(\d+)/) {
2165: if (($1 eq 'ubuntu') || ($2 > 5)) {
2166: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
2167: 'ufw','ssh, http, https')."\n";
2168: } else {
2169: my $fwadded = &get_iptables_rules($distro,$instdir,$apachefw);
2170: if ($fwadded) {
2171: print &mt('Enable firewall? ~[Y/n~]');
2172: my $enable_iptables = &get_user_selection(1);
2173: if ($enable_iptables) {
2174: system('/etc/network/if-pre-up.d/iptables');
2175: print &mt('Firewall enabled using rules defined in [_1].',
2176: '/etc/iptables.loncapa.rules');
2177: }
2178: }
2179: }
1.57 raeburn 2180: } elsif ($distro =~ /^(scientific|oracle)/) {
1.11 raeburn 2181: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
2182: 'system-config-firewall-tui -- Customize',
2183: 'ssh, http')."\n";
1.1 raeburn 2184: } else {
1.53 raeburn 2185: my $version;
2186: if ($distro =~ /^(redhat|centos)(\d+)$/) {
2187: $version = $1;
2188: }
2189: if ($version > 5) {
2190: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
2191: 'system-config-firewall-tui -- Customize',
2192: 'ssh, http')."\n";
2193: } else {
2194: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
2195: 'setup -- Firewall configuration -> Customize',
2196: 'ssh, http, https')."\n";
2197: }
1.1 raeburn 2198: }
2199: } else {
1.5 raeburn 2200: &print_and_log(&mt('Skipping Firewall configuration.')."\n");
1.1 raeburn 2201: }
2202:
2203: if ($callsub{'stopsrvcs'}) {
1.45 raeburn 2204: &kill_extra_services($distro,$recommended->{'stopsrvcs'},$uses_systemctl);
1.1 raeburn 2205: } else {
1.10 raeburn 2206: &print_and_log(&mt('Skipping stopping unnecessary service ([_1] daemons).',"'cups','memcached'")."\n");
1.1 raeburn 2207: }
2208:
2209: my ($have_tarball,$updateshown);
2210: if ($callsub{'download'}) {
2211: ($have_tarball,$updateshown) = &download_loncapa($instdir,$sourcetarball);
2212: } else {
2213: print_and_log(&mt('Skipping download of LON-CAPA tar file.')."\n\n");
2214: print &mt('LON-CAPA is available for download from: [_1]',
2215: 'http://install.loncapa.org/')."\n";
2216: if (!-e '/etc/loncapa-release') {
2217: &print_and_log(&mt('LON-CAPA is not yet installed on your system.').
2218: "\n\n".
2219: &mt('You may retrieve the source for LON-CAPA by executing:')."\n".
2220: "wget http://install.loncapa.org/versions/$lctarball\n");
2221: } else {
2222: my $currentversion;
2223: if (open(my $fh,"</etc/loncapa-release")) {
2224: my $version = <$fh>;
2225: chomp($version);
2226: if ($version =~ /^\QLON-CAPA release \E([\w\-.]+)$/) {
2227: $currentversion = $1;
2228: }
2229: }
2230: if ($currentversion ne '') {
2231: print &mt('Version of LON-CAPA currently installed on this server is: [_1].',
2232: $currentversion),"\n";
2233: if ($production) {
2234: print &mt('The latest production release of LON-CAPA is [_1].',$production)."\n";
2235: }
2236: if ($testing) {
2237: print &mt('The latest testing release of LON-CAPA is [_1].',$testing)."\n";
2238: }
2239: }
2240: }
2241: if ($filetouse ne '') {
2242: $have_tarball = 1;
2243: }
2244: }
2245:
2246: print "\n".&mt('Requested configuration complete.')."\n\n";
2247: my $apachename;
2248: if ($have_tarball && !$updateshown) {
2249: my ($lcdir) = ($sourcetarball =~ /^([\w.\-]+)\.tar.gz$/);
2250: if (!-e '/etc/loncapa-release') {
2251: print &mt('If you are now ready to install LON-CAPA, enter the following commands:')."\n\n";
2252: } else {
2253: print &mt('If you are now ready to update LON-CAPA, enter the following commands:')."\n\n".
2254: "/etc/init.d/loncontrol stop\n";
2255: if ($distro =~ /^(suse|sles|debian|ubuntu)([\d.]+)/) {
2256: if (($1 eq 'suse') && ($2 < 10)) {
2257: $apachename = 'apache';
2258: } else {
2259: $apachename = 'apache2';
2260: }
2261: } else {
2262: $apachename = 'httpd';
2263: }
2264: print "/etc/init.d/$apachename stop\n";
2265: }
2266: print "cd /root\n".
2267: "tar zxf $sourcetarball\n".
2268: "cd $lcdir\n".
2269: "./UPDATE\n";
2270: if (-e '/etc/loncapa-release') {
2271: print "/etc/init.d/loncontrol start\n";
2272: print "/etc/init.d/$apachename start\n";
2273: }
2274: }
2275: exit;
2276:
2277: #
2278: # End main script
2279: #
2280:
2281: #
2282: # Routines for the actions
2283: #
2284:
2285: sub setup_www {
2286: ##
2287: ## Set up www
2288: ##
2289: print_and_log(&mt('Creating user [_1]',"'www'")."\n");
2290: # -- Add group
2291:
2292: my $status = `/usr/sbin/groupadd www`;
2293: if ($status =~ /\QGroup `www' already exists.\E/) {
2294: print &mt('Group [_1] already exists.',"'www'")."\n";
2295: } elsif ($status ne '') {
2296: print &mt('Unable to add group [_1].',"'www'")."\n";
2297: }
2298:
2299: my $gid = getgrnam('www');
2300:
2301: if (open (PIPE, "/usr/sbin/useradd -c LONCAPA -g $gid www 2>&1 |")) {
2302: $status = <PIPE>;
2303: close(PIPE);
2304: chomp($status);
2305: if ($status =~ /\QAccount `www' already exists.\E/) {
2306: print &mt('Account [_1] already exists.',"'www'")."\n";
2307: } elsif ($status ne '') {
2308: print &mt('Unable to add user [_1].',"'www'")."\n";
2309: }
2310: } else {
2311: print &mt('Unable to run command to add user [_1].',"'www'")."\n";
2312: }
2313:
2314: my $uid = &uid_of_www();
2315: if (($gid ne '') && ($uid ne '')) {
2316: if (!-e '/home/www') {
2317: mkdir('/home/www',0755);
2318: system('chown www:www /home/www');
2319: }
2320: }
2321: writelog ($status);
2322: }
2323:
2324: sub uid_of_www {
2325: my ($num) = (getpwnam('www'))[2];
2326: return $num;
2327: }
2328:
2329: sub build_and_install_mod_auth_external {
2330: my ($instdir) = @_;
2331: my $num = &uid_of_www();
2332: # Patch pwauth
2333: print_and_log(&mt('Building authentication system for LON-CAPA users.')."\n");
2334: my $patch = <<"ENDPATCH";
2335: 148c148
2336: < #define SERVER_UIDS 99 /* user "nobody" */
2337: ---
2338: > #define SERVER_UIDS $num /* user "www" */
2339: ENDPATCH
2340:
2341: if (! -e "/usr/bin/patch") {
2342: print_and_log(&mt('You must install the software development tools package: [_1], when installing Linux.',"'patch'")."\n");
2343: print_and_log(&mt('Authentication installation not completed.')."\n");
2344: return;
2345: }
2346: if (&skip_if_nonempty(`cd /tmp; tar zxf $instdir/pwauth-2.2.8.tar.gz`,
2347: &mt('Unable to extract pwauth')."\n")) {
2348: return;
2349: }
2350: my $dir = "/tmp/pwauth-2.2.8";
2351: if (open(PATCH,"| patch $dir/config.h")) {
2352: print PATCH $patch;
2353: close(PATCH);
2354: print_and_log("\n");
2355: ##
2356: ## Compile patched pwauth
2357: ##
2358: print_and_log(&mt('Compiling pwauth')."\n");
1.12 raeburn 2359: my $result = `cd $dir/; make 2>/dev/null `;
1.1 raeburn 2360: my $expected = <<"END";
2361: gcc -g -c -o pwauth.o pwauth.c
2362: gcc -o pwauth -g pwauth.o -lcrypt
2363: END
2364: if ($result eq $expected) {
2365: print_and_log(&mt('Apparent success compiling pwauth:').
2366: "\n".$result );
2367: # Install patched pwauth
2368: print_and_log(&mt('Copying pwauth to [_1]',' /usr/local/sbin')."\n");
2369: if (copy "$dir/pwauth","/usr/local/sbin/pwauth") {
1.5 raeburn 2370: if (chmod(06755, "/usr/local/sbin/pwauth")) {
1.1 raeburn 2371: print_and_log(&mt('[_1] copied successfully',"'pwauth'").
2372: "\n");
2373: } else {
2374: print &mt('Unable to set permissions on [_1].'.
2375: "/usr/local/sbin/pwauth")."\n";
2376: }
2377: } else {
2378: print &mt('Unable to copy [_1] to [_2]',
2379: "'$dir/pwauth'","/usr/local/sbin/pwauth")."\n$!\n";
2380: }
2381: } else {
2382: print &mt('Unable to compile patched [_1].'."'pwauth'")."\n";
2383: }
2384: } else {
2385: print &mt('Unable to start patch for [_1]',"'pwauth'")."\n";
2386: }
2387: print_and_log("\n");
2388: }
2389:
2390: sub kill_extra_services {
1.45 raeburn 2391: my ($distro,$stopsrvcs,$uses_systemctl) = @_;
1.1 raeburn 2392: if (ref($stopsrvcs) eq 'HASH') {
2393: my @stopping = sort(keys(%{$stopsrvcs}));
2394: if (@stopping) {
1.6 raeburn 2395: my $kill_list = join("', '",@stopping);
1.1 raeburn 2396: if ($kill_list) {
2397: $kill_list = "'".$kill_list."'";
1.6 raeburn 2398: &print_and_log("\n".&mt('Killing unnecessary services ([_1] daemon(s)).',$kill_list)."\n");
2399: foreach my $service (@stopping) {
2400: my $daemon = $service;
2401: if ($service eq 'cups') {
2402: $daemon = 'cupsd';
2403: if ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
2404: my $version = $1;
2405: if (($distro =~ /^ubuntu/) && ($version <= 8)) {
2406: $daemon = 'cupsys';
2407: }
1.12 raeburn 2408: } else {
1.8 raeburn 2409: $daemon = 'cups';
1.6 raeburn 2410: }
2411: }
1.12 raeburn 2412: my $cmd = "ps -ef |grep '$daemon' |grep -v grep";
2413: if (open(PIPE,'-|',$cmd)) {
2414: my $daemonrunning = <PIPE>;
2415: chomp($daemonrunning);
2416: close(PIPE);
2417: if ($daemonrunning) {
2418: &print_and_log(`/etc/init.d/$daemon stop`);
2419: }
2420: }
1.1 raeburn 2421: &print_and_log(&mt('Removing [_1] from startup.',$service)."\n");
1.45 raeburn 2422: if ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
2423: my $version = $1;
2424: if (($distro =~ /^ubuntu/) && ($version > 16)) {
2425: if (ref($uses_systemctl) eq 'HASH') {
2426: if ($uses_systemctl->{$service}) {
2427: if (`systemctl is-enabled $service`) {
2428: &print_and_log(`systemctl disable $service`);
2429: }
2430: }
2431: }
2432: } else {
2433: &print_and_log(`update-rc.d -f $daemon remove`);
2434: }
1.1 raeburn 2435: } else {
1.35 raeburn 2436: if (ref($uses_systemctl) eq 'HASH') {
2437: if ($uses_systemctl->{$service}) {
2438: if (`systemctl is-enabled $service`) {
2439: &print_and_log(`systemctl disable $service`);
2440: }
2441: } else {
2442: &print_and_log(`/sbin/chkconfig --del $service`);
2443: }
2444: } else {
2445: &print_and_log(`/sbin/chkconfig --del $service`);
2446: }
1.1 raeburn 2447: }
2448: }
2449: }
2450: }
2451: }
2452: return;
2453: }
2454:
2455: sub setup_mysql {
1.68 raeburn 2456: my ($setup_mysql_permissions,$dbh,$has_pass,$mysql_unix_socket,$has_lcdb) = @_;
1.4 raeburn 2457: my @mysql_lc_commands;
1.1 raeburn 2458: unless ($has_lcdb) {
1.4 raeburn 2459: push(@mysql_lc_commands,"CREATE DATABASE loncapa");
1.1 raeburn 2460: }
1.4 raeburn 2461: push(@mysql_lc_commands,"USE loncapa");
2462: push(@mysql_lc_commands,qq{
1.18 raeburn 2463: 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 2464: });
1.1 raeburn 2465: if ($setup_mysql_permissions) {
1.68 raeburn 2466: &setup_mysql_permissions($dbh,$has_pass,$mysql_unix_socket,@mysql_lc_commands);
1.1 raeburn 2467: } else {
2468: print_and_log(&mt('Skipping MySQL permissions setup.')."\n");
2469: if ($dbh) {
1.4 raeburn 2470: if (@mysql_lc_commands) {
2471: foreach my $lccmd (@mysql_lc_commands) {
2472: $dbh->do($lccmd) || print $dbh->errstr."\n";
2473: }
2474: }
1.1 raeburn 2475: print_and_log(&mt('MySQL database set up complete.')."\n");
2476: } else {
2477: print_and_log(&mt('Problem accessing MySQL.')."\n");
2478: }
2479: }
2480: }
2481:
2482: sub setup_mysql_permissions {
1.68 raeburn 2483: my ($dbh,$has_pass,$mysql_unix_socket,@mysql_lc_commands) = @_;
1.38 raeburn 2484: my ($mysqlversion,$mysqlsubver,$mysqlname) = &get_mysql_version();
1.68 raeburn 2485: my ($usescreate,$usesauth,$is_mariadb,$hasauthcol,@mysql_commands);
1.38 raeburn 2486: if ($mysqlname =~ /^MariaDB/i) {
1.50 raeburn 2487: $is_mariadb = 1;
1.68 raeburn 2488: if ($mysqlversion >= 10.4) {
2489: $usescreate = 1;
2490: } elsif ($mysqlversion >= 10.2) {
1.38 raeburn 2491: $usesauth = 1;
1.42 raeburn 2492: } elsif ($mysqlversion >= 5.5) {
2493: $hasauthcol = 1;
1.38 raeburn 2494: }
2495: } else {
2496: if (($mysqlversion > 5.7) || (($mysqlversion == 5.7) && ($mysqlsubver > 5))) {
2497: $usesauth = 1;
1.42 raeburn 2498: } elsif (($mysqlversion >= 5.6) || (($mysqlversion == 5.5) && ($mysqlsubver >= 7))) {
2499: $hasauthcol = 1;
1.38 raeburn 2500: }
2501: }
1.68 raeburn 2502: if ($usescreate) {
2503: @mysql_commands = ("CREATE USER 'www'\@'localhost' IDENTIFIED BY 'localhostkey'");
2504: } elsif ($usesauth) {
1.50 raeburn 2505: @mysql_commands = ("INSERT user (Host, User, ssl_cipher, x509_issuer, x509_subject, authentication_string) VALUES('localhost','www','','','','')");
2506: if ($is_mariadb) {
1.52 raeburn 2507: push(@mysql_commands,"ALTER USER 'www'\@'localhost' IDENTIFIED BY 'localhostkey'");
1.50 raeburn 2508: } else {
1.52 raeburn 2509: push(@mysql_commands,"ALTER USER 'www'\@'localhost' IDENTIFIED WITH mysql_native_password BY 'localhostkey'");
1.50 raeburn 2510: }
1.42 raeburn 2511: } elsif ($hasauthcol) {
2512: @mysql_commands = ("INSERT user (Host, User, Password, ssl_cipher, x509_issuer, x509_subject, authentication_string) VALUES('localhost','www',password('localhostkey'),'','','','');");
1.36 raeburn 2513: } else {
1.42 raeburn 2514: @mysql_commands = ("INSERT user (Host, User, Password, ssl_cipher, x509_issuer, x509_subject) VALUES('localhost','www',password('localhostkey'),'','','');");
1.36 raeburn 2515: }
1.1 raeburn 2516: if ($mysqlversion < 4) {
1.4 raeburn 2517: push (@mysql_commands,"
2518: 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')");
2519: } else {
2520: push (@mysql_commands,"
2521: 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 2522: }
1.4 raeburn 2523: push(@mysql_commands,"DELETE FROM user WHERE host<>'localhost'");
1.68 raeburn 2524: if (($has_pass) || ($mysql_unix_socket)) {
1.1 raeburn 2525: if ($dbh) {
1.4 raeburn 2526: push(@mysql_commands,"FLUSH PRIVILEGES");
2527: if (@mysql_commands) {
2528: foreach my $cmd (@mysql_commands) {
2529: $dbh->do($cmd) || print $dbh->errstr."\n";
2530: }
2531: }
2532: if (@mysql_lc_commands) {
2533: foreach my $lccmd (@mysql_lc_commands) {
2534: $dbh->do($lccmd) || print $dbh->errstr."\n";
2535: }
2536: }
1.1 raeburn 2537: print_and_log(&mt('Permissions set for LON-CAPA MySQL user: [_1]',"'www'")."\n");
2538: } else {
2539: print_and_log(&mt('Problem accessing MySQL.')."\n".
2540: &mt('Permissions not set.')."\n");
2541: }
2542: } else {
2543: my ($firstpass,$secondpass,$got_passwd,$newmysqlpass);
2544: print &mt('Please enter a root password for the mysql database.')."\n".
2545: &mt('It does not have to match your root account password, but you will need to remember it.')."\n";
2546: my $maxtries = 10;
2547: my $trial = 0;
2548: while ((!$got_passwd) && ($trial < $maxtries)) {
2549: $firstpass = &get_mysql_password(&mt('Enter password'));
2550: if (length($firstpass) > 5) {
2551: $secondpass = &get_mysql_password(&mt('Enter password a second time'));
2552: if ($firstpass eq $secondpass) {
2553: $got_passwd = 1;
2554: $newmysqlpass = $firstpass;
2555: } else {
2556: print(&mt('Passwords did not match. Please try again.')."\n");
2557: }
2558: $trial ++;
2559: } else {
2560: print(&mt('Password too short.')."\n".
2561: &mt('Please choose a password with at least six characters.')."\n");
2562: }
2563: }
2564: if ($got_passwd) {
1.50 raeburn 2565: my (@newpass_cmds) = &new_mysql_rootpasswd($newmysqlpass,$usesauth,$is_mariadb);
1.4 raeburn 2566: push(@mysql_commands,@newpass_cmds);
1.1 raeburn 2567: } else {
2568: print_and_log(&mt('Failed to get MySQL root password from user input.')."\n");
2569: }
2570: if ($dbh) {
1.4 raeburn 2571: if (@mysql_commands) {
2572: foreach my $cmd (@mysql_commands) {
2573: $dbh->do($cmd) || print $dbh->errstr."\n";
2574: }
2575: }
2576: if (@mysql_lc_commands) {
2577: foreach my $lccmd (@mysql_lc_commands) {
2578: $dbh->do($lccmd) || print $dbh->errstr."\n";
2579: }
2580: }
1.1 raeburn 2581: if ($got_passwd) {
2582: print_and_log(&mt('MySQL root password stored.')."\n".
2583: &mt('Permissions set for LON-CAPA MySQL user: [_1].',"'www'")."\n");
2584: } else {
2585: print_and_log(&mt('Permissions set for LON-CAPA MySQL user: [_1].',"'www'")."\n");
2586: }
2587: } else {
2588: print_and_log(&mt('Problem accessing MySQL.')."\n".
2589: &mt('Permissions not set.')."\n");
2590: }
2591: }
2592: }
2593:
2594: sub new_mysql_rootpasswd {
1.50 raeburn 2595: my ($currmysqlpass,$usesauth,$is_mariadb) = @_;
1.36 raeburn 2596: if ($usesauth) {
1.50 raeburn 2597: if ($is_mariadb) {
1.51 raeburn 2598: return ("ALTER USER 'root'\@'localhost' IDENTIFIED BY '$currmysqlpass'",
1.50 raeburn 2599: "FLUSH PRIVILEGES;");
2600: } else {
1.51 raeburn 2601: return ("ALTER USER 'root'\@'localhost' IDENTIFIED WITH mysql_native_password BY '$currmysqlpass'",
1.50 raeburn 2602: "FLUSH PRIVILEGES;");
2603: }
1.36 raeburn 2604: } else {
2605: return ("SET PASSWORD FOR 'root'\@'localhost'=PASSWORD('$currmysqlpass')",
2606: "FLUSH PRIVILEGES;");
2607: }
1.1 raeburn 2608: }
2609:
2610: sub get_mysql_version {
1.38 raeburn 2611: my ($version,$subversion,$name);
1.1 raeburn 2612: if (open(PIPE," mysql -V |")) {
2613: my $info = <PIPE>;
2614: chomp($info);
2615: close(PIPE);
1.65 raeburn 2616: ($version,$subversion,$name) = ($info =~ /(\d+\.\d+)\.(\d+)(?:\-?(\w*),|)/);
1.1 raeburn 2617: } else {
2618: print &mt('Could not determine which version of MySQL is installed.').
2619: "\n";
2620: }
1.38 raeburn 2621: return ($version,$subversion,$name);
1.1 raeburn 2622: }
2623:
2624: ###########################################################
2625: ##
2626: ## RHEL/CentOS/Fedora/Scientific Linux
2627: ## Copy LON-CAPA httpd.conf to /etc/httpd/conf
2628: ##
2629: ###########################################################
2630:
2631: sub copy_httpd_conf {
1.46 raeburn 2632: my ($instdir,$distro,$hostname) = @_;
1.14 raeburn 2633: my $configfile = 'httpd.conf';
1.56 raeburn 2634: if ($distro =~ /^(?:centos|rhes|scientific|oracle)(\d+)$/) {
1.29 raeburn 2635: if ($1 >= 7) {
2636: $configfile = 'apache2.4/httpd.conf';
2637: } elsif ($1 > 5) {
1.14 raeburn 2638: $configfile = 'new/httpd.conf';
2639: }
2640: } elsif ($distro =~ /^fedora(\d+)$/) {
1.29 raeburn 2641: if ($1 > 17) {
2642: $configfile = 'apache2.4/httpd.conf';
2643: } elsif ($1 > 10) {
1.14 raeburn 2644: $configfile = 'new/httpd.conf';
2645: }
2646: }
1.1 raeburn 2647: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'httpd.conf'",
2648: "'/etc/httpd/conf/httpd.conf'")."\n");
2649: copy "/etc/httpd/conf/httpd.conf","/etc/httpd/conf/httpd.conf.original";
1.14 raeburn 2650: copy "$instdir/centos-rhes-fedora-sl/$configfile","/etc/httpd/conf/httpd.conf";
1.5 raeburn 2651: chmod(0444,"/etc/httpd/conf/httpd.conf");
1.1 raeburn 2652: print_and_log("\n");
2653: }
2654:
1.59 raeburn 2655: ###########################################################
2656: ##
2657: ## RHEL/CentOS/Fedora/Scientific Linux
2658: ## Copy LON-CAPA mpm.conf to /etc/httpd/conf.modules.d/00-mpm.conf
2659: ##
2660: ## The LON-CAPA mpm.conf enables the prefork MPM module in
2661: ## Apache. This is also the default for RHEL/CentOS/Oracle
1.60 raeburn 2662: ## Linux 7 and earlier, and Fedora 26 and earlier. For more
1.59 raeburn 2663: ## recent versions of those distros, the event MPM is enabled
2664: ## by default. After ©_mpm_conf() is run, the prefork MPM
2665: ## module will be enabled instead of the event MPM module.
2666: ##
2667: ###########################################################
2668:
2669: sub copy_mpm_conf {
2670: my ($instdir,$distro) = @_;
2671: my $mpmfile = 'mpm.conf';
2672: if ((-e "/etc/httpd/conf.modules.d/00-mpm.conf") &&
2673: (-e "$instdir/centos-rhes-fedora-sl/$mpmfile")) {
2674: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'mpm.conf'",
2675: "'/etc/httpd/conf.modules.d/00-mpm.conf'")."\n");
2676: copy "$instdir/centos-rhes-fedora-sl/$mpmfile","/etc/httpd/conf.modules.d/00-mpm.conf";
2677: chmod(0644,"/etc/httpd/conf.modules.d/00-mpm.conf");
2678: print_and_log("\n");
2679: } else {
2680: my $logfail;
2681: if ($distro =~ /^(?:centos|rhes|scientific|oracle)(\d+)$/) {
2682: if ($1 > 7) {
2683: $logfail = 1;
2684: }
2685: } elsif ($distro =~ /^fedora(\d+)$/) {
2686: if ($1 > 26) {
2687: $logfail = 1;
2688: }
2689: }
2690: if ($logfail) {
2691: print_and_log(&mt('Warning: copying the LON-CAPA [_1] failed because [_2] and/or [_3] are missing.',
2692: $mpmfile,"'$instdir/centos-rhes-fedora-sl/$mpmfile'",
2693: "'/etc/httpd/conf.modules.d/00-mpm.conf'"));
2694: print_and_log("\n");
2695: }
2696: }
2697: }
2698:
1.46 raeburn 2699: ###############################################
2700: ##
1.47 raeburn 2701: ## Copy loncapassl.conf and sslrewrite.conf
1.46 raeburn 2702: ##
2703: ###############################################
2704:
1.47 raeburn 2705: #
2706: # The Apache SSL configuration used by LON-CAPA is contained in
2707: # two files: sslrewrite.conf and loncapassl.conf.
2708: #
2709: # Starting with LON-CAPA 2.12, name-based virtual hosts are used
2710: # with port 443. The default virtual host (i.e., the one listed
2711: # first) is for the server's standard hostname, and that is the one
2712: # which will respond to client browser requests for https:// pages.
2713: #
2714: # Accordingly, a system administrator will need to edit the config
2715: # config file to include paths to a signed SSL certificate (public),
2716: # chain (public) and key (private) pem files. The certificate should
2717: # have been signed by a recognized certificate authority ((e.g.,
2718: # InCommon or Let's Encrypt).
2719: #
2720: # The sslrewrite.conf file contains the rewrite configuration for
2721: # the default virtual host. The rewrite rules defined are used to
2722: # allow internal HEAD requests to /cgi-bin/mimetex.cgi to be served
2723: # http://, in order to support vertical alignment of mimetex images
2724: # (one of the options for rendering Math content); (b) allow requests
2725: # for certain URLs (external resource, and syllabus, if external URL
2726: # used) to be served http:// to accommodate the use of iframes which
2727: # would otherwise result in browser blocking of mixed active content.
2728: #
2729: # The loncapassl.conf file contains the configuration for the
2730: # "internal" virtual host, which will respond to requests for https://
2731: # pages from other LON-CAPA servers in the network to which the node
2732: # belongs. The ServerName is internal-<hostname> where <hostname>
2733: # is the server's hostname. There is no need to create a DNS entry
2734: # for internal-<hostname>, as LON-CAPA 2.12 automatically performs
2735: # the required hostname to IP mapping.
2736: #
2737: # Requests to /raw on the "internal" virtual host require a valid
2738: # SSL client certificate, signed by the certificate authority
2739: # for the LON-CAPA network to which the node belongs.
2740: #
2741: # The configuration file to which the contents of sslrewrite.conf
2742: # and loncapassl.conf will be written will have either been identified
2743: # when &chkapachessl() was run, or if no files were found with
2744: # existing rewrite blocks, then a candidate file will be chosen
2745: # from the .conf files containing VirtualHosts definitions.
2746: # If there is more than one suitable candidate file, the system
2747: # administrator will be prompted to select from the available files.
2748: #
2749: # If there are no files containing VirtualHosts definitions, then
2750: # <VirtualHost *:443> </VirtualHost> blocks will be appended to
2751: # the standard Apache SSL config for the particular distro:
2752: # ssl.conf for RHEL/CentOS/Scientific/Fedora, vhost-ssl.conf
2753: # for SuSE/SLES, and default-ssl.conf for Ubuntu.
2754: #
2755: # Once a file is selected, the contents of sslrewrite.conf and
2756: # loncapassl.conf are compared with appropriate blocks in the file
2757: # and the user will be prompted to agree to insertion of missing lines
2758: # and/or deletion of surplus lines.
2759: #
2760:
2761: sub copy_apache_sslconf_files {
2762: my ($distro,$hostname,$hostip,$instdir,$targetdir,$targetfilesref,
2763: $has_std,$has_int,$rewritenum,$nochgstd,$nochgint) = @_;
2764: my ($new_std,$new_int);
2765: my (@internal,@standard,%int_by_linenum,%int_by_linetext,
2766: %rule_by_linenum,%rule_by_linetext,%foundint);
1.46 raeburn 2767: if (-e "$instdir/loncapassl.conf") {
2768: if (open(my $fh,'<',"$instdir/loncapassl.conf")) {
1.47 raeburn 2769: my $num = 1;
2770: while (<$fh>) {
2771: chomp();
2772: if (/^ServerName/) {
2773: s/(\Qinternal-{[[[[Hostname]]]]}\E)/internal-$hostname/;
2774: }
2775: push(@internal,$_);
2776: $int_by_linenum{$num} = $_;
2777: s/(^\s+|\s+$)//g;
2778: push(@{$int_by_linetext{$_}},$num);
2779: $num ++;
2780: }
2781: close($fh);
2782: }
2783: }
2784: if (-e "$instdir/sslrewrite.conf") {
2785: if (open(my $fh,'<',"$instdir/sslrewrite.conf")) {
2786: my $num = 1;
2787: while (<$fh>) {
2788: chomp();
2789: if (/\Q{[[[[HostIP]]]]}\E/) {
2790: s/(\QRewriteCond %{REMOTE_ADDR} {[[[[HostIP]]]]}\E)/RewriteCond %{REMOTE_ADDR} $hostip/;
2791: }
2792: push(@standard,$_);
2793: $rule_by_linenum{$num} = $_;
2794: s/(^\s+|\s+$)//g;
2795: push(@{$rule_by_linetext{$_}},$num);
2796: $num ++;
2797: }
2798: close($fh);
2799: }
2800: }
2801: if (!$nochgstd) {
2802: if ($has_std eq '') {
2803: my $file;
2804: if ($has_int ne '') {
2805: if (open(my $fh,'<',"$targetdir/$has_int")) {
2806: my @saved = <$fh>;
2807: close($fh);
2808: if (open(my $fhout, '>',"$targetdir/$has_int")) {
2809: print $fhout "<VirtualHost *:443>\n".
2810: "ServerName $hostname\n".
2811: join("\n",@standard)."\n".
2812: "</VirtualHost>\n\n".
2813: join('',@saved);
2814: close($fhout);
2815: $new_int = $has_int;
2816: }
2817: }
2818: }
2819: } else {
2820: if ($rewritenum eq '') {
2821: &append_to_vhost($targetdir,$has_std,$hostname,\%rule_by_linenum,'std');
2822: $new_std = $has_std;
2823: } else {
2824: $new_std = &modify_ssl_config($targetdir,$has_std,$hostname,$rewritenum,
2825: \%rule_by_linetext,\%rule_by_linenum,'std');
2826: }
2827: }
2828: }
2829: if (!$nochgint) {
2830: if ($has_int eq '') {
2831: if ($has_std ne '') {
2832: if (open(my $fhout,'>>',"$targetdir/$has_std")) {
2833: print $fhout "\n".join("\n",@internal)."\n";
2834: close($fhout);
2835: $new_int = $has_std;
2836: }
2837: }
2838: } else {
2839: $new_int = &modify_ssl_config($targetdir,$has_int,$hostname,$rewritenum,\%int_by_linetext,\%int_by_linenum,'int');
2840: }
2841: }
2842: if (($has_std eq '') && ($has_int eq '')) {
2843: my ($file,$numfiles) = &get_sslconf_filename($distro,$targetdir,$targetfilesref);
2844: if ($numfiles == 0) {
2845: if (open(my $fhout, '>>', "$targetdir/$file")) {
2846: print $fhout "<VirtualHost *:443>\n".
2847: "ServerName $hostname\n".
2848: join("\n",@standard)."\n".
2849: "</VirtualHost>\n\n".
2850: join("\n",@internal)."\n";
2851: close($fhout);
2852: $new_std = $file;
2853: $new_int = $file;
2854: }
2855: } elsif ($numfiles == 1) {
2856: &append_to_vhost($targetdir,$file,$hostname,\%rule_by_linenum,'std');
2857: if (open(my $fhout, '>>', "$targetdir/$file")) {
2858: print $fhout "\n".join("\n",@internal)."\n";
2859: close($fhout);
2860: $new_std = $file;
2861: $new_int = $file;
2862: }
2863: } elsif ($numfiles == -1) {
2864: print_and_log(&mt('Failed to copy contents of [_1] or [_2] to a file in [_3]',
2865: "'loncapassl.conf'","'sslrewrite.conf'","'$targetdir'")."\n");
2866: }
2867: }
2868: if ($nochgstd) {
2869: print_and_log(&mt('No change required to file: [_1] in [_2], (no difference between [_3] and rewrite block.)',
2870: "'$has_std'","'$targetdir'","'sslrewrite.conf'"));
2871: }
2872: if ($nochgint) {
2873: print_and_log(&mt('No change required to file: [_1] in [_2], (no difference between [_3] and virtualhost block.)',
2874: "'$has_int'","'$targetdir'","'loncapassl.conf'"));
2875: }
2876: if ($new_int) {
2877: print_and_log(&mt('Successfully copied contents of [_1] to [_2].',"'loncapassl.conf'","'$targetdir/$new_int'")."\n");
2878: chmod(0444,"$targetdir/loncapassl.conf");
2879: }
2880: if ($new_std) {
2881: print_and_log(&mt('Successfully copied contents of [_1] to [_2].',"'sslrewrite.conf'","'$targetdir/$new_std'")."\n");
2882: chmod(0444,"$targetdir/loncapassl.conf");
2883: }
2884: return ($new_int,$new_std);
2885: }
2886:
2887: #
2888: # append_to_vhost() is called to add rewrite rules (in a
2889: # <IfModule +mod_rewrite.c> </IfModule> block), provided
2890: # in the sslrewrite.conf configuration file, to an Apache
2891: # SSL configuration file within a VirtualHost for port 443
2892: # (for server's public-facing hostname).
2893: #
2894: sub append_to_vhost {
2895: my ($targetdir,$filename,$hostname,$by_linenum,$type) = @_;
2896: return unless (ref($by_linenum) eq 'HASH');
2897: my ($startvhost,$endvhost);
2898: if (-e "$targetdir/$filename") {
2899: my (@lines,$currname,$virtualhost,$hasname);
2900: if (open(my $fh,'<',"$targetdir/$filename")) {
2901: my $currline = 0;
2902: while (<$fh>) {
2903: $currline ++;
2904: push(@lines,$_);
2905: chomp();
2906: s/(^\s+|\s+$)//g;
2907: if (/^<VirtualHost\s+[^:]*\:443>/) {
2908: $virtualhost = 1;
2909: unless ($endvhost) {
2910: $startvhost = $currline;
1.46 raeburn 2911: }
2912: }
1.47 raeburn 2913: if ($virtualhost) {
2914: if (/^ServerName\s+([^\s]+)\s*$/) {
2915: $currname = $1;
2916: unless ($endvhost) {
2917: if ((($currname eq '') || ($currname eq $hostname)) && ($type eq 'std')) {
2918: $hasname = 1;
2919: }
2920: }
2921: }
2922: if (/^<\/VirtualHost>/) {
2923: $virtualhost = 0;
2924: unless ($endvhost) {
2925: if (((($currname eq '') || ($currname eq $hostname)) && ($type eq 'std')) ||
2926: (($currname eq 'internal-'.$hostname) && ($type eq 'int'))) {
2927: $endvhost = $currline;
2928: } else {
2929: undef($startvhost);
2930: }
2931: }
2932: }
2933: }
2934: }
2935: close($fh);
2936: }
2937: if ($endvhost) {
2938: if (open(my $fout,'>',"$targetdir/$filename")) {
2939: for (my $i=0; $i<@lines; $i++) {
2940: if ($i == $startvhost) {
2941: unless (($hasname) && ($type eq 'std')) {
2942: print $fout "ServerName $hostname\n";
2943: }
2944: }
2945: if ($i == $endvhost-1) {
2946: foreach my $item (sort { $a <=> $b } keys(%{$by_linenum})) {
2947: print $fout $by_linenum->{$item}."\n";
2948: }
2949: }
2950: print $fout $lines[$i];
2951: }
2952: close($fout);
2953: }
2954: }
2955: }
2956: return $endvhost;
2957: }
2958:
2959: #
2960: # get_sslconf_filename() is called when the Apache SSL configuration
2961: # option has been selected and there are no files containing
2962: # VirtualHost definitions containing rewrite blocks,
2963: #
2964: # In this case get_sslconf_filename() is used to chose from the
2965: # available .conf files containing VirtualHosts definitions. If
2966: # there is ambiguity about which file to use, &apacheconf_choice()
2967: # will be called to prompt the user to choose one of the possible
2968: # files.
2969: #
2970:
2971: sub get_sslconf_filename {
2972: my ($distro,$targetdir,$targetfilesref) = @_;
2973: my ($configfile,$numfiles,@possfiles);
2974: if (ref($targetfilesref) eq 'HASH') {
2975: if (keys(%{$targetfilesref}) > 0) {
2976: foreach my $name (sort(keys(%{$targetfilesref}))) {
2977: if (ref($targetfilesref->{$name}) eq 'HASH') {
2978: foreach my $file (sort(keys(%{$targetfilesref->{$name}}))) {
2979: next if ($file eq '');
2980: next if (!-e "$targetdir/$file");
2981: unless (grep(/^\Q$file\E$/,@possfiles)) {
2982: push(@possfiles,$file);
2983: }
2984: }
2985: }
2986: }
2987: }
2988: if (@possfiles == 0) {
2989: $configfile = 'ssl.conf';
2990: if ($distro =~ /^(suse|sles)/) {
2991: $configfile = 'vhost-ssl.conf';
2992: } elsif ($distro =~ /^(debian|ubuntu)/) {
2993: $configfile = 'default-ssl.conf';
2994: }
2995: $numfiles = 0;
2996: 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".
2997: &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";
2998: } elsif (@possfiles == 1) {
2999: $configfile = $possfiles[0];
3000: $numfiles = 1;
3001: print &mt('A single configuration file in [_1] contains a <VirtualHost *:443> </VirtualHost> block.',$targetdir)."\n".
3002: &mt('The contents of sslrewrite.conf will be added to this block.')."\n\n";
3003: } else {
3004: print &mt('More than one Apache config file contains a <VirtualHost *:443> </VirtualHost> block.')."\n\n".&mt('The possible files are:')."\n";
3005: my $counter = 1;
3006: my $max = scalar(@possfiles);
3007: foreach my $file (@possfiles) {
3008: print "$counter. $file\n";
3009: $counter ++;
3010: }
3011: 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";
3012: my $choice = &apacheconf_choice($max);
3013: if (($choice =~ /^\d+$/) && ($choice >= 1) && ($choice <= $max)) {
3014: $configfile = $possfiles[$choice-1];
3015: $numfiles = 1;
1.46 raeburn 3016: } else {
1.47 raeburn 3017: $numfiles = -1;
1.46 raeburn 3018: }
3019: }
3020: }
1.47 raeburn 3021: return ($configfile,$numfiles);
3022: }
3023:
3024: #
3025: # &apacheconf_choice() prompts a user to choose an integer between 1 and the
3026: # maximum number of available of possible Apache SSL config files found
3027: # at the distros standard location for Apache config files containing
3028: # VirtualHost definitions.
3029: #
3030: # This routine is called recursively until the user enters a valid integer.
3031: #
3032:
3033: sub apacheconf_choice {
3034: my ($max) = @_;
3035: my $choice = <STDIN>;
3036: chomp($choice);
3037: $choice =~ s/(^\s+|\s+$)//g;
3038: my $configfile;
3039: if (($choice =~ /^\d+$/) && ($choice >= 1) && ($choice <= $max)) {
3040: $configfile = $choice;
3041: }
3042: while ($configfile eq '') {
3043: print &mt('Invalid choice. Please enter a number between 1 and [_1].',$max)."\n";
3044: $configfile = &apacheconf_choice($max);
3045: }
3046: print "\n";
3047: return $configfile;
3048: }
3049:
3050: #
3051: # &modify_ssl_config() is called to modify the contents of an Apache SSL config
3052: # file so that it has two <VirtualHost *:443> </VirtualHost> blocks containing
3053: # (a) the default VirtualHost with the <IfModule mod_rewrite.c> </IfModule> block
3054: # provided in sslrewrites.conf, and (b) an "internal" VirtualHost with the
3055: # content provided in loncapassl.conf.
3056: #
3057: # This routine will prompted you to agree to insertion of lines present in the
3058: # shipped conf file, but missing from the local config file, and also for
3059: # deletion of lines present in the local config file, but not required in
3060: # the shipped conf file.
3061: #
3062:
3063: sub modify_ssl_config {
3064: my ($targetdir,$filename,$hostname,$rewritenum,$by_linetext,$by_linenum,$type) = @_;
3065: return unless ((ref($by_linetext) eq 'HASH') && (ref($by_linenum) eq 'HASH'));
3066: if (-e "$targetdir/$filename") {
3067: my (@lines,$virtualhost,$currname,$rewrite);
3068: if (open(my $fh,'<',"$targetdir/$filename")) {
3069: my %found;
3070: my %possible;
3071: my $currline = 0;
3072: my $rewritecount = 0;
3073: while (<$fh>) {
3074: $currline ++;
3075: push(@lines,$_);
3076: chomp();
3077: s/(^\s+|\s+$)//g;
3078: if (/^\s*<VirtualHost\s+[^:]*\:443>\s*$/) {
3079: $virtualhost = 1;
3080: }
3081: if ($virtualhost) {
3082: if ((exists($by_linetext->{$_})) && (ref($by_linetext->{$_}) eq 'ARRAY') &&
3083: (@{$by_linetext->{$_}} > 0)) {
3084: $possible{$currline} = shift(@{$by_linetext->{$_}});
3085: }
3086: if (/^\s*<\/VirtualHost>/) {
3087: if ((($currname eq 'internal-'.$hostname) && ($type eq 'int')) ||
3088: ((($currname eq $hostname) || ($currname eq '')) && ($type eq 'std') &&
3089: ($rewritecount == $rewritenum))) {
3090: %found = (%found,%possible);
3091: } else {
3092: foreach my $line (sort {$b <=> $a } keys(%possible)) {
3093: my $num = $possible{$line};
3094: if (ref($by_linetext->{$by_linenum->{$num}}) eq 'ARRAY') {
3095: unshift(@{$by_linetext->{$by_linenum->{$num}}},$num);
3096: }
3097: }
3098: }
3099: undef(%possible);
3100: $virtualhost = 0;
3101: $currname = '';
3102: } elsif (/^\s*ServerName\s+([^\s]+)\s*$/) {
3103: $currname = $1;
3104: } elsif (/^\s*<IfModule\s+mod_rewrite\.c>/) {
3105: $rewrite = 1;
3106: } elsif (/^\s*<\/IfModule>/) {
3107: $rewritecount ++;
3108: $rewrite = 0;
3109: }
3110: }
3111: }
3112: close($fh);
3113: if (open(my $fout,'>',"$targetdir/$filename")) {
3114: my $currline = 0;
3115: my ($lastfound,$done);
3116: my $numfound = 0;
3117: foreach my $line (@lines) {
3118: $currline ++;
3119: if ($done) {
3120: print $fout $line;
3121: } elsif ($lastfound) {
3122: if ($found{$currline}) {
3123: for (my $i=$lastfound+1; $i<$found{$currline}; $i++) {
3124: print &mt('The following line is missing from the current <VirtualHost *:443> </VirtualHost> block:')."\n".
3125: $by_linenum->{$i}."\n".
3126: &mt('Add this line? ~[Y/n~]');
3127: if (&get_user_selection(1)) {
3128: print $fout $by_linenum->{$i}."\n";
3129: }
3130: }
3131: $numfound ++;
3132: $lastfound = $found{$currline};
3133: print $fout $line;
3134: if ($numfound == scalar(keys(%found))) {
3135: $done = 1;
3136: for (my $i=$found{$currline}+1; $i<=scalar(keys(%{$by_linenum})); $i++) {
3137: print &mt('The following line is missing from the current <VirtualHost *:443> </VirtualHost> block:')."\n".
3138: $by_linenum->{$i}."\n".
3139: &mt('Add this line? ~[Y/n~]');
3140: if (&get_user_selection(1)) {
3141: print $fout $by_linenum->{$i}."\n";
3142: }
3143: }
3144: }
3145: } else {
3146: print &mt('The following line found within a <VirtualHost *:443> </VirtualHost> block does not match that expected by LON-CAPA:')."\n".
3147: $line.
3148: &mt('Delete this line? ~[Y/n~]');
3149: if (!&get_user_selection(1)) {
3150: print $fout $line;
3151: }
3152: }
3153: } elsif ($found{$currline}) {
3154: $numfound ++;
3155: $lastfound = $found{$currline};
3156: for (my $i=1; $i<$found{$currline}; $i++) {
3157: print &mt('The following line is missing from the current <VirtualHost *:443> </VirtualHost> block:')."\n".
3158: $by_linenum->{$i}."\n".
3159: &mt('Add this line? ~[Y/n~]');
3160: if (&get_user_selection(1)) {
3161: print $fout $by_linenum->{$i}."\n";
3162: }
3163: }
3164: print $fout $line;
3165: } else {
3166: print $fout $line;
3167: }
3168: }
3169: close($fout);
3170: }
1.46 raeburn 3171: }
3172: }
1.47 raeburn 3173: return $filename;
1.46 raeburn 3174: }
3175:
1.1 raeburn 3176: #########################################################
3177: ##
1.17 raeburn 3178: ## Ubuntu/Debian -- copy our loncapa configuration file to
1.1 raeburn 3179: ## sites-available and set the symlink from sites-enabled.
3180: ##
3181: #########################################################
3182:
3183: sub copy_apache2_debconf {
1.46 raeburn 3184: my ($instdir,$distro,$hostname) = @_;
1.6 raeburn 3185: my $apache2_mods_enabled_dir = '/etc/apache2/mods-enabled';
3186: my $apache2_mods_available_dir = '/etc/apache2/mods-available';
3187: foreach my $module ('headers.load','expires.load') {
3188: unless (-l "$apache2_mods_enabled_dir/$module") {
3189: symlink("$apache2_mods_available_dir/$module","$apache2_mods_enabled_dir/$module");
3190: print_and_log(&mt('Enabling "[_1]" Apache module.',$module)."\n");
3191: }
3192: }
1.28 raeburn 3193: my $apache2_sites_enabled_dir = '/etc/apache2/sites-enabled';
3194: my $apache2_sites_available_dir = '/etc/apache2/sites-available';
3195: my $defaultconfig = "$apache2_sites_enabled_dir/000-default";
1.69 ! raeburn 3196: my $defaultsite = "$apache2_sites_enabled_dir/loncapa.conf";
1.28 raeburn 3197: my ($distname,$version);
3198: if ($distro =~ /^(debian|ubuntu)(\d+)$/) {
3199: $distname = $1;
3200: $version = $2;
3201: }
3202: if (($distname eq 'ubuntu') && ($version > 12)) {
3203: $defaultconfig = "$apache2_sites_enabled_dir/000-default.conf";
3204: }
1.64 raeburn 3205: my ($skipconf,$skipsite,$skipstatus);
1.28 raeburn 3206: if (($distname eq 'ubuntu') && ($version > 12)) {
3207: my $apache2_conf_enabled_dir = '/etc/apache2/conf-enabled';
3208: my $apache2_conf_available_dir = '/etc/apache2/conf-available';
1.64 raeburn 3209: my $defaultconf = $apache2_conf_enabled_dir.'/loncapa.conf';
3210: if ((-e "$apache2_conf_available_dir/loncapa") && (-e "$instdir/debian-ubuntu/ubuntu14/loncapa_conf")) {
1.67 raeburn 3211: if (open(PIPE, "diff --brief $apache2_conf_available_dir/loncapa $instdir/debian-ubuntu/ubuntu14/loncapa_conf |")) {
1.64 raeburn 3212: my $diffres = <PIPE>;
3213: close(PIPE);
3214: chomp($diffres);
3215: if ($diffres) {
1.69 ! raeburn 3216: copy("$apache2_conf_available_dir/loncapa","$apache2_conf_available_dir/loncapa.conf.original");
! 3217: } else {
! 3218: copy("$apache2_conf_available_dir/loncapa","$apache2_conf_available_dir/loncapa.conf");
! 3219: symlink("$apache2_conf_available_dir/loncapa.conf","$defaultconf");
1.64 raeburn 3220: }
3221: if (-l $defaultconf) {
3222: my $linkfname = readlink($defaultconf);
3223: if ($linkfname eq "$apache2_conf_available_dir/loncapa") {
1.69 ! raeburn 3224: unlink($defaultconf);
! 3225: }
! 3226: }
! 3227: unlink("$apache2_conf_available_dir/loncapa");
! 3228: }
! 3229: }
! 3230: if ((-e "$apache2_conf_available_dir/loncapa.conf") && (-e "$instdir/debian-ubuntu/ubuntu14/loncapa_conf")) {
! 3231: if (open(PIPE, "diff --brief $apache2_conf_available_dir/loncapa.conf $instdir/debian-ubuntu/ubuntu14/loncapa_conf |")) {
! 3232: my $diffres = <PIPE>;
! 3233: close(PIPE);
! 3234: chomp($diffres);
! 3235: if ($diffres) {
! 3236: copy("$apache2_conf_available_dir/loncapa.conf","$apache2_conf_available_dir/loncapa.conf.original");
! 3237: }
! 3238: if (-l $defaultconf) {
! 3239: my $linkfname = readlink($defaultconf);
! 3240: if ($linkfname eq "$apache2_conf_available_dir/loncapa.conf") {
1.64 raeburn 3241: unless ($diffres) {
3242: $skipconf = 1;
3243: }
3244: }
3245: }
3246: }
3247: }
3248: unless ($skipconf) {
3249: 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 3250: copy("$instdir/debian-ubuntu/ubuntu14/loncapa_conf","$apache2_conf_available_dir/loncapa.conf");
! 3251: chmod(0444,"$apache2_conf_available_dir/loncapa.conf");
1.64 raeburn 3252: if (-l $defaultconf) {
3253: unlink($defaultconf);
3254: }
1.69 ! raeburn 3255: symlink("$apache2_conf_available_dir/loncapa.conf","$defaultconf");
1.64 raeburn 3256: }
3257: my $stdsite = "$instdir/debian-ubuntu/ubuntu14/loncapa_site";
3258: if ((-e $stdsite) && (-e "$apache2_sites_available_dir/loncapa")) {
3259: if (open(PIPE, "diff --brief $stdsite $apache2_sites_available_dir/loncapa |")) {
3260: my $diffres = <PIPE>;
3261: close(PIPE);
3262: chomp($diffres);
3263: if ($diffres) {
1.69 ! raeburn 3264: copy("$apache2_sites_available_dir/loncapa","$apache2_sites_available_dir/loncapa.conf.original");
! 3265: } else {
! 3266: copy("$apache2_sites_available_dir/loncapa","$apache2_sites_available_dir/loncapa.conf");
1.64 raeburn 3267: }
3268: if (-l $defaultconfig) {
3269: my $linkfname = readlink($defaultconfig);
3270: if ($linkfname eq "$apache2_sites_available_dir/loncapa") {
1.69 ! raeburn 3271: unlink($defaultconfig);
! 3272: }
! 3273: }
! 3274: unlink("$apache2_sites_available_dir/loncapa");
! 3275: }
! 3276: }
! 3277: if ((-e $stdsite) && (-e "$apache2_sites_available_dir/loncapa.conf")) {
! 3278: if (open(PIPE, "diff --brief $stdsite $apache2_sites_available_dir/loncapa.conf |")) {
! 3279: my $diffres = <PIPE>;
! 3280: close(PIPE);
! 3281: chomp($diffres);
! 3282: if ($diffres) {
! 3283: copy("$apache2_sites_available_dir/loncapa.conf","$apache2_sites_available_dir/loncapa.conf.original");
! 3284: }
! 3285: if (-l $defaultsite) {
! 3286: my $linkfname = readlink($defaultsite);
! 3287: if ($linkfname eq "$apache2_conf_available_dir/loncapa.conf") {
1.64 raeburn 3288: unless ($diffres) {
3289: $skipsite = 1;
3290: }
1.65 raeburn 3291: }
1.64 raeburn 3292: }
3293: }
3294: }
3295: unless ($skipsite) {
1.69 ! raeburn 3296: 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");
! 3297: copy("$instdir/debian-ubuntu/ubuntu14/loncapa_site","$apache2_sites_available_dir/loncapa.conf");
! 3298: chmod(0444,"$apache2_sites_available_dir/loncapa.conf");
! 3299: symlink("$apache2_sites_available_dir/loncapa.conf","$defaultsite");
! 3300: }
! 3301: if (-l defaultconfig) {
! 3302: my $linkfname = readlink($defaultconfig);
! 3303: if ($linkfname eq "$apache2_sites_available_dir/000-default") {
! 3304: unlink($defaultconfig);
! 3305: }
1.64 raeburn 3306: }
3307: } else {
3308: if ((-e "$instdir/debian-ubuntu/loncapa") && (-e "$apache2_sites_available_dir/loncapa")) {
3309: if (open(PIPE, "diff --brief $instdir/debian-ubuntu/loncapa $apache2_sites_available_dir/loncapa |")) {
3310: my $diffres = <PIPE>;
3311: close(PIPE);
3312: chomp($diffres);
3313: if ($diffres) {
3314: copy("$apache2_sites_available_dir/loncapa","$apache2_sites_available_dir/loncapa.original");
3315: }
3316: if (-l $defaultconfig) {
3317: my $linkfname = readlink($defaultconfig);
3318: if ($linkfname eq "$apache2_sites_available_dir/loncapa") {
3319: unless ($diffres) {
3320: $skipsite = 1;
3321: }
3322: }
3323: }
3324: }
3325: }
3326: unless ($skipsite) {
3327: if (-l $defaultconfig) {
3328: unlink($defaultconfig);
3329: }
3330: 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");
3331: if (-e "$instdir/debian-ubuntu/loncapa") {
3332: copy("$instdir/debian-ubuntu/loncapa","$apache2_sites_available_dir/loncapa");
3333: chmod(0444,"$apache2_sites_available_dir/loncapa");
3334: symlink("$apache2_sites_available_dir/loncapa","$apache2_sites_enabled_dir/000-default");
3335: }
3336: }
3337: }
3338: if ($distname eq 'ubuntu') {
3339: my $sitestatus = "$apache2_mods_available_dir/status.conf";
3340: my $stdstatus = "$instdir/debian-ubuntu/status.conf";
3341: if ((-e $sitestatus) && (-e $stdstatus)) {
3342: if (open(PIPE, "diff --brief $stdstatus $sitestatus |")) {
3343: my $diffres = <PIPE>;
3344: close(PIPE);
3345: chomp($diffres);
3346: if ($diffres) {
3347: copy("$apache2_mods_available_dir/status.conf","$apache2_mods_available_dir/status.conf.original");
3348: } else {
3349: $skipstatus = 1;
3350: }
3351: }
3352: }
3353: unless ($skipstatus) {
3354: if (-e $stdstatus) {
3355: print_and_log(&mt('Copying loncapa [_1] file to [_2],',"'status.conf'","'/etc/apache2/mods-available/status.conf'")."\n");
3356: copy($stdstatus,$sitestatus);
3357: chmod(0644,$sitestatus);
3358: }
1.28 raeburn 3359: }
3360: }
1.1 raeburn 3361: print_and_log("\n");
3362: }
3363:
3364: ###########################################################
3365: ##
3366: ## openSuSE/SLES Copy apache2 config files:
3367: ## default-server.conf, uid.conf, /etc/sysconfig/apache2
3368: ## and create symlink from /srv/www/conf to /etc/apache2
3369: ##
3370: ###########################################################
3371:
3372: sub copy_apache2_suseconf {
1.49 raeburn 3373: my ($instdir,$hostname,$distro) = @_;
3374: my ($name,$version) = ($distro =~ /^(suse|sles)([\d\.]+)$/);
3375: my $conf_file = "$instdir/sles-suse/default-server.conf";
3376: if (($name eq 'sles') && ($version >= 12)) {
3377: $conf_file = "$instdir/sles-suse/apache2.4/default-server.conf";
3378: }
1.1 raeburn 3379: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',
3380: "'default-server.conf'",
3381: "'/etc/apache2/default-server.conf'")."\n");
3382: if (!-e "/etc/apache2/default-server.conf.original") {
3383: copy "/etc/apache2/default-server.conf","/etc/apache2/default-server.conf.original";
3384: }
1.49 raeburn 3385: copy $conf_file,"/etc/apache2/default-server.conf";
1.5 raeburn 3386: chmod(0444,"/etc/apache2/default-server.conf");
1.1 raeburn 3387: # Make symlink for conf directory (included in loncapa_apache.conf)
3388: my $can_symlink = (eval { symlink('/etc/apache2','/srv/www/conf'); }, $@ eq '');
3389: if ($can_symlink) {
3390: &print_and_log(&mt('Symlink created for [_1] to [_2].',
3391: "'/srv/www/conf'","'/etc/apache2'")."\n");
3392: } else {
3393: &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");
3394: }
3395: ©_apache2_conf_files($instdir);
1.49 raeburn 3396: ©_sysconfig_apache2_file($instdir,$name,$version);
1.1 raeburn 3397: print_and_log("\n");
3398: }
3399:
3400: ###############################################
3401: ##
3402: ## Modify uid.conf
3403: ##
3404: ###############################################
3405: sub copy_apache2_conf_files {
3406: my ($instdir) = @_;
3407: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',
3408: "'uid.conf'","'/etc/apache2/uid.conf'")."\n");
3409: if (!-e "/etc/apache2/uid.conf.original") {
3410: copy "/etc/apache2/uid.conf","/etc/apache2/uid.conf.original";
3411: }
1.9 raeburn 3412: copy "$instdir/sles-suse/uid.conf","/etc/apache2/uid.conf";
1.5 raeburn 3413: chmod(0444,"/etc/apache2/uid.conf");
1.1 raeburn 3414: }
3415:
3416: ###############################################
3417: ##
3418: ## Modify /etc/sysconfig/apache2
3419: ##
3420: ###############################################
3421: sub copy_sysconfig_apache2_file {
1.49 raeburn 3422: my ($instdir,$name,$version) = @_;
1.1 raeburn 3423: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'sysconfig/apache2'","'/etc/sysconfig/apache2'")."\n");
3424: if (!-e "/etc/sysconfig/apache2.original") {
3425: copy "/etc/sysconfig/apache2","/etc/sysconfig/apache2.original";
3426: }
1.49 raeburn 3427: my $sysconf_file = "$instdir/sles-suse/sysconfig_apache2";
3428: if (($name eq 'sles') && ($version >= 12)) {
3429: $sysconf_file = "$instdir/sles-suse/apache2.4/sysconfig_apache2";
3430: }
1.57 raeburn 3431: copy $sysconf_file,"/etc/sysconfig/apache2";
1.5 raeburn 3432: chmod(0444,"/etc/sysconfig/apache2");
1.1 raeburn 3433: }
3434:
3435: ###############################################
3436: ##
3437: ## Add/Modify /etc/insserv/overrides
3438: ##
3439: ###############################################
3440:
3441: sub update_SuSEfirewall2_setup {
3442: my ($instdir) = @_;
3443: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'SuSEfirewall2_setup'","'/etc/insserv/overrides/SuSEfirewall2_setup'")."\n");
3444: if (!-e "/etc/insserv/overrides/SuSEfirewall2_setup") {
3445: if (!-d "/etc/insserv") {
3446: mkdir("/etc/insserv",0755);
3447: }
3448: if (!-d "/etc/insserv/overrides") {
3449: mkdir("/etc/insserv/overrides",0755);
3450: }
3451: } elsif (!-e "/etc/insserv/overrides/SuSEfirewall2_setup.original") {
3452: copy "/etc/insserv/overrides/SuSEfirewall2_setup","/etc/insserv/overrides/SuSEfirewall2_setup.original"
3453: }
1.9 raeburn 3454: copy "$instdir/sles-suse/SuSEfirewall2_setup","/etc/insserv/overrides/SuSEfirewall2_setup";
1.5 raeburn 3455: chmod(0444,"/etc/insserv/overrides/SuSEfirewall2_setup");
3456: }
3457:
3458: sub get_iptables_rules {
3459: my ($distro,$instdir,$apachefw) = @_;
3460: my (@fwchains,@ports);
3461: if (&firewall_is_active()) {
3462: my $iptables = &get_pathto_iptables();
3463: if ($iptables ne '') {
3464: @fwchains = &get_fw_chains($iptables,$distro);
3465: }
3466: }
3467: if (ref($apachefw) eq 'HASH') {
3468: foreach my $service ('http','https') {
3469: unless ($apachefw->{$service}) {
3470: push (@ports,$service);
3471: }
3472: }
3473: } else {
3474: @ports = ('http','https');
3475: }
3476: if (@ports == 0) {
3477: return;
3478: }
3479: my $ask_to_enable;
3480: if (-e "/etc/iptables.loncapa.rules") {
1.9 raeburn 3481: if (open(PIPE, "diff --brief $instdir/debian-ubuntu/iptables.loncapa.rules /etc/iptables.loncapa.rules |")) {
1.5 raeburn 3482: my $diffres = <PIPE>;
3483: close(PIPE);
3484: chomp($diffres);
3485: if ($diffres) {
3486: print &mt('Warning: [_1] exists but differs from LON-CAPA supplied file.','/etc/iptables.loncapa.rules')."\n";
3487: }
3488: } else {
3489: print &mt('Error: unable to open [_1] to compare contents with LON-CAPA supplied file.','/etc/iptables.loncapa.rules')."\n";
3490: }
3491: } else {
1.9 raeburn 3492: if (-e "$instdir/debian-ubuntu/iptables.loncapa.rules") {
3493: copy "$instdir/debian-ubuntu/iptables.loncapa.rules","/etc/iptables.loncapa.rules";
1.5 raeburn 3494: chmod(0600,"/etc/iptables.loncapa.rules");
3495: }
3496: }
3497: if (-e "/etc/iptables.loncapa.rules") {
3498: if (-e "/etc/network/if-pre-up.d/iptables") {
1.9 raeburn 3499: if (open(PIPE, "diff --brief $instdir/debian-ubuntu/iptables /etc/network/if-pre-up/iptables |")) {
1.5 raeburn 3500: my $diffres = <PIPE>;
3501: close(PIPE);
3502: chomp($diffres);
3503: if ($diffres) {
3504: print &mt('Warning: [_1] exists but differs from LON-CAPA supplied file.','/etc/network/if-pre-up.d/iptables')."\n";
3505: }
3506: } else {
3507: print &mt('Error: unable to open [_1] to compare contents with LON-CAPA supplied file.','/etc/network/if-pre-up.d/iptables')."\n";
3508: }
3509: } else {
1.9 raeburn 3510: copy "$instdir/debian-ubuntu/iptables","/etc/network/if-pre-up.d/iptables";
1.5 raeburn 3511: chmod(0755,"/etc/network/if-pre-up.d/iptables");
3512: 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'));
3513: $ask_to_enable = 1;
3514: }
3515: }
3516: return $ask_to_enable;
1.1 raeburn 3517: }
3518:
3519: sub download_loncapa {
3520: my ($instdir,$lctarball) = @_;
3521: my ($have_tarball,$updateshown);
3522: if (! -e "$instdir/$lctarball") {
3523: print_and_log(&mt('Retrieving LON-CAPA source files from: [_1]',
3524: 'http://install.loncapa.org')."\n");
3525: system("wget http://install.loncapa.org/versions/$lctarball ".
3526: "2>/dev/null 1>/dev/null");
3527: if (! -e "./$lctarball") {
3528: print &mt('Unable to retrieve LON-CAPA source files from: [_1].',
3529: "http://install.loncapa.org/versions/$lctarball")."\n";
3530: } else {
3531: $have_tarball = 1;
3532: }
3533: print_and_log("\n");
3534: } else {
3535: $have_tarball = 1;
3536: print_and_log("
3537: ------------------------------------------------------------------------
3538:
3539: ".&mt('You seem to have a version of loncapa-current.tar.gz in [_1]',$instdir)."\n".
3540: &mt('This copy will be used and a new version will NOT be downloaded.')."\n".
3541: &mt('If you wish, you may download a new version by executing:')."
3542:
1.2 raeburn 3543: wget http://install.loncapa.org/versions/loncapa-current.tar.gz
1.1 raeburn 3544:
3545: ------------------------------------------------------------------------
3546: ");
3547: }
3548:
3549: ##
3550: ## untar loncapa.tar.gz
3551: ##
3552: if ($have_tarball) {
3553: print_and_log(&mt('Extracting LON-CAPA source files')."\n");
3554: writelog(`cd ~root; tar zxf $instdir/$lctarball`);
3555: print_and_log("\n");
3556: print &mt('LON-CAPA source files extracted.')."\n".
3557: &mt('It remains for you to execute the following commands:')."
3558:
1.63 raeburn 3559: cd /root/loncapa-X.Y.Z (X.Y.Z should correspond to a version number like '2.11.3')
1.1 raeburn 3560: ./UPDATE
3561:
3562: ".&mt('If you have any trouble, please see [_1] and [_2]',
3563: 'http://install.loncapa.org/','http://help.loncapa.org/')."\n";
3564: $updateshown = 1;
3565: }
3566: return ($have_tarball,$updateshown);
3567: }
3568:
3569: close LOG;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>