* Created Database->read() to store and return the handle to whichever database is used for read operations. Also created Database->quote that uses ->read to access the DBI 'quote' method more cleanly. Updated all calls to use these new methods.

* anvil-manage-files now identifies peers on the same subnet(s) and stores them in a sortable hash.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 6 years ago
parent 040f189ea6
commit 27ba3dcbb9
  1. 16
      Anvil/Tools/Account.pm
  2. 42
      Anvil/Tools/Alert.pm
  3. 699
      Anvil/Tools/Database.pm
  4. 4
      Anvil/Tools/Get.pm
  5. 10
      Anvil/Tools/Job.pm
  6. 2
      Anvil/Tools/System.pm
  7. 6
      cgi-bin/striker
  8. 8
      tools/anvil-daemon
  9. 162
      tools/anvil-manage-files
  10. 16
      tools/anvil-update-states
  11. 2
      tools/striker-configure-host
  12. 4
      tools/striker-manage-peers

@ -273,7 +273,7 @@ FROM
WHERE WHERE
user_algorithm != 'DELETED' user_algorithm != 'DELETED'
AND AND
user_name = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{cgi}{username}{value})." user_name = ".$anvil->Database->quote($anvil->data->{cgi}{username}{value})."
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
@ -434,14 +434,14 @@ UPDATE
sessions sessions
SET SET
session_salt = '', session_salt = '',
modified_date = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{sys}{database}{timestamp})." modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
WHERE WHERE
session_user_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($user_uuid)." "; session_user_uuid = ".$anvil->Database->quote($user_uuid)." ";
if ($host_uuid ne "all") if ($host_uuid ne "all")
{ {
$query .= " $query .= "
AND AND
session_host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($host_uuid)." "; session_host_uuid = ".$anvil->Database->quote($host_uuid)." ";
} }
$query .= " $query .= "
;"; ;";
@ -535,9 +535,9 @@ SELECT
FROM FROM
sessions sessions
WHERE WHERE
session_user_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{cookie}{anvil_user_uuid})." session_user_uuid = ".$anvil->Database->quote($anvil->data->{cookie}{anvil_user_uuid})."
AND AND
session_host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->host_uuid)." session_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
;"; ;";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0124", variables => { query => $query }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0124", variables => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
@ -661,7 +661,7 @@ SELECT
FROM FROM
users users
WHERE WHERE
user_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($user_uuid)." user_uuid = ".$anvil->Database->quote($user_uuid)."
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
@ -784,7 +784,7 @@ SELECT
FROM FROM
users users
WHERE WHERE
user_name = ".$anvil->data->{sys}{database}{use_handle}->quote($user)." user_name = ".$anvil->Database->quote($user)."
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});

