* More progress on managing/removing back keys. Updated it to have jobs list one or more state_uuid(s) to be removed, instead of bulk-removing all found back keys. Created the web interface to let the user select the keys to be deleted. Works partially now, but bugs need to be removed.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 5 years ago
parent 566ec896ca
commit 6bca354d87
  1. 135
      cgi-bin/striker
  2. 9
      html/skins/alteeve/main.css
  3. 97
      html/skins/alteeve/striker.html
  4. 23
      share/words.xml
  5. 444
      tools/anvil-manage-keys

@ -500,39 +500,60 @@ sub process_keys
### TODO: Left off here... Create a check-box list of state_uuid(s) the user selected, if any, and store them as a comma-separated list.
### NOTE: This doesn't update Striker (the Alteeve) stack yet, just the base OK.
$anvil->data->{cgi}{confirm}{value} = "" if not defined $anvil->data->{cgi}{confirm}{value};
if ($anvil->data->{cgi}{confirm}{value})
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 = "";
foreach my $key (sort {$a cmp $b} keys %{$anvil->data->{cgi}})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { key => $key }});
if ($key =~ /^state_uuid_(.*)$/)
{
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,
}});
}
}
$job_data =~ s/,$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_data => $job_data }});
if ($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'},
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 }});
die;
my ($job_uuid) = $anvil->Database->insert_or_update_jobs({
file => $THIS_FILE,
line => __LINE__,
job_command => $anvil->data->{path}{exe}{'anvil-manage-keys'},
job_data => "",
job_name => "manage::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 }});
# 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 => "",
reload_url => "/cgi-bin/".$THIS_FILE,
title => "#!string!job_0056!#",
description => "#!string!job_0057!#",
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "form::body" => $anvil->data->{form}{body} }});
# 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 => "",
reload_url => "/cgi-bin/".$THIS_FILE,
title => "#!string!job_0056!#",
description => "#!string!job_0057!#",
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "form::body" => $anvil->data->{form}{body} }});
}
}
else
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { show_list => $show_list }});
if ($show_list)
{
# Get a list of bad keys we know about and ask the user which they want to remove
my $query = "
@ -543,7 +564,7 @@ SELECT
state_note
FROM
states
AND
WHERE
state_name LIKE 'host_key_changed::%'
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
@ -575,16 +596,58 @@ AND
state_name => $state_name,
state_note => $state_note,
}});
my $bad_file = "";
my $bad_line = "";
foreach my $pair (split/,/, $state_note)
{
my ($variable, $value) = ($pair =~ /^(.*?)=(.*)$/);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
pair => $pair,
variable => $variable,
value => $value,
}});
if ($variable eq "file")
{
$bad_file = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bad_file => $bad_file }});
}
if ($variable eq "line")
{
$bad_line = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bad_line => $bad_line }});
}
}
my ($target, $user) = ($state_name =~ /host_key_changed::(.*)::(.*)$/);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
target => $target,
user => $user,
bad_file => $bad_file,
bad_line => $bad_line,
}});
my $checkbox_key = "state_uuid_".$state_uuid;
my $checked = "";
if ((exists $anvil->data->{cgi}{$checkbox_key}) && ($anvil->data->{cgi}{$checkbox_key}{value}))
{
$checked = "checked";
}
$bad_key_list .= $anvil->Template->get({file => "striker.html", name => "broken-key-entry", variables => {
checkbox_name => $checkbox_key,
checkbox_checked => $checked,
target => $target,
user => $user,
file => $bad_file,
line => $bad_line,
}});
}
}
die;
#Show the screen the confirm the addition.
$anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "confirm-action", variables => {
title => "#!string!job_0056!#",
message => "#!string!!#",
hidden_fields => "",
}});
#Show the screen the confirm the addition.
$anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "broken-key-list", variables => {
bad_keys => $bad_key_list,
}});
}
}
return(0);

