* Got tools/anvil-configure-striker updating the system passwords now.

* Updated System->get_ips to only record 'sys::mac::<mac>::iface' for actual interfaces, not bonds.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent b0232c6180
commit 39c06f364f
  1. 1
      Anvil/Tools.pm
  2. 8
      Anvil/Tools/Database.pm
  3. 4
      Anvil/Tools/Storage.pm
  4. 13
      Anvil/Tools/System.pm
  5. 3
      share/words.xml
  6. 105
      tools/anvil-configure-striker

@ -806,6 +806,7 @@ sub _set_paths
units => "/usr/lib/systemd/system", units => "/usr/lib/systemd/system",
}, },
exe => { exe => {
'anvil-change-password' => "/usr/sbin/anvil-change-password",
'anvil-prep-database' => "/usr/sbin/anvil-prep-database", 'anvil-prep-database' => "/usr/sbin/anvil-prep-database",
'anvil-update-states' => "/usr/sbin/anvil-update-states", 'anvil-update-states' => "/usr/sbin/anvil-update-states",
'anvil-report-memory' => "/usr/sbin/anvil-report-memory", 'anvil-report-memory' => "/usr/sbin/anvil-report-memory",

@ -1375,7 +1375,13 @@ sub initialize
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "<< sql" => $sql }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "<< sql" => $sql }});
# Now that I am ready, disable autocommit, write and commit. # Now that I am ready, disable autocommit, write and commit.
$anvil->Database->write({uuid => $uuid, query => $sql, source => $THIS_FILE, line => __LINE__}); $anvil->Database->write({
debug => 2,
uuid => $uuid,
query => $sql,
source => $THIS_FILE,
line => __LINE__,
});
$anvil->data->{sys}{db_initialized}{$uuid} = 1; $anvil->data->{sys}{db_initialized}{$uuid} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::db_initialized::${uuid}" => $anvil->data->{sys}{db_initialized}{$uuid} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::db_initialized::${uuid}" => $anvil->data->{sys}{db_initialized}{$uuid} }});

@ -294,6 +294,10 @@ fi";
# Log that the file was backed up. # Log that the file was backed up.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0154", variables => { source_file => $source_file, target_file => $target_file }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0154", variables => { source_file => $source_file, target_file => $target_file }});
} }
else
{
die;
}
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { target_file => $target_file }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { target_file => $target_file }});

@ -573,11 +573,20 @@ sub get_ips
{ {
my $mac = $1; my $mac = $1;
$anvil->data->{sys}{network}{interface}{$in_iface}{mac} = $mac; $anvil->data->{sys}{network}{interface}{$in_iface}{mac} = $mac;
$anvil->data->{sys}{mac}{$mac}{iface} = $in_iface;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"sys::network::interface::${in_iface}::mac" => $anvil->data->{sys}{network}{interface}{$in_iface}{mac}, "sys::network::interface::${in_iface}::mac" => $anvil->data->{sys}{network}{interface}{$in_iface}{mac},
"sys::mac::${mac}::iface" => $anvil->data->{sys}{mac}{$mac}{iface},
}}); }});
# We only record the mac in 'sys::mac' if this isn't a bond.
my $test_file = "/proc/net/bonding/".$in_iface;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { test_file => $test_file }});
if (not -e $test_file)
{
$anvil->data->{sys}{mac}{$mac}{iface} = $in_iface;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"sys::mac::${mac}::iface" => $anvil->data->{sys}{mac}{$mac}{iface},
}});
}
} }
} }

