Fixed a bug with /etc/hosts generation

Signed-off-by: digimer <mkelly@alteeve.ca>
main
digimer 10 months ago
parent a9850bef4e
commit f40d25f2dd
  1. 39
      Anvil/Tools/System.pm
  2. 1
      share/words.xml
  3. 1
      tools/anvil-join-anvil

@ -5265,13 +5265,13 @@ sub update_hosts
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }});
if ($line) if ($line)
{ {
$last_line_blank = 0; $last_line_blank = 0;
$cleaned_body .= $line."\n"; $cleaned_body .= $line."\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { last_line_blank => $last_line_blank }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { last_line_blank => $last_line_blank }});
} }
elsif (not $last_line_blank) elsif (not $last_line_blank)
{ {
$last_line_blank = 1; $last_line_blank = 1;
$cleaned_body .= $line."\n"; $cleaned_body .= $line."\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { last_line_blank => $last_line_blank }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { last_line_blank => $last_line_blank }});
} }
@ -5490,6 +5490,41 @@ sub update_hosts
}}); }});
} }
# Clean spaces off the end of lines, and look for invalid entries.
$cleaned_body = "";
foreach my $line (split/\n/, $new_body)
{
$line =~ s/\s+$//;
$line =~ s/^\s+(\d.*)$/$1/;
if ($line =~ /^#/)
{
$cleaned_body .= $line."\n";
}
elsif ($line =~ /^(.*?)\s+(.*?)/)
{
my $ip = $1;
my $name = $2;
if ($anvil->Validate->ip({ip => $ip}))
{
# Valid
$cleaned_body .= $line."\n";
}
else
{
# The is not a valid hosts entry.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "warning_0172", variables => { line => $line }});
}
}
}
$difference = "";
$difference = diff \$new_body, \$cleaned_body, { STYLE => 'Unified' };
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { difference => $difference }});
if ($difference)
{
$new_body = $cleaned_body;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { new_body => $new_body }});
}
my $new_line_count = @{$ip_order}; my $new_line_count = @{$ip_order};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { new_line_count => $new_line_count }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { new_line_count => $new_line_count }});
if ($new_line_count) if ($new_line_count)

@ -4177,6 +4177,7 @@ We will try to proceed anyway.</key>
<key name="warning_0169">[ Warning ] - After reconfiguring the network, we've failed to connect to any database for two minutes. Rebooting in case this fixes the connection.</key> <key name="warning_0169">[ Warning ] - After reconfiguring the network, we've failed to connect to any database for two minutes. Rebooting in case this fixes the connection.</key>
<key name="warning_0170">[ Warning ] - The attempt to boot: [#!variable!host_name!#] appears to have failed. The return code received was: [#!variable!return_code!#] (expected '0'). The output, if any, was: [#!variable!output!#].</key> <key name="warning_0170">[ Warning ] - The attempt to boot: [#!variable!host_name!#] appears to have failed. The return code received was: [#!variable!return_code!#] (expected '0'). The output, if any, was: [#!variable!output!#].</key>
<key name="warning_0171">[ Warning ] - The daemon: [#!variable!daemon!#] appears to have failed! Attempting to restart it now.</key> <key name="warning_0171">[ Warning ] - The daemon: [#!variable!daemon!#] appears to have failed! Attempting to restart it now.</key>
<key name="warning_0172">[ Warning ] - The line: [#!variable!line!#] that was going to be added to the hosts file is invalid, removing it.</key>
</language> </language>
<!-- 日本語 --> <!-- 日本語 -->

@ -367,7 +367,6 @@ sub wait_for_etc_hosts
if ($difference) if ($difference)
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 3, key => "job_0112"});
update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0112"); update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0112");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0835"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "log_0835"});
my $failed = $anvil->Storage->write_file({ my $failed = $anvil->Storage->write_file({

Loading…
Cancel
Save