* Finished the web interface components of the Anvil! File Manager! Files can be purged, sync'ed or removed from specific Anvil! systems, renamed and their file types changed (and setting/removing the executable bits) as needed.

* Fixed a bug in Database->insert_or_update_jobs() where the 'job_host_uuid' being set to 'all' only translated to a job for the running host.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 4 years ago
parent 6da2b3b17b
commit 68ea6da1d3
  1. 7
      Anvil/Tools/Database.pm
  2. 2
      Anvil/Tools/Storage.pm
  3. 283
      cgi-bin/striker
  4. 2
      cgi-bin/upload.pl
  5. 21
      html/skins/alteeve/files.html
  6. 14
      html/skins/alteeve/main.css
  7. 28
      share/words.xml
  8. 274
      tools/anvil-sync-shared

@ -6337,7 +6337,7 @@ INSERT INTO
".$anvil->Database->quote($file_md5sum).",
".$anvil->Database->quote($file_type).",
".$anvil->Database->quote($file_mtime).",
".$anvil->Database->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 }});
@ -7470,9 +7470,10 @@ sub insert_or_update_jobs
host_name => $host_name,
}});
$host_name->{$host_uuid} = $anvil->Database->insert_or_update_jobs({
$job_uuids->{$host_uuid} = $anvil->Database->insert_or_update_jobs({
debug => $debug,
job_command => $job_command,
job_host_uuid => $host_uuid,
job_data => $job_data,
job_picked_up_by => $job_picked_up_by,
job_picked_up_at => $job_picked_up_at,
@ -7485,7 +7486,7 @@ sub insert_or_update_jobs
update_progress_only => $update_progress_only,
clear_status => $clear_status,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "host_name->{$host_uuid}" => $host_name->{$host_uuid} }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "job_uuids->{$host_uuid}" => $job_uuids->{$host_uuid} }});
}
return($job_uuids);

@ -338,7 +338,7 @@ Parameters;
=head3 mode (required)
This is the numeric mode to set on the file. It expects four digits to cover the sticky bit, but will work with three digits.
This is the numeric mode to set on the file. It expects four digits to cover the sticky bit, but will work with three digits. It also supports the C<< + >> and C<< - >> formats, like C<< a+x >> or C<< g-w >>.
=head3 path (required)