@ -177,13 +177,13 @@ SELECT
FROM FROM
alert_sent alert_sent
WHERE WHERE
alert_sent_host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{sys}{host_uuid})." alert_sent_host_uuid = ".$anvil->Database->quote($anvil->data->{sys}{host_uuid})."
AND AND
alert_set_by = ".$anvil->data->{sys}{database}{use_handle}->quote($set_by)." alert_set_by = ".$anvil->Database->quote($set_by)."
AND AND
alert_record_locator = ".$anvil->data->{sys}{database}{use_handle}->quote($record_locator)." alert_record_locator = ".$anvil->Database->quote($record_locator)."
AND AND
alert_name = ".$anvil->data->{sys}{database}{use_handle}->quote($name)." alert_name = ".$anvil->Database->quote($name)."
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
@ -209,7 +209,7 @@ SELECT
FROM FROM
hosts hosts
WHERE WHERE
host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{sys}{host_uuid})." host_uuid = ".$anvil->Database->quote($anvil->data->{sys}{host_uuid})."
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
@ -247,12 +247,12 @@ INSERT INTO
alert_name, alert_name,
modified_date modified_date
) VALUES ( ) VALUES (
".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->uuid).", ".$anvil->Database->quote($anvil->Get->uuid).",
".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{sys}{host_uuid}).", ".$anvil->Database->quote($anvil->data->{sys}{host_uuid}).",
".$anvil->data->{sys}{database}{use_handle}->quote($set_by).", ".$anvil->Database->quote($set_by).",
".$anvil->data->{sys}{database}{use_handle}->quote($record_locator).", ".$anvil->Database->quote($record_locator).",
".$anvil->data->{sys}{database}{use_handle}->quote($name).", ".$anvil->Database->quote($name).",
".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{sys}{database}{timestamp})." ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
); );
"; ";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
@ -269,7 +269,7 @@ INSERT INTO
DELETE FROM DELETE FROM
alert_sent alert_sent
WHERE WHERE
alert_sent_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($alert_sent_uuid)." alert_sent_uuid = ".$anvil->Database->quote($alert_sent_uuid)."
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
query => $query, query => $query,
@ -490,15 +490,15 @@ INSERT INTO
alert_show_header, alert_show_header,
modified_date modified_date
) VALUES ( ) VALUES (
".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->uuid()).", ".$anvil->Database->quote($anvil->Get->uuid()).",
".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{sys}{host_uuid}).", ".$anvil->Database->quote($anvil->data->{sys}{host_uuid}).",
".$anvil->data->{sys}{database}{use_handle}->quote($set_by).", ".$anvil->Database->quote($set_by).",
".$anvil->data->{sys}{database}{use_handle}->quote($level).", ".$anvil->Database->quote($level).",
".$anvil->data->{sys}{database}{use_handle}->quote($title).", ".$anvil->Database->quote($title).",
".$anvil->data->{sys}{database}{use_handle}->quote($message).", ".$anvil->Database->quote($message).",
".$anvil->data->{sys}{database}{use_handle}->quote($sort_position).", ".$anvil->Database->quote($sort_position).",
".$anvil->data->{sys}{database}{use_handle}->quote($show_header).", ".$anvil->Database->quote($show_header).",
".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{sys}{database}{timestamp})." ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
); );
"; ";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});

File diff suppressed because it is too large Load Diff

@ -482,7 +482,7 @@ SELECT
FROM FROM
hosts hosts
WHERE WHERE
host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($host_uuid)."; host_uuid = ".$anvil->Database->quote($host_uuid).";
"; ";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
@ -650,7 +650,7 @@ Parameters;
This is the IPv4 IP address being calculated. This is the IPv4 IP address being calculated.
=head3 subnet (optional) =head3 subnet (required)
This is the subnet of the IP address being calculated. This is the subnet of the IP address being calculated.

@ -190,7 +190,7 @@ SELECT
FROM FROM
jobs jobs
WHERE WHERE
job_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{switches}{'job-uuid'})." job_uuid = ".$anvil->Database->quote($anvil->data->{switches}{'job-uuid'})."
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }});
@ -297,11 +297,11 @@ SELECT
FROM FROM
jobs jobs
WHERE WHERE
job_command LIKE ".$anvil->data->{sys}{database}{use_handle}->quote($program."%")." job_command LIKE ".$anvil->Database->quote($program."%")."
AND AND
job_progress != '100' job_progress != '100'
AND AND
job_host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($host_uuid)." job_host_uuid = ".$anvil->Database->quote($host_uuid)."
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
@ -347,7 +347,7 @@ FROM
WHERE WHERE
job_progress != '100' job_progress != '100'
AND AND
job_host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->host_uuid)." job_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
@ -567,7 +567,7 @@ SELECT
FROM FROM
jobs jobs
WHERE WHERE
job_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($job_uuid)." job_uuid = ".$anvil->Database->quote($job_uuid)."
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});

