* Renamed all Validate->is_X to Validate->X. Also created Validate->ipv6() to validate IPv6 addresses using Data::Validate::IP (and added it as a requirement to the .spec base RPM).

* Added the fix from the last commit for System->call to handle returned data without an ending newline to Remote->call.
* Got more work done on System->update_hosts(). It's able to add new hosts, but misses the short and FQDN host names. Need to fix that and the verify existing / manual entries aren't molested.

Signed-off-by: digimer <digimer@pulsar.alteeve.com>
main
Digimer 5 years ago
parent 76b6550ac6
commit de43ea3ac1
  1. 18
      Anvil/Tools.t
  2. 4
      Anvil/Tools/Account.pm
  3. 4
      Anvil/Tools/Convert.pm
  4. 16
      Anvil/Tools/Database.pm
  5. 2
      Anvil/Tools/Get.pm
  6. 2
      Anvil/Tools/Job.pm
  7. 14
      Anvil/Tools/Network.pm
  8. 17
      Anvil/Tools/Remote.pm
  9. 4
      Anvil/Tools/Striker.pm
  10. 235
      Anvil/Tools/System.pm
  11. 396
      Anvil/Tools/Validate.pm
  12. 70
      cgi-bin/striker
  13. 1
      rpm/SPECS/anvil.spec
  14. 12
      share/words.xml
  15. 8
      tools/anvil-configure-host
  16. 2
      tools/anvil-download-file
  17. 2
      tools/anvil-manage-keys
  18. 6
      tools/striker-get-peer-data
  19. 4
      tools/striker-initialize-host
  20. 2
      tools/striker-manage-install-target
  21. 2
      tools/striker-manage-peers
  22. 10
      tools/striker-scan-network

@ -517,20 +517,20 @@ unlink $test_template_file;
### Anvil::Tools::Validate tests ### Anvil::Tools::Validate tests
# is_ipv4 # is_ipv4
is($anvil->Validate->is_ipv4({ip => "0.0.0.0"}), "1", "Verifying that 'Validate->is_ipv4' recognizes '0.0.0.0' as a valid IP address."); is($anvil->Validate->ipv4({ip => "0.0.0.0"}), "1", "Verifying that 'Validate->ipv4' recognizes '0.0.0.0' as a valid IP address.");
is($anvil->Validate->is_ipv4({ip => "255.255.255.255"}), "1", "Verifying that 'Validate->is_ipv4' recognizes '255.255.255.255' as a valid IP address."); is($anvil->Validate->ipv4({ip => "255.255.255.255"}), "1", "Verifying that 'Validate->ipv4' recognizes '255.255.255.255' as a valid IP address.");
is($anvil->Validate->is_ipv4({ip => "256.255.255.255"}), "0", "Verifying that 'Validate->is_ipv4' recognizes '256.255.255.255' as an invalid IP address."); is($anvil->Validate->ipv4({ip => "256.255.255.255"}), "0", "Verifying that 'Validate->ipv4' recognizes '256.255.255.255' as an invalid IP address.");
is($anvil->Validate->is_ipv4({ip => "alteeve.com"}), "0", "Verifying that 'Validate->is_ipv4' recognizes 'alteeve.com' as an invalid IP address."); is($anvil->Validate->ipv4({ip => "alteeve.com"}), "0", "Verifying that 'Validate->ipv4' recognizes 'alteeve.com' as an invalid IP address.");
is($anvil->Validate->is_ipv4({ip => "::1"}), "0", "Verifying that 'Validate->is_ipv4' recognizes '::1' as an invalid IP address."); is($anvil->Validate->ipv4({ip => "::1"}), "0", "Verifying that 'Validate->ipv4' recognizes '::1' as an invalid IP address.");
my $test_uuid = $anvil->Get->uuid; my $test_uuid = $anvil->Get->uuid;
is($anvil->Validate->is_uuid({uuid => $test_uuid}), "1", "Verifying that 'Validate->is_uuid' recognized: [".$test_uuid."] as a valid UUID."); is($anvil->Validate->uuid({uuid => $test_uuid}), "1", "Verifying that 'Validate->uuid' recognized: [".$test_uuid."] as a valid UUID.");
my $bad_uuid_1 = $test_uuid; my $bad_uuid_1 = $test_uuid;
$bad_uuid_1 =~ s/-//g; $bad_uuid_1 =~ s/-//g;
is($anvil->Validate->is_uuid({uuid => $bad_uuid_1}), "0", "Verifying that 'Validate->is_uuid' recognized: [".$bad_uuid_1."] as an invalid UUID."); is($anvil->Validate->uuid({uuid => $bad_uuid_1}), "0", "Verifying that 'Validate->uuid' recognized: [".$bad_uuid_1."] as an invalid UUID.");
my $bad_uuid_2 = uc($test_uuid); my $bad_uuid_2 = uc($test_uuid);
is($anvil->Validate->is_uuid({uuid => $bad_uuid_2}), "0", "Verifying that 'Validate->is_uuid' recognized: [".$bad_uuid_2."] as an invalid UUID."); is($anvil->Validate->uuid({uuid => $bad_uuid_2}), "0", "Verifying that 'Validate->uuid' recognized: [".$bad_uuid_2."] as an invalid UUID.");
my $bad_uuid_3 = $test_uuid."toolong"; my $bad_uuid_3 = $test_uuid."toolong";
is($anvil->Validate->is_uuid({uuid => $bad_uuid_3}), "0", "Verifying that 'Validate->is_uuid' recognized: [".$bad_uuid_3."] as an invalid UUID."); is($anvil->Validate->uuid({uuid => $bad_uuid_3}), "0", "Verifying that 'Validate->uuid' recognized: [".$bad_uuid_3."] as an invalid UUID.");
### Anvil::Tools::Words tests ### Anvil::Tools::Words tests
# clean_spaces # clean_spaces

@ -649,7 +649,7 @@ sub read_details
my $user_uuid = defined $parameter->{user_uuid} ? $parameter->{user_uuid} : $anvil->data->{cookie}{anvil_user_uuid}; my $user_uuid = defined $parameter->{user_uuid} ? $parameter->{user_uuid} : $anvil->data->{cookie}{anvil_user_uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { user_uuid => $user_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { user_uuid => $user_uuid }});
if (not $anvil->Validate->is_uuid({uuid => $user_uuid})) if (not $anvil->Validate->uuid({uuid => $user_uuid}))
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "error_0025", variables => { uuid => $user_uuid }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "error_0025", variables => { uuid => $user_uuid }});
return(0); return(0);
@ -937,7 +937,7 @@ sub _build_cookie_hash
uuid => $uuid, uuid => $uuid,
}}); }});
if (not $anvil->Validate->is_uuid({uuid => $uuid})) if (not $anvil->Validate->uuid({uuid => $uuid}))
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Account->_build_cookie_hash()", parameter => "uuid" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Account->_build_cookie_hash()", parameter => "uuid" }});
return(0, 0); return(0, 0);

@ -565,7 +565,7 @@ sub cidr
elsif ($cidr eq "31") { $output = "255.255.255.254"; } elsif ($cidr eq "31") { $output = "255.255.255.254"; }
elsif ($cidr eq "32") { $output = "255.255.255.255"; } elsif ($cidr eq "32") { $output = "255.255.255.255"; }
} }
elsif ($anvil->Validate->is_ipv4({ip => $subnet_mask})) elsif ($anvil->Validate->ipv4({ip => $subnet_mask}))
{ {
if ($subnet_mask eq "0.0.0.0" ) { $output = "0"; } if ($subnet_mask eq "0.0.0.0" ) { $output = "0"; }
elsif ($subnet_mask eq "128.0.0.0" ) { $output = "1"; } elsif ($subnet_mask eq "128.0.0.0" ) { $output = "1"; }
@ -642,7 +642,7 @@ sub host_name_to_ip
foreach my $line (split/\n/, $output) foreach my $line (split/\n/, $output)
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }});
if ($anvil->Validate->is_ipv4({ip => $line})) if ($anvil->Validate->ipv4({ip => $line}))
{ {
$ip = $line; $ip = $line;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { ip => $ip }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { ip => $ip }});

@ -857,7 +857,7 @@ sub connect
{ {
# Periodically, autovivication causes and empty key to appear. # Periodically, autovivication causes and empty key to appear.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { uuid => $uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { uuid => $uuid }});
next if ((not $uuid) or (not $anvil->Validate->is_uuid({uuid => $uuid}))); next if ((not $uuid) or (not $anvil->Validate->uuid({uuid => $uuid})));
if (($db_uuid) && ($db_uuid ne $uuid)) if (($db_uuid) && ($db_uuid ne $uuid))
{ {
@ -5881,7 +5881,7 @@ sub insert_or_update_jobs
} }
# Make sure I have the either a valid job UUID or a name # Make sure I have the either a valid job UUID or a name
if ((not $anvil->Validate->is_uuid({uuid => $job_uuid})) && (not $job_name)) if ((not $anvil->Validate->uuid({uuid => $job_uuid})) && (not $job_name))
{ {
$anvil->Log->entry({source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__, level => 0, priority => "err", key => "log_0136", variables => { $anvil->Log->entry({source => $file ? $file." -> ".$THIS_FILE : $THIS_FILE, line => $line ? $line." -> ".__LINE__ : __LINE__, level => 0, priority => "err", key => "log_0136", variables => {
method => "Database->insert_or_update_jobs()", method => "Database->insert_or_update_jobs()",
@ -6982,13 +6982,13 @@ sub insert_or_update_network_interfaces
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_name" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_name" }});
return(""); return("");
} }
if (($network_interface_bond_uuid ne 'NULL') && (not $anvil->Validate->is_uuid({uuid => $network_interface_bond_uuid}))) if (($network_interface_bond_uuid ne 'NULL') && (not $anvil->Validate->uuid({uuid => $network_interface_bond_uuid})))
{ {
# Bad UUID. # Bad UUID.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0130", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_bond_uuid", uuid => $network_interface_bond_uuid }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0130", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_bond_uuid", uuid => $network_interface_bond_uuid }});
return(""); return("");
} }
if (($network_interface_bridge_uuid ne 'NULL') && (not $anvil->Validate->is_uuid({uuid => $network_interface_bridge_uuid}))) if (($network_interface_bridge_uuid ne 'NULL') && (not $anvil->Validate->uuid({uuid => $network_interface_bridge_uuid})))
{ {
# Bad UUID. # Bad UUID.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0130", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_bridge_uuid", uuid => $network_interface_bridge_uuid }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0130", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_bridge_uuid", uuid => $network_interface_bridge_uuid }});
@ -7531,7 +7531,7 @@ sub insert_or_update_mac_to_ip
} }
# If the MAC isn't 12 or 17 bytes long (18 being xx:xx:xx:xx:xx:xx), or isn't a valid hex string, abort. # If the MAC isn't 12 or 17 bytes long (18 being xx:xx:xx:xx:xx:xx), or isn't a valid hex string, abort.
if (((length($mac_to_ip_mac_address) != 12) && (length($mac_to_ip_mac_address) != 17)) or (not $anvil->Validate->is_hex({debug => $debug, string => $mac_to_ip_mac_address, sloppy => 1}))) if (((length($mac_to_ip_mac_address) != 12) && (length($mac_to_ip_mac_address) != 17)) or (not $anvil->Validate->hex({debug => $debug, string => $mac_to_ip_mac_address, sloppy => 1})))
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0096", variables => { mac_to_ip_mac_address => $mac_to_ip_mac_address }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0096", variables => { mac_to_ip_mac_address => $mac_to_ip_mac_address }});
return(""); return("");
@ -7740,7 +7740,7 @@ sub insert_or_update_oui
} }
# If the MAC isn't 6 or 8 bytes long (8 being xx:xx:xx), or isn't a valid hex string, abort. # If the MAC isn't 6 or 8 bytes long (8 being xx:xx:xx), or isn't a valid hex string, abort.
if (((length($oui_mac_prefix) != 6) && (length($oui_mac_prefix) != 8)) or (not $anvil->Validate->is_hex({debug => $debug, string => $oui_mac_prefix, sloppy => 1}))) if (((length($oui_mac_prefix) != 6) && (length($oui_mac_prefix) != 8)) or (not $anvil->Validate->hex({debug => $debug, string => $oui_mac_prefix, sloppy => 1})))
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0096", variables => { oui_mac_prefix => $oui_mac_prefix }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0096", variables => { oui_mac_prefix => $oui_mac_prefix }});
return(""); return("");
@ -9223,7 +9223,7 @@ sub insert_or_update_variables
# If we have a variable UUID but not a name, read the variable name. If we don't have a UUID, see if # If we have a variable UUID but not a name, read the variable name. If we don't have a UUID, see if
# we can find one for the given variable name. # we can find one for the given variable name.
if (($anvil->Validate->is_uuid({uuid => $variable_uuid})) && (not $variable_name)) if (($anvil->Validate->uuid({uuid => $variable_uuid})) && (not $variable_name))
{ {
my $query = " my $query = "
SELECT SELECT
@ -9880,7 +9880,7 @@ sub manage_anvil_conf
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->manage_anvil_conf()", parameter => "db_host_uuid" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->manage_anvil_conf()", parameter => "db_host_uuid" }});
return(1); return(1);
} }
elsif (not $anvil->Validate->is_uuid({uuid => $db_host_uuid})) elsif (not $anvil->Validate->uuid({uuid => $db_host_uuid}))
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0031", variables => { db_host_uuid => $db_host_uuid }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0031", variables => { db_host_uuid => $db_host_uuid }});
return(1); return(1);

