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