* Created Database->get_manifests() that loads manifests into a hash but UUID and name.

* Got deleting of manifests done.
* Fixed a couple bugs from the _network to _ip variable rename.
* Fixed a bug where fence variables with double-quotes in them weren't being handled properly.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 5 years ago
parent 0dbb07dfb7
commit c5c75f1ddf
  1. 122
      Anvil/Tools/Database.pm
  2. 2
      Anvil/Tools/Striker.pm
  3. 133
      cgi-bin/striker
  4. 68
      html/skins/alteeve/anvil.html
  5. 5
      share/words.xml

@ -28,6 +28,7 @@ my $THIS_FILE = "Database.pm";
# get_jobs
# get_local_uuid
# get_mail_servers
# get_manifests
# get_notifications
# get_recipients
# get_upses
@ -2266,6 +2267,127 @@ AND
}
=head2 get_manifests
This loads the known install manifests into the C<< anvil::data >> hash at:
* manifests::manifest_uuid::<manifest_uuid>::manifest_name
* manifests::manifest_uuid::<manifest_uuid>::manifest_last_ran
* manifests::manifest_uuid::<manifest_uuid>::manifest_xml
* manifests::manifest_uuid::<manifest_uuid>::manifest_note
* manifests::manifest_uuid::<manifest_uuid>::modified_date
And, to allow for lookup by name;
* manifests::manifest_name::<manifest_name>::manifest_uuid
* manifests::manifest_name::<manifest_name>::manifest_last_ran
* manifests::manifest_name::<manifest_name>::manifest_xml
* manifests::manifest_name::<manifest_name>::manifest_note
* manifests::manifest_name::<manifest_name>::modified_date
If the hash was already populated, it is cleared before repopulating to ensure no stray data remains.
B<<Note>>: Deleted devices (ones where C<< manifest_note >> is set to C<< DELETED >>) are ignored. See the C<< include_deleted >> parameter to include them.
Parameters;
=head3 include_deleted (Optional, default 0)
If set to C<< 1 >>, deleted last_rans are included when loading the data. When C<< 0 >> is set, the default, any manifest last_ran with C<< manifest_note >> set to C<< DELETED >> is ignored.
=cut
sub get_manifests
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Database->get_manifests()" }});
my $include_deleted = defined $parameter->{include_deleted} ? $parameter->{include_deleted} : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
include_deleted => $include_deleted,
}});
if (exists $anvil->data->{manifests})
{
delete $anvil->data->{manifests};
}
my $query = "
SELECT
manifest_uuid,
manifest_name,
manifest_last_ran,
manifest_xml,
manifest_note,
modified_date
FROM
manifests ";
if (not $include_deleted)
{
$query .= "
WHERE
manifest_note != 'DELETED'";
}
$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 $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
foreach my $row (@{$results})
{
my $manifest_uuid = $row->[0];
my $manifest_name = $row->[1];
my $manifest_last_ran = $row->[2];
my $manifest_xml = $row->[3];
my $manifest_note = $row->[4];
my $modified_date = $row->[5];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
manifest_uuid => $manifest_uuid,
manifest_name => $manifest_name,
manifest_last_ran => $manifest_last_ran,
manifest_note => $manifest_note,
manifest_xml => $manifest_xml,
modified_date => $modified_date,
}});
# Record the data in the hash, too.
$anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{manifest_name} = $manifest_name;
$anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{manifest_last_ran} = $manifest_last_ran;
$anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{manifest_xml} = $manifest_xml;
$anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{manifest_note} = $manifest_note;
$anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{modified_date} = $modified_date;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"manifests::manifest_uuid::${manifest_uuid}::manifest_name" => $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{manifest_name},
"manifests::manifest_uuid::${manifest_uuid}::manifest_last_ran" => $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{manifest_last_ran},
"manifests::manifest_uuid::${manifest_uuid}::manifest_xml" => $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{manifest_xml},
"manifests::manifest_uuid::${manifest_uuid}::manifest_note" => $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{manifest_note},
"manifests::manifest_uuid::${manifest_uuid}::modified_date" => $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{modified_date},
}});
$anvil->data->{manifests}{manifest_name}{$manifest_name}{manifest_uuid} = $manifest_uuid;
$anvil->data->{manifests}{manifest_name}{$manifest_name}{manifest_last_ran} = $manifest_last_ran;
$anvil->data->{manifests}{manifest_name}{$manifest_name}{manifest_xml} = $manifest_xml;
$anvil->data->{manifests}{manifest_name}{$manifest_name}{manifest_note} = $manifest_note;
$anvil->data->{manifests}{manifest_name}{$manifest_name}{modified_date} = $modified_date;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"manifests::manifest_name::${manifest_name}::manifest_uuid" => $anvil->data->{manifests}{manifest_name}{$manifest_name}{manifest_uuid},
"manifests::manifest_name::${manifest_name}::manifest_last_ran" => $anvil->data->{manifests}{manifest_name}{$manifest_name}{manifest_last_ran},
"manifests::manifest_name::${manifest_name}::manifest_xml" => $anvil->data->{manifests}{manifest_name}{$manifest_name}{manifest_xml},
"manifests::manifest_name::${manifest_name}::manifest_note" => $anvil->data->{manifests}{manifest_name}{$manifest_name}{manifest_note},
"manifests::manifest_name::${manifest_name}::modified_date" => $anvil->data->{manifests}{manifest_name}{$manifest_name}{modified_date},
}});
}
return(0);
}
=head2 get_notifications
This gets the list of configured mail servers.

