* Added enabling/disabling 'Install Target' feature to Striker's WebUI.

* Fixed a bug in Get->anvil_version where the version of local systems and remote systems differed in closing new lines.
* Fixed a bug in Database->insert_or_update_variables() where the 'debug' parameter wasn't working.
* Renamed System->determine_host_type -> System->get_host_type.
* Fixed a bug in System->get_uptime where there was a newline after the uptime integer.
* Updated anvil-daemon to track and record the state of the Install Target feature on Striker dashboards.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 6 years ago
parent 67e8f26bdb
commit 4b66379aaa
  1. 8
      Anvil/Tools.pm
  2. 52
      Anvil/Tools/Database.pm
  3. 6
      Anvil/Tools/Get.pm
  4. 9
      Anvil/Tools/System.pm
  5. 115
      cgi-bin/striker
  6. BIN
      html/skins/alteeve/images/install_target_disabled.png
  7. BIN
      html/skins/alteeve/images/install_target_enabled.png
  8. BIN
      html/skins/alteeve/images/install_target_original.png
  9. BIN
      html/skins/alteeve/images/install_target_original.xcf
  10. 2
      html/skins/alteeve/images/sources.txt
  11. 6
      html/skins/alteeve/main.css
  12. 4
      html/skins/alteeve/main.html
  13. 13
      html/skins/alteeve/striker.html
  14. 4
      rpm/SPECS/anvil.spec
  15. 17
      share/words.xml
  16. 87
      tools/anvil-daemon
  17. 113
      tools/anvil-manage-install-target