@ -859,7 +859,7 @@ sub host_uuid
return("#!error!#"); return("#!error!#");
} }
if ($anvil->Validate->is_uuid({uuid => $uuid})) if ($anvil->Validate->uuid({uuid => $uuid}))
{ {
$anvil->{HOST}{UUID} = $uuid; $anvil->{HOST}{UUID} = $uuid;
if (not -e $anvil->data->{path}{data}{host_uuid}) if (not -e $anvil->data->{path}{data}{host_uuid})

@ -209,7 +209,7 @@ AND
} }
} }
if (not $anvil->Validate->is_uuid({uuid => $anvil->data->{switches}{'job-uuid'}})) if (not $anvil->Validate->uuid({uuid => $anvil->data->{switches}{'job-uuid'}}))
{ {
# It's not a UUID. # It's not a UUID.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, secure => 0, key => "error_0033", variables => { uuid => $anvil->data->{switches}{'job-uuid'} } }); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, secure => 0, key => "error_0033", variables => { uuid => $anvil->data->{switches}{'job-uuid'} } });

@ -300,8 +300,8 @@ sub check_internet
# Is the domain valid? # Is the domain valid?
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { domain => $domain }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { domain => $domain }});
if ((not $anvil->Validate->is_domain_name({debug => $debug, name => $domain})) and if ((not $anvil->Validate->domain_name({debug => $debug, name => $domain})) and
(not $anvil->Validate->is_ipv4({debug => $debug, ip => $domain}))) (not $anvil->Validate->ipv4({debug => $debug, ip => $domain})))
{ {
# Not valid, skip # Not valid, skip
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0442", variables => { name => $domain }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0442", variables => { name => $domain }});
@ -1394,7 +1394,7 @@ sub get_company_from_mac
return($anvil->data->{cache}{mac_to_oui}{$mac}); return($anvil->data->{cache}{mac_to_oui}{$mac});
} }
my $valid_mac = $anvil->Validate->is_mac({mac => $mac}); my $valid_mac = $anvil->Validate->mac({mac => $mac});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { mac => $mac }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { mac => $mac }});
if ($valid_mac) if ($valid_mac)
{ {
@ -1893,7 +1893,7 @@ sub get_network
my $base = $block->base(); my $base = $block->base();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { base => $base }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { base => $base }});
if ($anvil->Validate->is_ipv4({ip => $base})) if ($anvil->Validate->ipv4({ip => $base}))
{ {
$network = $base; $network = $base;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { network => $network }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { network => $network }});
@ -2006,7 +2006,7 @@ sub is_ip_in_network
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Network->is_ip_in_network()", parameter => "network" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Network->is_ip_in_network()", parameter => "network" }});
return(0); return(0);
} }
elsif (not $anvil->Validate->is_ipv4({ip => $network})) elsif (not $anvil->Validate->ipv4({ip => $network}))
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "warning_0019", variables => { parameter => "network", network => $network }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "warning_0019", variables => { parameter => "network", network => $network }});
return(0); return(0);
@ -2016,7 +2016,7 @@ sub is_ip_in_network
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Network->is_ip_in_network()", parameter => "ip" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Network->is_ip_in_network()", parameter => "ip" }});
return(0); return(0);
} }
elsif (not $anvil->Validate->is_ipv4({ip => $ip})) elsif (not $anvil->Validate->ipv4({ip => $ip}))
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "warning_0019", variables => { parameter => "ip", network => $ip }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "warning_0019", variables => { parameter => "ip", network => $ip }});
return(0); return(0);
@ -2026,7 +2026,7 @@ sub is_ip_in_network
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Network->is_ip_in_network()", parameter => "subnet_mask" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Network->is_ip_in_network()", parameter => "subnet_mask" }});
return(0); return(0);
} }
elsif (not $anvil->Validate->is_subnet_mask({subnet_mask => $subnet_mask})) elsif (not $anvil->Validate->subnet_mask({subnet_mask => $subnet_mask}))
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "warning_0020", variables => { parameter => "subnet_mask", subnet_mask => $subnet_mask }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "warning_0020", variables => { parameter => "subnet_mask", subnet_mask => $subnet_mask }});
return(0); return(0);

@ -396,7 +396,7 @@ sub call
} }
# If the target is a host name, convert it to an IP. # If the target is a host name, convert it to an IP.
if (not $anvil->Validate->is_ipv4({ip => $target})) if (not $anvil->Validate->ipv4({ip => $target}))
{ {
my $new_target = $anvil->Convert->host_name_to_ip({host_name => $target}); my $new_target = $anvil->Convert->host_name_to_ip({host_name => $target});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { new_target => $new_target }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { new_target => $new_target }});
@ -668,6 +668,21 @@ sub call
{ {
$return_code = $1; $return_code = $1;
} }
elsif ($line =~ /return_code:(\d+)$/)
{
### NOTE: This should never happen given we have a newline before the echo,
### but it's here just in case.
# If the output of the shell call doesn't end in a newline, the return_code:X
# could be appended. This catches those cases and removes it.
$return_code = $1;
$line =~ s/return_code:\d+$//;
$output .= $line."\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => {
line => $line,
output => $output,
return_code => $return_code,
}});
}
else else
{ {
$clean_output .= $line."\n"; $clean_output .= $line."\n";

@ -670,7 +670,7 @@ sub get_peer_data
$anvil->Database->write({uuid => $anvil->data->{sys}{host_uuid}, debug => 3, query => $query, source => $THIS_FILE, line => __LINE__}); $anvil->Database->write({uuid => $anvil->data->{sys}{host_uuid}, debug => 3, query => $query, source => $THIS_FILE, line => __LINE__});
# Verify that the host UUID is actually valid. # Verify that the host UUID is actually valid.
if (not $anvil->Validate->is_uuid({uuid => $data->{host_uuid}})) if (not $anvil->Validate->uuid({uuid => $data->{host_uuid}}))
{ {
$data->{host_uuid} = ""; $data->{host_uuid} = "";
} }
@ -817,7 +817,7 @@ sub load_manifest
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Striker->load_manifest()", parameter => "manifest_uuid" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Striker->load_manifest()", parameter => "manifest_uuid" }});
return(1); return(1);
} }
elsif (not $anvil->Validate->is_uuid({uuid => $manifest_uuid})) elsif (not $anvil->Validate->uuid({uuid => $manifest_uuid}))
{ {
# UUID isn't valid # UUID isn't valid
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0130", variables => { method => "Striker->load_manifest()", parameter => "manifest_uuid", uuid => $manifest_uuid}}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0130", variables => { method => "Striker->load_manifest()", parameter => "manifest_uuid", uuid => $manifest_uuid}});