@ -1446,8 +1446,37 @@ sub process_file_change
$anvil->data->{cgi}{confirm}{value} = "";
# Are we being asked to purge a file?
$anvil->Database->get_anvils();
$anvil->Database->get_files();
$anvil->Database->get_file_locations();
my $file_uuid = $anvil->data->{cgi}{file_uuid}{value};
my $file_name = $anvil->data->{files}{file_uuid}{$file_uuid}{file_name};
my $file_type = $anvil->data->{files}{file_uuid}{$file_uuid}{file_type};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
file_uuid => $file_uuid,
file_name => $file_name,
file_type => $file_type,
}});
if ($anvil->data->{cgi}{purge}{value})
{
# Update the file to set the file type to 'DELETED'.
my $old_file_type = $anvil->data->{files}{file_uuid}{$file_uuid}{file_type};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { old_file_type => $old_file_type }});
if ($old_file_type ne "DELETED")
{
my $query = "
UPDATE
files
SET
file_type = 'DELETED',
modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
WHERE
file_uuid = ".$anvil->Database->quote($file_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
}
# Register jobs on all systems to remove this file.
$anvil->Database->insert_or_update_jobs({
debug => 2,
@ -1455,16 +1484,191 @@ sub process_file_change
line => __LINE__,
job_host_uuid => "all",
job_command => $anvil->data->{path}{exe}{'anvil-sync-shared'},
job_data => "file_uuid=".$anvil->data->{cgi}{file_uuid}{value},
job_data => "file_uuid=".$file_uuid,
job_name => "storage::purge",
job_title => "job_0136",
job_description => "job_0137",
job_progress => 0,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { node1_job_uuid => $node1_job_uuid }});
$anvil->data->{form}{ok_message} = $anvil->Template->get({file => "main.html", name => "ok_message", variables => { ok_message => "#!string!ok_0012!#" }});
}
else
{
### Nope, we're doing other things. Possibly multiple things.
# Did the file name change?
my $ok_messages = "";
if (($anvil->data->{cgi}{new_file_name}{value}) && ($anvil->data->{cgi}{new_file_name}{value} ne $file_name))
{
# Rename the file.
my $old_file_name = $anvil->data->{files}{file_uuid}{$file_uuid}{file_name};
my $new_file_name = $anvil->data->{cgi}{new_file_name}{value};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
old_file_name => $old_file_name,
new_file_name => $new_file_name,
}});
if ($old_file_name ne $new_file_name)
{
my $query = "
UPDATE
files
SET
file_name = ".$anvil->Database->quote($new_file_name).",
modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
WHERE
file_uuid = ".$anvil->Database->quote($file_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
}
$anvil->Database->insert_or_update_jobs({
debug => 2,
file => $THIS_FILE,
line => __LINE__,
job_host_uuid => "all",
job_command => $anvil->data->{path}{exe}{'anvil-sync-shared'},
job_data => "file_uuid=".$file_uuid."\nold_name=".$file_name."\nnew_name=".$anvil->data->{cgi}{new_file_name}{value},
job_name => "storage::rename",
job_title => "job_0138",
job_description => "job_0139",
job_progress => 0,
});
$ok_messages .= "#!string!ok_0013!# ";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ok_messages => $ok_messages }});
}
# Did the file type change?
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"cgi::new_file_type::value" => $anvil->data->{cgi}{new_file_type}{value},
file_type => $file_type,
}});
if (($anvil->data->{cgi}{new_file_type}{value}) && ($anvil->data->{cgi}{new_file_type}{value} ne $file_type))
{
# Easy peasy, update the DBey.
my $query = "
UPDATE
files
SET
file_type = ".$anvil->Database->quote($anvil->data->{cgi}{new_file_type}{value}).",
modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
WHERE
file_uuid = ".$anvil->Database->quote($file_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
# Register a job on all machines (that have this file) to set the mode.
$anvil->Database->insert_or_update_jobs({
debug => 2,
file => $THIS_FILE,
line => __LINE__,
job_host_uuid => "all",
job_command => $anvil->data->{path}{exe}{'anvil-sync-shared'},
job_data => "file_uuid=".$file_uuid,
job_name => "storage::check_mode",
job_title => "job_0143",
job_description => "job_0144",
job_progress => 0,
});
$ok_messages .= "#!string!ok_0014!# ";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ok_messages => $ok_messages }});
}
# Loop through the Anvil! systems and see if any have changed from sync to remove or vice
# versa.
foreach my $variable (sort {$a cmp $b} keys %{$anvil->data->{cgi}})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { variable => $variable }});
if ($variable =~ /anvil_uuid::(.*?)::sync/)
{
my $anvil_uuid = $1;
my $anvil_name = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_name};
my $sync_value = $anvil->data->{cgi}{$variable}{value};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
anvil_uuid => $anvil_uuid,
sync_value => $sync_value,
}});
# Coming from the CGI, sync will be 'true' or 'false', while the 'active'
# value from the database is '1' or '0'. We'll convert the database version
# for comparison versions.
my $file_location_uuid = $anvil->data->{file_locations}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_location_uuid};
my $old_file_location_active = $anvil->data->{file_locations}{file_location_uuid}{$file_location_uuid}{file_location_active} ? "true" : "falsa";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
file_location_uuid => $file_location_uuid,
old_file_location_active => $old_file_location_active,
}});
if ($sync_value ne $old_file_location_active)
{
# Update the database and create a job for the member nodes to purge
# the file.
my $new_active = "FALSE";
my $ok_key = "ok_0016";
my $job_type = "storage::purge";
my $job_title = "job_0136";
my $job_description = "job_0137";
if ($sync_value eq "true")
{
$new_active = "TRUE";
$ok_key = "ok_0015";
$job_type = "storage::pull_file";
$job_title = "job_0132";
$job_description = "job_0133";
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
new_active => $new_active,
ok_key => $ok_key,
job_type => $job_type,
job_title => $job_title,
job_description => $job_description,
}});
$ok_messages .= $anvil->Words->string({key => $ok_key, variables => { anvil_name => $anvil_name }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ok_messages => $ok_messages }});
my $query = "
UPDATE
file_locations
SET
file_location_active = ".$anvil->Database->quote($new_active).",
modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
WHERE
file_location_uuid = ".$anvil->Database->quote($file_location_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
# Now create a job for each Anvil! member.
my $member_uuids = [];
push @{$member_uuids}, $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid};
push @{$member_uuids}, $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node2_host_uuid};
if ($anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid})
{
push @{$member_uuids}, $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid};
}
foreach my $host_uuid (@{$member_uuids})
{
my $job_uuid = $anvil->Database->insert_or_update_jobs({
debug => 2,
file => $THIS_FILE,
line => __LINE__,
job_host_uuid => $host_uuid,
job_command => $anvil->data->{path}{exe}{'anvil-sync-shared'},
job_data => "file_uuid=".$file_uuid,
job_name => $job_type,
job_title => $job_title,
job_description => $job_description,
job_progress => 0,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }});
}
}
}
}
$anvil->data->{form}{ok_message} = $anvil->Template->get({file => "main.html", name => "ok_message", variables => { ok_message => $ok_messages }});
}
return(0);
}
@ -1474,21 +1678,30 @@ sub process_file_menu
{
my ($anvil) = @_;
$anvil->data->{form}{refresh_link} = "?files=true";
#$anvil->data->{form}{back_link} = "?striker=true";
$anvil->data->{cgi}{task}{value} = "" if not defined $anvil->data->{cgi}{task}{value};
$anvil->data->{cgi}{action}{value} = "" if not defined $anvil->data->{cgi}{action}{value};
$anvil->data->{cgi}{confirm}{value} = "" if not defined $anvil->data->{cgi}{confirm}{value};
$anvil->data->{cgi}{file_uuid}{value} = "" if not defined $anvil->data->{cgi}{file_uuid}{value};
$anvil->data->{cgi}{purge}{value} = "" if not defined $anvil->data->{cgi}{purge}{value};
$anvil->data->{cgi}{save}{value} = "" if not defined $anvil->data->{cgi}{save}{value};
$anvil->data->{cgi}{confirm}{value} = "" if not defined $anvil->data->{cgi}{confurm}{value};
$anvil->data->{cgi}{task}{value} = "" if not defined $anvil->data->{cgi}{task}{value};
$anvil->data->{form}{refresh_link} = "?files=true";
$anvil->Database->get_files();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"cgi::file_uuid::value" => $anvil->data->{cgi}{file_uuid}{value},
"cgi::save::value" => $anvil->data->{cgi}{save}{value},
"cgi::confirm::value" => $anvil->data->{cgi}{confirm}{value},
}});
if (($anvil->data->{cgi}{file_uuid}{value}) && ($anvil->data->{cgi}{save}{value}) && ($anvil->data->{cgi}{confirm}{value}))
{
process_file_change($anvil);
}
# (Re)load the data.
$anvil->Database->get_files();
$anvil->Database->get_file_locations();
# Build the list of existing files.
$anvil->Database->get_files();
my $file_list = $anvil->Template->get({file => "files.html", name => "open-file-list"});
foreach my $file_name (sort {$a cmp $b} keys %{$anvil->data->{files}{file_name}})
{
@ -1504,6 +1717,7 @@ sub process_file_menu
file_md5sum => $file_md5sum,
file_type => $file_type,
}});
$file_list .= $anvil->Template->get({file => "files.html", name => "file-list-entry", variables => {
file_uuid => $file_uuid,
file_name => $file_name,
@ -1516,7 +1730,7 @@ sub process_file_menu
{
$anvil->data->{form}{refresh_link} = "?files=true&file_uuid=".$anvil->data->{cgi}{file_uuid}{value};
$anvil->data->{form}{back_link} = "?files=true";
$anvil->data->{cgi}{new_file_name}{value} = "" if not defined $anvil->data->{cgi}{new_file_name}{value};
$anvil->data->{cgi}{new_file_name}{value} = $file_name if not defined $anvil->data->{cgi}{new_file_name}{value};
$anvil->data->{cgi}{new_file_name}{alert} = "" if not defined $anvil->data->{cgi}{new_file_name}{alert};
$anvil->data->{cgi}{new_file_type}{value} = $file_type if not defined $anvil->data->{cgi}{new_file_type}{value};
@ -1542,8 +1756,9 @@ sub process_file_menu
$anvil->Database->get_anvils();
$anvil->Database->get_file_locations();
my $say_confirm = "&nbsp;";
my $anvil_list = "";
my $say_save_confirm = "&nbsp;";
my $say_purge_confirm = "&nbsp;";
my $anvil_list = "";
if (not exists $anvil->data->{anvils}{anvil_name})
{
$anvil_list .= $anvil->Template->get({file => "files.html", name => "file-list-manager-no-anvils"});
@ -1556,17 +1771,32 @@ sub process_file_menu
my $anvil_description = $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_description};
my $file_location_uuid = $anvil->data->{file_locations}{anvil_uuid}{$anvil_uuid}{file_uuid}{$file_uuid}{file_location_uuid};
my $synced = $anvil->data->{file_locations}{file_location_uuid}{$file_location_uuid}{file_location_active};
my $radio_key = "anvil_uuid::".$anvil_uuid."::sync";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"s1:anvil_name" => $anvil_name,
"s2:anvil_uuid" => $anvil_uuid,
"s3:anvil_description" => $anvil_description,
"s4:file_location_uuid" => $file_location_uuid,
"s5:synced" => $synced,
"s6:radio_key" => $radio_key,
}});
$anvil->data->{cgi}{$radio_key}{value} = "" if not defined $anvil->data->{cgi}{$radio_key}{value};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"cgi::${radio_key}::value" => $anvil->data->{cgi}{$radio_key}{value},
}});
my $true_checked = "checked";
my $false_checked = "";
if (not $synced)
if ($anvil->data->{cgi}{$radio_key}{value})
{
if ($anvil->data->{cgi}{$radio_key}{value} eq "false")
{
$true_checked = "";
$false_checked = "checked";
}
}
elsif (not $synced)
{
$true_checked = "";
$false_checked = "checked";
@ -1576,16 +1806,24 @@ sub process_file_menu
"s2:false_checked" => $false_checked,
}});
if (($anvil->data->{cgi}{purge}{value}) && (not $anvil->data->{cgi}{confirm}{value}))
{
$say_purge_confirm = $anvil->Template->get({file => "files.html", name => "file-list-manager-confirm-purge-button", variables => {
url => "?files=true&file_uuid=".$file_uuid."&purge=true&&save=true&confirm=true",
}});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_save_confirm => $say_save_confirm }});
if (($anvil->data->{cgi}{save}{value}) && (not $anvil->data->{cgi}{confirm}{value}))
{
$say_confirm = $anvil->Template->get({file => "files.html", name => "file-list-manager-confirm-button"});
$say_save_confirm = $anvil->Template->get({file => "files.html", name => "file-list-manager-confirm-save-button"});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_confirm => $say_confirm }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_save_confirm => $say_save_confirm }});
$anvil_list .= $anvil->Template->get({file => "files.html", name => "file-list-manager-anvil-entry", variables => {
anvil_name => $anvil_name,
anvil_description => $anvil_description,
radio_name => "anvil_uuid::".$anvil_uuid."::sync",
radio_name => $radio_key,
true_checked => $true_checked,
false_checked => $false_checked,
}});
@ -1594,12 +1832,13 @@ sub process_file_menu
# Insert the file management section under the file entry.
$file_list .= $anvil->Template->get({file => "files.html", name => "file-list-manager", variables => {
file_uuid => $file_uuid,
new_file_name => $anvil->data->{cgi}{new_file_name}{value},
new_file_type => $select_file_type,
confirm_button => $say_confirm,
new_file_name_class => $anvil->data->{cgi}{new_file_name}{alert} ? "input_alert_fixed" : "input_clear_fixed",
anvil_list => $anvil_list,
file_uuid => $file_uuid,
new_file_name => $anvil->data->{cgi}{new_file_name}{value},
new_file_type => $select_file_type,
confirm_save_button => $say_save_confirm,
confirm_purge_button => $say_purge_confirm,
new_file_name_class => $anvil->data->{cgi}{new_file_name}{alert} ? "input_alert_fixed" : "input_clear_fixed",
anvil_list => $anvil_list,
}});
}
}

