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