@ -129,7 +129,7 @@ sub generate_manifest
foreach my $machine ("node1", "node2", "dr1")
{
# Record the network
my $ip_key = $machine."_".$network_name."_network";
my $ip_key = $machine."_".$network_name."_ip";
$machines->{$machine}{network}{$network_name} = defined $anvil->data->{cgi}{$ip_key}{value} ? $anvil->data->{cgi}{$ip_key}{value} : "";
# On the first loop (bcn1), pull in the other information as well.

@ -1561,6 +1561,9 @@ sub handle_manifest
$anvil->data->{cgi}{ntp}{alert} = 0 if not defined $anvil->data->{cgi}{ntp}{alert};
$anvil->data->{cgi}{mtu}{value} = 1500 if not defined $anvil->data->{cgi}{mtu}{value};
$anvil->data->{cgi}{mtu}{alert} = 0 if not defined $anvil->data->{cgi}{mtu}{alert};
$anvil->data->{cgi}{'delete'}{value} = "" if not defined $anvil->data->{cgi}{'delete'}{alert};
$anvil->data->{cgi}{manifest_uuid}{value} = "" if not defined $anvil->data->{cgi}{manifest_uuid}{alert};
$anvil->data->{cgi}{confirm}{value} = "" if not defined $anvil->data->{cgi}{confirm}{alert};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"cgi::step::value" => $anvil->data->{cgi}{step}{value},
"cgi::prefix::value" => $anvil->data->{cgi}{prefix}{value},
@ -1572,7 +1575,94 @@ sub handle_manifest
"cgi::dns::value" => $anvil->data->{cgi}{dns}{value},
"cgi::ntp::value" => $anvil->data->{cgi}{ntp}{value},
"cgi::mtu::value" => $anvil->data->{cgi}{mtu}{value},
"cgi::delete::value" => $anvil->data->{cgi}{'delete'}{value},
"cgi::manifest_uuid::value" => $anvil->data->{cgi}{manifest_uuid}{value},
"cgi::confirm::value" => $anvil->data->{cgi}{confirm}{value},
}});
# Are we deleting a manifest?
if (($anvil->data->{cgi}{'delete'}{value}) && ($anvil->data->{cgi}{manifest_uuid}{value}))
{
# Verify that the UUID is valid.
$anvil->Database->get_manifests({debug => 2, include_deleted => 1});
my $manifest_uuid = $anvil->data->{cgi}{manifest_uuid}{value};
my $manifest_name = $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{manifest_name};
my $manifest_last_ran = $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{manifest_last_ran};
my $manifest_xml = $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{manifest_xml};
my $manifest_note = $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{manifest_note};
if (not exists $anvil->data->{manifests}{manifest_uuid}{$manifest_uuid})
{
# Doesn't exist.
my $message = $anvil->Words->string({key => "warning_0043", variables => { uuid => $manifest_uuid }});
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $message }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "form::error_massage" => $anvil->data->{form}{error_massage} }});
}
elsif ($anvil->data->{manifests}{manifest_uuid}{$manifest_uuid}{manifest_note} eq "DELETED")
{
# Already deleted.
my $message = $anvil->Words->string({key => "warning_0044", variables => {
name => $manifest_name,
uuid => $manifest_uuid,
}});
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $message }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "form::error_massage" => $anvil->data->{form}{error_massage} }});
}
# Has the user confirmed?
if ($anvil->data->{cgi}{confirm}{value})
{
# Delete it
my ($manifest_uuid) = $anvil->Database->insert_or_update_manifests({
debug => 2,
manifest_uuid => $manifest_uuid,
manifest_name => $manifest_name,
manifest_last_ran => $manifest_last_ran,
manifest_xml => $manifest_xml,
manifest_note => "DELETED",
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { manifest_uuid => $manifest_uuid }});
if ($manifest_uuid)
{
# Deleted successfully
my $message = $anvil->Words->string({key => "ok_0010", variables => { name => $manifest_name }});
$anvil->data->{form}{ok_message} = $anvil->Template->get({file => "main.html", name => "ok_message", variables => { ok_message => $message }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "form::ok_message" => $anvil->data->{form}{ok_message} }});
}
else
{
# Something went wrong.
my $message = $anvil->Words->string({key => "warning_0045", variables => {
name => $manifest_name,
uuid => $manifest_uuid,
}});
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $message }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "form::error_massage" => $anvil->data->{form}{error_massage} }});
}
# Go back to the main page.
process_create($anvil);
return(0);
}
else
{
# Ask the user to confirm.
my $say_manifest = $manifest_name;
if ($manifest_note)
{
$say_manifest = $manifest_name." : ".$manifest_note;
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_manifest => $say_manifest }});
$anvil->data->{form}{back_link} = "?anvil=true&task=create";
$anvil->data->{form}{body} = $anvil->Template->get({file => "anvil.html", name => "manifest-delete-confirm", variables => {
name => $manifest_name,
say_manifest => $say_manifest,
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'form::body' => $anvil->data->{form}{body} }});
return(0);
}
}
if ($anvil->data->{cgi}{step}{value} > 1)
{
@ -2401,7 +2491,7 @@ sub sanity_check_manifest_step3
my $say_network = $anvil->Words->string({key => $say_network_code, variables => { number => $i }});
my $network_key = $network.$i."_network";
my $subnet_key = $network.$i."_subnet";
my $machine_ip_key = $machine."_".$network.$i."_network";
my $machine_ip_key = $machine."_".$network.$i."_ip";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
say_network => $say_network,
network_key => $network_key,
@ -2418,7 +2508,7 @@ sub sanity_check_manifest_step3
}});
# Is the IP valid?
if (not $anvil->Validate->is_ipv4({ip => $anvil->data->{cgi}{$machine_ip_key}{value}}))
if (not $anvil->Validate->is_ipv4({ip => $anvil->data->{cgi}{$machine_ip_key}{value}, debug => 2}))
{
# Bad subnet
my $say_network = "#!string!striker_0255!#";
@ -2830,35 +2920,14 @@ sub process_create
my ($anvil) = @_;
# Show existing manifests.
my $query = "
SELECT
manifest_uuid,
manifest_name,
manifest_last_ran,
manifest_xml,
manifest_note
FROM
manifests
ORDER BY
manifest_name ASC;";
$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 $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
results => $results,
count => $count,
}});
$anvil->Database->get_manifests();
my $manifest_template = "";
if ($count)
{
foreach my $row (@{$results})
foreach my $manifest_name (sort {$a cmp $b} keys %{$anvil->data->{manifests}{manifest_name}})
{
my $manifest_uuid = $row->[0];
my $manifest_name = $row->[1];
my $manifest_last_ran = $row->[2];
my $manifest_xml = $row->[3];
my $manifest_note = $row->[4];
my $manifest_uuid = $anvil->data->{manifests}{manifest_name}{$manifest_name}{manifest_uuid};
my $manifest_last_ran = $anvil->data->{manifests}{manifest_name}{$manifest_name}{manifest_last_ran};
my $manifest_xml = $anvil->data->{manifests}{manifest_name}{$manifest_name}{manifest_xml};
my $manifest_note = $anvil->data->{manifests}{manifest_name}{$manifest_name}{manifest_note};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
manifest_uuid => $manifest_uuid,
manifest_name => $manifest_name,
@ -2871,7 +2940,6 @@ ORDER BY
manifest_name => $manifest_name,
}});
}
}
# Store the previous CGI variables and display the new fields.
$anvil->data->{form}{back_link} = "?anvil=true";
@ -3892,6 +3960,7 @@ sub process_fences
my $description = $anvil->data->{fence_data}{$fence_agent}{parameters}{$name}{description};
my $type = $anvil->data->{fence_data}{$fence_agent}{parameters}{$name}{content_type};
my $default = exists $anvil->data->{fence_data}{$fence_agent}{parameters}{$name}{'default'} ? $anvil->data->{fence_data}{$fence_agent}{parameters}{$name}{'default'} : "";
$default =~ s/"/&quot;/g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
option_key => $option_key,
unique => $unique,
@ -3901,10 +3970,6 @@ sub process_fences
'default' => $default,
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ">> default" => $default }});
$default =~ s/"/&quot;/g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "<< default" => $default }});
# Set the cgi variable to the default, if not already set.
$anvil->data->{cgi}{$option_key}{alert} = "" if not defined $anvil->data->{cgi}{$option_key}{alert};
$anvil->data->{cgi}{$option_key}{value} = $default if not defined $anvil->data->{cgi}{$option_key}{value};