@ -127,7 +127,7 @@ sub activate_lv
my $path = defined $parameter->{path} ? $parameter->{path} : ""; my $path = defined $parameter->{path} ? $parameter->{path} : "";
my $activated = 0; my $activated = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
path => $path, path => $path,
}}); }});
@ -144,7 +144,7 @@ sub activate_lv
} }
my ($output, $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{lvchange}." --activate y ".$path}); my ($output, $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{lvchange}." --activate y ".$path});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
output => $output, output => $output,
return_code => $return_code, return_code => $return_code,
}}); }});
@ -154,7 +154,7 @@ sub activate_lv
# Check if it worked. # Check if it worked.
$activated = $anvil->data->{lvm}{'local'}{lv}{$path}{active}; $activated = $anvil->data->{lvm}{'local'}{lv}{$path}{active};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { activated => $activated }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { activated => $activated }});
return($activated); return($activated);
} }
@ -341,7 +341,7 @@ sub call
if ($line =~ /^return_code:(\d+)$/) if ($line =~ /^return_code:(\d+)$/)
{ {
$return_code = $1; $return_code = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { return_code => $return_code }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { return_code => $return_code }});
} }
elsif ($line =~ /return_code:(\d+)$/) elsif ($line =~ /return_code:(\d+)$/)
{ {
@ -351,7 +351,7 @@ sub call
$return_code = $1; $return_code = $1;
$line =~ s/return_code:\d+$//; $line =~ s/return_code:\d+$//;
$output .= $line."\n"; $output .= $line."\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
line => $line, line => $line,
output => $output, output => $output,
return_code => $return_code, return_code => $return_code,
@ -360,13 +360,13 @@ sub call
else else
{ {
$output .= $line."\n"; $output .= $line."\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { output => $output }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output }});
} }
} }
close $file_handle; close $file_handle;
chomp($output); chomp($output);
$output =~ s/\n$//s; $output =~ s/\n$//s;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { output => $output }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output }});
} }
} }
} }
@ -429,7 +429,7 @@ sub change_shell_user_password
my $target = defined $parameter->{target} ? $parameter->{target} : ""; my $target = defined $parameter->{target} ? $parameter->{target} : "";
my $user = defined $parameter->{user} ? $parameter->{user} : ""; my $user = defined $parameter->{user} ? $parameter->{user} : "";
my $return_code = 255; my $return_code = 255;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
user => $user, user => $user,
target => $target, target => $target,
port => $port, port => $port,
@ -466,7 +466,7 @@ sub change_shell_user_password
# Generate a salt and then use it to create a hash. # Generate a salt and then use it to create a hash.
(my $salt, $return_code) = $anvil->System->call({debug => $debug, shell_call => $anvil->data->{path}{exe}{openssl}." rand 1000 | ".$anvil->data->{path}{exe}{strings}." | ".$anvil->data->{path}{exe}{'grep'}." -io [0-9A-Za-z\.\/] | ".$anvil->data->{path}{exe}{head}." -n 16 | ".$anvil->data->{path}{exe}{'tr'}." -d '\\n'" }); (my $salt, $return_code) = $anvil->System->call({debug => $debug, shell_call => $anvil->data->{path}{exe}{openssl}." rand 1000 | ".$anvil->data->{path}{exe}{strings}." | ".$anvil->data->{path}{exe}{'grep'}." -io [0-9A-Za-z\.\/] | ".$anvil->data->{path}{exe}{head}." -n 16 | ".$anvil->data->{path}{exe}{'tr'}." -d '\\n'" });
my $new_hash = crypt($new_password,"\$6\$".$salt."\$"); my $new_hash = crypt($new_password,"\$6\$".$salt."\$");
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
salt => $salt, salt => $salt,
new_hash => $new_hash, new_hash => $new_hash,
return_code => $return_code, return_code => $return_code,
@ -1689,7 +1689,7 @@ sub find_matching_ip
} }
# Translate the host name to an IP address, if it isn't already an IP address. # Translate the host name to an IP address, if it isn't already an IP address.
if (not $anvil->Validate->is_ipv4({ip => $host})) if (not $anvil->Validate->ipv4({ip => $host}))
{ {
# This will be '0' if it failed, and pre-validated if it returns an IP. # This will be '0' if it failed, and pre-validated if it returns an IP.
$host = $anvil->Convert->host_name_to_ip({host_name => $host}); $host = $anvil->Convert->host_name_to_ip({host_name => $host});
@ -2956,7 +2956,7 @@ sub stty_echo
if ($set eq "off") if ($set eq "off")
{ {
($anvil->data->{sys}{terminal}{stty}, my $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{stty}." --save"}); ($anvil->data->{sys}{terminal}{stty}, my $return_code) = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{stty}." --save"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { 'sys::terminal::stty' => $anvil->data->{sys}{terminal}{stty}, return_code => $return_code }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { 'sys::terminal::stty' => $anvil->data->{sys}{terminal}{stty}, return_code => $return_code }});
$anvil->System->call({shell_call => $anvil->data->{path}{exe}{stty}." -echo"}); $anvil->System->call({shell_call => $anvil->data->{path}{exe}{stty}." -echo"});
} }
elsif (($set eq "on") && ($anvil->data->{sys}{terminal}{stty})) elsif (($set eq "on") && ($anvil->data->{sys}{terminal}{stty}))
@ -2992,7 +2992,7 @@ sub update_hosts
my $short_host_name = $host_name; my $short_host_name = $host_name;
$short_host_name =~ s/\..*$//; $short_host_name =~ s/\..*$//;
my $host_type = $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_type}; my $host_type = $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_type};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:host_name' => $host_name, 's1:host_name' => $host_name,
's2:short_host_name' => $short_host_name, 's2:short_host_name' => $short_host_name,
's3:host_type' => $host_type, 's3:host_type' => $host_type,
@ -3001,7 +3001,7 @@ sub update_hosts
# We store this in a way that lets us later sort by type -> host_name # We store this in a way that lets us later sort by type -> host_name
$anvil->data->{trusted_host}{$host_type}{$short_host_name}{host_name} = $host_name; $anvil->data->{trusted_host}{$host_type}{$short_host_name}{host_name} = $host_name;
$anvil->data->{trusted_host}{$host_type}{$short_host_name}{host_uuid} = $host_uuid; $anvil->data->{trusted_host}{$host_type}{$short_host_name}{host_uuid} = $host_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"trusted_host::${host_type}::${short_host_name}::host_name" => $anvil->data->{trusted_host}{$host_type}{$short_host_name}{host_name}, "trusted_host::${host_type}::${short_host_name}::host_name" => $anvil->data->{trusted_host}{$host_type}{$short_host_name}{host_name},
"trusted_host::${host_type}::${short_host_name}::host_uuid" => $anvil->data->{trusted_host}{$host_type}{$short_host_name}{host_uuid}, "trusted_host::${host_type}::${short_host_name}::host_uuid" => $anvil->data->{trusted_host}{$host_type}{$short_host_name}{host_uuid},
}}); }});
@ -3019,20 +3019,225 @@ sub update_hosts
}}); }});
$anvil->data->{trusted_host}{$host_type}{$short_host_name}{network}{$network_type}{$sequence}{ip_address} = $ip_address; $anvil->data->{trusted_host}{$host_type}{$short_host_name}{network}{$network_type}{$sequence}{ip_address} = $ip_address;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"trusted_host::${host_type}::${short_host_name}::network::${network_type}::${sequence}::ip_address" => $anvil->data->{trusted_host}{$host_type}{$short_host_name}{network}{$network_type}{$sequence}{ip_address}, "trusted_host::${host_type}::${short_host_name}::network::${network_type}::${sequence}::ip_address" => $anvil->data->{trusted_host}{$host_type}{$short_host_name}{network}{$network_type}{$sequence}{ip_address},
}}); }});
# Store the hostname in an easy to lookup format, too.
my $store_host_name = $short_host_name.".".$on_network;
$anvil->data->{hosts}{needed}{$store_host_name}{ip_address} = $ip_address;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"hosts::needed::${store_host_name}::ip_address" => $anvil->data->{hosts}{needed}{$store_host_name}{ip_address},
}});
# If this is BCN 1, store the full and short host names as well.
if ($on_network eq "bcn1")
{
# If the host name and short host name, this will be duplicate. No harm...
$anvil->data->{hosts}{needed}{$host_name}{ip_address} = $ip_address;
$anvil->data->{hosts}{needed}{$short_host_name}{ip_address} = $ip_address;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"hosts::needed::${host_name}::ip_address" => $anvil->data->{hosts}{needed}{$host_name}{ip_address},
"hosts::needed::${short_host_name}::ip_address" => $anvil->data->{hosts}{needed}{$short_host_name}{ip_address},
}});
}
} }
} }
die;
# Read in the existing hosts file # Read in the existing hosts file
my $add_header = 1;
my $changes = 0;
my $new_body = "";
my $old_body = $anvil->Storage->read_file({ my $old_body = $anvil->Storage->read_file({
debug => $debug, debug => $debug,
file => $anvil->data->{path}{configs}{hosts}, file => $anvil->data->{path}{configs}{hosts},
}); });
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { old_body => $old_body }});
# Parse the existing # Parse the existing
foreach my $line (split/\n/, $old_body)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }});
# Delete everything follow a hash, then clear spaces.
my $line_comment = "";
my $line_hosts = "";
if ($line =~ /^#/)
{
$new_body .= $line."\n";
next;
}
if ($line =~ /#(.*)$/)
{
$line_comment = $1;
}
$line =~ s/^\s+//;
$line =~ s/\s+$//;
next if not $line;
# Now pull apart the line and store the entries.
my ($ip_address, $names) = ($line =~ /^(.*?)\s+(.*)$/);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:ip_address' => $ip_address,
's2:names' => $names,
}});
# Make sure the IP is valid.
my $is_ip = $anvil->Validate->ip({ip => $ip_address, debug => $debug});
if (not $is_ip)
{
# Log and skip.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, key => "warning_0051", variables => {
ip => $ip_address,
names => $names,
}});
next;
}
foreach my $name (split/\s+/, $names)
{
if ($line =~ /##] anvil-daemon \[##/)
{
$add_header = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { add_header => $add_header }});
}
# Is this name one we manage? If so, has the IP changed?
if ((exists $anvil->data->{hosts}{needed}{$name}) && ($anvil->data->{hosts}{needed}{$name}{ip_address}))
{
my $current_ip = $anvil->data->{hosts}{needed}{$name}{ip_address};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
ip_address => $ip_address,
current_ip => $current_ip,
}});
if ($current_ip eq $ip_address)
{
# Matches, we don't need to deal with this name.
delete $anvil->data->{hosts}{needed}{$name};
}
else
{
# The IP has changed. Skip this name (which removes it from the list).
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0481", variables => {
old_ip => $current_ip,
new_ip => $ip_address,
name => $name,
}});
$changes = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { changes => $changes }});
next;
}
}
else
{
$line_hosts .= $name." ";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line_hosts => $line_hosts }});
}
}
# If we have any names for this IP, store it.
if ($line_hosts)
{
my $new_line .= $ip_address." ".$line_hosts;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { new_line => $new_line }});
if ($line_comment)
{
$new_line .= "\t# ".$line_comment."\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { new_line => $new_line }});
}
else
{
$new_line =~ s/\s+$//;
$new_line .= "\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { new_line => $new_line }});
}
$new_body .= $new_line;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { new_body => $new_body }});
}
}
# Do we need to pre-pend the header?
if ($add_header)
{
# Prepend the header.
my $header = $anvil->Words->string({key => "message_0177"});
$new_body = $header.$new_body;
$changes = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:changes' => $changes,
's2:header' => $header,
's3:new_body' => $new_body,
}});
}
# Now add any hosts we still need.
my $ip_order = [];
my $lines = {};
foreach my $host_type ("node", "dr", "striker")
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host_type => $host_type }});
foreach my $short_host_name (sort {$a cmp $b} keys %{$anvil->data->{trusted_host}{$host_type}})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { short_host_name => $short_host_name }});
foreach my $network_type ("bcn", "sn", "ifn")
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { short_host_name => $short_host_name }});
foreach my $sequence (sort {$a cmp $b} keys %{$anvil->data->{trusted_host}{$host_type}{$short_host_name}{network}{$network_type}})
{
my $ip_address = $anvil->data->{trusted_host}{$host_type}{$short_host_name}{network}{$network_type}{$sequence}{ip_address};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { ip_address => $ip_address }});
# Make sure this host is in the 'hosts::needed::xxx::ip_address'
# hash. If we saw it already and it was OK, it was deleted from
# there.
if (not exists $anvil->data->{hosts}{needed}{$short_host_name})
{
### NOTE: We're possibly missing short and full hostnames if
### this is BCN1, but they should all change at once.
### Maybe need to rethink this later.
# Already seen.
next;
}
# Start the line for this IP.
if (not exists $lines->{$ip_address})
{
$lines->{$ip_address} = $ip_address."\t";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "lines->${ip_address}" => $lines->{$ip_address} }});
# Push the IP into the array so that we print them in the
# order be first saw them.
push @{$ip_order}, $ip_address;
}
$lines->{$ip_address} .= $short_host_name.".".$network_type.$sequence." ";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"lines->${ip_address}" => $lines->{$ip_address},
}});
}
}
}
}
my $new_line_count = \@{$ip_order};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { new_line_count => $new_line_count }});
if ($new_line_count)
{
$changes = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { changes => $changes }});
foreach my $ip_address (@{$ip_order})
{
$new_body .= $lines->{$ip_address}."\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { new_body => $new_body }});
}
}
if ($changes)
{
# Write the new file.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { new_body => $new_body }});
die;
}
return(0); return(0);
} }