@ -933,11 +933,15 @@ sub _set_paths
},
exe => {
'anvil-change-password' => "/usr/sbin/anvil-change-password",
'anvil-configure-striker' => "/usr/sbin/anvil-configure-striker",
'anvil-daemon' => "/usr/sbin/anvil-daemon",
'anvil-maintenance-mode' => "/usr/sbin/anvil-maintenance-mode",
'anvil-manage-power' => "/usr/sbin/anvil-manage-power",
'anvil-manage-striker-peers' => "/usr/sbin/anvil-manage-striker-peers",
'anvil-manage-install-target' => "/usr/sbin/anvil-manage-install-target",
'anvil-prep-database' => "/usr/sbin/anvil-prep-database",
'anvil-update-states' => "/usr/sbin/anvil-update-states",
'anvil-manage-power' => "/usr/sbin/anvil-manage-power",
'anvil-report-memory' => "/usr/sbin/anvil-report-memory",
'anvil-update-states' => "/usr/sbin/anvil-update-states",
'chmod' => "/usr/bin/chmod",
'chown' => "/usr/bin/chown",
cp => "/usr/bin/cp",

@ -9,6 +9,7 @@ use DBI;
use Scalar::Util qw(weaken isweak);
use Data::Dumper;
use Time::HiRes qw(gettimeofday tv_interval);
use Text::Diff;
our $VERSION = "3.0.0";
my $THIS_FILE = "Database.pm";
@ -840,6 +841,7 @@ sub connect
# sure it matches ours. If it doesn't, skip this database.
if (not $is_local)
{
my $local_version = $anvil->_anvil_version({debug => $debug});
my $remote_version = $anvil->Get->anvil_version({
debug => $debug,
target => $host,
@ -847,10 +849,9 @@ sub connect
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
remote_version => $remote_version,
"anvil->_anvil_version" => $anvil->_anvil_version,
local_version => $local_version,
}});
if ($remote_version ne $anvil->_anvil_version({debug => $debug}))
if ($remote_version ne $local_version)
{
# Version doesn't match,
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0145", variables => {
@ -2183,7 +2184,7 @@ This default value is the local hostname.
=head3 host_type (required)
This default value is the value returned by C<< System->determine_host_type >>.
This default value is the value returned by C<< System->get_host_type >>.
=head3 host_uuid (required)
@ -2202,7 +2203,7 @@ sub insert_or_update_hosts
my $file = defined $parameter->{file} ? $parameter->{file} : "";
my $line = defined $parameter->{line} ? $parameter->{line} : "";
my $host_name = defined $parameter->{host_name} ? $parameter->{host_name} : $anvil->_hostname;
my $host_type = defined $parameter->{host_type} ? $parameter->{host_type} : $anvil->System->determine_host_type;
my $host_type = defined $parameter->{host_type} ? $parameter->{host_type} : $anvil->System->get_host_type;
my $host_uuid = defined $parameter->{host_uuid} ? $parameter->{host_uuid} : $anvil->Get->host_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
uuid => $uuid,
@ -4162,7 +4163,7 @@ This is an optional field to mark a source UUID that this variable belongs to. B
This is an optional database table name that the variables relates to. Generally it is used along side C<< variable_source_uuid >>, but that isn't required.
=head3 update_value_only (optional)
=head3 update_value_only (optional, default '0')
When set to C<< 1 >>, this method will only update the variable's C<< variable_value >> column. Any other parameters are used to help locate the variable to update only.
@ -4186,9 +4187,8 @@ sub insert_or_update_variables
my $variable_section = defined $parameter->{variable_section} ? $parameter->{variable_section} : "";
my $variable_source_uuid = defined $parameter->{variable_source_uuid} ? $parameter->{variable_source_uuid} : "";
my $variable_source_table = defined $parameter->{variable_source_table} ? $parameter->{variable_source_table} : "";
my $update_value_only = defined $parameter->{update_value_only} ? $parameter->{update_value_only} : 1;
my $log_level = defined $parameter->{log_level} ? $parameter->{log_level} : 3; # Undocumented for now.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => {
my $update_value_only = defined $parameter->{update_value_only} ? $parameter->{update_value_only} : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
uuid => $uuid,
file => $file,
line => $line,
@ -4201,7 +4201,7 @@ sub insert_or_update_variables
variable_source_uuid => $variable_source_uuid,
variable_source_table => $variable_source_table,
update_value_only => $update_value_only,
log_level => $log_level,
log_level => $debug,
}});
# We'll need either the name or UUID.
@ -4223,11 +4223,11 @@ FROM
variables
WHERE
variable_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($variable_uuid);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { query => $query }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$variable_name = $anvil->Database->query({query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__})->[0]->[0];
$variable_name = "" if not defined $variable_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { variable_name => $variable_name }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { variable_name => $variable_name }});
}
if (($variable_name) && (not $variable_uuid))
@ -4249,23 +4249,23 @@ AND
";
}
$query .= ";";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { query => $query }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
foreach my $row (@{$results})
{
$variable_uuid = $row->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { variable_uuid => $variable_uuid }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { variable_uuid => $variable_uuid }});
}
}
# If I still don't have an variable_uuid, we're INSERT'ing .
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { variable_uuid => $variable_uuid }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { variable_uuid => $variable_uuid }});
if (not $variable_uuid)
{
# INSERT
@ -4295,7 +4295,7 @@ INSERT INTO
".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{sys}{database}{timestamp})."
);
";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { query => $query }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
}
@ -4321,11 +4321,11 @@ AND
";
}
$query .= ";";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { query => $query }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
@ -4342,7 +4342,7 @@ AND
foreach my $row (@{$results})
{
my $old_variable_value = $row->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { old_variable_value => $old_variable_value }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { old_variable_value => $old_variable_value }});
# Anything change?
if ($old_variable_value ne $variable_value)
@ -4366,7 +4366,7 @@ AND
";
}
$query .= ";";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { query => $query }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
}
@ -4387,11 +4387,11 @@ FROM
WHERE
variable_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($variable_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { query => $query }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
@ -4408,7 +4408,7 @@ WHERE
my $old_variable_default = $row->[2];
my $old_variable_description = $row->[3];
my $old_variable_section = $row->[4];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
old_variable_name => $old_variable_name,
old_variable_value => $old_variable_value,
old_variable_default => $old_variable_default,
@ -4437,7 +4437,7 @@ SET
WHERE
variable_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($variable_uuid)."
";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { query => $query }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__});
}
@ -4445,7 +4445,7 @@ WHERE
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { variable_uuid => $variable_uuid }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { variable_uuid => $variable_uuid }});
return($variable_uuid);
}

@ -115,6 +115,7 @@ If C<< target >> is set, this will be the user we connect to the remote machine
This is the IP or host name of the machine to read the version of. If this is not set, the local system's version is checked.
=cut
# NOTE: the version is set in anvil.spec by sed'ing the release and arch onto anvil.version in anvil-core's %post
sub anvil_version
{
my $self = shift;
@ -174,6 +175,9 @@ fi;
}
}
# Clear off any newline.
$version =~ s/\n//gs;
return($version);
}
@ -332,7 +336,7 @@ sub cgi
# This is a password and we're not logging sensitive data, obfuscate it.
$censored_value = $anvil->Words->string({key => "log_0186"});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"cgi::${variable}::$say_value" => $censored_value,
}});
}