@ -85,10 +85,10 @@
<a href="?anvil=true&task=manifests&manifest_uuid=#!variable!manifest_uuid!#&step=1" class="fixed_link_highlight">#!variable!manifest_name!#</a> &nbsp;
</td>
<td style="text-align: center;">
<a href="?anvil=true&task=manifest&run=true&manifest_uuid=#!variable!manifest_uuid!#"><img src="#!data!skin::url!#/images/run.png" alt="#!string!striker_0206!#" style="height: .8em;"></a>
<a href="?anvil=true&task=manifests&run=true&manifest_uuid=#!variable!manifest_uuid!#"><img src="#!data!skin::url!#/images/run.png" alt="#!string!striker_0206!#" style="height: .8em;"></a>
</td>
<td style="text-align: center;">
<a href="?anvil=true&task=manifest&delete=true&manifest_uuid=#!variable!manifest_uuid!#"><img src="#!data!skin::url!#/images/delete.png" alt="#!string!striker_0068!#" style="height: .8em;"></a>
<a href="?anvil=true&task=manifests&delete=true&manifest_uuid=#!variable!manifest_uuid!#"><img src="#!data!skin::url!#/images/delete.png" alt="#!string!striker_0068!#" style="height: .8em;"></a>
</td>
</tr>
<!-- end create-menu-existing-manifest-entry -->
@ -1202,6 +1202,70 @@
</table>
<!-- end ups-delete-confirm -->
<!-- start manifest-delete-confirm -->
<table align="center" class="anvil_main_menu">
<script type="text/javascript" src="/skins/alteeve/anvil.js"></script>
<tr>
<td colspan="2">
&nbsp;
</td>
</tr>
<tr>
<td class="main_option_icon">
<img src="#!data!skin::url!#/images/manifest.png" class="top_icon" >
</td>
<td class="title">
#!string!striker_0225!#
</td>
</tr>
<tr>
<td colspan="2">
&nbsp;
</td>
</tr>
<tr>
<td colspan="2">
<form name="manifest_delete" action="" method="post">
<table class="centered">
<tr style="border: 1px dotted #7f7f7f;">
<td colspan="2" class="column_header">
#!string!header_0028!#
</td>
</tr>
<tr style="border: 1px dotted #7f7f7f;">
<td colspan="2" class="column_row_value">
#!variable!say_manifest!#
</td>
</tr>
<tr>
<td colspan="2">
&nbsp;
</td>
</tr>
<tr>
<td>
<input type="submit" name="back" id="back" value="#!string!striker_0098!#" class="button"> &nbsp;
</td>
<td style="text-align: right;">
&nbsp; <input type="submit" name="confirm" id="confirm" value="#!string!striker_0082!#" class="button">
</td>
<input type="hidden" name="anvil" id="anvil" value="true">
<input type="hidden" name="task" id="task" value="manifests">
<input type="hidden" name="delete" id="delete" value="true">
<input type="hidden" name="manifest_uuid" id="manifest_uuid" value="#!data!cgi::manifest_uuid::value!#">
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td colspan="2">
&nbsp;
</td>
</tr>
</table>
<!-- end manifest-delete-confirm -->
<!-- start fence-agent-delete-confirm -->
<table align="center" class="anvil_main_menu">
<script type="text/javascript" src="/skins/alteeve/anvil.js"></script>