@ -15,6 +15,9 @@ a {
color: #f2f2f2;
text-decoration: none;
}
a.highlight {
color: #ff80ee;
}
body {
font-family: 'Dejavu Sans', Arial, Helvetica, Verdana, Sans-Serif;
@ -367,3 +370,9 @@ tr.data_row {
text-align: left;
font-size: 0.9em;
}
.warning {
color: #dc9012;
font-size: 1.1em;
font-weight: bold;
}

@ -1,3 +1,96 @@
<!-- start broken-key-entry -->
<tr>
<td>
<input type="checkbox" id="#!variable!checkbox_name!#" name="#!variable!checkbox_name!#" #!variable!checkbox_checked!# />
</td>
<td class="column_row_value_fixed">
#!variable!user!#
</td>
<td class="column_row_value_fixed">
#!variable!target!#
</td>
<td class="column_row_value_fixed">
#!variable!file!#
</td>
<td class="column_row_value_fixed">
#!variable!line!#
</td>
</tr>
<!-- end broken-key-entry -->
<!-- start broken-key-list -->
<table align="center">
<tr>
<td class="menu_title">
#!string!striker_0133!#
</td>
</tr>
<tr>
<td class="menu_details">
#!string!striker_0137!#
</td>
</tr>
<tr>
<td>
&nbsp;
</td>
</tr>
<tr>
<td align="center">
<table class="data_table">
<form name="broken_keys" action="" method="post">
<tr>
<td>
&nbsp;
</td>
<!-- User -->
<td class="column_header">
#!string!header_0013!#
</td>
</td>
<!-- Target -->
<td class="column_header">
#!string!header_0012!#
</td>
<!-- File -->
<td class="column_header">
#!string!header_0014!#
</td>
<!-- Line -->
<td class="column_header">
#!string!header_0015!#
</td>
</tr>
<tr>
<td colspan="5">
&nbsp;
</td>
</tr>
#!variable!bad_keys!#
<tr>
<td colspan="5">
&nbsp;
</td>
</tr>
<tr>
<td class="button_cell" colspan="5" align="center">
<input type="submit" id="delete" name="delete" class="button" value="#!string!striker_0068!#" />
</td>
</tr>
<input type="hidden" name="striker" value="true" />
<input type="hidden" name="task" value="keys" />
</form>
</table>
</td>
</tr>
<tr>
<td>
&nbsp;
</td>
</tr>
</table>
<!-- end broken-key-list -->
<!-- start confirm-action -->
<table align="center">
<form name="confirm-update" action="" method="post">
@ -446,12 +539,12 @@
<table align="center">
<tr>
<td class="menu_title">
Add or remove Striker peers.
#!string!striker_0135!#
</td>
</tr>
<tr>
<td class="menu_details">
Peer dashboards are Striker machines whose databases this Striker will use to record data. If this machine ever needs to be replaced, or goes offline for a period of time, it will automatically pull the data back from any peers that it is missing.
#!string!striker_0136!#
</td>
</tr>
<tr>

@ -800,6 +800,10 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st
<key name="header_0009">Peer Connections</key>
<key name="header_0010">Ping</key>
<key name="header_0011">Jobs</key>
<key name="header_0012">Target</key>
<key name="header_0013">User</key>
<key name="header_0014">File</key>
<key name="header_0015">Line</key>
<!-- General strings shown in Striker -->
<key name="striker_0001">Welcome! Lets setup your #!string!brand_0003!# dashboard...</key>
@ -936,6 +940,15 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st
<key name="striker_0132">There are one or more broken keys, blocking access to target machines. If a target has been rebuilt, you can clear the old keys here.</key>
<key name="striker_0133">Manage Changed Keys</key>
<key name="striker_0134">There are no known bad keys at this time.</key>
<key name="striker_0135">Add or remove Striker peers.</key>
<key name="striker_0136">Peer dashboards are Striker machines whose databases this Striker will use to record data. If this machine ever needs to be replaced, or goes offline for a period of time, it will automatically pull the data back from any peers that it is missing.</key>
<key name="striker_0137"><![CDATA[
The machines responding when we try to connect to the targets below are responding with a different "fingerprint". This indicates that the target is no longer the machine we saw before.<br />
<br />
<span class="warning">Warning</span>: If you haven't rebuilt the target, then the "broken key" could actually be a "<a href="https://en.wikipedia.org/wiki/Man-in-the-middle_attack" target="_new" class="highlight">man in the middle<a/>" attack. Verify that the target has changed for a known reason before proceeding!<br />
<br />
If you are comfortable that the target has changed for a known reason, you can select the broken keys below to have them removed.<br />
]]></key>
<!-- These are generally units and appended to numbers -->
<key name="suffix_0001">#!variable!number!#/sec</key>
@ -1011,7 +1024,10 @@ Failure! The return code: [#!variable!return_code!#] was received ('0' was expec
<key name="job_0054">[ Error ] - The line number: [#!variable!line!#] in: [#!variable!file!#] does not appear to be for the target: [#!variable!target!#]. Has the file already been updated? Skipping it.</key>
<key name="job_0055">Rewriing: [#!variable!file!#].</key>
<key name="job_0056">Manage Keys</key>
<key name="job_0057">The bad keys will be removed from the specified files.</key>
<key name="job_0057">The selected bad key(s) will be removed from the specified files.</key>
<key name="job_0058">The state UUID: [#!variable!state_uuid!#] is for the machine with the host UUID: [#!variable!host_uuid!#], which is not us. This is probably a progrem error, skipping this.</key>
<key name="job_0059">[ Error ] - There was a problem writing the file: [#!variable!file!#]. Details will be found in the logs.</key>
<key name="job_0060">Success! The file: [#!variable!file!#] has been updated.</key>
<!-- Warnings -->
<key name="striker_warning_0001">The IP address will change. You will need to reconnect after applying these changes.</key>
@ -1122,6 +1138,11 @@ Failed to generate an RSA public key for the user: [#!variable!user!#]. The outp
<key name="error_0076">There was a problem adding out database to the target's anvil.conf file.</key>
<key name="error_0077">Unable to connect to the database, unable to read the details of the key to remove.</key>
<key name="error_0078">Did not find any offending keys on this host, exiting.</key>
<key name="error_0079">Job data not found for job_uuid: [#!variable!job_uuid!#].</key>
<key name="error_0080">No job UUID was passwed .</key>
<key name="error_0081">The job_uuid: [#!variable!job_uuid!#] appears valid, but there was no job_data.</key>
<key name="error_0082">The state UUID: [#!variable!state_uuid!#] does not appear to be a valid UUID.</key>
<key name="error_0083">No (good) state UUIDs found, unable to run this job.</key>
<!-- These are units, words and so on used when displaying information. -->
<key name="unit_0001">Yes</key>

@ -8,8 +8,8 @@
# Exit codes;
# 0 = Normal exit.
# 1 = No database connection.
# 2 = No offending keys found.
# 3 =
# 2 = Job not found.
# 3 = No offending keys found.
#
use strict;
@ -46,186 +46,314 @@ if (not $anvil->data->{sys}{database}{connections})
$anvil->nice_exit({exit_code => 1});
}
### TODO: Store the state_uuid(s) of the key(s) to remove.
# If we don't have a state_uuid, pick it up from the job_data
# Pick up the job details
$anvil->data->{switches}{'job-uuid'} = "";
$anvil->Get->switches;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'switches::job-uuid' => $anvil->data->{switches}{'job-uuid'},
}});
# Load data.
load_job_data($anvil);
# Process the bad keys
process_keys($anvil);
# Done.
update_progress($anvil, 100, "job_0051");
$anvil->nice_exit({code => 0});
#############################################################################################################
# Functions #
#############################################################################################################
sub process_keys
{
my ($anvil) = @_;
# Read in the details and make sure the bad the bad key is on our system.
my $query = "SELECT
state_uuid,
foreach my $state_uuid (@{$anvil->data->{state_uuids}})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { state_uuid => $state_uuid }});
my $query = "
SELECT
state_host_uuid,
state_name,
state_note
FROM
states
WHERE
state_host_uuid = ".$anvil->Database->quote($anvil->data->{sys}{host_uuid})."
AND
state_name LIKE 'host_key_changed::%'
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)
{
# No bad keys found on this host.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0078"});
sleep 10;
$anvil->nice_exit({exit_code => 2});
}
my $progress = 0;
update_progress($anvil, 0, "clear");
$progress += 5;
update_progress($anvil, $progress, "job_0048");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0048"});
foreach my $row (@{$results})
{
my $state_uuid = $row->[0];
my $state_name = $row->[1];
my $state_note = $row->[2];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
state_uuid => $state_uuid,
state_name => $state_name,
state_note => $state_note,
}});
# Pull out the details.
my $bad_file = "";
my $bad_line = "";
foreach my $pair (split/,/, $state_note)
{
my ($variable, $value) = ($pair =~ /^(.*?)=(.*)$/);
$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 => {
pair => $pair,
variable => $variable,
value => $value,
results => $results,
count => $count,
}});
if ($variable eq "file")
if (not $count)
{
$bad_file = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bad_file => $bad_file }});
# No bad keys found on this host.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0078"});
sleep 10;
$anvil->nice_exit({exit_code => 2});
}
if ($variable eq "line")
foreach my $row (@{$results})
{
$bad_line = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bad_line => $bad_line }});
}
}
my ($target, $user) = ($state_name =~ /host_key_changed::(.*)::(.*)$/);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
target => $target,
user => $user,
bad_file => $bad_file,
bad_line => $bad_line,
}});
$progress += 5; $progress = 95 if $progress > 95;
update_progress($anvil, $progress, "job_0049,!!line!:".$bad_line.",!!file!".$bad_file."!!,!!target!".$target."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0049", variables => {
line => $bad_line,
file => $bad_file,
target => $target,
}});
my $state_host_uuid = $row->[0];
my $state_name = $row->[1];
my $state_note = $row->[2];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:sys::host_uuid' => $anvil->data->{sys}{host_uuid},
's2:state_host_uuid' => $state_host_uuid,
's3:state_name' => $state_name,
's4:state_note' => $state_note,
}});
# Read in the file, if it exists.
if (not -e $bad_file)
{
$progress += 10; $progress = 95 if $progress > 95;
update_progress($anvil, $progress, "job_0050,!!file!".$bad_file."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0050", variables => { file => $bad_file }});
# Is this meant for us?
if ($state_host_uuid ne $anvil->data->{sys}{host_uuid})
{
# Um...
$anvil->data->{job}{progress} += 10; $anvil->data->{job}{progress} = 95 if $anvil->data->{job}{progress} > 95;
update_progress($anvil, $anvil->data->{job}{progress}, "job_0058,!!state_uuid!".$state_uuid."!!,!!host_uuid!".$state_host_uuid."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0058", variables => {
state_uuid => $state_uuid,
host_uuid => $state_host_uuid,
}});
next;
}
# Remove this job and go on to the next bad key (if any).
delete_state($anvil, $state_uuid);
next;
}
# Pull out the details.
my $bad_file = "";
my $bad_line = "";
foreach my $pair (split/,/, $state_note)
{
my ($variable, $value) = ($pair =~ /^(.*?)=(.*)$/);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
pair => $pair,
variable => $variable,
value => $value,
}});
if ($variable eq "file")
{
$bad_file = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bad_file => $bad_file }});
}
if ($variable eq "line")
{
$bad_line = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bad_line => $bad_line }});
}
}
my ($target, $user) = ($state_name =~ /host_key_changed::(.*)::(.*)$/);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
target => $target,
user => $user,
bad_file => $bad_file,
bad_line => $bad_line,
}});
# Read in the file
my ($old_body) = $anvil->Storage->read_file({file => $bad_file});
if ($old_body eq "!!error!!")
{
# Failed to read the file
$progress += 10; $progress = 95 if $progress > 95;
update_progress($anvil, $progress, "job_0052,!!file!".$bad_file."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0052", variables => { file => $bad_file }});
# Remove this job and go on to the next bad key (if any).
delete_state($anvil, $state_uuid);
next;
}
$anvil->data->{job}{progress} += 5; $anvil->data->{job}{progress} = 95 if $anvil->data->{job}{progress} > 95;
update_progress($anvil, $anvil->data->{job}{progress}, "job_0049,!!line!:".$bad_line.",!!file!".$bad_file."!!,!!target!".$target."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0049", variables => {
line => $bad_line,
file => $bad_file,
target => $target,
}});
# Find our key
my $line_number = 0;
my $new_body = "";
my $update = 0;
foreach my $line (split/\n/, $old_body)
{
$line_number++;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:line_number' => $line_number,
's2:bad_line' => $bad_line,
's3:line' => $line,
}});
if ($line_number eq $bad_line)
{
# Verify that this is, indeed, the right line.
if ($line =~ /^$target /)
# Read in the file, if it exists.
if (not -e $bad_file)
{
# Found it!
$progress += 5; $progress = 95 if $progress > 95;
update_progress($anvil, $progress, "job_0053");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0053"});
$update = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { update => $update }});
last;
$anvil->data->{job}{progress} += 10; $anvil->data->{job}{progress} = 95 if $anvil->data->{job}{progress} > 95;
update_progress($anvil, $anvil->data->{job}{progress}, "job_0050,!!file!".$bad_file."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0050", variables => { file => $bad_file }});
# Remove this job and go on to the next bad key (if any).
delete_state($anvil, $state_uuid);
next;
}
else
# Read in the file
my ($old_body) = $anvil->Storage->read_file({file => $bad_file});
if ($old_body eq "!!error!!")
{
# Line found, but not for the target.
$progress += 10; $progress = 95 if $progress > 95;
update_progress($anvil, $progress, "job_0054,!!line!".$bad_line."!!,!!file!".$bad_file."!!,!!target!".$target."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0054", variables => {
line => $bad_line,
file => $bad_file,
target => $target,
}});
# Failed to read the file
$anvil->data->{job}{progress} += 10; $anvil->data->{job}{progress} = 95 if $anvil->data->{job}{progress} > 95;
update_progress($anvil, $anvil->data->{job}{progress}, "job_0052,!!file!".$bad_file."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0052", variables => { file => $bad_file }});
# Remove this job and go on to the next bad key (if any).
delete_state($anvil, $state_uuid);
last;
next;
}
# Find our key
my $line_number = 0;
my $new_body = "";
my $update = 0;
foreach my $line (split/\n/, $old_body)
{
$line_number++;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:line_number' => $line_number,
's2:bad_line' => $bad_line,
's3:line' => $line,
}});
if ($line_number eq $bad_line)
{
# Verify that this is, indeed, the right line.
if ($line =~ /^$target /)
{
# Found it!
$anvil->data->{job}{progress} += 5; $anvil->data->{job}{progress} = 95 if $anvil->data->{job}{progress} > 95;
update_progress($anvil, $anvil->data->{job}{progress}, "job_0053");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0053"});
$update = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { update => $update }});
}
else
{
# Line found, but not for the target.
$anvil->data->{job}{progress} += 10; $anvil->data->{job}{progress} = 95 if $anvil->data->{job}{progress} > 95;
update_progress($anvil, $anvil->data->{job}{progress}, "job_0054,!!line!".$bad_line."!!,!!file!".$bad_file."!!,!!target!".$target."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0054", variables => {
line => $bad_line,
file => $bad_file,
target => $target,
}});
# Remove this job and go on to the next bad key (if any).
delete_state($anvil, $state_uuid);
last;
}
}
else
{
$new_body .= $line."\n";
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:old_body' => $old_body,
's2:new_body' => $new_body,
's3:update' => $update,
}});
if ($update)
{
# Write the file out.
$anvil->data->{job}{progress} += 5; $anvil->data->{job}{progress} = 95 if $anvil->data->{job}{progress} > 95;
update_progress($anvil, $anvil->data->{job}{progress}, "job_0055,!!file!".$bad_file."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0055", variables => { file => $bad_file }});
my $error = $anvil->Storage->write_file({
body => $new_body,
debug => 2,
file => $bad_file,
overwrite => 1,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, list => { error => $error }});
if ($error)
{
$anvil->data->{job}{progress} += 5; $anvil->data->{job}{progress} = 95 if $anvil->data->{job}{progress} > 95;
update_progress($anvil, $anvil->data->{job}{progress}, "job_0059,!!file!".$bad_file."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0059", variables => { file => $bad_file }});
}
else
{
# Success!
delete_state($anvil, $state_uuid);
$anvil->data->{job}{progress} += 5; $anvil->data->{job}{progress} = 95 if $anvil->data->{job}{progress} > 95;
update_progress($anvil, $anvil->data->{job}{progress}, "job_0060,!!file!".$bad_file."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0060", variables => { file => $bad_file }});
}
}
}
else
{
$new_body .= $line."\n";
}
}
return(0);
}
# Load the job data or exit
sub load_job_data
{
my ($anvil) = @_;
if (not $anvil->data->{switches}{'job-uuid'})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0080"});
$anvil->nice_exit({exit_code => 1});
}
my $query = "SELECT job_data FROM jobs WHERE job_uuid = ".$anvil->Database->quote($anvil->data->{switches}{'job-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 => {
's1:old_body' => $old_body',
's2:new_body' => $new_body,
's3:update' => $update,
results => $results,
count => $count,
}});
if ($update)
if (not $count)
{
# Write the file out.
$progress += 5; $progress = 95 if $progress > 95;
update_progress($anvil, $progress, "job_0055,!!file!".$bad_file."!!");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0055", variables => { file => $bad_file }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0079", variables => {
job_uuid => $anvil->data->{switches}{'job-uuid'},
}});
$anvil->nice_exit({exit_code => 1});
}
}
# Pick up the data.
my $job_data = $results->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_data => $job_data }});
if (not $job_data)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0081", variables => {
job_uuid => $anvil->data->{switches}{'job-uuid'},
}});
$anvil->nice_exit({exit_code => 1});
}
# Done.
update_progress($anvil, 100, "job_0051");
$anvil->nice_exit({code => 0});
# Pick up the job.
$anvil->data->{job}{progress} = 0;
update_progress($anvil, 0, "clear");
$anvil->data->{job}{progress} += 5;
update_progress($anvil, $anvil->data->{job}{progress}, "job_0048");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0048"});
#############################################################################################################
# Functions #
#############################################################################################################
# Break the job up.
$anvil->data->{state_uuids} = [];
foreach my $state_uuid (split/,/, $job_data)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { state_uuid => $state_uuid }});
if ($anvil->Validate->is_uuid({uuid => $state_uuid}))
{
push @{$anvil->data->{state_uuids}}, $state_uuid;
}
else
{
# Invalid, skip it.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0082", variables => {
state_uuid => $state_uuid,
}});
}
}
my $uuid_count = @{$anvil->data->{state_uuids}};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { uuid_count => $uuid_count }});
# Did I find any actual UUIDs?
if (not $uuid_count)
{
# Nope.
update_progress($anvil, 100, "error_0083");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "error_0083"});
}
return(0);
}
# This deletes a state entry.
sub delete_state
@ -236,7 +364,7 @@ sub delete_state
if ($state_uuid)
{
my $query = "DELETE FROM states WHERE state_uuid = ".$anvil->Database->quote($state_uuid).";";
$anvil->Database->write({debug => 2, query => $merged, source => $THIS_FILE, line => __LINE__});
$anvil->Database->write({debug => 2, query => $query, source => $THIS_FILE, line => __LINE__});
}
return(0);
@ -249,20 +377,16 @@ sub update_progress
# Log the progress percentage.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
progress => $progress,
message => $message,
"jobs::job_uuid" => $anvil->data->{jobs}{job_uuid},
progress => $progress,
message => $message,
}});
if ($anvil->data->{jobs}{job_uuid})
{
$anvil->Job->update_progress({
debug => 3,
progress => $progress,
message => $message,
job_uuid => $anvil->data->{jobs}{job_uuid},
});
}
$anvil->Job->update_progress({
debug => 3,
progress => $progress,
message => $message,
job_uuid => $anvil->data->{switches}{'job-uuid'},
});
return(0);
}

Loading…
Cancel
Save