@ -728,6 +728,8 @@ This method checks the local system for interfaces and stores them in:
To aid in look-up by MAC address, C<< sys::mac::<mac_address>::iface >> is also set. To aid in look-up by MAC address, C<< sys::mac::<mac_address>::iface >> is also set.
No parameters are accepted by this method.
=cut =cut
sub get_ips sub get_ips
{ {

@ -1311,7 +1311,7 @@ WHERE
AND AND
job_progress != 100 job_progress != 100
AND AND
job_host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->host_uuid)." job_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
@ -1371,7 +1371,7 @@ WHERE
AND AND
variable_source_table = 'hosts' variable_source_table = 'hosts'
AND AND
variable_source_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->host_uuid)." variable_source_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
ORDER BY ORDER BY
variable_name ASC;"; variable_name ASC;";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }});
@ -1521,7 +1521,7 @@ WHERE
AND AND
variable_source_table = 'hosts' variable_source_table = 'hosts'
AND AND
variable_source_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->host_uuid)." variable_source_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
ORDER BY ORDER BY
variable_name ASC;"; variable_name ASC;";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0124", variables => { query => $query }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0124", variables => { query => $query }});

@ -641,7 +641,7 @@ SELECT
FROM FROM
hosts hosts
WHERE WHERE
host_uuid != ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->host_uuid)." host_uuid != ".$anvil->Database->quote($anvil->Get->host_uuid)."
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }});
@ -678,7 +678,7 @@ WHERE
} }
# Find any IP addresses for this host. # Find any IP addresses for this host.
my $query = "SELECT ip_address_address FROM ip_addresses WHERE ip_address_host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($host_uuid).";"; my $query = "SELECT ip_address_address FROM ip_addresses WHERE ip_address_host_uuid = ".$anvil->Database->quote($host_uuid).";";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
@ -711,7 +711,7 @@ SELECT
FROM FROM
host_keys host_keys
WHERE WHERE
host_key_host_uuid != ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->host_uuid)." host_key_host_uuid != ".$anvil->Database->quote($anvil->Get->host_uuid)."
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }});
@ -851,7 +851,7 @@ FROM
WHERE WHERE
variable_source_table = 'hosts' variable_source_table = 'hosts'
AND AND
variable_source_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->host_uuid)." variable_source_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
AND AND
variable_name = 'reboot::needed' variable_name = 'reboot::needed'
;"; ;";

