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