From dc459bf2b8a937eef03b38eca4d2dffa151496db Mon Sep 17 00:00:00 2001 From: Jed Reynolds Date: Thu, 23 May 2019 12:42:28 -0700 Subject: [PATCH] updates apache files on ubuntu --- adjust_apache.pl | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/adjust_apache.pl b/adjust_apache.pl index 5d835c27..a46d7cf7 100755 --- a/adjust_apache.pl +++ b/adjust_apache.pl @@ -75,6 +75,8 @@ print "Updated /etc/hosts\n"; # grab the 0000-default.conf file my @places_to_check = ( + "/etc/apache2/apache2.conf", + "/etc/apache2/ports.conf", "/etc/apache2/sites-available/0000-default.conf", "/etc/httpd/conf/http.conf", "/etc/httpd/conf/httpd.conf", @@ -84,27 +86,35 @@ foreach my $file (@places_to_check) { if ( -f $file) { print "Checking $file...\n"; my @lines = `cat $file`; + chomp @lines; # we want to match Listen 80$ or Listen 443 https$ # we want to replace with Listen lanforge-mgr:80$ or Listen lanforge-mgr:443 https$ @hunks = grep { /^\s*Listen\s+(?:80|443) */ } @lines; if (@hunks) { + my $edited = 0; my @newlines = (); @hunks = (@hunks, "\n"); print "Something to change in $file\n"; print "These lines are interesting:\n"; print join("\n", @hunks); foreach my $confline (@lines) { - if ($confline !~ /^\s*Listen\s+(?:80|443) */) { - } - else { + if ($confline =~ /^\s*Listen\s+(?:80|443) */) { $confline =~ s/Listen /Listen ${MgrHostname}:/; print "$confline\n"; } + push @newlines, $confline; + $edited++ if ($confline =~ /# modified by lanforge/); } + push(@newlines, "# modified by lanforge\n") if ($edited == 0); + + die ($!) unless open($fh, ">", $file); + print $fh join("\n", @newlines); + close $fh; } else { print "Nothing to change in $file\n"; } } -} +} # ~for places_to_check + #