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