@ -21,7 +21,7 @@ my $THIS_FILE = "System.pm";
# check_daemon
# check_if_configured
# check_memory
# determine_host_type
# get_host_type
# enable_daemon
# find_matching_ip
# get_ips
@ -536,7 +536,7 @@ sub check_memory
return($used_ram);
}
=head2 determine_host_type
=head2 get_host_type
This method tries to determine the host type and returns a value suitable for use is the C<< hosts >> table.
@ -549,13 +549,13 @@ If that isn't set, it then looks at the short host name. The following rules are
3. If the host name ends in C<< dr<digits> >>, C<< dr >> is returned.
=cut
sub determine_host_type
sub get_host_type
{
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 => "System->determine_host_type()" }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "System->get_host_type()" }});
my $host_type = "";
my $host_name = $anvil->_short_hostname;
@ -916,6 +916,7 @@ sub get_uptime
# Clean it up. We'll have gotten two numbers, the uptime in seconds (to two decimal places) and the
# total idle time. We only care about the int number.
$uptime =~ s/^(\d+)\..*$/$1/;
$uptime =~ s/\n//gs;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { uptime => $uptime }});
return($uptime);

@ -37,6 +37,7 @@ $anvil->Storage->read_config();
$anvil->data->{skin}{url} = $anvil->data->{path}{urls}{skins}."/".$anvil->Template->skin;
$anvil->data->{form}{body} = "";
$anvil->data->{form}{error_massage} = "";
$anvil->data->{form}{ok_message} = "";
$anvil->data->{form}{back_link} = "";
$anvil->data->{form}{refresh_link} = "";
@ -141,10 +142,19 @@ sub print_and_exit
}});
# Display the page.
my $say_center_top_bar = "&nbsp;";
if ($anvil->data->{form}{error_massage})
{
$say_center_top_bar = $anvil->data->{form}{error_massage};
}
elsif ($anvil->data->{form}{ok_message})
{
$say_center_top_bar = $anvil->data->{form}{ok_message};
}
my $body = $anvil->Template->get({file => "main.html", name => "master", variables => {
header => $header,
skin_url => $anvil->data->{path}{urls}{skins}."/".$anvil->Template->skin,
center_top_bar => $anvil->data->{form}{error_massage} ? $anvil->data->{form}{error_massage} : "&nbsp;",
center_top_bar => $say_center_top_bar,
right_top_bar => $right_buttons,
left_top_bar => $left_buttons,
center_body => $anvil->data->{form}{body},
@ -243,6 +253,10 @@ sub process_task
{
process_update($anvil);
}
elsif ($anvil->data->{cgi}{task}{value} eq "install-target")
{
process_install_target($anvil);
}
elsif ($anvil->data->{cgi}{task}{value} eq "reboot")
{
process_power($anvil, "reboot");
@ -257,12 +271,53 @@ sub process_task
my $reboot_needed = $anvil->System->reboot_needed();
my $reboot_icon = $reboot_needed ? "reboot_needed_icon.png" : "reboot_icon.png";
my $reboot_message = $reboot_needed ? "#!string!striker_0093!#" : "#!string!striker_0092!#";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
reboot_needed => $reboot_needed,
reboot_icon => $reboot_icon,
reboot_message => $reboot_message,
}});
# What we show for the install target icon and text depends on if it is enabled or not.
my $install_target_title = "#!string!striker_0109!#";
my $install_target_icon = "install_target_disabled.png";
my $install_target_subtask = "unavailable";
my ($install_manifest_status, $variable_uuid, $modified_date) = $anvil->Database->read_variable({
variable_name => "install-target::enabled",
variable_source_uuid => $anvil->Get->host_uuid,
variable_source_table => "hosts",
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
install_manifest_status => $install_manifest_status,
variable_uuid => $variable_uuid,
modified_date => $modified_date,
}});
if ($install_manifest_status eq "enabled")
{
# Offer the button to disable it.
$install_target_title = "#!string!striker_0108!#";
$install_target_icon = "install_target_enabled.png";
$install_target_subtask = "disable";
}
elsif ($install_manifest_status eq "disabled")
{
# Offer the button to enable it.
$install_target_title = "#!string!striker_0107!#";
$install_target_subtask = "enable";
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
install_target_title => $install_target_title,
install_target_icon => $install_target_icon,
install_target_subtask => $install_target_subtask,
}});
# The 'back' goes home
$anvil->data->{form}{back_link} = "?";
$anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "striker-setup", variables => {
reboot_icon => $reboot_icon,
reboot_message => $reboot_message,
install_target_icon => $install_target_icon,
install_target_title => $install_target_title,
install_target_subtask => $install_target_subtask,
}});
}
}
@ -289,6 +344,52 @@ sub process_task
return(0);
}
# This enables or disables the Install Target feature
sub process_install_target
{
my ($anvil) = @_;
# NOTE: We don't ask for confirmation, it's a low risk task.
# What are we doing?
$anvil->data->{cgi}{subtask}{value} = "" if not defined $anvil->data->{cgi}{subtask}{value};
if (($anvil->data->{cgi}{subtask}{value} eq "enable") or ($anvil->data->{cgi}{subtask}{value} eq "disable"))
{
my ($job_uuid) = $anvil->Database->insert_or_update_jobs({
file => $THIS_FILE,
line => __LINE__,
job_command => $anvil->data->{path}{exe}{'anvil-manage-install-target'}." --".$anvil->data->{cgi}{subtask}{value},
job_data => "",
job_name => "install-target::".$anvil->data->{cgi}{task}{value},
job_title => "job_0015",
job_description => "job_0016",
job_progress => 0,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }});
# Show the use that the job has been saved.
my $message = "striker_0111";
if ($anvil->data->{cgi}{subtask}{value} eq "enable")
{
$message = "striker_0112";
}
$anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "job recorded", variables => {
title_id => "",
message_id => "",
reload_url => "/cgi-bin/".$THIS_FILE."?striker=true",
title => "#!string!striker_0044!#",
description => "#!string!".$message."!#",
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "form::body" => $anvil->data->{form}{body} }});
}
else
{
# Just ignore it, someone's mucking with the subask value.
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "striker_warning_0009"}) }});
}
return(0);
}
# This handles powering off or rebooting this machine
sub process_power
{
@ -304,7 +405,7 @@ sub process_power
debug => 3,
file => $THIS_FILE,
line => __LINE__,
job_command => $task eq "poweroff" ? "anvil-manage-power --poweroff -y" : "anvil-manage-power --reboot -y",
job_command => $task eq "poweroff" ? $anvil->data->{path}{exe}{'anvil-manage-power'}." --poweroff -y" : $anvil->data->{path}{exe}{'anvil-manage-power'}." --reboot -y",
job_data => "",
job_name => "reboot::system",
job_title => $task eq "poweroff" ? "job_0010" : "job_0009",
@ -355,7 +456,7 @@ sub process_update
debug => 3,
file => $THIS_FILE,
line => __LINE__,
job_command => "anvil-update-system",
job_command => $anvil->data->{path}{exe}{'anvil-update-system'},
job_data => "",
job_name => "update::system",
job_title => "job_0003",
@ -615,7 +716,7 @@ sub delete_sync_peer
debug => 3,
file => $THIS_FILE,
line => __LINE__,
job_command => "anvil-manage-striker-peers --remove --host-uuid ".$uuid,
job_command => $anvil->data->{path}{exe}{'anvil-manage-striker-peers'}." --remove --host-uuid ".$uuid,
job_data => "",
job_name => "striker-peer::remove",
job_title => "job_0013",
@ -818,7 +919,7 @@ sub add_sync_peer
if ($anvil->data->{cgi}{confirm}{value})
{
# OK, save the job!
my $job_command = "anvil-manage-striker-peers --add --host-uuid ".$peer_uuid." --host ".$host." --port ".$port." --ping ".$ping;
my $job_command = $anvil->data->{path}{exe}{'anvil-manage-striker-peers'}." --add --host-uuid ".$peer_uuid." --host ".$host." --port ".$port." --ping ".$ping;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
job_command => $job_command,
password => $anvil->Log->secure ? $password : $anvil->Words->string({key => "log_0186"}),
@ -838,7 +939,7 @@ sub add_sync_peer
# See which of our IPs match theirs. If the peer is a hostname, first
my $host_uuid = $anvil->Get->host_uuid;
my $sql_port = $anvil->data->{database}{$host_uuid}{port};
my $job_command = "anvil-manage-striker-peers --add --host-uuid ".$host_uuid." --host ".$use_ip." --port ".$sql_port." --ping ".$ping;
my $job_command = $anvil->data->{path}{exe}{'anvil-manage-striker-peers'}." --add --host-uuid ".$host_uuid." --host ".$use_ip." --port ".$sql_port." --ping ".$ping;
$job_data .= "\npeer_job_command=".$job_command;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, list => { job_command => $job_command }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 1, list => { job_data => $job_data }});
@ -932,7 +1033,7 @@ sub configure_striker
debug => 3,
file => $THIS_FILE,
line => __LINE__,
job_command => "anvil-configure-striker",
job_command => $anvil->data->{path}{exe}{'anvil-configure-striker'},
job_data => "form::config_step2",
job_name => "configure::network",
job_title => "job_0001",

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