@ -176,7 +176,7 @@ FROM
hosts b, hosts b,
file_locations c file_locations c
WHERE WHERE
b.host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{sys}{host_uuid})." b.host_uuid = ".$anvil->Database->quote($anvil->data->{sys}{host_uuid})."
AND AND
a.file_uuid = c.file_location_file_uuid a.file_uuid = c.file_location_file_uuid
AND AND
@ -207,7 +207,7 @@ ORDER BY
my $test_file = $file_directory."/".$file_name; my $test_file = $file_directory."/".$file_name;
$test_file =~ s/\/\//\//g; $test_file =~ s/\/\//\//g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { test_file => $test_file }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { test_file => $test_file }});
if (not -e $test_file) if (not -e $test_file)
{ {
@ -240,7 +240,48 @@ sub find_file
my $port = ""; my $port = "";
my $password = ""; my $password = "";
# Find the file on any/all other hosts. # What are my IPs?
$anvil->System->get_ips();
foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{sys}{network}{interface}})
{
next if not $anvil->data->{sys}{network}{interface}{$interface}{ip};
next if not $anvil->data->{sys}{network}{interface}{$interface}{subnet};
my $ip = $anvil->data->{sys}{network}{interface}{$interface}{ip};
my $subnet = $anvil->data->{sys}{network}{interface}{$interface}{subnet};
my $network = $anvil->Get->network({ip => $ip, subnet => $subnet});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
's1:interface' => $interface,
's2:ip' => $ip,
's3:subnet' => $subnet,
's4:network' => $network,
}});
my $type = "other";
my $sort = $interface;
if ($interface =~ /^((?:bc|s|if)n)(\d+)/)
{
$type = $1;
$sort = $2;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:type' => $type,
's2:sort' => $sort,
}});
}
$anvil->data->{local_ip}{by_network}{$network}{type} = $type;
$anvil->data->{local_ip}{by_network}{$network}{'sort'} = $sort;
$anvil->data->{local_ip}{by_network}{$network}{interface} = $interface;
$anvil->data->{local_ip}{by_network}{$network}{ip} = $ip;
$anvil->data->{local_ip}{by_network}{$network}{subnet} = $subnet;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"s1:local_ip::by_network::${network}::type" => $anvil->data->{local_ip}{by_network}{$network}{type},
"s1:local_ip::by_network::${network}::sort" => $anvil->data->{local_ip}{by_network}{$network}{'sort'},
"s2:local_ip::by_network::${network}::interface" => $anvil->data->{local_ip}{by_network}{$network}{interface},
"s3:local_ip::by_network::${network}::ip" => $anvil->data->{local_ip}{by_network}{$network}{ip},
"s4:local_ip::by_network::${network}::subnet" => $anvil->data->{local_ip}{by_network}{$network}{subnet},
}});
}
# Create a hash we can sort through that are on the same subnet as us.
my $query = " my $query = "
SELECT SELECT
a.host_uuid, a.host_uuid,
@ -259,29 +300,31 @@ WHERE
AND AND
b.file_uuid = c.file_location_file_uuid b.file_uuid = c.file_location_file_uuid
AND AND
b.file_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($file_uuid)." b.file_uuid = ".$anvil->Database->quote($file_uuid)."
AND AND
a.host_uuid != ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{sys}{host_uuid})." a.host_uuid != ".$anvil->Database->quote($anvil->data->{sys}{host_uuid})."
ORDER BY ORDER BY
file_mtime DESC; file_mtime DESC;
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results}; my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
results => $results, results => $results,
count => $count, count => $count,
}}); }});
foreach my $row (@{$results}) foreach my $row (@{$results})
{ {
my $host_uuid = $row->[0]; my $host_uuid = $row->[0];
my $host_name = $row->[1]; my $host_name = $row->[1];
my $host_type = $row->[2]; my $host_type = $row->[2];
my $file_directory = $row->[3]; my $file_directory = $row->[3];
my $file_name = $row->[4]; my $file_name = $row->[4];
my $file_size = $row->[5]; my $file_size = $row->[5];
my $file_md5sum = $row->[6]; my $file_md5sum = $row->[6];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { my $test_file = $file_directory."/".$file_name;
$test_file =~ s/\/\//\//g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
host_uuid => $host_uuid, host_uuid => $host_uuid,
host_name => $host_name, host_name => $host_name,
host_type => $host_type, host_type => $host_type,
@ -289,16 +332,91 @@ ORDER BY
file_name => $file_name, file_name => $file_name,
file_size => $file_size, file_size => $file_size,
file_md5sum => $file_md5sum, file_md5sum => $file_md5sum,
test_file => $test_file,
}}); }});
my $test_file = $file_directory."/".$file_name; # What IP addresses are on this machine?
$test_file =~ s/\/\//\//g; my $query = "
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { test_file => $test_file }}); SELECT
ip_address_address,
ip_address_subnet_mask
FROM
ip_addresses
WHERE
ip_address_on_type != 'DELETED'
AND
ip_address_host_uuid = ".$anvil->Database->quote($host_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
results => $results,
count => $count,
}});
foreach my $row (@{$results})
{
my $ip_address_address = $row->[0];
my $ip_address_subnet_mask = $row->[1];
my $network = $anvil->Get->network({ip => $ip_address_address, subnet => $ip_address_subnet_mask});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
ip_address_address => $ip_address_address,
ip_address_subnet_mask => $ip_address_subnet_mask,
network => $network,
}});
# Are we on the same subnet?
if (exists $anvil->data->{local_ip}{by_network}{$network})
{
# We're on the same subnet!
my $type = $anvil->data->{local_ip}{by_network}{$network}{type};
my $sort = $anvil->data->{local_ip}{by_network}{$network}{'sort'};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"s1:type" => $type,
"s2:sort" => $sort,
}});
# Record.
$anvil->data->{peer_ip}{$host_type}{$type}{$sort}{ip} = $ip_address_address;
$anvil->data->{peer_ip}{$host_type}{$type}{$sort}{name} = $host_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"s1:peer_ip::${host_type}::${type}::${sort}::name" => $anvil->data->{peer_ip}{$host_type}{$type}{$sort}{name},
"s2:peer_ip::${host_type}::${type}::${sort}::ip" => $anvil->data->{peer_ip}{$host_type}{$type}{$sort}{ip},
}});
}
}
# Can I connect to this machine? ### NOTE: Use '$anvil->Get->network({ip => "10.2.4.1", subnet => "255.255.0.0"});' with our IPs and this machines IPs to see if we're on the same subnet.
} }
# Sort through what we've found.
my $file_found = 0;
foreach my $host_type (sort {$a cmp $b} keys %{$anvil->data->{peer_ip}})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { host_type => $host_type }});
foreach my $type (sort {$a cmp $b} keys %{$anvil->data->{peer_ip}{$host_type}})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { type => $type }});
foreach my $sort (sort {$a cmp $b} keys %{$anvil->data->{peer_ip}{$host_type}{$type}})
{
my $ip = $anvil->data->{peer_ip}{$host_type}{$type}{$sort}{ip};
my $name = $anvil->data->{peer_ip}{$host_type}{$type}{$sort}{name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:sort' => $sort,
's2:name' => $name,
's3:ip' => $ip,
}});
}
}
}
die;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
target => $target,
port => $port,
password => $anvil->Log->secure ? $password : $anvil->Words->string({key => "log_0186"}),
}});
die;
return($target, $port, $password); return($target, $port, $password);
} }
@ -505,11 +623,11 @@ WHERE
"; ";
if ($file_md5sum) if ($file_md5sum)
{ {
$query .= " file_md5sum = ".$anvil->data->{sys}{database}{use_handle}->quote($file_md5sum)."\n"; $query .= " file_md5sum = ".$anvil->Database->quote($file_md5sum)."\n";
} }
elsif ($file_name) elsif ($file_name)
{ {
$query .= " file_name = ".$anvil->data->{sys}{database}{use_handle}->quote($file_name)."\n"; $query .= " file_name = ".$anvil->Database->quote($file_name)."\n";
} }
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results}; my $count = @{$results};
@ -603,7 +721,7 @@ SELECT
FROM FROM
files files
WHERE WHERE
file_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($file_uuid)." file_uuid = ".$anvil->Database->quote($file_uuid)."
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});

