From e15c1651edb7f032233263a83c6f962e0dfa27f5 Mon Sep 17 00:00:00 2001 From: Digimer Date: Sat, 5 Jun 2021 19:07:25 -0400 Subject: [PATCH] * Fixed a bug with deleting bad keys where jobs to delete keys on non-dashboard machine wasn't being assigned to the proper target machine. * Fixed a bug with anvil-manage-keys where a state_uuid entry recorded on one database may not be read from a machine reading from another database. Signed-off-by: Digimer --- cgi-bin/striker | 71 +++++++++++++++++++++++++++++------------ tools/anvil-manage-keys | 30 +++++++++++------ 2 files changed, 71 insertions(+), 30 deletions(-) diff --git a/cgi-bin/striker b/cgi-bin/striker index 9358960d..455b76f5 100755 --- a/cgi-bin/striker +++ b/cgi-bin/striker @@ -1282,13 +1282,13 @@ sub process_keys { my ($anvil) = @_; - ### NOTE: This doesn't update Striker (the Alteeve) stack yet, just the base OK. + ### NOTE: This doesn't update Striker (the Alteeve) stack yet, just the base OS. my $show_list = 1; $anvil->data->{cgi}{'delete'}{value} = "" if not defined $anvil->data->{cgi}{'delete'}{value}; if ($anvil->data->{cgi}{'delete'}{value}) { # Record the job! - my $job_data = ""; + my $job_data = {}; foreach my $key (sort {$a cmp $b} keys %{$anvil->data->{cgi}}) { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { key => $key }}); @@ -1296,34 +1296,63 @@ sub process_keys { my $state_uuid = $1; $show_list = 0; - $job_data .= $state_uuid.","; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { state_uuid => $state_uuid, show_list => $show_list, - job_data => $job_data, + }}); + + my $query = "SELECT state_host_uuid FROM states WHERE state_uuid = ".$anvil->Database->quote($state_uuid).";"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); + + my $host_uuid = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0]; + $host_uuid = "" if not defined $host_uuid; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { host_uuid => $host_uuid }}); + next if not $host_uuid; + + if (not exists $job_data->{$host_uuid}) + { + $job_data->{$host_uuid} = ""; + } + $job_data->{$host_uuid} .= $state_uuid.","; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + "job_data->{$host_uuid}" => $job_data->{$host_uuid}, }}); } } - $job_data =~ s/,$//; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_data => $job_data }}); - if ($job_data) + my $show_template = 0; + foreach my $host_uuid (keys %{$job_data}) { - my ($job_uuid) = $anvil->Database->insert_or_update_jobs({ - file => $THIS_FILE, - line => __LINE__, - job_command => $anvil->data->{path}{exe}{'anvil-manage-keys'}.$anvil->Log->switches, - job_data => $job_data, - job_name => "manage::broken_keys", - job_title => "job_0056", - job_description => "job_0057", - job_progress => 0, - job_host_uuid => $anvil->data->{sys}{host_uuid}, - }); - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }}); + $job_data->{$host_uuid} =~ s/,$//; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + "job_data->{$host_uuid}" => $job_data->{$host_uuid}, + }}); - # We don't need to store anything as hidden variables, we'll read it back from the database - # later. + if ($job_data->{$host_uuid}) + { + $show_template = 1; + my ($job_uuid) = $anvil->Database->insert_or_update_jobs({ + file => $THIS_FILE, + line => __LINE__, + job_command => $anvil->data->{path}{exe}{'anvil-manage-keys'}.$anvil->Log->switches, + job_data => $job_data->{$host_uuid}, + job_name => "manage::broken_keys", + job_title => "job_0056", + job_description => "job_0057", + job_progress => 0, + job_host_uuid => $host_uuid, + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + show_template => $show_template, + job_uuid => $job_uuid, + }}); + } + } + + if ($show_template) + { + # We don't need to store anything as hidden variables, we'll read it back from the + # database later. $anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "job recorded", variables => { title_id => "", message_id => "", diff --git a/tools/anvil-manage-keys b/tools/anvil-manage-keys index e091a965..d9b7e752 100755 --- a/tools/anvil-manage-keys +++ b/tools/anvil-manage-keys @@ -41,8 +41,8 @@ $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list 'switches::job-uuid' => $anvil->data->{switches}{'job-uuid'}, }}); -$anvil->Database->connect(); -$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"}); +$anvil->Database->connect({check_for_resync => 1}); +$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"}); if (not $anvil->data->{sys}{database}{connections}) { # No databases, update the job, sleep for a bit and then exit. The daemon will pick it up and try @@ -85,13 +85,25 @@ WHERE state_uuid = ".$anvil->Database->quote($state_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, - }}); - if (not $count) + + # States aren't sync'ed, so we may need to check both/all DBs to find our data. + my $state_found = 0; + my $results = []; + foreach my $uuid (keys %{$anvil->data->{cache}{database_handle}}) + { + $results = $anvil->Database->query({uuid => $uuid, 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, + }}); + if ($count) + { + $state_found = 1; + last; + } + } + if (not $state_found) { # No bad keys found on this host. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0078"});