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