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