@ -101,7 +101,7 @@ if ($cgi->param())
line => __LINE__,
job_command => $anvil->data->{path}{exe}{'anvil-sync-shared'},
job_data => "file=".$out_file,
job_name => "upload::move_incoming",
job_name => "storage::move_incoming",
job_title => "job_0132",
job_description => "job_0133",
job_progress => 0,

@ -147,7 +147,7 @@
<tr>
<td class="row_header">
<!-- Purge option -->
<a href="?files=true&file_uuid=#!variable!file_uuid!#&purge=true"><span class="risky_click">#!string!header_0049!#</span></a> &nbsp;
<a href="?files=true&file_uuid=#!variable!file_uuid!#&purge=true&save=true"><span class="risky_click">#!string!header_0049!#</span></a> &nbsp;
</td>
<td colspan="3" style="text-align: left;">
#!string!striker_0282!#
@ -156,6 +156,7 @@
&nbsp;
</td>
</tr>
#!variable!confirm_purge_button!#
<tr>
<td colspan="5">
&nbsp;
@ -196,7 +197,7 @@
&nbsp;
</td>
<td style="text-align: right;">
#!variable!confirm_button!#
#!variable!confirm_save_button!#
</td>
<td style="text-align: right;">
<input type="submit" name="save" id="save" value="#!string!striker_0067!#" class="button">
@ -223,10 +224,22 @@
</tr>
<!-- end file-list-manager -->
<!-- start file-list-manager-confirm-button -->
<!-- start file-list-manager-confirm-save-button -->
<input type="submit" name="confirm" id="confirm" value="#!string!striker_0082!#" class="button"> &nbsp;
<input type="hidden" name="save" id="save" value="true">
<!-- end file-list-manager-confirm-button -->
<!-- end file-list-manager-confirm-save-button -->
<!-- start file-list-manager-confirm-purge-button -->
<tr>
<td class="row_header">
<!-- Purge option -->
<a href="#!variable!url!#" class="button">#!string!striker_0082!#</a>
</td>
<td colspan="4">
&nbsp;
</td>
</tr>
<!-- end file-list-manager-confirm-purge-button -->
<!-- start file-list-manager-anvil-entry -->
<tr>