@ -451,7 +451,7 @@ SELECT
FROM FROM
bonds bonds
WHERE WHERE
bond_host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->host_uuid)." bond_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
AND AND
bond_mode != 'DELETED' bond_mode != 'DELETED'
;"; ;";
@ -497,7 +497,7 @@ AND
if ((not exists $anvil->data->{seen}{bond}{$bond_name}) or (not $anvil->data->{seen}{bond}{$bond_name})) if ((not exists $anvil->data->{seen}{bond}{$bond_name}) or (not $anvil->data->{seen}{bond}{$bond_name}))
{ {
# Mark it as deleted. # Mark it as deleted.
my $query = "UPDATE bonds SET bond_mode = 'DELETED' WHERE bond_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($bond_uuid).";"; my $query = "UPDATE bonds SET bond_mode = 'DELETED' WHERE bond_uuid = ".$anvil->Database->quote($bond_uuid).";";
$anvil->Database->write({debug => 2, query => $query, source => $THIS_FILE, line => __LINE__}); $anvil->Database->write({debug => 2, query => $query, source => $THIS_FILE, line => __LINE__});
# Remove it from the hash so we don't add it to the .json and .xml files. # Remove it from the hash so we don't add it to the .json and .xml files.
@ -514,7 +514,7 @@ SELECT
FROM FROM
bridges bridges
WHERE WHERE
bridge_host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->host_uuid)." bridge_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
AND AND
bridge_id != 'DELETED' bridge_id != 'DELETED'
;"; ;";
@ -544,7 +544,7 @@ AND
if ((not exists $anvil->data->{seen}{bridge}{$bridge_name}) or (not $anvil->data->{seen}{bridge}{$bridge_name})) if ((not exists $anvil->data->{seen}{bridge}{$bridge_name}) or (not $anvil->data->{seen}{bridge}{$bridge_name}))
{ {
# Mark it as deleted. # Mark it as deleted.
my $query = "UPDATE bridges SET bridge_id = 'DELETED' WHERE bridge_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($bridge_uuid).";"; my $query = "UPDATE bridges SET bridge_id = 'DELETED' WHERE bridge_uuid = ".$anvil->Database->quote($bridge_uuid).";";
$anvil->Database->write({debug => 2, query => $query, source => $THIS_FILE, line => __LINE__}); $anvil->Database->write({debug => 2, query => $query, source => $THIS_FILE, line => __LINE__});
# Remove it from the hash so we don't add it to the .json and .xml files. # Remove it from the hash so we don't add it to the .json and .xml files.
@ -568,7 +568,7 @@ SELECT
FROM FROM
network_interfaces network_interfaces
WHERE WHERE
network_interface_host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->host_uuid)." network_interface_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
AND AND
network_interface_operational != 'DELETED' network_interface_operational != 'DELETED'
ORDER BY ORDER BY
@ -621,7 +621,7 @@ ORDER BY
if ((not exists $anvil->data->{seen}{interface}{$network_interface_name}) or (not $anvil->data->{seen}{interface}{$network_interface_name})) if ((not exists $anvil->data->{seen}{interface}{$network_interface_name}) or (not $anvil->data->{seen}{interface}{$network_interface_name}))
{ {
# Mark it as deleted. # Mark it as deleted.
my $query = "UPDATE network_interfaces SET network_interface_operational = 'DELETED' WHERE network_interface_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($network_interface_uuid).";"; my $query = "UPDATE network_interfaces SET network_interface_operational = 'DELETED' WHERE network_interface_uuid = ".$anvil->Database->quote($network_interface_uuid).";";
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); $anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
# Remove it from the hash so we don't add it to the .json and .xml files. # Remove it from the hash so we don't add it to the .json and .xml files.
@ -667,7 +667,7 @@ SELECT
FROM FROM
ip_addresses ip_addresses
WHERE WHERE
ip_address_host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->host_uuid)." ip_address_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
AND AND
ip_address_on_type != 'DELETED' ip_address_on_type != 'DELETED'
;"; ;";
@ -741,7 +741,7 @@ WHERE
else else
{ {
# Stale, mark it as deleted. # Stale, mark it as deleted.
my $query = "UPDATE ip_addresses SET ip_address_on_type = 'DELETED' WHERE ip_address_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($ip_address_uuid).";"; my $query = "UPDATE ip_addresses SET ip_address_on_type = 'DELETED' WHERE ip_address_uuid = ".$anvil->Database->quote($ip_address_uuid).";";
$anvil->Database->write({debug => 2, query => $query, source => $THIS_FILE, line => __LINE__}); $anvil->Database->write({debug => 2, query => $query, source => $THIS_FILE, line => __LINE__});
} }
} }

@ -802,7 +802,7 @@ LIKE
AND AND
variable_source_table = 'hosts' variable_source_table = 'hosts'
AND AND
variable_source_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->host_uuid)." variable_source_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }});

@ -226,7 +226,7 @@ sub process_entry
if ($anvil->data->{sys}{database}{connections}) if ($anvil->data->{sys}{database}{connections})
{ {
# See if the password is in job_data. # See if the password is in job_data.
my $query = "SELECT job_data FROM jobs WHERE job_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($job_uuid).";"; my $query = "SELECT job_data FROM jobs WHERE job_uuid = ".$anvil->Database->quote($job_uuid).";";
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results}; my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
@ -575,7 +575,7 @@ sub process_entry
until($host_seen) until($host_seen)
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0212"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0212"});
my $query = "SELECT host_name FROM hosts WHERE host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($host_uuid).";"; my $query = "SELECT host_name FROM hosts WHERE host_uuid = ".$anvil->Database->quote($host_uuid).";";
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results}; my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {

Loading…
Cancel
Save