adjust_apache: quieter now

This commit is contained in:
Jed Reynolds
2020-05-06 16:00:36 -07:00
parent 48caf7e8cf
commit 56e84cbbc4

View File

@@ -65,31 +65,31 @@ if (-f "$fname") {
#my $blank = 0; #my $blank = 0;
#my $was_blank = 0; #my $was_blank = 0;
my $counter = 0; my $counter = 0;
#my $found_defaultip = 0; my $debug = 0;
my %address_map = ( my %address_map = (
"127.0.0.1" => "localhost.localdomain localhost localhost4.localdomain4 localhost4", "127.0.0.1" => "localhost.localdomain localhost localhost4.localdomain4 localhost4",
"::1" => "localhost.localdomain localhost localhost6.loaldomain6 localhost6", "::1" => "localhost.localdomain localhost localhost6.loaldomain6 localhost6",
$ip => $MgrHostname, $ip => $MgrHostname,
"192.168.1.101" => "lanforge.localnet lanforge.localdomain", "192.168.1.101" => "lanforge.localnet lanforge.localdomain",
); );
print Dumper(\%address_map); print Dumper(\%address_map) if ($debug);
my $prevname = ""; my $prevname = "";
my $previp = ""; my $previp = "";
for my $ln (@lines) { for my $ln (@lines) {
print "\nLN[$ln]\n"; print "\nLN[$ln]\n" if ($debug);
next if ($ln =~ /^\s*$/); next if ($ln =~ /^\s*$/);
next if ($ln =~ /^###-LF-HOSTAME-NEXT-###/); # old typo next if ($ln =~ /^###-LF-HOSTAME-NEXT-###/); # old typo
next if ($ln =~ /^###-LF-HOSTNAME-NEXT-###/); next if ($ln =~ /^###-LF-HOSTNAME-NEXT-###/);
print "PARSING IPv4 ln[$ln]\n"; print "PARSING IPv4 ln[$ln]\n" if ($debug);
@hunks = split(/\s+/, $ln); @hunks = split(/\s+/, $ln);
my $middleip = 0; my $middleip = 0;
my $counter2 = -1; my $counter2 = -1;
my $linehasip = 0; my $linehasip = 0;
my $lfhostname = 0; my $lfhostname = 0;
for my $hunk (@hunks) { for my $hunk (@hunks) {
print "\n ZUNK",$counter2,"-:$hunk:- "; print "\n HUNK",$counter2,"-:$hunk:- " if ($debug);
$counter2++; $counter2++;
next if ($hunk =~ /^localhost/); next if ($hunk =~ /^localhost/);
next if ($hunk =~ /^lanforge-srv\b/); next if ($hunk =~ /^lanforge-srv\b/);
@@ -97,8 +97,7 @@ if (-f "$fname") {
next if ($hunk =~ /^extra6?-\d+/); next if ($hunk =~ /^extra6?-\d+/);
if (($hunk =~ /^$ip\b/) if (($hunk =~ /^$ip\b/)
|| ($hunk =~ /^$MgrHostname\b/) || ($hunk =~ /^$MgrHostname\b/)){
){
$linehasip++; $linehasip++;
$lfhostname++; $lfhostname++;
$prevname = $hunk; $prevname = $hunk;
@@ -106,37 +105,36 @@ if (-f "$fname") {
if (($hunk =~ /^127\.0\.0\.1/) if (($hunk =~ /^127\.0\.0\.1/)
|| ($hunk =~ /^192\.168\.1\.101/) || ($hunk =~ /^192\.168\.1\.101/)
|| ($hunk =~ /^::1\b/) || ($hunk =~ /^::1\b/)){
){
$previp = $hunk; $previp = $hunk;
$linehasip++; $linehasip++;
} }
if ($hunk =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/) { if ($hunk =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/) {
$linehasip++; $linehasip++;
print " IP4($hunk)"; print " IP4($hunk)" if ($debug);
$previp = $hunk; $previp = $hunk;
if ($counter2 > 0) { # we're not first item on line if ($counter2 > 0) { # we're not first item on line
$middleip++ if ($counter2 > 0); $middleip++ if ($counter2 > 0);
print "MIDDLE"; print "middle" if ($debug);
} }
if (!(defined $address_map{$hunk})) { if (!(defined $address_map{$hunk})) {
$address_map{$hunk} = ""; $address_map{$hunk} = "";
} }
print "+IP4"; print "+IP4" if ($debug);
$previp = $hunk; $previp = $hunk;
} }
elsif (($hunk =~ /[G-Zg-z]+\.?/) || ($hunk =~ /^[^:A-Fa-f0-9]+/)) { elsif (($hunk =~ /[G-Zg-z]+\.?/) || ($hunk =~ /^[^:A-Fa-f0-9]+/)) {
print " notIP($hunk)"; print " notIP($hunk)" if ($debug);
$prevname = $hunk; $prevname = $hunk;
if ($middleip) { if ($middleip) {
print " middle($previp)"; print " middle($previp)" if ($debug);
$address_map{$previp} .= " $hunk" $address_map{$previp} .= " $hunk"
if ($address_map{$previp} !~ /\b$hunk\b/); if ($address_map{$previp} !~ /\b$hunk\b/);
$prevname = $hunk; $prevname = $hunk;
} }
elsif ($linehasip) { elsif ($linehasip) {
print " prev($previp $hunk)"; print " prev($previp $hunk)" if ($debug);
$address_map{$previp} .= " $hunk" $address_map{$previp} .= " $hunk"
if ($address_map{$previp} !~ /\b$hunk\b/); if ($address_map{$previp} !~ /\b$hunk\b/);
} }
@@ -144,8 +142,8 @@ if (-f "$fname") {
$more_hostnames{$hunk} = 1; $more_hostnames{$hunk} = 1;
} }
else { # strange word else { # strange word
print " hunk($hunk) has no IP***";
if ("" eq $previp) { if ("" eq $previp) {
print " hunk($hunk) has no IP***" if ($debug);
$more_hostnames{$hunk} = 1; $more_hostnames{$hunk} = 1;
} }
elsif ($address_map{$previp} !~ /\b$hunk\b/) { elsif ($address_map{$previp} !~ /\b$hunk\b/) {
@@ -155,7 +153,7 @@ if (-f "$fname") {
} }
elsif (($hunk =~ /::/) elsif (($hunk =~ /::/)
|| ($hunk =~ /[0-9A-Fa-f]+:/)) { || ($hunk =~ /[0-9A-Fa-f]+:/)) {
print " hunk6($hunk)"; print " hunk6($hunk)" if ($debug);
$linehasip++; $linehasip++;
if (!(defined $address_map{$hunk})) { if (!(defined $address_map{$hunk})) {
$address_map{$hunk} = ""; $address_map{$hunk} = "";
@@ -163,7 +161,7 @@ if (-f "$fname") {
$previp = $hunk; $previp = $hunk;
} }
elsif ($hunk =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/) { elsif ($hunk =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/) {
print " hunk($hunk)prev($prevname)"; print " hunk($hunk)prev($prevname)" if ($debug);
$address_map{$hunk} .= " $prevname" $address_map{$hunk} .= " $prevname"
if ($address_map{$hunk} !~ /\b$prevname\b/); if ($address_map{$hunk} !~ /\b$prevname\b/);
$previp = $hunk; $previp = $hunk;
@@ -177,11 +175,11 @@ if (-f "$fname") {
} # ~foreach line } # ~foreach line
for my $name (sort keys %more_hostnames) { for my $name (sort keys %more_hostnames) {
$address_map{$ip} .=" $name"; $address_map{$ip} .= " $name";
print "NEWSTUFF $ip $address_map{$ip}\n"; print "NEWSTUFF $ip $address_map{$ip}\n" if ($debug);
} }
print Dumper(\%address_map); print Dumper(\%address_map) if ($debug);
unshift(@newlines, "192.168.1.101 ".$address_map{"192.168.1.101"}); unshift(@newlines, "192.168.1.101 ".$address_map{"192.168.1.101"});
unshift(@newlines, "127.0.0.1 ".$address_map{"127.0.0.1"}); unshift(@newlines, "127.0.0.1 ".$address_map{"127.0.0.1"});
@@ -197,17 +195,13 @@ if (-f "$fname") {
} }
push(@newlines, "###-LF-HOSTNAME-NEXT-###"); push(@newlines, "###-LF-HOSTNAME-NEXT-###");
push(@newlines, $ip." ".$address_map{$ip}); push(@newlines, $ip." ".$address_map{$ip});
print Dumper(\@newlines); print Dumper(\@newlines) if ($debug);
sleep 5; sleep 5 if ($debug);
for my $ln (@newlines) { for my $ln (@newlines) {
print FILE "$ln\n"; print FILE "$ln\n";
} }
#print FILE "$ip $MgrHostname"; print FILE "\n";
#for my $name (keys %more_hostnames) {
# print FILE " $name";
#}
print FILE "\n\n";
close FILE; close FILE;
} }