@ -228,9 +228,14 @@ input[type=text], input[type=number], input[type=password] {
color: #f7f7f7;
}
input[type=text].input_alert, input[type=number].input_alert, select.input_alert {
input[type=text].input_alert, input[type=number].input_alert {
border: 1px solid #ff3f3f;
}
select.input_alert {
border: 1px solid #ff3f3f;
font-size: 0.8em;
padding: 0.2em;
}
input[type=text].input_alert_fixed, input[type=number].input_alert_fixed, select.input_alert_fixed {
border: 1px solid #ff3f3f;
@ -244,9 +249,14 @@ input[type=text].input_alert_fixed, input[type=number].input_alert_fixed, select
color: #3ed688;
}
input[type=text].input_clear, input[type=number].input_clear, select.input_clear {
input[type=text].input_clear, input[type=number].input_clear {
border: 1px solid #9ba0a5;
}
select.input_clear {
border: 1px solid #9ba0a5;
font-size: 0.8em;
padding: 0.2em;
}
input[type=text].input_clear_fixed, input[type=number].input_clear_fixed, select.input_clear_fixed {
border: 1px solid #9ba0a5;

@ -250,9 +250,15 @@ The error was:
<key name="error_0175">Unable to pull the file: [#!variable!file!#], we're not an Anvil! member.</key>
<key name="error_0176">The downloaded file's md5sum: [#!variable!local_md5sum!#] doesn't match what is expected: [#!variable!file_md5sum!#]. The file has been removed. We'll wait for a minute and then exit, and the download will be attempted again.</key>
<key name="error_0177">Something went wrong and the file wasn't downloaded. More information should be in the logs. We'll wait for a minute and then exit, and the download will be attempted again.</key>
<key name="error_0178">Unable to purge the file because a file UUID wasn't set (or failed to parse) from the 'job_data' in the job: [#!variable!job_uuid!#].</key>
<key name="error_0178">Unable to purge the a because a file UUID wasn't set (or failed to parse) from the 'job_data' in the job: [#!variable!job_uuid!#].</key>
<key name="error_0179">Unable to purge a file as the file UUID: [#!variable!file_uuid!#] is either invalid or doesn't exist in the database.</key>
<key name="error_0180">Failed to delete: [#!variable!file_path!#]. The error returned was: [#!variable!error!#]. There may be more details in the logs.</key>
<key name="error_0181">Unable to rename a file because a file UUID wasn't set (or failed to parse) from the 'job_data' in the job: [#!variable!job_uuid!#].</key>
<key name="error_0182">Unable to purge a file as the file UUID: [#!variable!file_uuid!#] is either invalid or doesn't exist in the database.</key>
<key name="error_0183">Unable to rename the file: [#!variable!file_name!#] because the new file name wasn't set (or failed to parse) from the 'job_data' in the job: [#!variable!job_uuid!#].</key>
<key name="error_0184">Moving the file failed. The problem should be logged. We'll sleep for a minute and then exit. We'll try again after that.</key>
<key name="error_0185">Unable to check the file mode because a file UUID wasn't set (or failed to parse) from the 'job_data' in the job: [#!variable!job_uuid!#].</key>
<key name="error_0186">Unable to check the file mode because the file UUID: [#!variable!file_uuid!#] is either invalid or doesn't exist in the database.</key>
<!-- Table headers -->
<key name="header_0001">Current Network Interfaces and States</key>
@ -450,7 +456,16 @@ Failure! The return code: [#!variable!return_code!#] was received ('0' was expec
<key name="job_0134">Successfully deleted the file: [#!variable!file_path!#].</key>
<key name="job_0135">No need to delete the file: [#!variable!file_path!#], it already doesn't exist.</key>
<key name="job_0136">Purge File.</key>
<key name="job_0137">This askes all systems to delete the associated file from their systems.</key>
<key name="job_0137">This askes the host to delete the associated file from their system.</key>
<key name="job_0138">Rename File.</key>
<key name="job_0139">This askes all systems to rename the associated file.</key>
<key name="job_0140">No need to rename the file: [#!variable!file_path!#], it doesn't exist on this host.</key>
<key name="job_0141">About to rename the old file: [#!variable!old_file!#] to: [#!variable!new_file!#].</key>
<key name="job_0142">File renamed successfully.</key>
<key name="job_0143">Check File Mode.</key>
<key name="job_0144">This is used when a file type changes, setting the executable bits when the type is script, and removing the executable bits when set to another type.</key>
<key name="job_0145">The file: [#!variable!file_path!#]'s mode has been set to: [#!variable!new_mode!#].</key>
<key name="job_0146">No need to set the mode on the file: [#!variable!file_path!#], it doesn't exist here.</key>
<!-- Log entries -->
<key name="log_0001">Starting: [#!variable!program!#].</key>
@ -461,7 +476,7 @@ It is multiple lines with single quotes ['] and double-quotes (") and here are r
It also has replacement variables: [#!variable!first!#] and [#!variable!second!#].
</key>
<key name="log_0003">This is a test log entry that contains a secret [#!variable!password!#]!</key>
<key name="log_0003">This is a test log entry that contains a secret [#!variable!passwaord!#]!</key>
<key name="log_0004">This is a test log entry at log level 2.</key>
<key name="log_0005">This is a test log entry at log level 3.</key>
<key name="log_0006">This is a test log entry at log level 4.</key>
@ -1419,6 +1434,8 @@ About to try to download aproximately: [#!variable!packages!#] packages needed t
<key name="message_0201">Download appears to be complete, calculating md5sum to verify, please be patient...</key>
<key name="message_0202">Success! The file has been successfully downloaded.</key>
<key name="message_0203">Processing a file purge.</key>
<key name="message_0204">Processing an uploaded file.</key>
<key name="message_0205">Processing a file mode check.</key>
<!-- Success messages shown to the user -->
<key name="ok_0001">Saved the mail server information successfully!</key>
@ -1432,6 +1449,11 @@ About to try to download aproximately: [#!variable!packages!#] packages needed t
<key name="ok_0009">The install manifest: [#!variable!name!#] has been successfully saved!</key>
<key name="ok_0010">The install manifest: [#!variable!name!#] has been successfully deleted!</key>
<key name="ok_0011">The install manifest job has be initiated! Target machines should start configuring momentarily!</key>
<key name="ok_0012">The file has been scheduled to purge from all systems.</key>
<key name="ok_0013">The file has been scheduled to be renamed on all systems.</key>
<key name="ok_0014">The file type been changed.</key>
<key name="ok_0015">The Anvil!: [#!variable!anvil_name!#] members will now sync this file.</key>
<key name="ok_0016">The Anvil!: [#!variable!anvil_name!#] members will now remove this file.</key>
<!-- String prefixes -->
<key name="prefix_0001">[ Error ] - </key>

@ -59,11 +59,11 @@ if ($anvil->data->{switches}{'job-uuid'})
$anvil->Job->clear({debug => 3});
$anvil->data->{sys}{progress} = 1;
if ($anvil->data->{jobs}{job_name} eq "upload::move_incoming")
if ($anvil->data->{jobs}{job_name} eq "storage::move_incoming")
{
process_incoming_file($anvil);
}
if ($anvil->data->{jobs}{job_name} eq "upload::pull_file")
if ($anvil->data->{jobs}{job_name} eq "storage::pull_file")
{
process_pull_file($anvil);
}
@ -71,6 +71,14 @@ if ($anvil->data->{switches}{'job-uuid'})
{
process_purge_file($anvil);
}
if ($anvil->data->{jobs}{job_name} eq "storage::rename")
{
process_rename_file($anvil);
}
if ($anvil->data->{jobs}{job_name} eq "storage::check_mode")
{
process_file_mode($anvil);
}
# Job data will be in $anvil->data->{jobs}{job_data}
}
@ -88,18 +96,244 @@ $anvil->nice_exit({exit_code => 0});
# Functions #
#############################################################################################################
sub process_purge_file
sub process_file_mode
{
my ($anvil) = @_;
$anvil->Job->update_progress({
progress => $anvil->data->{sys}{progress},
message => "message_0191",
message => "message_0205",
});
# We have to include deleted because purges will already have the file flagged as deleted.
$anvil->Database->get_files({debug => 3, include_deleted => 1});
$anvil->Database->get_file_locations({debug => 3});
my $file_uuid = ($anvil->data->{jobs}{job_data} =~ /file_uuid=(.*)$/)[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { file_uuid => $file_uuid }});
if (not $file_uuid)
{
# Can't do anything, file wasn't parsed.
$anvil->Job->update_progress({
progress => 100,
message => "error_0185,!!job_uuid!".$anvil->data->{switches}{'job-uuid'}."!!",
job_status => "failed",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => 'err', key => "error_0185", variables => { job_uuid => $anvil->data->{switches}{'job-uuid'} }});
$anvil->nice_exit({exit_code => 1});
}
elsif (not exists $anvil->data->{files}{file_uuid}{$file_uuid})
{
# File UUID doesn't appear to be valid.
$anvil->Job->update_progress({
progress => 100,
message => "error_0186,!!file_uuid!".$file_uuid."!!",
job_status => "failed",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => 'err', key => "error_0186", variables => { file_uuid => $file_uuid }});
$anvil->nice_exit({exit_code => 1});
}
my $file_name = $anvil->data->{files}{file_uuid}{$file_uuid}{file_name};
my $file_directory = $anvil->data->{files}{file_uuid}{$file_uuid}{file_directory};
my $file_path = $file_directory."/".$file_name;
my $file_type = $anvil->data->{files}{file_uuid}{$file_uuid}{file_type};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:file_name' => $file_name,
's2:file_directory' => $file_directory,
's3:file_path' => $file_path,
's4:file_type' => $file_type,
}});
# From here, we'll unlink if it exists. If it doesn't exist, we still exit sucessfully.
if (-e $file_path)
{
# Change the mode, if need it.
my $new_mode = "a-x";
if ($file_type eq "script")
{
$new_mode = "a+x";
}
$anvil->Storage->change_mode({
path => $file_path,
mode => $new_mode,
});
$anvil->Job->update_progress({
progress => 100,
message => "job_0145,!!file_path!".$file_path."!!,!!new_mode!".$new_mode."!!",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "job_0145", variables => {
file_path => $file_path,
new_mode => $new_mode,
}});
$anvil->nice_exit({exit_code => 0});
}
else
{
# Doesn't exist, nothing to do.
$anvil->Job->update_progress({
progress => 100,
message => "job_0146,!!file_path!".$file_path."!!",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "job_0146", variables => { file_path => $file_path }});
$anvil->nice_exit({exit_code => 0});
}
return(0);
}
sub process_rename_file
{
my ($anvil) = @_;
$anvil->Job->update_progress({
progress => $anvil->data->{sys}{progress},
message => "message_0204",
});
$anvil->Database->get_files({debug => 3});
$anvil->Database->get_file_locations({debug => 3});
my $file_uuid = "";
my $old_name = "";
my $new_name = "";
foreach my $line (split/\n/, $anvil->data->{jobs}{job_data})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }});
if ($line =~ /file_uuid=(.*)$/)
{
$file_uuid = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { file_uuid => $file_uuid }});
}
if ($line =~ /old_name=(.*)$/)
{
$old_name = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { old_name => $old_name }});
}
if ($line =~ /new_name=(.*)$/)
{
$new_name = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { new_name => $new_name }});
}
}
if (not $file_uuid)
{
# Can't do anything, file wasn't parsed.
$anvil->Job->update_progress({
progress => 100,
message => "error_0181,!!job_uuid!".$anvil->data->{switches}{'job-uuid'}."!!",
job_status => "failed",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => 'err', key => "error_0181", variables => { job_uuid => $anvil->data->{switches}{'job-uuid'} }});
$anvil->nice_exit({exit_code => 1});
}
elsif (not exists $anvil->data->{files}{file_uuid}{$file_uuid})
{
# File UUID doesn't appear to be valid.
$anvil->Job->update_progress({
progress => 100,
message => "error_0182,!!file_uuid!".$file_uuid."!!",
job_status => "failed",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => 'err', key => "error_0182", variables => { file_uuid => $file_uuid }});
$anvil->nice_exit({exit_code => 1});
}
my $file_name = $anvil->data->{files}{file_uuid}{$file_uuid}{file_name};
my $file_directory = $anvil->data->{files}{file_uuid}{$file_uuid}{file_directory};
my $old_file_path = $file_directory."/".$old_name;
my $new_file_path = $file_directory."/".$new_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:file_name' => $file_name,
's2:file_directory' => $file_directory,
's3:old_file_path' => $old_file_path,
's4:new_file_path' => $new_file_path,
}});
if (not $new_name)
{
# Can't do anything, file wasn't parsed.
$anvil->Job->update_progress({
progress => 100,
message => "error_0183,!!file_name!".$new_file_path."!!,!!job_uuid!".$anvil->data->{switches}{'job-uuid'}."!!",
job_status => "failed",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => 'err', key => "error_0183", variables => {
file_name => $new_file_path,
job_uuid => $anvil->data->{switches}{'job-uuid'},
}});
$anvil->nice_exit({exit_code => 1});
}
# If the file doesn't exist, there's nothing to do (and that's OK).
if (-e $old_file_path)
{
# Move the file.
$anvil->Job->update_progress({
progress => 50,
message => "job_0141,!!old_file!".$old_file_path."!!,!!new_file!".$new_file_path."!!",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "job_0141", variables => {
old_file => $old_file_path,
new_file => $new_file_path,
}});
$anvil->Storage->move_file({
source_file => $old_file_path,
target_file => $new_file_path,
});
if ((not -e $old_file_path) && (-e $new_file_path))
{
# Success!
$anvil->Job->update_progress({
progress => 100,
message => "job_0142",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "job_0142"});
$anvil->nice_exit({exit_code => 0});
}
elsif ((-e $old_file_path) && (not -e $new_file_path))
{
# Move failed
$anvil->Job->update_progress({
progress => 1,
message => "error_0184",
job_status => "failed",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => 'err', key => "error_0184"});
sleep 60;
$anvil->nice_exit({exit_code => 1});
}
}
else
{
# Nothing to do
$anvil->Job->update_progress({
progress => 100,
message => "job_0140,!!file_path!".$old_file_path."!!",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "job_0140", variables => { old_file_path => $old_file_path }});
$anvil->nice_exit({exit_code => 0});
}
return(0);
}
sub process_purge_file
{
my ($anvil) = @_;
$anvil->Job->update_progress({
progress => $anvil->data->{sys}{progress},
message => "message_0203",
});
# We have to include deleted because purges will already have the file flagged as deleted.
$anvil->Database->get_files({debug => 3, include_deleted => 1});
$anvil->Database->get_file_locations({debug => 3});
my $file_uuid = ($anvil->data->{jobs}{job_data} =~ /file_uuid=(.*)$/)[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { file_uuid => $file_uuid }});
@ -161,10 +395,10 @@ sub process_purge_file
{
# Success!
$anvil->Job->update_progress({
progress => 100,
message => "job_0134,!!file_path!".$file_path."!!",
progress => 100,
message => "job_0134,!!file_path!".$file_path."!!",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => 'err', key => "job_0134", variables => { file_path => $file_path }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "job_0134", variables => { file_path => $file_path }});
$anvil->nice_exit({exit_code => 0});
}
}
@ -172,10 +406,10 @@ sub process_purge_file
{
# Doesn't exist, nothing to do.
$anvil->Job->update_progress({
progress => 100,
message => "job_0135,!!file_path!".$file_path."!!",
progress => 100,
message => "job_0135,!!file_path!".$file_path."!!",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => 'err', key => "job_0135", variables => { file_path => $file_path }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "job_0135", variables => { file_path => $file_path }});
$anvil->nice_exit({exit_code => 0});
}
@ -373,7 +607,6 @@ sub process_incoming_file
});
}
### TODO: Make is an upload-time option to choose if the uploaded file automatically goes to any given Anvil!
# Tell other Anvil! systems to download this file.
$anvil->Database->get_anvils({debug => 2});
foreach my $anvil_name (sort {$a cmp $b} keys %{$anvil->data->{anvils}{anvil_name}})
@ -405,11 +638,6 @@ sub process_incoming_file
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { file_location_uuid => $file_location_uuid }});
### TODO: Register a job for each member to run this file with an 'upload::pull_file' with
### the job_data being the 'file=$target_file'. Have node1 try the first striker, and
### node2 from the second striker, if it exists. DR should watch node1 and node2's
### jobs and not download until those jobs hit 100.
# Register a job to call anvil-sync-shared
foreach my $host_uuid ($anvil_node1_host_uuid, $anvil_node2_host_uuid, $anvil_dr1_host_uuid)
{
@ -419,7 +647,7 @@ sub process_incoming_file
line => __LINE__,
job_command => $anvil->data->{path}{exe}{'anvil-sync-shared'},
job_data => "file_uuid=".$file_uuid,
job_name => "upload::pull_file",
job_name => "storage::pull_file",
job_title => "job_0132",
job_description => "job_0133",
job_progress => 0,
@ -448,7 +676,7 @@ sub process_pull_file
progress => $anvil->data->{sys}{progress},
message => "message_0198",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => 'err', key => "message_0198" });
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "message_0198" });
# Collect some data
$anvil->Database->get_anvils({debug => 3});
@ -681,7 +909,7 @@ SELECT
FROM
jobs
WHERE
job_name = 'upload::pull_file'
job_name = 'storage::pull_file'
AND
(
job_host_uuid = ".$anvil->Database->quote($anvil_node1_host_uuid)."
@ -818,15 +1046,15 @@ AND
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "message_0201"});
my $local_md5sum = $anvil->Get->md5sum({file => $file_path});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "message_0199", variables => { local_md5sum => $local_md5sum }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { local_md5sum => $local_md5sum }});
if ($file_md5sum eq $local_md5sum)
{
$anvil->Job->update_progress({
progress => 100,
message => "message_0202",
progress => 100,
message => "message_0202",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => 'err', key => "message_0202"});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "message_0202"});
$anvil->nice_exit({exit_code => 0});
}
else

Loading…
Cancel
Save