@ -214,6 +214,7 @@ The error was:
<key name="header_0025">IP Address</key>
<key name="header_0026">Host Name</key>
<key name="header_0027">Brand</key>
<key name="header_0028">Install Manifest</key>
<!-- Strings used by jobs -->
<key name="job_0001">Configure Network</key>
@ -1102,6 +1103,7 @@ About to try to download aproximately: [#!variable!packages!#] packages needed t
<key name="ok_0007">The UPS: [#!variable!name!#] has been successfully saved!</key>
<key name="ok_0008">The UPS: [#!variable!name!#] has been successfully deleted!</key>
<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>
<!-- String prefixes -->
<key name="prefix_0001">[ Error ] - </key>
@ -1550,6 +1552,9 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st
<key name="warning_0040">[ Warning ] - The UPS: [#!variable!name!#] with the UUID: [#!variable!uuid!#] was NOT deleted. The reason may be in the: [#!data!path::log::main!#] log file on this host.</key>
<key name="warning_0041">[ Warning ] - There was a problem saving the install manifest. The reason may be in the: [#!data!path::log::main!#] log file on this host.</key>
<key name="warning_0042">[ Warning ] - No record found for the table/columns: [#!variable!table!# -> #!variable!column!#] for the value: [#!variable!value!#].</key>
<key name="warning_0043">[ Warning ] - The install manifest with the UUID: [#!variable!uuid!#] was not found.</key>
<key name="warning_0044">[ Warning ] - The install manifest: [#!variable!name!#] with the UUID: [#!variable!uuid!#] has already been deleted.</key>
<key name="warning_0045">[ Warning ] - The install manifest: [#!variable!name!#] with the UUID: [#!variable!uuid!#] was NOT deleted. The reason may be in the: [#!data!path::log::main!#] log file on this host.</key>
</language>
<!-- 日本語 -->

Loading…
Cancel
Save