@ -44,3 +44,5 @@ power by Blair Adams from the Noun Project (https://thenounproject.com/search/?q
reset by Mooms from the Noun Project (https://thenounproject.com/search/?q=reset&i=1033425)
- reboot_icon.png
Target by bezier master from the Noun Project (https://thenounproject.com/term/target/898037/)
- install_target.png

@ -73,6 +73,10 @@ body {
font-size: 1em;
}
.disabled {
color: #9D9D9D;
}
.error_message {
border-left: 3px solid #d02724;
border-right: 3px solid #d02724;
@ -321,7 +325,7 @@ td.top_padded_cell {
}
.title {
font-size: 1.2em;
font-size: 1.8em;
text-align: center;
}

@ -64,6 +64,10 @@
<div class="error_message"><span style="color: #ff3f7f;">*</span> #!variable!error_message!# </div>
<!-- end error_message -->
<!-- start ok_message -->
<div class="ok_message"><span style="color: #00934d;">*</span> #!variable!ok_message!# </div>
<!-- end ok_message -->
<!-- start footer -->
<div class="footer">
<table width="100%">

@ -338,6 +338,19 @@
#!string!striker_0059!#
</td>
</tr>
<tr>
<td rowspan="2" class="icon_button">
<a href="?striker=true&task=install-target&subtask=#!variable!install_target_subtask!#"><img src="#!data!skin::url!#/images/#!variable!install_target_icon!#" class="top_icon" ></a>
</td>
<td class="menu_title">
<a href="?striker=true&task=install-target&subtask=#!variable!install_target_subtask!#">#!variable!install_target_title!#</a>
</td>
</tr>
<tr>
<td class="menu_details">
#!string!striker_0110!#
</td>
</tr>
<tr>
<td rowspan="2" class="icon_button">
<a href="?striker=true&task=reboot"><img src="#!data!skin::url!#/images/#!variable!reboot_icon!#" class="top_icon" ></a>

@ -404,10 +404,10 @@ firewall-cmd --add-service=postgresql --permanent
%changelog
* Madison Kelly <mkelly@alteeve.ca> 3.0-19
* Fri Nov 30 2018 Madison Kelly <mkelly@alteeve.ca> 3.0-19
- Added packages to anvil-striker to support PXE server / install target
functions.
-
- Updated source.
* Sat Oct 06 2018 Madison Kelly <mkelly@alteeve.ca> 3.0-18
- Updated the source to resolve a major bug introduced by the code in the .17

@ -224,8 +224,12 @@ About to try to download aproximately: [#!variable!packages!#] packages needed t
</key>
<key name="message_0121">Successfully enabled the Install Target function.</key>
<key name="message_0122">Successfully disabled the Install Target function.</key>
<key name="message_0123">The Install Target function is enabled.</key>
<key name="message_0124">The Install Target function is disabled.</key>
<key name="message_0123">The 'Install Target' function is enabled.</key>
<key name="message_0124">The 'Install Target' function is disabled.</key>
<key name="message_0125">The 'Install Target' function has been disabled.</key>
<key name="message_0126">The attempt to disabled the 'Install Target' function failed! Please check the logs for details.</key>
<key name="message_0127">The 'Install Target' function has been enabled.</key>
<key name="message_0128">The attempt to enable the 'Install Target' function failed! Please check the logs for details.</key>
<!-- Log entries -->
<key name="log_0001">Starting: [#!variable!program!#].</key>
@ -647,6 +651,12 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st
<key name="striker_0104">The peer will be removed from to the local configuration shortly. Any existing data will remain but no further data will be shared.</key>
<key name="striker_0105"><![CDATA[Are you sure that you want to remove the peer: [<span class="code">#!variable!peer!#</span>]? If so, no further data from this system will be written to the peer. Do note that any existing data will remain and will be reused if you add the peer back again.]]></key>
<key name="striker_0106">Indicates when the last time the host system's RPM repository was refreshed. If the last refresh failed, this will be incremented by one day before another attempt is made (regardless of 'install-manifest::refresh-period' setting).</key>
<key name="striker_0107">Enable 'Install Target'</key>
<key name="striker_0108">Disable 'Install Target'</key>
<key name="striker_0109"><![CDATA[<span class="disabled">'Install Target' Not Available</span>]]></key>
<key name="striker_0110">The 'Install Target' feature is used to do base (stage 1) installs on new or rebuilt Striker dashboards, Anvil! nodes or Disaster Recivery hosts. Specifically, it allows machines to boot off their BCN network interface and install the base operating system.</key>
<key name="striker_0111">The 'Install Target' disable job has been requested. It should be completed in a few moments. You may need to reload the next page in a minute to see that it has been enabled.</key>
<key name="striker_0112">The 'Install Target' enabled job has been requested. It should be completed in a few moments. You may need to reload the next page in a minute to see that it has been disabled.</key>
<!-- Strings used by jobs -->
<key name="job_0001">Configure Network</key>
@ -663,6 +673,8 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st
<key name="job_0012">The Striker peer will now be added to the local configuration.</key>
<key name="job_0013">Remove a Striker Peer</key>
<key name="job_0014">The Striker peer will now be removed from the local configuration.</key>
<key name="job_0015">Manager Install Target.</key>
<key name="job_0016">Enable or disable the 'Install Target' feature.</key>
<!-- Warnings -->
<key name="striker_warning_0001">The IP address will change. You will need to reconnect after applying these changes.</key>
@ -673,6 +685,7 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st
<key name="striker_warning_0006">An SSH connection was established to: [#!variable!target!#], but we failed to establish a channel. The last error was: [#!variable!error!#].</key>
<key name="striker_warning_0007">The job: [#!variable!command!#] was picked up by: [#!variable!pid!#], but that process is not running and it appears to only be: [#!variable!percent!# %] complete. Restarting the job.</key>
<key name="striker_warning_0008">Unable to find a local IP on the same subnet as the IP/host: [#!variable!host!#] given for the target. Bi-directional setup not currently possible.</key>
<key name="striker_warning_0009">The subtask request for manipulating the 'Install Target' feature is not valid. It should be 'enabled' or 'disabled'</key> <!-- NOTE: 'enabled' and 'disabled' are variable values, don't translate them. -->
<!-- Errors -->
<key name="error_0001">There are not enough network interfaces on this machine. You have: [#!variable!interface_count!#] interface(s), and you need at least: [#!variable!required_interfaces_for_single!#] interfaces to connect to the requested networks (one for Back-Channel and one for each Internet-Facing network).</key>

@ -129,15 +129,10 @@ while(1)
}
else
{
# No databases available, we can't do anything this run.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => 0, key => "log_0202"});
}
# Exit if called with '--run-once'
if ($anvil->data->{switches}{'run-once'})
{
$anvil->nice_exit({code => 0});
}
# Has the file on disk changed?
$now_time = time;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
@ -183,6 +178,62 @@ $anvil->nice_exit({code => 0});
# Functions #
#############################################################################################################
# This calls anvil-manage-install-target to see if the dhcpd is running or not. If it is or isn't, the config
# variable 'install-target::enabled' is set/updated. On non-Striker hosts, this simply returns without doing
# anything.
sub check_install_target
{
my ($anvil) = @_;
my $system_type = $anvil->System->get_host_type();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { system_type => $system_type }});
if ($system_type ne "dashboard")
{
# Not a dashboard, nothing to do.
return(0);
}
my $shell_call = $anvil->data->{path}{exe}{'anvil-manage-install-target'}." --status";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { shell_call => $shell_call }});
my $status = "unavailable";
my $output = $anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { output => $output }});
foreach my $line (split/\n/, $output)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { line => $line }});
if ($line =~ /status=(\d)/)
{
my $digit = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { digit => $digit }});
if ($digit == 0)
{
$status = "disabled";
}
elsif ($digit == 1)
{
$status = "enabled";
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { status => $status }});
last;
}
}
# Record the status
$anvil->Database->insert_or_update_variables({
variable_name => "install-target::enabled",
variable_source_uuid => $anvil->Get->host_uuid,
variable_source_table => "hosts",
variable_value => $status,
variable_default => "unavailable",
variable_description => "striker_0110",
variable_section => "system",
});
return(0);
}
# These are tools that don't need to constantly run. They'll typically run when the server starts up or the
# daemon is restarted or reloaded.
sub run_once
@ -210,7 +261,7 @@ sub boot_time_tasks
# If the uptime is less than ten minutes, clear the reboot flag.
my $uptime = $anvil->System->get_uptime;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { uptime => $uptime }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { uptime => $uptime }});
# Now find out if a reboot is listed as needed and when it was last changed.
my $reboot_needed = 0;
@ -228,10 +279,10 @@ AND
AND
variable_name = 'reboot::needed'
;";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0124", variables => { 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 => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
results => $results,
count => $count,
}});
@ -240,7 +291,7 @@ AND
$reboot_needed = $results->[0]->[0];
$changed_seconds_ago = $results->[0]->[1];
$changed_seconds_ago =~ s/^(\d+)\..*$/$1/;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
reboot_needed => $reboot_needed,
changed_seconds_ago => $changed_seconds_ago,
}});
@ -250,7 +301,7 @@ AND
# set. If the uptime is less, then the system rebooted since it was requested so clear it. h/t to
# Lisa Seelye (@thedoh) for this idea!
my $difference = ($changed_seconds_ago - $uptime);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
"s1:reboot_needed" => $reboot_needed,
"s2:changed_seconds_ago" => $changed_seconds_ago,
"s3:uptime" => $uptime,
@ -259,21 +310,20 @@ AND
if (($reboot_needed) && ($uptime < $changed_seconds_ago))
{
# Clear the reboot request.
$reboot_needed = $anvil->System->reboot_needed({debug => 2, set => 0});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { reboot_needed => $reboot_needed }});
$reboot_needed = $anvil->System->reboot_needed({set => 0});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { reboot_needed => $reboot_needed }});
# Check to see if there was a reboot job in progress. If so, finish it off.
my $job_uuid = $anvil->Job->get_job_uuid({debug => 2, program => "anvil-manage-power"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }});
my $job_uuid = $anvil->Job->get_job_uuid({program => "anvil-manage-power"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { job_uuid => $job_uuid }});
if ($job_uuid)
{
# Update the percentage to '100' and then clear the old PID.
my $date_time = $anvil->Get->date_and_time();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { date_time => $date_time }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { date_time => $date_time }});
$anvil->Job->update_progress({
debug => 2,
progress => 100,
message => "message_0064,!!date_and_time!".$date_time."!!",
job_uuid => $job_uuid,
@ -343,6 +393,9 @@ sub keep_running
update_state_file($anvil);
}
# Is the Install Target enabled (if applicable)?
check_install_target($anvil);
# Run any pending jobs by calling 'anvil-jobs' with the 'job_uuid' as a background process.
run_jobs($anvil);

@ -47,14 +47,15 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
$running_directory =~ s/^\./$ENV{PWD}/;
}
my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1});
my $anvil = Anvil::Tools->new({log_level => 1, log_secure => 0});
$anvil->Storage->read_config({file => $anvil->data->{path}{configs}{'anvil.conf'}});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
# Read switches
$anvil->data->{switches}{'y'} = "";
$anvil->Get->switches;
$anvil->data->{switches}{'job-uuid'} = "";
$anvil->Get->switches();
# Make sure we're running as 'root'
# $< == real UID, $> == effective UID
@ -73,46 +74,76 @@ if ($anvil->data->{switches}{status})
if ($dhcpd_running)
{
print $anvil->Words->string({key => "message_0123"})."\n";
print "status=1\n";
$anvil->nice_exit({code => 0});
}
else
{
print $anvil->Words->string({key => "message_0124"})."\n";
print "status=0\n";
$anvil->nice_exit({code => 0});
}
}
# Connect to the database(s).
$anvil->Database->connect;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections})
{
# No databases, exit.
print $anvil->Words->string({key => "error_0003"})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => 0, key => "error_0003"});
$anvil->nice_exit({exit_code => 8});
}
### NOTE: Enabling is handled at the end, after checks/updates are applied
# If we're being asked to disable, just do so and exit.
if ($anvil->data->{switches}{disable})
{
my $exit_code = 0;
my $job_message = "message_0125";
my $return_code = $anvil->System->stop_daemon({daemon => $anvil->data->{sys}{daemon}{dhcpd}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { return_code => $return_code }});
if ($return_code)
{
# non-0 means something went wrong.
$job_message = "message_0126";
$exit_code = 8;
print $anvil->Words->string({key => "error_0047", variables => { rc => $return_code }})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => 0, key => "error_0048", variables => { rc => $return_code }});
$anvil->nice_exit({exit_code => 8});
}
else
{
# Success!
print $anvil->Words->string({key => "message_0122"})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => 0, key => "message_0122"});
$anvil->nice_exit({code => 0});
}
}
# Connect to the database(s).
$anvil->Database->connect;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections})
{
# No databases, exit.
print $anvil->Words->string({key => "error_0003"})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => 0, key => "error_0003"});
$anvil->nice_exit({exit_code => 8});
# Record the new state
$anvil->Database->insert_or_update_variables({
variable_name => "install-target::enabled",
variable_source_uuid => $anvil->Get->host_uuid,
variable_source_table => "hosts",
variable_value => "disabled",
variable_default => "unavailable",
variable_description => "striker_0110",
variable_section => "system",
});
### NOTE: There is no complex job processing here. If we've been asked to enable or disable, it only
### takes a second to do it.
# If we're being called as a job, mark that we've picked it up
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "switches::job_uuid" => $anvil->data->{switches}{'job-uuid'} }});
if ($anvil->data->{switches}{'job-uuid'})
{
$anvil->Job->update_progress({
debug => 1,
progress => 100,
message => $job_message,
job_uuid => $anvil->data->{switches}{'job-uuid'},
});
}
$anvil->nice_exit({exit_code => $exit_code});
}
# Exit if we're not configured yet
@ -143,27 +174,34 @@ if ($anvil->_short_hostname !~ /striker/)
$anvil->nice_exit({code => 4});
}
# load the list of packages;
print $anvil->Words->string({key => "message_0102"})."\n";
load_packages($anvil);
# If this isn't being called as a job, check/update the configuration and packages.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "switches::job_uuid" => $anvil->data->{switches}{'job-uuid'} }});
if (not $anvil->data->{switches}{'job-uuid'})
{
print $anvil->Words->string({key => "message_0102"})."\n";
load_packages($anvil);
# Setup PXE/tftp/dhcpd config.
setup_boot_environment($anvil);
# Setup PXE/tftp/dhcpd config.
setup_boot_environment($anvil);
# Store the RPMs in repo directory.
update_install_source($anvil);
# Store the RPMs in repo directory.
update_install_source($anvil);
}
# If we've been asked to enable or disable the install target, do so now.
if ($anvil->data->{switches}{enable})
{
my $exit_code = 0;
my $job_message = "message_0127";
my $return_code = $anvil->System->start_daemon({daemon => $anvil->data->{sys}{daemon}{dhcpd}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { return_code => $return_code }});
if ($return_code)
{
# non-0 means something went wrong.
$exit_code = 8;
$job_message = "message_0128";
print $anvil->Words->string({key => "error_0047", variables => { rc => $return_code }})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => 0, key => "error_0047", variables => { rc => $return_code }});
$anvil->nice_exit({exit_code => 8});
}
else
{
@ -171,6 +209,35 @@ if ($anvil->data->{switches}{enable})
print $anvil->Words->string({key => "message_0121"})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => 0, key => "message_0121"});
}
# Record the new state
$anvil->Database->insert_or_update_variables({
variable_name => "install-target::enabled",
variable_source_uuid => $anvil->Get->host_uuid,
variable_source_table => "hosts",
variable_value => "enabled",
variable_default => "unavailable",
variable_description => "striker_0110",
variable_section => "system",
});
### NOTE: There is no complex job processing here. If we've been asked to enable or disable, it only
### takes a second to do it.
# If we're being called as a job, mark that we've picked it up
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "switches::job_uuid" => $anvil->data->{switches}{'job-uuid'} }});
if ($anvil->data->{switches}{'job-uuid'})
{
$anvil->Job->update_progress({
debug => 1,
progress => 100,
message => $job_message,
job_uuid => $anvil->data->{switches}{'job-uuid'},
});
}
if ($exit_code)
{
$anvil->nice_exit({exit_code => $exit_code});
}
}
# We're done

Loading…
Cancel
Save