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