@ -7,6 +7,7 @@ use strict;
use warnings; use warnings;
use Data::Dumper; use Data::Dumper;
use Data::Validate::Domain qw(is_domain); use Data::Validate::Domain qw(is_domain);
use Data::Validate::IP;
use Scalar::Util qw(weaken isweak); use Scalar::Util qw(weaken isweak);
use Mail::RFC822::Address qw(valid validlist); use Mail::RFC822::Address qw(valid validlist);
@ -14,17 +15,19 @@ our $VERSION = "3.0.0";
my $THIS_FILE = "Validate.pm"; my $THIS_FILE = "Validate.pm";
### Methods; ### Methods;
# alphanumeric
# domain_name
# email
# form_field # form_field
# is_alphanumeric # hex
# is_domain_name # host_name
# is_email # ip
# is_hex # ipv4
# is_host_name # ipv6
# is_ipv4 # mac
# is_mac # positive_integer
# is_positive_integer # subnet_mask
# is_subnet_mask # uuid
# is_uuid
=pod =pod
@ -45,8 +48,8 @@ Provides all methods related to data validation.
# Access to methods using '$anvil->Validate->X'. # Access to methods using '$anvil->Validate->X'.
# #
# Example using 'is_uuid()'; # Example using 'uuid()';
if ($anvil->Validate->is_uuid({uuid => $string})) if ($anvil->Validate->uuid({uuid => $string}))
{ {
print "The UUID: [$string] is valid!\n"; print "The UUID: [$string] is valid!\n";
} }
@ -89,6 +92,108 @@ sub parent
# Public methods # # Public methods #
############################################################################################################# #############################################################################################################
=head2 alphanumeric
This verifies that the passed-in string contains only alpha-numeric characters. This is strict and will return invalid if spaces, hyphens or other characters are found.
NOTE: An empty string is considered invalid.
$string = "4words";
if ($anvil->Validate->alphanumeric({string => $string}))
{
print "The string: [$string] is valid!\n";
}
Parameters;
=head3 string (required)
This is the string name to validate.
=cut
sub alphanumeric
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $valid = 1;
my $string = defined $parameter->{string} ? $parameter->{string} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { string => $string }});
if (not $string)
{
$valid = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
}
if ($string !~ /^[a-zA-Z0-9]+$/)
{
$valid = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
return($valid);
}
=head2 domain_name
Checks if the passed-in string is a valid domain name. Returns 'C<< 1 >>' if OK, 'C<< 0 >>' if not.
$name = "alteeve.com";
if ($anvil->Validate->domain_name({name => $name}))
{
print "The domain name: [$name] is valid!\n";
}
Parameters;
=head3 name (required)
This is the domain name to validate.
=cut
sub domain_name
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $valid = 1;
my $name = $parameter->{name} ? $parameter->{name} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { name => $name }});
if (not $name)
{
$valid = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
}
else
{
# Underscores are allowd in domain names, but not host names. We disable TLD checks as we
# frequently use '.remote', '.bcn', etc.
### TODO: Add a 'strict' parameter to control this) and/or support domain_private_tld
my %options = (domain_allow_underscore => 1, domain_disable_tld_validation => 1);
my $dvd = Data::Validate::Domain->new(%options);
my $test = $dvd->domain($name);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { test => $test }});
if (not $test)
{
# Doesn't appear to be valid.
$valid = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
return($valid);
}
=head2 form_field =head2 form_field
This validates that a given HTML form field is valid. It takes an input ID and the type of data that is expected. If it is sane, C<< 1 >> is returned. If it fails to validate, C<< 0 >> is returned and C<< cgi::<name>::alert >> is set to C<< 1 >>. This validates that a given HTML form field is valid. It takes an input ID and the type of data that is expected. If it is sane, C<< 1 >> is returned. If it fails to validate, C<< 0 >> is returned and C<< cgi::<name>::alert >> is set to C<< 1 >>.
@ -173,49 +278,49 @@ sub form_field
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
} }
} }
elsif (($type eq "alphanumeric") && (not $anvil->Validate->is_alphanumeric({string => $anvil->data->{cgi}{$name}{value}}))) elsif (($type eq "alphanumeric") && (not $anvil->Validate->alphanumeric({string => $anvil->data->{cgi}{$name}{value}})))
{ {
$valid = 0; $valid = 0;
$anvil->data->{cgi}{$name}{alert} = 1; $anvil->data->{cgi}{$name}{alert} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }});
} }
elsif (($type eq "domain_name") && (not $anvil->Validate->is_domain_name({name => $anvil->data->{cgi}{$name}{value}}))) elsif (($type eq "domain_name") && (not $anvil->Validate->domain_name({name => $anvil->data->{cgi}{$name}{value}})))
{ {
$valid = 0; $valid = 0;
$anvil->data->{cgi}{$name}{alert} = 1; $anvil->data->{cgi}{$name}{alert} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }});
} }
elsif (($type eq "email") && (not $anvil->Validate->is_email({email => $anvil->data->{cgi}{$name}{value}}))) elsif (($type eq "email") && (not $anvil->Validate->email({email => $anvil->data->{cgi}{$name}{value}})))
{ {
$valid = 0; $valid = 0;
$anvil->data->{cgi}{$name}{alert} = 1; $anvil->data->{cgi}{$name}{alert} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }});
} }
elsif (($type eq "ipv4") && (not $anvil->Validate->is_ipv4({ip => $anvil->data->{cgi}{$name}{value}}))) elsif (($type eq "ipv4") && (not $anvil->Validate->ipv4({ip => $anvil->data->{cgi}{$name}{value}})))
{ {
$valid = 0; $valid = 0;
$anvil->data->{cgi}{$name}{alert} = 1; $anvil->data->{cgi}{$name}{alert} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }});
} }
elsif (($type eq "mac") && (not $anvil->Validate->is_mac({mac => $anvil->data->{cgi}{$name}{value}}))) elsif (($type eq "mac") && (not $anvil->Validate->mac({mac => $anvil->data->{cgi}{$name}{value}})))
{ {
$valid = 0; $valid = 0;
$anvil->data->{cgi}{$name}{alert} = 1; $anvil->data->{cgi}{$name}{alert} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }});
} }
elsif (($type eq "positive_integer") && (not $anvil->Validate->is_positive_integer({number => $anvil->data->{cgi}{$name}{value}, zero => $zero}))) elsif (($type eq "positive_integer") && (not $anvil->Validate->positive_integer({number => $anvil->data->{cgi}{$name}{value}, zero => $zero})))
{ {
$valid = 0; $valid = 0;
$anvil->data->{cgi}{$name}{alert} = 1; $anvil->data->{cgi}{$name}{alert} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }});
} }
elsif (($type eq "subnet_mask") && (not $anvil->Validate->is_subnet_mask({subnet_mask => $anvil->data->{cgi}{$name}{value}}))) elsif (($type eq "subnet_mask") && (not $anvil->Validate->subnet_mask({subnet_mask => $anvil->data->{cgi}{$name}{value}})))
{ {
$valid = 0; $valid = 0;
$anvil->data->{cgi}{$name}{alert} = 1; $anvil->data->{cgi}{$name}{alert} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $anvil->data->{cgi}{$name}{alert} }});
} }
elsif (($type eq "uuid") && (not $anvil->Validate->is_uuid({uuid => $anvil->data->{cgi}{$name}{value}}))) elsif (($type eq "uuid") && (not $anvil->Validate->uuid({uuid => $anvil->data->{cgi}{$name}{value}})))
{ {
$valid = 0; $valid = 0;
$anvil->data->{cgi}{$name}{alert} = 1; $anvil->data->{cgi}{$name}{alert} = 1;
@ -228,109 +333,8 @@ sub form_field
return($valid); return($valid);
} }
=head2 is_alphanumeric
This verifies that the passed-in string contains only alpha-numeric characters. This is strict and will return invalid if spaces, hyphens or other characters are found.
NOTE: An empty string is considered invalid.
$string = "4words";
if ($anvil->Validate->is_alphanumeric({string => $string}))
{
print "The string: [$string] is valid!\n";
}
Parameters;
=head3 string (required)
This is the string name to validate.
=cut
sub is_alphanumeric
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $valid = 1;
my $string = defined $parameter->{string} ? $parameter->{string} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { string => $string }});
if (not $string)
{
$valid = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
}
if ($string !~ /^[a-zA-Z0-9]+$/)
{
$valid = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
return($valid);
}
=head2 is_domain_name
Checks if the passed-in string is a valid domain name. Returns 'C<< 1 >>' if OK, 'C<< 0 >>' if not.
$name = "alteeve.com";
if ($anvil->Validate->is_domain_name({name => $name}))
{
print "The domain name: [$name] is valid!\n";
}
Parameters;
=head3 name (required)
This is the domain name to validate.
=cut
sub is_domain_name
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $valid = 1;
my $name = $parameter->{name} ? $parameter->{name} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { name => $name }});
if (not $name)
{
$valid = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
}
else
{
# Underscores are allowd in domain names, but not host names. We disable TLD checks as we
# frequently use '.remote', '.bcn', etc.
### TODO: Add a 'strict' parameter to control this) and/or support domain_private_tld
my %options = (domain_allow_underscore => 1, domain_disable_tld_validation => 1);
my $dvd = Data::Validate::Domain->new(%options);
my $test = $dvd->is_domain($name);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { test => $test }});
if (not $test)
{
# Doesn't appear to be valid.
$valid = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
return($valid);
}
=head2 is_hex =head2 hex
Checks if the passed-in string contains only hexidecimal characters. A prefix of C<< 0x >> is allowed. Checks if the passed-in string contains only hexidecimal characters. A prefix of C<< 0x >> is allowed.
@ -345,7 +349,7 @@ If set to C<< 1 >>, the string will be allowed to contain C<< : >> and C<< - >>
This is the string to validate This is the string to validate
=cut =cut
sub is_hex sub hex
{ {
my $self = shift; my $self = shift;
my $parameter = shift; my $parameter = shift;
@ -380,14 +384,14 @@ sub is_hex
} }
=head2 is_host_name =head2 host_name
Checks if the passed-in string is a valid host name. Returns 'C<< 1 >>' if OK, 'C<< 0 >>' if not. Checks if the passed-in string is a valid host name. Returns 'C<< 1 >>' if OK, 'C<< 0 >>' if not.
B<NOTE>: If this method receives a full domain name, the host name is checked in this method and the domain (anything after the first C<< . >>) is tested using C<< Validate->is_domain_name >>. If either fails, C<< 0 >> is returned. B<NOTE>: If this method receives a full domain name, the host name is checked in this method and the domain (anything after the first C<< . >>) is tested using C<< Validate->domain_name >>. If either fails, C<< 0 >> is returned.
$name = "an-a05n01"; $name = "an-a05n01";
if ($anvil->Validate->is_host_name({name => $name})) if ($anvil->Validate->host_name({name => $name}))
{ {
print "The host name: [$name] is valid!\n"; print "The host name: [$name] is valid!\n";
} }
@ -399,7 +403,7 @@ Parameters;
This is the host name to validate. This is the host name to validate.
=cut =cut
sub is_host_name sub host_name
{ {
my $self = shift; my $self = shift;
my $parameter = shift; my $parameter = shift;
@ -422,7 +426,7 @@ sub is_host_name
if ($domain) if ($domain)
{ {
$valid = $anvil->Validate->is_domain_name({ $valid = $anvil->Validate->domain_name({
name => $domain, name => $domain,
debug => $debug, debug => $debug,
}); });
@ -439,7 +443,7 @@ sub is_host_name
# Underscores are allowd in domain names, but not host names. # Underscores are allowd in domain names, but not host names.
my %options = (domain_allow_underscore => 1); my %options = (domain_allow_underscore => 1);
my $dvd = Data::Validate::Domain->new(%options); my $dvd = Data::Validate::Domain->new(%options);
my $test = $dvd->is_hostname($name); my $test = $dvd->hostname($name);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { test => $test }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { test => $test }});
if (not $test) if (not $test)
{ {
@ -454,12 +458,12 @@ sub is_host_name
} }
=head2 is_email =head2 email
Checks if the passed-in string is a valid address. Returns 'C<< 1 >>' if OK, 'C<< 0 >>' if not. Checks if the passed-in string is a valid address. Returns 'C<< 1 >>' if OK, 'C<< 0 >>' if not.
$email = "test@example.com"; $email = "test@example.com";
if ($anvil->Validate->is_email({email => $email})) if ($anvil->Validate->email({email => $email}))
{ {
print "The email address: [$email] is valid!\n"; print "The email address: [$email] is valid!\n";
} }
@ -471,7 +475,7 @@ Parameters;
This is the email address to verify. This is the email address to verify.
=cut =cut
sub is_email sub email
{ {
my $self = shift; my $self = shift;
my $parameter = shift; my $parameter = shift;
@ -493,12 +497,53 @@ sub is_email
return($valid); return($valid);
} }
=head2 is_ipv4 =head2 ip
This is a meta method. It takes the IP and tests it against both C<< ipv4 >> and C<< ipv6 >>. If either return as valid, this method returns as valid.
Said more simply; This tests an IP to see if it is IPv4 OR IPv6. Returns 'C<< 1 >>' if OK, 'C<< 0 >>' if not.
Parameters;
=head3 ip (required)
This is the IP address to validate.
=cut
sub ip
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $ip = defined $parameter->{ip} ? $parameter->{ip} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { ip => $ip }});
my $ipv4 = $anvil->Validate->ipv4({ip => $ip, debug => $debug});
my $ipv6 = not $ipv4 ? $anvil->Validate->ipv6({ip => $ip, debug => $debug}) : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
ipv4 => $ipv4,
ipv6 => $ipv6,
}});
my $valid = 1;
if ((not $ipv4) && (not $ipv6))
{
$valid = 0;
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
return($valid);
}
=head2 ipv4
Checks if the passed-in string is an IPv4 address. Returns 'C<< 1 >>' if OK, 'C<< 0 >>' if not. Checks if the passed-in string is an IPv4 address. Returns 'C<< 1 >>' if OK, 'C<< 0 >>' if not.
$ip = "111.222.33.44"; $ip = "111.222.33.44";
if ($anvil->Validate->is_ipv4({ip => $ip})) if ($anvil->Validate->ipv4({ip => $ip}))
{ {
print "The IP address: [$ip] is valid!\n"; print "The IP address: [$ip] is valid!\n";
} }
@ -510,7 +555,7 @@ Parameters;
This is the IP address to verify. This is the IP address to verify.
=cut =cut
sub is_ipv4 sub ipv4
{ {
my $self = shift; my $self = shift;
my $parameter = shift; my $parameter = shift;
@ -521,33 +566,46 @@ sub is_ipv4
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { ip => $ip }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { ip => $ip }});
my $valid = 1; my $valid = 1;
if ($ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) if (not is_ipv4($ip))
{ {
# It is in the right format.
my $first_octet = $1;
my $second_octet = $2;
my $third_octet = $3;
my $fourth_octet = $4;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
first_octet => $first_octet,
second_octet => $second_octet,
third_octet => $third_octet,
fourth_octet => $fourth_octet,
}});
if (($first_octet < 0) or ($first_octet > 255) or
($second_octet < 0) or ($second_octet > 255) or
($third_octet < 0) or ($third_octet > 255) or
($fourth_octet < 0) or ($fourth_octet > 255))
{
# One of the octets is out of range.
$valid = 0; $valid = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
return($valid);
}
=head2 ipv6
Checks if the passed-in string is an IPv6 address. Returns 'C<< 1 >>' if OK, 'C<< 0 >>' if not.
$ip = "::1";
if ($anvil->Validate->ipv6({ip => $ip}))
{
print "The IP address: [$ip] is valid!\n";
} }
else
Parameters;
=head3 ip (required)
This is the IPv6 address to verify.
=cut
sub ipv6
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $ip = defined $parameter->{ip} ? $parameter->{ip} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { ip => $ip }});
my $valid = 1;
if (not is_ipv6($ip))
{ {
# Not in the right format.
$valid = 0; $valid = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
} }
@ -556,7 +614,7 @@ sub is_ipv4
return($valid); return($valid);
} }
=head2 is_mac =head2 mac
Checks if the passed-in string is a valid network MAC address. Returns 'C<< 1 >>' if OK, 'C<< 0 >>' if not. Checks if the passed-in string is a valid network MAC address. Returns 'C<< 1 >>' if OK, 'C<< 0 >>' if not.
@ -567,7 +625,7 @@ Parameters;
This is the network MAC address to verify. This is the network MAC address to verify.
=cut =cut
sub is_mac sub mac
{ {
my $self = shift; my $self = shift;
my $parameter = shift; my $parameter = shift;
@ -589,7 +647,7 @@ sub is_mac
return($valid); return($valid);
} }
=head2 is_port =head2 port
This tests to see if the value passed is a valid TCP/UDP port (1 ~ 65536). Returns 'C<< 1 >>' if OK, 'C<< 0 >>' if not. This tests to see if the value passed is a valid TCP/UDP port (1 ~ 65536). Returns 'C<< 1 >>' if OK, 'C<< 0 >>' if not.
@ -602,7 +660,7 @@ Parameters;
This is the port being tested. This is the port being tested.
=cut =cut
sub is_port sub port
{ {
my $self = shift; my $self = shift;
my $parameter = shift; my $parameter = shift;
@ -630,14 +688,14 @@ sub is_port
return($valid); return($valid);
} }
=head2 is_positive_integer =head2 positive_integer
This method verifies that the passed in value is a positive integer. This method verifies that the passed in value is a positive integer.
NOTE: This method is strict and will only validate numbers without decimal places and that have no sign or a positive sign only (ie: C<< +3 >>, or C<< 3 >> are valid, but C<< -3 >> or C<< 3.0 >> are not). NOTE: This method is strict and will only validate numbers without decimal places and that have no sign or a positive sign only (ie: C<< +3 >>, or C<< 3 >> are valid, but C<< -3 >> or C<< 3.0 >> are not).
my $number = 3; my $number = 3;
if ($anvil->Validate->is_positive_integer({number => $number})) if ($anvil->Validate->positive_integer({number => $number}))
{ {
print "The number: [$number] is valid!\n"; print "The number: [$number] is valid!\n";
} }
@ -653,7 +711,7 @@ This is the number to verify.
If set, the number C<< 0 >> will be considered valid. By default, c<< 0 >> is not considered "positive". If set, the number C<< 0 >> will be considered valid. By default, c<< 0 >> is not considered "positive".
=cut =cut
sub is_positive_integer sub positive_integer
{ {
my $self = shift; my $self = shift;
my $parameter = shift; my $parameter = shift;
@ -688,7 +746,7 @@ sub is_positive_integer
return($valid); return($valid);
} }
=head2 is_subnet_mask =head2 subnet_mask
This method takes a subnet mask string and checks to see if it is a valid IPv4 address or CIDR notation. It returns 'C<< 1 >>' if it is a valid address. Otherwise it returns 'C<< 0 >>'. This method takes a subnet mask string and checks to see if it is a valid IPv4 address or CIDR notation. It returns 'C<< 1 >>' if it is a valid address. Otherwise it returns 'C<< 0 >>'.
@ -699,7 +757,7 @@ Parameters;
This is the address to verify. This is the address to verify.
=cut =cut
sub is_subnet_mask sub subnet_mask
{ {
my $self = shift; my $self = shift;
my $parameter = shift; my $parameter = shift;
@ -715,7 +773,7 @@ sub is_subnet_mask
if ($subnet_mask) if ($subnet_mask)
{ {
# We have something. Is it an IPv4 address? # We have something. Is it an IPv4 address?
if ($anvil->Validate->is_ipv4({ip => $subnet_mask})) if ($anvil->Validate->ipv4({ip => $subnet_mask}))
{ {
# It is. Try converting it to a CIDR notation. If we get an empty string back, it isn't valid. # It is. Try converting it to a CIDR notation. If we get an empty string back, it isn't valid.
my $cidr = $anvil->Convert->cidr({subnet_mask => $subnet_mask}); my $cidr = $anvil->Convert->cidr({subnet_mask => $subnet_mask});
@ -745,13 +803,13 @@ sub is_subnet_mask
return($valid); return($valid);
} }
=head2 is_uuid =head2 uuid
This method takes a UUID string and returns 'C<< 1 >>' if it is a valid UUID string. Otherwise it returns 'C<< 0 >>'. This method takes a UUID string and returns 'C<< 1 >>' if it is a valid UUID string. Otherwise it returns 'C<< 0 >>'.
NOTE: This method is strict and will only validate UUIDs that are lower case! NOTE: This method is strict and will only validate UUIDs that are lower case!
if ($anvil->Validate->is_uuid({uuid => $string})) if ($anvil->Validate->uuid({uuid => $string}))
{ {
print "The UUID: [$string] is valid!\n"; print "The UUID: [$string] is valid!\n";
} }
@ -763,7 +821,7 @@ Parameters;
This is the UUID to verify. This is the UUID to verify.
=cut =cut
sub is_uuid sub uuid
{ {
my $self = shift; my $self = shift;
my $parameter = shift; my $parameter = shift;

@ -551,7 +551,7 @@ WHERE
} }
# Verify that the mail server and ports are sane. # Verify that the mail server and ports are sane.
if (not $anvil->Validate->is_email({email => $recipient_email})) if (not $anvil->Validate->email({email => $recipient_email}))
{ {
# Bad domain # Bad domain
my $error_message = $anvil->Words->string({key => "warning_0026"}); my $error_message = $anvil->Words->string({key => "warning_0026"});
@ -946,8 +946,8 @@ WHERE
} }
# Verify that the mail server and ports are sane. # Verify that the mail server and ports are sane.
if ((not $anvil->Validate->is_ipv4({ip => $test_outgoing_mail_server})) and if ((not $anvil->Validate->ipv4({ip => $test_outgoing_mail_server})) and
(not $anvil->Validate->is_domain_name({name => $test_outgoing_mail_server}))) (not $anvil->Validate->domain_name({name => $test_outgoing_mail_server})))
{ {
# Bad domain # Bad domain
my $error_message = $anvil->Words->string({key => "warning_0023"}); my $error_message = $anvil->Words->string({key => "warning_0023"});
@ -963,7 +963,7 @@ WHERE
confirm => $confirm, confirm => $confirm,
}}); }});
} }
if (not $anvil->Validate->is_port({port => $port})) if (not $anvil->Validate->port({port => $port}))
{ {
# Bad port # Bad port
my $error_message = $anvil->Words->string({key => "warning_0024"}); my $error_message = $anvil->Words->string({key => "warning_0024"});
@ -1552,7 +1552,7 @@ sub process_manifests
}}); }});
# Are we running a manifest, or creating/editing one? # Are we running a manifest, or creating/editing one?
if (($anvil->data->{cgi}{run}{value}) && ($anvil->Validate->is_uuid({uuid => $anvil->data->{cgi}{manifest_uuid}{value}}))) if (($anvil->data->{cgi}{run}{value}) && ($anvil->Validate->uuid({uuid => $anvil->data->{cgi}{manifest_uuid}{value}})))
{ {
run_manifest($anvil); run_manifest($anvil);
} }
@ -2947,7 +2947,7 @@ sub sanity_check_manifest_step3
if ($anvil->data->{cgi}{$key}{value}) if ($anvil->data->{cgi}{$key}{value})
{ {
# Is it a valid IPv4 address? # Is it a valid IPv4 address?
if (not $anvil->Validate->is_ipv4({ip => $anvil->data->{cgi}{$key}{value}})) if (not $anvil->Validate->ipv4({ip => $anvil->data->{cgi}{$key}{value}}))
{ {
# Bad subnet # Bad subnet
my $say_network = "#!string!striker_0255!#"; my $say_network = "#!string!striker_0255!#";
@ -3042,7 +3042,7 @@ sub sanity_check_manifest_step3
}}); }});
# Is the IP valid? # Is the IP valid?
if (not $anvil->Validate->is_ipv4({ip => $anvil->data->{cgi}{$machine_ip_key}{value}, debug => 2})) if (not $anvil->Validate->ipv4({ip => $anvil->data->{cgi}{$machine_ip_key}{value}, debug => 2}))
{ {
# Bad subnet # Bad subnet
my $say_network = "#!string!striker_0255!#"; my $say_network = "#!string!striker_0255!#";
@ -3181,7 +3181,7 @@ sub sanity_check_manifest_step2
$ip =~ s/\s+$//; $ip =~ s/\s+$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ip => $ip }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ip => $ip }});
if (not $anvil->Validate->is_ipv4({ip => $ip})) if (not $anvil->Validate->ipv4({ip => $ip}))
{ {
# Bad network # Bad network
my $message = $anvil->Words->string({key => "error_0015"}); my $message = $anvil->Words->string({key => "error_0015"});
@ -3208,7 +3208,7 @@ sub sanity_check_manifest_step2
$ip =~ s/\s+$//; $ip =~ s/\s+$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ip => $ip }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ip => $ip }});
if (not $anvil->Validate->is_ipv4({ip => $ip})) if (not $anvil->Validate->ipv4({ip => $ip}))
{ {
# Bad network # Bad network
my $message = $anvil->Words->string({key => "error_0122"}); my $message = $anvil->Words->string({key => "error_0122"});
@ -3226,7 +3226,7 @@ sub sanity_check_manifest_step2
} }
# Make sure the MTU is sane # Make sure the MTU is sane
if (not $anvil->Validate->is_positive_integer({number => $anvil->data->{cgi}{mtu}{value}})) if (not $anvil->Validate->positive_integer({number => $anvil->data->{cgi}{mtu}{value}}))
{ {
my $message = $anvil->Words->string({key => "error_0123"}); my $message = $anvil->Words->string({key => "error_0123"});
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $message }}); $anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $message }});
@ -3249,7 +3249,7 @@ sub check_network
# Make sure the network and subnet are valid # Make sure the network and subnet are valid
my $local_sane = 1; my $local_sane = 1;
if (not $anvil->Validate->is_ipv4({ip => $anvil->data->{cgi}{$network_key}{value}})) if (not $anvil->Validate->ipv4({ip => $anvil->data->{cgi}{$network_key}{value}}))
{ {
# Bad network # Bad network
my $message = $anvil->Words->string({key => "error_0020", variables => { field => $say_network." - #!string!striker_0149!#" }}); my $message = $anvil->Words->string({key => "error_0020", variables => { field => $say_network." - #!string!striker_0149!#" }});
@ -3264,7 +3264,7 @@ sub check_network
"cgi::${network_key}::value" => $anvil->data->{cgi}{$network_key}{value}, "cgi::${network_key}::value" => $anvil->data->{cgi}{$network_key}{value},
}}); }});
} }
if (not $anvil->Validate->is_ipv4({ip => $anvil->data->{cgi}{$subnet_key}{value}})) if (not $anvil->Validate->ipv4({ip => $anvil->data->{cgi}{$subnet_key}{value}}))
{ {
# Bad subnet # Bad subnet
my $message = $anvil->Words->string({key => "error_0020", variables => { field => $say_network." - #!string!striker_0025!#" }}); my $message = $anvil->Words->string({key => "error_0020", variables => { field => $say_network." - #!string!striker_0025!#" }});
@ -3281,7 +3281,7 @@ sub check_network
} }
# The gateway can be blank # The gateway can be blank
if (($anvil->data->{cgi}{$gateway_key}{value}) && (not $anvil->Validate->is_ipv4({ip => $anvil->data->{cgi}{$gateway_key}{value}}))) if (($anvil->data->{cgi}{$gateway_key}{value}) && (not $anvil->Validate->ipv4({ip => $anvil->data->{cgi}{$gateway_key}{value}})))
{ {
# It's not a valid IP. # It's not a valid IP.
my $message = $anvil->Words->string({key => "error_0118", variables => { ip => $anvil->data->{cgi}{$gateway_key}{value} }}); my $message = $anvil->Words->string({key => "error_0118", variables => { ip => $anvil->data->{cgi}{$gateway_key}{value} }});
@ -3376,7 +3376,7 @@ sub sanity_check_manifest_step1
my ($anvil) = @_; my ($anvil) = @_;
my $sane = 1; my $sane = 1;
if ((not $anvil->Validate->is_alphanumeric({string => $anvil->data->{cgi}{prefix}{value}})) or (length($anvil->data->{cgi}{prefix}{value}) > 5)) if ((not $anvil->Validate->alphanumeric({string => $anvil->data->{cgi}{prefix}{value}})) or (length($anvil->data->{cgi}{prefix}{value}) > 5))
{ {
my $message = $anvil->Words->string({key => "error_0020", variables => { field => "#!string!striker_0228!#" }}); my $message = $anvil->Words->string({key => "error_0020", variables => { field => "#!string!striker_0228!#" }});
if ($anvil->data->{cgi}{prefix}{value}) if ($anvil->data->{cgi}{prefix}{value})
@ -3394,7 +3394,7 @@ sub sanity_check_manifest_step1
} }
# We can use Validate to check the domain. # We can use Validate to check the domain.
if (not $anvil->Validate->is_domain_name({name => $anvil->data->{cgi}{domain}{value}, debug => 2})) if (not $anvil->Validate->domain_name({name => $anvil->data->{cgi}{domain}{value}, debug => 2}))
{ {
my $message = $anvil->Words->string({key => "error_0020", variables => { field => "#!string!striker_0007!#" }}); my $message = $anvil->Words->string({key => "error_0020", variables => { field => "#!string!striker_0007!#" }});
if ($anvil->data->{cgi}{domain}{value}) if ($anvil->data->{cgi}{domain}{value})
@ -3412,7 +3412,7 @@ sub sanity_check_manifest_step1
} }
# The sequence and IFN count need to be integers. # The sequence and IFN count need to be integers.
if (not $anvil->Validate->is_positive_integer({number => $anvil->data->{cgi}{sequence}{value}})) if (not $anvil->Validate->positive_integer({number => $anvil->data->{cgi}{sequence}{value}}))
{ {
my $message = $anvil->Words->string({key => "error_0020", variables => { field => "#!string!striker_0009!#" }}); my $message = $anvil->Words->string({key => "error_0020", variables => { field => "#!string!striker_0009!#" }});
if ($anvil->data->{cgi}{sequence}{value}) if ($anvil->data->{cgi}{sequence}{value})
@ -3428,7 +3428,7 @@ sub sanity_check_manifest_step1
"cgi::sequence::value" => $anvil->data->{cgi}{sequence}{value}, "cgi::sequence::value" => $anvil->data->{cgi}{sequence}{value},
}}); }});
} }
if (not $anvil->Validate->is_positive_integer({number => $anvil->data->{cgi}{ifn_count}{value}})) if (not $anvil->Validate->positive_integer({number => $anvil->data->{cgi}{ifn_count}{value}}))
{ {
my $message = $anvil->Words->string({key => "error_0020", variables => { field => "#!string!striker_0230!#" }}); my $message = $anvil->Words->string({key => "error_0020", variables => { field => "#!string!striker_0230!#" }});
if ($anvil->data->{cgi}{ifn_count}{value}) if ($anvil->data->{cgi}{ifn_count}{value})
@ -3736,7 +3736,7 @@ sub process_upses
}}); }});
# Are any values insane? # Are any values insane?
if (not $anvil->Validate->is_host_name({name => $anvil->data->{cgi}{$ups_name_key}{value}, debug => 2})) if (not $anvil->Validate->host_name({name => $anvil->data->{cgi}{$ups_name_key}{value}, debug => 2}))
{ {
# Bad host name # Bad host name
$sane = 0; $sane = 0;
@ -3746,7 +3746,7 @@ sub process_upses
sane => $sane, sane => $sane,
}}); }});
} }
if (not $anvil->Validate->is_ipv4({ip => $anvil->data->{cgi}{$ups_ip_address_key}{value}})) if (not $anvil->Validate->ipv4({ip => $anvil->data->{cgi}{$ups_ip_address_key}{value}}))
{ {
# Bad IP address. # Bad IP address.
$sane = 0; $sane = 0;
@ -4998,7 +4998,7 @@ sub process_prep_network
if ($anvil->data->{cgi}{host_name}{value}) if ($anvil->data->{cgi}{host_name}{value})
{ {
# Is the host name sane? # Is the host name sane?
if (not $anvil->Validate->is_domain_name({name => $anvil->data->{cgi}{host_name}{value}})) if (not $anvil->Validate->domain_name({name => $anvil->data->{cgi}{host_name}{value}}))
{ {
# Nope # Nope
my $error_message = $anvil->Words->string({key => "error_0012", variables => { host_name => $anvil->data->{cgi}{host_name}{value} }}); my $error_message = $anvil->Words->string({key => "error_0012", variables => { host_name => $anvil->data->{cgi}{host_name}{value} }});
@ -5022,7 +5022,7 @@ sub process_prep_network
if ($anvil->data->{cgi}{gateway}{value}) if ($anvil->data->{cgi}{gateway}{value})
{ {
# Is if valid? # Is if valid?
if (not $anvil->Validate->is_ipv4({ip => $anvil->data->{cgi}{gateway}{value}})) if (not $anvil->Validate->ipv4({ip => $anvil->data->{cgi}{gateway}{value}}))
{ {
# Bad IP # Bad IP
my $error_message = $anvil->Words->string({key => "warning_0010", variables => { ip_address => $anvil->data->{cgi}{gateway}{value} }}); my $error_message = $anvil->Words->string({key => "warning_0010", variables => { ip_address => $anvil->data->{cgi}{gateway}{value} }});
@ -5050,7 +5050,7 @@ sub process_prep_network
{ {
$dns =~ s/^\s+//; $dns =~ s/^\s+//;
$dns =~ s/\s+$//; $dns =~ s/\s+$//;
if (not $anvil->Validate->is_ipv4({ip => $dns})) if (not $anvil->Validate->ipv4({ip => $dns}))
{ {
# Bad IP # Bad IP
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "warning_0010", variables => { ip_address => $anvil->data->{cgi}{dns}{value} }}) }}); $anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "warning_0010", variables => { ip_address => $anvil->data->{cgi}{dns}{value} }}) }});
@ -5136,7 +5136,7 @@ sub process_prep_network
} }
my $say_ip_address = "#!string!striker_0152!#"; my $say_ip_address = "#!string!striker_0152!#";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_ip_address => $say_ip_address }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_ip_address => $say_ip_address }});
if (($anvil->data->{cgi}{$ip_key}{value}) && (not $anvil->Validate->is_ipv4({ip => $anvil->data->{cgi}{$ip_key}{value}}))) if (($anvil->data->{cgi}{$ip_key}{value}) && (not $anvil->Validate->ipv4({ip => $anvil->data->{cgi}{$ip_key}{value}})))
{ {
# Bad IP # Bad IP
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "warning_0010", variables => { ip_address => $anvil->data->{cgi}{$ip_key}{value} }}) }}); $anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "warning_0010", variables => { ip_address => $anvil->data->{cgi}{$ip_key}{value} }}) }});
@ -5146,7 +5146,7 @@ sub process_prep_network
"cgi::${ip_key}::alert" => $anvil->data->{cgi}{$ip_key}{alert}, "cgi::${ip_key}::alert" => $anvil->data->{cgi}{$ip_key}{alert},
}}); }});
} }
elsif (($anvil->data->{cgi}{$subnet_key}{value}) && (not $anvil->Validate->is_subnet_mask({subnet_mask => $anvil->data->{cgi}{$subnet_key}{value}}))) elsif (($anvil->data->{cgi}{$subnet_key}{value}) && (not $anvil->Validate->subnet_mask({subnet_mask => $anvil->data->{cgi}{$subnet_key}{value}})))
{ {
# Bad subnet # Bad subnet
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "warning_0017"}) }}); $anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "warning_0017"}) }});
@ -5706,7 +5706,7 @@ sub process_prep_host_page
} }
elsif ($connect) elsif ($connect)
{ {
if (not $anvil->Validate->is_ipv4({ip => $host_ip_address})) if (not $anvil->Validate->ipv4({ip => $host_ip_address}))
{ {
# Bad IP # Bad IP
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "warning_0010", variables => { ip_address => $host_ip_address }}) }}); $anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "warning_0010", variables => { ip_address => $host_ip_address }}) }});
@ -6162,8 +6162,8 @@ sub process_sync_page
foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{'local'}{interface}}) foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{'local'}{interface}})
{ {
next if (($interface !~ /^bcn/) && ($interface !~ /^ifn/)); next if (($interface !~ /^bcn/) && ($interface !~ /^ifn/));
next if not $anvil->Validate->is_ipv4({ip => $anvil->data->{network}{'local'}{interface}{$interface}{ip}}); next if not $anvil->Validate->ipv4({ip => $anvil->data->{network}{'local'}{interface}{$interface}{ip}});
next if not $anvil->Validate->is_subnet_mask({subnet_mask => $anvil->data->{network}{'local'}{interface}{$interface}{subnet_mask}}); next if not $anvil->Validate->subnet_mask({subnet_mask => $anvil->data->{network}{'local'}{interface}{$interface}{subnet_mask}});
my ($network_type, $network_number) = ($interface =~ /^(.*?)(\d+)_/); my ($network_type, $network_number) = ($interface =~ /^(.*?)(\d+)_/);
my $database_user = $anvil->data->{database}{$host_uuid}{user} ? $anvil->data->{database}{$host_uuid}{user} : $anvil->data->{sys}{database}{user}; my $database_user = $anvil->data->{database}{$host_uuid}{user} ? $anvil->data->{database}{$host_uuid}{user} : $anvil->data->{sys}{database}{user};
@ -6197,7 +6197,7 @@ sub process_sync_page
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { uuid => $uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { uuid => $uuid }});
next if not $anvil->Validate->is_uuid({uuid => $uuid}); next if not $anvil->Validate->uuid({uuid => $uuid});
next if $uuid eq $host_uuid; next if $uuid eq $host_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { uuid => $uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { uuid => $uuid }});
@ -6402,8 +6402,8 @@ sub add_sync_peer
# Is the host a domain or IP? # Is the host a domain or IP?
# If so, and 'bi-directional' is set, verify we can ssh into the peer. # If so, and 'bi-directional' is set, verify we can ssh into the peer.
my $is_domain = $anvil->Validate->is_domain_name({name => $host}); my $is_domain = $anvil->Validate->domain_name({name => $host});
my $is_ipv4 = $anvil->Validate->is_ipv4({ip => $host}); my $is_ipv4 = $anvil->Validate->ipv4({ip => $host});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
is_domain => $is_domain, is_domain => $is_domain,
is_ipv4 => $is_ipv4, is_ipv4 => $is_ipv4,
@ -7375,7 +7375,7 @@ sub sanity_check_step2
$ip =~ s/^\s+//; $ip =~ s/^\s+//;
$ip =~ s/\s+$//; $ip =~ s/\s+$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { ip => $ip }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { ip => $ip }});
if (not $anvil->Validate->is_ipv4({ip => $ip})) if (not $anvil->Validate->ipv4({ip => $ip}))
{ {
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0015"}) }}); $anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0015"}) }});
$anvil->data->{cgi}{dns}{alert} = 1; $anvil->data->{cgi}{dns}{alert} = 1;
@ -7701,7 +7701,7 @@ sub sanity_check_step1
} }
# The prefix needs to be alphanumeric and be between 1 ~ 5 chatacters. # The prefix needs to be alphanumeric and be between 1 ~ 5 chatacters.
if ((not $anvil->Validate->is_alphanumeric({string => $anvil->data->{cgi}{prefix}{value}})) or (length($anvil->data->{cgi}{prefix}{value}) > 5)) if ((not $anvil->Validate->alphanumeric({string => $anvil->data->{cgi}{prefix}{value}})) or (length($anvil->data->{cgi}{prefix}{value}) > 5))
{ {
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0021"}) }}); $anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0021"}) }});
$anvil->data->{cgi}{prefix}{alert} = 1; $anvil->data->{cgi}{prefix}{alert} = 1;
@ -7747,7 +7747,7 @@ sub sanity_check_step1
} }
# The sequence and IFN count need to be integers. # The sequence and IFN count need to be integers.
if (not $anvil->Validate->is_positive_integer({number => $anvil->data->{cgi}{sequence}{value}})) if (not $anvil->Validate->positive_integer({number => $anvil->data->{cgi}{sequence}{value}}))
{ {
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0022", variables => { field => "striker_0009" }}) }}); $anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0022", variables => { field => "striker_0009" }}) }});
$anvil->data->{cgi}{sequence}{alert} = 1; $anvil->data->{cgi}{sequence}{alert} = 1;
@ -7769,7 +7769,7 @@ sub sanity_check_step1
}); });
} }
if (not $anvil->Validate->is_positive_integer({number => $anvil->data->{cgi}{ifn_count}{value}})) if (not $anvil->Validate->positive_integer({number => $anvil->data->{cgi}{ifn_count}{value}}))
{ {
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0022", variables => { field => "striker_0011" }}) }}); $anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0022", variables => { field => "striker_0011" }}) }});
$anvil->data->{cgi}{ifn_count}{alert} = 1; $anvil->data->{cgi}{ifn_count}{alert} = 1;
@ -8237,7 +8237,7 @@ sub generate_ip
default_subnet_mask => $default_subnet_mask, default_subnet_mask => $default_subnet_mask,
}}); }});
if (($anvil->Validate->is_ipv4({ip => $default_ip})) && ($anvil->Validate->is_ipv4({ip => $default_subnet_mask}))) if (($anvil->Validate->ipv4({ip => $default_ip})) && ($anvil->Validate->ipv4({ip => $default_subnet_mask})))
{ {
# Valid values. # Valid values.
my ($ip_octet1, $ip_octet2, $ip_octet3, $ip_octet4) = (split/\./, $default_ip); my ($ip_octet1, $ip_octet2, $ip_octet3, $ip_octet4) = (split/\./, $default_ip);

@ -42,6 +42,7 @@ Requires: mlocate
Requires: perl-Capture-Tiny Requires: perl-Capture-Tiny
Requires: perl-Data-Dumper Requires: perl-Data-Dumper
Requires: perl-Data-Validate-Domain Requires: perl-Data-Validate-Domain
Requires: perl-Data-Validate-IP
Requires: perl-DBD-Pg Requires: perl-DBD-Pg
Requires: perl-DBI Requires: perl-DBI
Requires: perl-Data-Validate-Domain Requires: perl-Data-Validate-Domain

@ -897,6 +897,7 @@ If the targets are unique, did you copy the full database directory? A unique id
<key name="log_0478">The libvirtd' daemon isn't running. Will check for and remove virsh networks set to start on boot.</key> <key name="log_0478">The libvirtd' daemon isn't running. Will check for and remove virsh networks set to start on boot.</key>
<key name="log_0479">Removing the symlink: [#!variable!symlink!#].</key> <key name="log_0479">Removing the symlink: [#!variable!symlink!#].</key>
<key name="log_0480">Updating the cache state file.</key> <key name="log_0480">Updating the cache state file.</key>
<key name="log_0481">[ Note ] - The host: [#!variable!host!#] entry in /etc/hosts has changed IP from: [#!variable!old_ip!#] to: [#!variable!new_ip!#].</key>
<!-- Messages for users (less technical than log entries), though sometimes used for logs, too. --> <!-- Messages for users (less technical than log entries), though sometimes used for logs, too. -->
<key name="message_0001">The host name: [#!variable!target!#] does not resolve to an IP address.</key> <key name="message_0001">The host name: [#!variable!target!#] does not resolve to an IP address.</key>
@ -1155,6 +1156,16 @@ About to try to download aproximately: [#!variable!packages!#] packages needed t
<key name="message_0174">Confirmed by switch, proceeding with purge of: [#!variable!host_name!#].</key> <key name="message_0174">Confirmed by switch, proceeding with purge of: [#!variable!host_name!#].</key>
<key name="message_0175">Thank you, proceeding.</key> <key name="message_0175">Thank you, proceeding.</key>
<key name="message_0176">The host: [#!variable!host_name!#] has been purged.</key> <key name="message_0176">The host: [#!variable!host_name!#] has been purged.</key>
<key name="message_0177">
##] anvil-daemon [###########################################################################################
# NOTE: The /etc/hosts file is managed by the Anvil! system. Manual additions will be retained, but #
# conflicts with hosts managed by the Anvil! system will be overwritten. Specifically, all hosts #
# related to Striker dashboards and, for hosts in an Anvil!, peer nodes and DR hosts will be set to #
# use the IPs recorded in the Anvil! database (which themselves are recorded by the anvil-daemon #
# running on each host). If / when an IP address changes, the host files on all associated hosts #
# should update within a minute. #
#############################################################################################################
</key> <!-- Translation note: System->update_hosts() looks for '##] anvil-daemon [##' to know if this alert was added to /etc/hosts. As such, please retain that exact string in your translation.
<!-- Success messages shown to the user --> <!-- Success messages shown to the user -->
<key name="ok_0001">Saved the mail server information successfully!</key> <key name="ok_0001">Saved the mail server information successfully!</key>
@ -1632,6 +1643,7 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st
<key name="warning_0048">[ Warning ] - The password verification was not set.</key> <key name="warning_0048">[ Warning ] - The password verification was not set.</key>
<key name="warning_0049">[ Warning ] - The passwords do not match.</key> <key name="warning_0049">[ Warning ] - The passwords do not match.</key>
<key name="warning_0050">[ Warning ] - The host: [#!variable!host!#] now belongs to the #!string!brand_0006!#, it can't be used here anymore.</key> <key name="warning_0050">[ Warning ] - The host: [#!variable!host!#] now belongs to the #!string!brand_0006!#, it can't be used here anymore.</key>
<key name="warning_0051">[ Warning ] - The IP address: [#!variable!ip!#] is not valid. Ignoring associated hosts: [#!variable!hosts!#].</key>
</language> </language>
<!-- 日本語 --> <!-- 日本語 -->

@ -398,7 +398,7 @@ sub reconfigure_network
} }
if (($anvil->data->{variables}{form}{config_step2}{$ip_key}{value}) && if (($anvil->data->{variables}{form}{config_step2}{$ip_key}{value}) &&
($anvil->data->{variables}{form}{config_step2}{$ip_key}{value} ne "dhcp") && ($anvil->data->{variables}{form}{config_step2}{$ip_key}{value} ne "dhcp") &&
(not $anvil->Validate->is_ipv4({ip => $anvil->data->{variables}{form}{config_step2}{$ip_key}{value}}))) (not $anvil->Validate->ipv4({ip => $anvil->data->{variables}{form}{config_step2}{$ip_key}{value}})))
{ {
# Something was set, but it isn't valid. # Something was set, but it isn't valid.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "log_0148", variables => { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "log_0148", variables => {
@ -417,7 +417,7 @@ sub reconfigure_network
}}); }});
# Are we building bonded interfaces? # Are we building bonded interfaces?
if ($anvil->Validate->is_mac({mac => $link2_mac})) if ($anvil->Validate->mac({mac => $link2_mac}))
{ {
# Yup! # Yup!
my $say_network = ""; my $say_network = "";
@ -733,7 +733,7 @@ sub reconfigure_network
rename_interface($anvil, $anvil->data->{network}{'local'}{mac_address}{$link2_mac}{interface}, $new_link2_iface); rename_interface($anvil, $anvil->data->{network}{'local'}{mac_address}{$link2_mac}{interface}, $new_link2_iface);
} }
} }
elsif ((exists $anvil->data->{variables}{form}{config_step2}{$link1_key}{value}) && ($anvil->Validate->is_mac({mac => $anvil->data->{variables}{form}{config_step2}{$link1_key}{value}}))) elsif ((exists $anvil->data->{variables}{form}{config_step2}{$link1_key}{value}) && ($anvil->Validate->mac({mac => $anvil->data->{variables}{form}{config_step2}{$link1_key}{value}})))
{ {
### NOTE: This only applies when configuring Striker dashboards. They can't ### NOTE: This only applies when configuring Striker dashboards. They can't
### be 'dhcp', either, so no checks are made for those cases. Likewise, ### be 'dhcp', either, so no checks are made for those cases. Likewise,
@ -1024,7 +1024,7 @@ sub get_uuid_from_interface_file
{ {
my $test_uuid = $1; my $test_uuid = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { test_uuid => $test_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { test_uuid => $test_uuid }});
if ($anvil->Validate->is_uuid({uuid => $test_uuid})) if ($anvil->Validate->uuid({uuid => $test_uuid}))
{ {
$uuid = $test_uuid; $uuid = $test_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { uuid => $uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { uuid => $uuid }});

@ -112,7 +112,7 @@ sub get_job_details
{ {
my $job_uuid = $anvil->Job->get_job_uuid({debug => 2, program => $THIS_FILE}); my $job_uuid = $anvil->Job->get_job_uuid({debug => 2, program => $THIS_FILE});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }});
if ($anvil->Validate->is_uuid({uuid => $job_uuid})) if ($anvil->Validate->uuid({uuid => $job_uuid}))
{ {
# Got one! # Got one!
$anvil->data->{switches}{'job-uuid'} = $job_uuid; $anvil->data->{switches}{'job-uuid'} = $job_uuid;

@ -369,7 +369,7 @@ sub load_job_data
foreach my $state_uuid (split/,/, $job_data) foreach my $state_uuid (split/,/, $job_data)
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { state_uuid => $state_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { state_uuid => $state_uuid }});
if ($anvil->Validate->is_uuid({uuid => $state_uuid})) if ($anvil->Validate->uuid({uuid => $state_uuid}))
{ {
push @{$anvil->data->{state_uuids}}, $state_uuid; push @{$anvil->data->{state_uuids}}, $state_uuid;
} }

@ -263,7 +263,7 @@ fi;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { file_body => $file_body }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { file_body => $file_body }});
my $host_uuid = ""; my $host_uuid = "";
if ((not $file_body) or (not $anvil->Validate->is_uuid({uuid => $file_body}))) if ((not $file_body) or (not $anvil->Validate->uuid({uuid => $file_body})))
{ {
# No good, Try dmidecode. # No good, Try dmidecode.
my ($output, $error, $return_code) = $anvil->Remote->call({ my ($output, $error, $return_code) = $anvil->Remote->call({
@ -279,7 +279,7 @@ fi;
error => $error, error => $error,
return_code => $return_code, return_code => $return_code,
}}); }});
if ($anvil->Validate->is_uuid({uuid => $output})) if ($anvil->Validate->uuid({uuid => $output}))
{ {
# Got it. # Got it.
$host_uuid = $output; $host_uuid = $output;
@ -334,7 +334,7 @@ sub get_password
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0083"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0083"});
$anvil->nice_exit({exit_code => 1}); $anvil->nice_exit({exit_code => 1});
} }
elsif (not $anvil->Validate->is_uuid({uuid => $anvil->data->{switches}{'state-uuid'}})) elsif (not $anvil->Validate->uuid({uuid => $anvil->data->{switches}{'state-uuid'}}))
{ {
print "connected=0\n"; print "connected=0\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0082", variables => {state_uuid => $anvil->data->{switches}{'state-uuid'} }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0082", variables => {state_uuid => $anvil->data->{switches}{'state-uuid'} }});

@ -82,7 +82,7 @@ sub set_host_name
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, 'print' => 1, key => "job_0061", variables => { host_name => $anvil->data->{data}{host_name} }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, 'print' => 1, key => "job_0061", variables => { host_name => $anvil->data->{data}{host_name} }});
update_progress($anvil, $anvil->data->{job}{progress}, "job_0061,!!host_name!".$anvil->data->{data}{host_name}."!!"); update_progress($anvil, $anvil->data->{job}{progress}, "job_0061,!!host_name!".$anvil->data->{data}{host_name}."!!");
if (not $anvil->Validate->is_domain_name({name => $anvil->data->{data}{host_name}})) if (not $anvil->Validate->domain_name({name => $anvil->data->{data}{host_name}}))
{ {
# Bad host_name. # Bad host_name.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, 'print' => 1, key => "job_0062", variables => { host_name => $anvil->data->{data}{host_name} }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, 'print' => 1, key => "job_0062", variables => { host_name => $anvil->data->{data}{host_name} }});
@ -163,7 +163,7 @@ sub add_databases
interface => $interface, interface => $interface,
local_ip => $local_ip, local_ip => $local_ip,
}}); }});
if (($local_ip) && ($anvil->Validate->is_ipv4({ip => $local_ip}))) if (($local_ip) && ($anvil->Validate->ipv4({ip => $local_ip})))
{ {
$db_host = $local_ip; $db_host = $local_ip;
$db_port = $anvil->data->{database}{$host_uuid}{port}; $db_port = $anvil->data->{database}{$host_uuid}{port};

@ -462,7 +462,7 @@ sub setup_boot_environment
next if $interface !~ /^bcn/; next if $interface !~ /^bcn/;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "network::local::${interface}::ip" => $anvil->data->{network}{'local'}{interface}{$interface}{ip} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "network::local::${interface}::ip" => $anvil->data->{network}{'local'}{interface}{$interface}{ip} }});
if ($anvil->Validate->is_ipv4({ip => $anvil->data->{network}{'local'}{interface}{$interface}{ip} })) if ($anvil->Validate->ipv4({ip => $anvil->data->{network}{'local'}{interface}{$interface}{ip} }))
{ {
$bcn_interface = $interface; $bcn_interface = $interface;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { bcn_interface => $bcn_interface }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { bcn_interface => $bcn_interface }});