@ -55,6 +55,8 @@ Author: Madison Kelly <mkelly@alteeve.ca>
NOTE: You must update the password of any other system using this host's NOTE: You must update the password of any other system using this host's
database manually! database manually!
</key> </key>
<key name="message_0030">Failed to write the new password to the temporary file: [#!variable!file!#]. Please check the logs for details.</key>
<key name="message_0031">Beginning configuration of local system.</key>
<!-- Log entries --> <!-- Log entries -->
<key name="log_0001">Starting: [#!variable!program!#].</key> <key name="log_0001">Starting: [#!variable!program!#].</key>
@ -365,6 +367,7 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st
<key name="error_0008">Failed to read the file: [#!variable!file!#]. It doesn't appear to exist.</key> <key name="error_0008">Failed to read the file: [#!variable!file!#]. It doesn't appear to exist.</key>
<key name="error_0009">Failed to add the target: [#!variable!target!#]:[#!variable!port!#]'s RSA fingerprint to: [#!variable!user!#]'s list of known hosts.</key> <key name="error_0009">Failed to add the target: [#!variable!target!#]:[#!variable!port!#]'s RSA fingerprint to: [#!variable!user!#]'s list of known hosts.</key>
<key name="error_0010">There was a problem adding the local machine to the: [#!data!path::configs::anvil.conf!#] file. Please see the log for details.</key> <key name="error_0010">There was a problem adding the local machine to the: [#!data!path::configs::anvil.conf!#] file. Please see the log for details.</key>
<key name="error_0011">Something went wrong while trying to update the password. The return code was: [#!variable!return_code!#], but '0' was expected.</key>
<!-- These are works and strings used by javascript/jqery --> <!-- These are works and strings used by javascript/jqery -->
<key name="js_0001">Up</key> <key name="js_0001">Up</key>

@ -8,6 +8,7 @@
# 2 = Failed to connect to database(s). # 2 = Failed to connect to database(s).
# 3 = Job was already picked up by another running instance. # 3 = Job was already picked up by another running instance.
# 4 = The host name did not update properly. # 4 = The host name did not update properly.
# 5 = Failed to write the temp file with the new password needed to call anvil-change-password.
# #
use strict; use strict;
@ -27,7 +28,7 @@ $| = 1;
my $anvil = Anvil::Tools->new(); my $anvil = Anvil::Tools->new();
$anvil->Log->level({set => 2}); $anvil->Log->level({set => 2});
$anvil->Log->secure({set => 0}); $anvil->Log->secure({set => 1});
# Read switches # Read switches
$anvil->Get->switches; $anvil->Get->switches;
@ -40,7 +41,7 @@ $anvil->Storage->read_config({file => $anvil->data->{path}{configs}{'anvil.conf'
if (($< != 0) && ($> != 0)) if (($< != 0) && ($> != 0))
{ {
# Not root # Not root
print $anvil->Words->string({key => "error_0005"})."\n"; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, key => "error_0005"});
$anvil->nice_exit({code => 1}); $anvil->nice_exit({code => 1});
} }
@ -50,12 +51,12 @@ my $connections = $anvil->Database->connect({
test_table => "network_interfaces", test_table => "network_interfaces",
}); });
print $THIS_FILE." ".__LINE__."; connections: [".$connections."]\n"; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "message_0031"});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0132", variables => { connections => $connections }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0132", variables => { connections => $connections }});
if (not $connections) if (not $connections)
{ {
# No databases, exit. # No databases, exit.
print $anvil->Words->string({key => "error_0003"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, key => "error_0003"});
$anvil->nice_exit({exit_code => 2}); $anvil->nice_exit({exit_code => 2});
} }
@ -64,9 +65,6 @@ pickup_job_details($anvil);
reconfigure_network($anvil); reconfigure_network($anvil);
update_passwords($anvil); update_passwords($anvil);
# Set the passwords
my $password = $anvil->data->{variables}{form}{config_step2}{striker_password}{value};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 1, list => { password => $password }});
@ -85,18 +83,57 @@ sub update_passwords
{ {
my ($anvil) = @_; my ($anvil) = @_;
# Set the passwords
my $password = $anvil->data->{variables}{form}{config_step2}{striker_password}{value};
my $temp_file = "/tmp/anvil-".$anvil->Get->uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 1, list => { password => $password }});
# Write the password into a temporary file. # Write the password into a temporary file.
my $error = $anvil->Storage->write_file({ my $error = $anvil->Storage->write_file({
body => , body => $password,
debug => $debug, debug => 2,
file => $temp_file, file => $temp_file,
group => $group, group => "root",
mode => $mode, mode => "0600",
overwrite => 1, overwrite => 1,
secure => $secure, secure => 1,
user => $user, user => "root",
}); });
# Call anvil-change-password
if ($error)
{
# Couldn't write the temp file.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, key => "message_0030", variables => { file => $temp_file }});
$anvil->nice_exit({code => 5});
}
else
{
my $return_code = "";
my $output = $anvil->System->call({
debug => 2,
shell_call => $anvil->data->{path}{exe}{'anvil-change-password'}." -y --password-file ".$temp_file."; ".$anvil->data->{path}{exe}{'echo'}." return_code:\$!",
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, list => { output => $output }});
foreach my $line (split/\n/, $output)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, list => { line => $line }});
if ($line =~ /return_code:(\d+)$/)
{
$return_code = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, list => { return_code => $return_code }});
}
}
# Unlink the temp file.
unlink $temp_file;
if ($return_code)
{
# Something went wrong
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, key => "error_0011", variables => { return_code => $return_code }});
}
}
return(0); return(0);
} }
@ -201,16 +238,16 @@ sub reconfigure_network
my $old_link1_iface = $anvil->data->{sys}{mac}{$link1_mac}{iface} ? $anvil->data->{sys}{mac}{$link1_mac}{iface} : ""; my $old_link1_iface = $anvil->data->{sys}{mac}{$link1_mac}{iface} ? $anvil->data->{sys}{mac}{$link1_mac}{iface} : "";
my $old_link2_iface = $anvil->data->{sys}{mac}{$link2_mac}{iface} ? $anvil->data->{sys}{mac}{$link2_mac}{iface} : ""; my $old_link2_iface = $anvil->data->{sys}{mac}{$link2_mac}{iface} ? $anvil->data->{sys}{mac}{$link2_mac}{iface} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
this_network => $this_network,
link1_key => $link1_key,
link2_key => $link2_key,
subnet_key => $subnet_key,
ip_key => $ip_key, ip_key => $ip_key,
is_gateway => $is_gateway, is_gateway => $is_gateway,
link1_key => $link1_key,
link1_mac => $link1_mac, link1_mac => $link1_mac,
link2_key => $link2_key,
link2_mac => $link2_mac, link2_mac => $link2_mac,
old_link1_iface => $old_link1_iface, old_link1_iface => $old_link1_iface,
old_link2_iface => $old_link2_iface, old_link2_iface => $old_link2_iface,
subnet_key => $subnet_key,
this_network => $this_network,
}}); }});
# Skip if this doesn't exist or isn't a valid IPv4 address. # Skip if this doesn't exist or isn't a valid IPv4 address.
@ -362,17 +399,32 @@ sub reconfigure_network
}}); }});
# Make backups of existing files # Make backups of existing files
if (-e $bond_file) { $anvil->Storage->backup({file => $bond_file}); } if (-e $bond_file)
if (-e $old_link1_file) { $anvil->Storage->backup({file => $old_link1_file}); } {
if (-e $old_link2_file) { $anvil->Storage->backup({file => $old_link1_file}); } $anvil->Storage->backup({debug => 2, file => $bond_file});
if (-e $new_link1_file) { $anvil->Storage->backup({file => $new_link1_file}); } }
if (-e $new_link2_file) { $anvil->Storage->backup({file => $new_link1_file}); } if (-e $old_link1_file)
{
$anvil->Storage->backup({debug => 2, file => $old_link1_file});
}
if (-e $old_link2_file)
{
$anvil->Storage->backup({debug => 2, file => $old_link2_file});
}
if (($old_link1_file ne $new_link1_file) && (-e $new_link1_file))
{
$anvil->Storage->backup({debug => 2, file => $new_link1_file});
}
if (($old_link2_file ne $new_link2_file) && (-e $new_link2_file))
{
$anvil->Storage->backup({debug => 2, file => $new_link2_file});
}
### Write out the new configs ### Write out the new configs
# Bond, Link 1 and Link 2 # Bond, Link 1 and Link 2
$anvil->Storage->write_file({file => $bond_file, body => $bond_config, user => "root", group => "root", mode => "0644"}); $anvil->Storage->write_file({file => $bond_file, body => $bond_config, user => "root", group => "root", mode => "0644", overwrite => 1});
$anvil->Storage->write_file({file => $new_link1_file, body => $link1_config, user => "root", group => "root", mode => "0644"}); $anvil->Storage->write_file({file => $new_link1_file, body => $link1_config, user => "root", group => "root", mode => "0644", overwrite => 1});
$anvil->Storage->write_file({file => $new_link2_file, body => $link2_config, user => "root", group => "root", mode => "0644"}); $anvil->Storage->write_file({file => $new_link2_file, body => $link2_config, user => "root", group => "root", mode => "0644", overwrite => 1});
### NOTE: Everything except the unlink is disabled until we sort out the reload ### NOTE: Everything except the unlink is disabled until we sort out the reload
# Shut down (and rename) Link 1 # Shut down (and rename) Link 1
@ -564,7 +616,6 @@ LIMIT 1;";
# Is the PID that picked up the job still alive? # Is the PID that picked up the job still alive?
if (exists $anvil->data->{pids}{$job_picked_up_by}) if (exists $anvil->data->{pids}{$job_picked_up_by})
{ {
print Dumper $anvil->data->{pids}{$job_picked_up_by};
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0146", variables => { pid => $job_picked_up_by }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0146", variables => { pid => $job_picked_up_by }});
$anvil->nice_exit({code => 3}); $anvil->nice_exit({code => 3});
} }

Loading…
Cancel
Save