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