@ -185,7 +185,7 @@ sub process_entry
$anvil->data->{config}{rewrite} = 0; $anvil->data->{config}{rewrite} = 0;
# Is anything missing? # Is anything missing?
if ((not $host_uuid) or (not $anvil->Validate->is_uuid({uuid => $host_uuid}))) if ((not $host_uuid) or (not $anvil->Validate->uuid({uuid => $host_uuid})))
{ {
# Invalid UUID. # Invalid UUID.
print $anvil->Words->string({key => "error_0031", variables => { host_uuid => $host_uuid }})."\n"; print $anvil->Words->string({key => "error_0031", variables => { host_uuid => $host_uuid }})."\n";

@ -193,8 +193,8 @@ sub scan
my $subnet_mask = $2; my $subnet_mask = $2;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "switches::network" => $anvil->data->{switches}{network} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "switches::network" => $anvil->data->{switches}{network} }});
my $ip_valid = $anvil->Validate->is_ipv4({ip => $ip}); my $ip_valid = $anvil->Validate->ipv4({ip => $ip});
my $subnet_mask_valid = $anvil->Validate->is_ipv4({ip => $subnet_mask}); my $subnet_mask_valid = $anvil->Validate->ipv4({ip => $subnet_mask});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
ip_valid => $ip_valid, ip_valid => $ip_valid,
subnet_mask_valid => $subnet_mask_valid, subnet_mask_valid => $subnet_mask_valid,
@ -330,7 +330,7 @@ sub call_nmap
ip => $ip, ip => $ip,
subnet_mask => $subnet_mask, subnet_mask => $subnet_mask,
}}); }});
if ($anvil->Validate->is_ipv4({ip => $subnet_mask})) if ($anvil->Validate->ipv4({ip => $subnet_mask}))
{ {
# Convert to CIDR # Convert to CIDR
my $cidr = $anvil->Convert->cidr({subnet_mask => $subnet_mask}); my $cidr = $anvil->Convert->cidr({subnet_mask => $subnet_mask});
@ -383,8 +383,8 @@ sub call_nmap
}}); }});
# Sane? # Sane?
my $mac_valid = $anvil->Validate->is_hex({string => $this_mac, sloppy => 1}); my $mac_valid = $anvil->Validate->hex({string => $this_mac, sloppy => 1});
my $ip_valid = $anvil->Validate->is_ipv4({ip => $this_ip}); my $ip_valid = $anvil->Validate->ipv4({ip => $this_ip});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
mac_valid => $mac_valid, mac_valid => $mac_valid,
ip_valid => $ip_valid, ip_valid => $ip_valid,

Loading…
Cancel
Save