* Added an undocumented (does this count?) parameter 'log_level' to Database->insert_or_update_variables() to allow per-call logging levels.

* Created Validate->form_field() which makes it a little quicker/easier to sanity check a form field that uses one of the other Validate methods.
* Added Validate->is_mac to validate MAC addresses.
* Got config_step2 finishes and sanity checked.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent 3d385a5731
commit bb89254207
  1. 64
      AN/Tools/Database.pm
  2. 9
      AN/Tools/Template.pm
  3. 220
      AN/Tools/Validate.pm
  4. 296
      cgi-bin/home
  5. 2
      cgi-bin/words.xml
  6. 2
      html/skins/alteeve/main.css
  7. 52
      html/skins/alteeve/main.html

@ -2020,7 +2020,7 @@ sub insert_or_update_variables
my $self = shift; my $self = shift;
my $parameter = shift; my $parameter = shift;
my $an = $self->parent; my $an = $self->parent;
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0125", variables => { method => "Database->insert_or_update_variables()" }}); $an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0125", variables => { method => "Database->insert_or_update_variables()" }});
my $variable_uuid = defined $parameter->{variable_uuid} ? $parameter->{variable_uuid} : ""; my $variable_uuid = defined $parameter->{variable_uuid} ? $parameter->{variable_uuid} : "";
my $variable_name = defined $parameter->{variable_name} ? $parameter->{variable_name} : ""; my $variable_name = defined $parameter->{variable_name} ? $parameter->{variable_name} : "";
@ -2031,7 +2031,8 @@ sub insert_or_update_variables
my $variable_source_uuid = defined $parameter->{variable_source_uuid} ? $parameter->{variable_source_uuid} : "NULL"; my $variable_source_uuid = defined $parameter->{variable_source_uuid} ? $parameter->{variable_source_uuid} : "NULL";
my $variable_source_table = defined $parameter->{variable_source_table} ? $parameter->{variable_source_table} : "NULL"; my $variable_source_table = defined $parameter->{variable_source_table} ? $parameter->{variable_source_table} : "NULL";
my $update_value_only = defined $parameter->{update_value_only} ? $parameter->{update_value_only} : 1; my $update_value_only = defined $parameter->{update_value_only} ? $parameter->{update_value_only} : 1;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { my $log_level = defined $parameter->{log_level} ? $parameter->{log_level} : 3; # Undocumented for now.
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => {
variable_uuid => $variable_uuid, variable_uuid => $variable_uuid,
variable_name => $variable_name, variable_name => $variable_name,
variable_value => $variable_value, variable_value => $variable_value,
@ -2041,6 +2042,7 @@ sub insert_or_update_variables
variable_source_uuid => $variable_source_uuid, variable_source_uuid => $variable_source_uuid,
variable_source_table => $variable_source_table, variable_source_table => $variable_source_table,
update_value_only => $update_value_only, update_value_only => $update_value_only,
log_level => $log_level,
}}); }});
# We'll need either the name or UUID. # We'll need either the name or UUID.
@ -2062,11 +2064,11 @@ FROM
variables variables
WHERE WHERE
variable_uuid = ".$an->data->{sys}{use_db_fh}->quote($variable_uuid); variable_uuid = ".$an->data->{sys}{use_db_fh}->quote($variable_uuid);
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { query => $query }});
$variable_name = $an->Database->query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0]; $variable_name = $an->Database->query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0];
$variable_name = "" if not defined $variable_name; $variable_name = "" if not defined $variable_name;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { variable_name => $variable_name }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { variable_name => $variable_name }});
} }
if (($variable_name) && (not $variable_uuid)) if (($variable_name) && (not $variable_uuid))
@ -2088,23 +2090,23 @@ AND
"; ";
} }
$query .= ";"; $query .= ";";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { query => $query }});
my $results = $an->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $an->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results}; my $count = @{$results};
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => {
results => $results, results => $results,
count => $count, count => $count,
}}); }});
foreach my $row (@{$results}) foreach my $row (@{$results})
{ {
$variable_uuid = $row->[0]; $variable_uuid = $row->[0];
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { variable_uuid => $variable_uuid }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { variable_uuid => $variable_uuid }});
} }
} }
# If I still don't have an variable_uuid, we're INSERT'ing . # If I still don't have an variable_uuid, we're INSERT'ing .
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { variable_uuid => $variable_uuid }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { variable_uuid => $variable_uuid }});
if (not $variable_uuid) if (not $variable_uuid)
{ {
# INSERT # INSERT
@ -2135,7 +2137,7 @@ INSERT INTO
); );
"; ";
$query =~ s/'NULL'/NULL/g; $query =~ s/'NULL'/NULL/g;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { query => $query }});
$an->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); $an->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
} }
@ -2161,18 +2163,18 @@ AND
"; ";
} }
$query .= ";"; $query .= ";";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { query => $query }});
my $results = $an->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $an->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results}; my $count = @{$results};
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => {
results => $results, results => $results,
count => $count, count => $count,
}}); }});
foreach my $row (@{$results}) foreach my $row (@{$results})
{ {
my $old_variable_value = defined $row->[0] ? $row->[0] : ""; my $old_variable_value = defined $row->[0] ? $row->[0] : "";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { old_variable_value => $old_variable_value }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { old_variable_value => $old_variable_value }});
# Anything change? # Anything change?
if ($old_variable_value ne $variable_value) if ($old_variable_value ne $variable_value)
@ -2197,7 +2199,7 @@ AND
} }
$query .= ";"; $query .= ";";
$query =~ s/'NULL'/NULL/g; $query =~ s/'NULL'/NULL/g;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { query => $query }});
$an->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); $an->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
} }
@ -2218,11 +2220,11 @@ FROM
WHERE WHERE
variable_uuid = ".$an->data->{sys}{use_db_fh}->quote($variable_uuid)." variable_uuid = ".$an->data->{sys}{use_db_fh}->quote($variable_uuid)."
;"; ;";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { query => $query }});
my $results = $an->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $an->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results}; my $count = @{$results};
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => {
results => $results, results => $results,
count => $count, count => $count,
}}); }});
@ -2233,7 +2235,7 @@ WHERE
my $old_variable_default = $row->[2] ? $row->[2] : "NULL"; my $old_variable_default = $row->[2] ? $row->[2] : "NULL";
my $old_variable_description = $row->[3] ? $row->[3] : "NULL"; my $old_variable_description = $row->[3] ? $row->[3] : "NULL";
my $old_variable_section = $row->[4] ? $row->[4] : "NULL"; my $old_variable_section = $row->[4] ? $row->[4] : "NULL";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => {
old_variable_name => $old_variable_name, old_variable_name => $old_variable_name,
old_variable_value => $old_variable_value, old_variable_value => $old_variable_value,
old_variable_default => $old_variable_default, old_variable_default => $old_variable_default,
@ -2263,7 +2265,7 @@ WHERE
variable_uuid = ".$an->data->{sys}{use_db_fh}->quote($variable_uuid)." variable_uuid = ".$an->data->{sys}{use_db_fh}->quote($variable_uuid)."
"; ";
$query =~ s/'NULL'/NULL/g; $query =~ s/'NULL'/NULL/g;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { query => $query }});
$an->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); $an->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
} }
@ -2271,7 +2273,7 @@ WHERE
} }
} }
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { variable_uuid => $variable_uuid }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $log_level, list => { variable_uuid => $variable_uuid }});
return($variable_uuid); return($variable_uuid);
} }
@ -3233,7 +3235,7 @@ sub write
my $secure = $parameter->{secure} ? $parameter->{secure} : 0; my $secure = $parameter->{secure} ? $parameter->{secure} : 0;
my $source = $parameter->{source} ? $parameter->{source} : $THIS_FILE; my $source = $parameter->{source} ? $parameter->{source} : $THIS_FILE;
my $reenter = $parameter->{reenter} ? $parameter->{reenter} : ""; my $reenter = $parameter->{reenter} ? $parameter->{reenter} : "";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
id => $id, id => $id,
"cache::db_fh::${id}" => $an->data->{cache}{db_fh}{$id}, "cache::db_fh::${id}" => $an->data->{cache}{db_fh}{$id},
line => $line, line => $line,
@ -3262,14 +3264,14 @@ sub write
my @db_ids; my @db_ids;
if ($id) if ($id)
{ {
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { id => $id }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { id => $id }});
push @db_ids, $id; push @db_ids, $id;
} }
else else
{ {
foreach my $id (sort {$a cmp $b} keys %{$an->data->{cache}{db_fh}}) foreach my $id (sort {$a cmp $b} keys %{$an->data->{cache}{db_fh}})
{ {
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { id => $id }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { id => $id }});
push @db_ids, $id; push @db_ids, $id;
} }
} }
@ -3278,19 +3280,19 @@ sub write
my $limit = 25000; my $limit = 25000;
my $count = 0; my $count = 0;
my $query_set = []; my $query_set = [];
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "sys::database::maximum_batch_size" => $an->data->{sys}{database}{maximum_batch_size} }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "sys::database::maximum_batch_size" => $an->data->{sys}{database}{maximum_batch_size} }});
if ($an->data->{sys}{database}{maximum_batch_size}) if ($an->data->{sys}{database}{maximum_batch_size})
{ {
if ($an->data->{sys}{database}{maximum_batch_size} =~ /\D/) if ($an->data->{sys}{database}{maximum_batch_size} =~ /\D/)
{ {
# Bad value. # Bad value.
$an->data->{sys}{database}{maximum_batch_size} = 25000; $an->data->{sys}{database}{maximum_batch_size} = 25000;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "sys::database::maximum_batch_size" => $an->data->{sys}{database}{maximum_batch_size} }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "sys::database::maximum_batch_size" => $an->data->{sys}{database}{maximum_batch_size} }});
} }
# Use the set value now. # Use the set value now.
$limit = $an->data->{sys}{database}{maximum_batch_size}; $limit = $an->data->{sys}{database}{maximum_batch_size};
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { limit => $limit }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { limit => $limit }});
} }
if (ref($query) eq "ARRAY") if (ref($query) eq "ARRAY")
{ {
@ -3299,7 +3301,7 @@ sub write
# If I am re-entering, then we'll proceed normally. If not, and if we have more than 10k # If I am re-entering, then we'll proceed normally. If not, and if we have more than 10k
# queries, we'll split up the queries into 10k chunks and re-enter. # queries, we'll split up the queries into 10k chunks and re-enter.
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
count => $count, count => $count,
limit => $limit, limit => $limit,
reenter => $reenter, reenter => $reenter,
@ -3308,7 +3310,7 @@ sub write
{ {
my $i = 0; my $i = 0;
my $next = $limit; my $next = $limit;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { i => $i, 'next' => $next }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { i => $i, 'next' => $next }});
foreach my $this_query (@{$query}) foreach my $this_query (@{$query})
{ {
push @{$query_set}, $this_query; push @{$query_set}, $this_query;
@ -3327,7 +3329,7 @@ sub write
# This can get memory intensive, so check our RAM usage and # This can get memory intensive, so check our RAM usage and
# bail if we're eating too much. # bail if we're eating too much.
my $ram_use = $an->System->check_memory({program_name => $THIS_FILE}); my $ram_use = $an->System->check_memory({program_name => $THIS_FILE});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ram_use => $ram_use }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { ram_use => $ram_use }});
# Wipe out the old set array, create it as a new anonymous array and reset 'i'. # Wipe out the old set array, create it as a new anonymous array and reset 'i'.
undef $query_set; undef $query_set;
@ -3353,11 +3355,11 @@ sub write
foreach my $id (@db_ids) foreach my $id (@db_ids)
{ {
# Test access to the DB before we do the actual query # Test access to the DB before we do the actual query
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { id => $id }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { id => $id }});
$an->Database->_test_access({id => $id}); $an->Database->_test_access({id => $id});
# Do the actual query(ies) # Do the actual query(ies)
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
id => $id, id => $id,
count => $count, count => $count,
}}); }});
@ -3391,7 +3393,7 @@ sub write
}}); }});
} }
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { count => $count }});
if ($count) if ($count)
{ {
# Commit the changes. # Commit the changes.
@ -3399,7 +3401,7 @@ sub write
} }
} }
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { count => $count }});
if ($count) if ($count)
{ {
# Free up some memory. # Free up some memory.

@ -132,6 +132,7 @@ sub get
name => $name, name => $name,
skin => $skin, skin => $skin,
}}); }});
my $show_name = $name eq "http_headers" ? 0 : 1;
my $error = 0; my $error = 0;
if (not $file) if (not $file)
@ -187,6 +188,10 @@ sub get
if ($line =~ /^<!-- start $name -->/) if ($line =~ /^<!-- start $name -->/)
{ {
$in_template = 1; $in_template = 1;
if ($show_name)
{
$template .= $line."\n";
}
next; next;
} }
if ($in_template) if ($in_template)
@ -194,6 +199,10 @@ sub get
if ($line =~ /^<!-- end $name -->/) if ($line =~ /^<!-- end $name -->/)
{ {
$in_template = 0; $in_template = 0;
if ($show_name)
{
$template .= $line."\n";
}
last; last;
} }
else else

@ -12,10 +12,13 @@ our $VERSION = "3.0.0";
my $THIS_FILE = "Validate.pm"; my $THIS_FILE = "Validate.pm";
### Methods; ### Methods;
# form_field
# is_alphanumeric # is_alphanumeric
# is_domain_name # is_domain_name
# is_ipv4 # is_ipv4
# is_mac
# is_positive_integer # is_positive_integer
# is_subnet
# is_uuid # is_uuid
=pod =pod
@ -81,6 +84,132 @@ sub parent
# Public methods # # Public methods #
############################################################################################################# #############################################################################################################
=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 >>.
=head2 Parameters;
=head3 empty_ok (optional)
This can be set to C<< 1 >> to have this method return valid is the variable exists, is defined by is an empty string.
=head3 name (required)
This is the input field name, which is used to check C<< cgi::<name>::value >>.
=head3 type (required)
This is the type to be checked. Valid options are;
=head4 alphanumeric
=head4 domain_name
=head4 ipv4
=head4 mac
=head4 positive_integer
If this type is used, you can use the C<< zero >> parameter which can be set to C<< 1 >> to have a value of C<< 0 >> be considered valid.
=head4 subnet
=head4 uuid
=cut
sub form_field
{
my $self = shift;
my $parameter = shift;
my $an = $self->parent;
my $valid = 1;
my $debug = 2;
my $name = defined $parameter->{name} ? $parameter->{name} : "";
my $type = defined $parameter->{type} ? $parameter->{type} : "";
my $empty_ok = defined $parameter->{empty_ok} ? $parameter->{empty_ok} : 0;
my $zero = defined $parameter->{zero} ? $parameter->{zero} : 0;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
name => $name,
type => $type,
empty_ok => $empty_ok,
}});
if ((not $name) or (not $type))
{
$valid = 0;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
}
else
{
if ((not exists $an->data->{cgi}{$name}{value}) or (not defined $an->data->{cgi}{$name}{value}))
{
# Not defined
$valid = 0;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
}
else
{
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "cgi::${name}::value" => $an->data->{cgi}{$name}{value} }});
if (not $an->data->{cgi}{$name}{value})
{
if (not $empty_ok)
{
$valid = 0;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
}
}
elsif (($type eq "alphanumeric") && (not $an->Validate->is_alphanumeric({string => $an->data->{cgi}{$name}{value}})))
{
$valid = 0;
$an->data->{cgi}{$name}{alert} = 1;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $an->data->{cgi}{$name}{alert} }});
}
elsif (($type eq "domain_name") && (not $an->Validate->is_domain_name({name => $an->data->{cgi}{$name}{value}})))
{
$valid = 0;
$an->data->{cgi}{$name}{alert} = 1;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $an->data->{cgi}{$name}{alert} }});
}
elsif (($type eq "ipv4") && (not $an->Validate->is_ipv4({ip => $an->data->{cgi}{$name}{value}})))
{
$valid = 0;
$an->data->{cgi}{$name}{alert} = 1;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $an->data->{cgi}{$name}{alert} }});
}
elsif (($type eq "mac") && (not $an->Validate->is_mac({mac => $an->data->{cgi}{$name}{value}})))
{
$valid = 0;
$an->data->{cgi}{$name}{alert} = 1;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $an->data->{cgi}{$name}{alert} }});
}
elsif (($type eq "positive_integer") && (not $an->Validate->is_positive_integer({number => $an->data->{cgi}{$name}{value}, zero => $zero})))
{
$valid = 0;
$an->data->{cgi}{$name}{alert} = 1;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $an->data->{cgi}{$name}{alert} }});
}
elsif (($type eq "subnet") && (not $an->Validate->is_subnet({subnet => $an->data->{cgi}{$name}{value}})))
{
$valid = 0;
$an->data->{cgi}{$name}{alert} = 1;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $an->data->{cgi}{$name}{alert} }});
}
elsif (($type eq "uuid") && (not $an->Validate->is_uuid({uuid => $an->data->{cgi}{$name}{value}})))
{
$valid = 0;
$an->data->{cgi}{$name}{alert} = 1;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { valid => $valid, "cgi::${name}::alert" => $an->data->{cgi}{$name}{alert} }});
}
}
}
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
return($valid);
}
=head2 is_alphanumeric =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. 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.
@ -234,6 +363,39 @@ sub is_ipv4
return($valid); return($valid);
} }
=head2 is_mac
Checks if the passed-in string is a valid network MAC address. Returns 'C<< 1 >>' if OK, 'C<< 0 >>' if not.
=head2 Parameters;
=head3 mac (required)
This is the network MAC address to verify.
=cut
sub is_mac
{
my $self = shift;
my $parameter = shift;
my $an = $self->parent;
my $debug = 3;
my $mac = defined $parameter->{mac} ? $parameter->{mac} : "";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { mac => $mac }});
my $valid = 0;
if ($mac =~ /^([0-9a-f]{2}([:-]|$)){6}$/i)
{
# It is in the right format.
$valid = 1;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
}
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
return($valid);
}
=head2 is_positive_integer =head2 is_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.
@ -292,6 +454,61 @@ sub is_positive_integer
return($valid); return($valid);
} }
=head2 is_subnet
This method takes a subnet 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 >>'.
=head2 Parameters;
=head3 subnet (required)
This is the address to verify.
=cut
sub is_subnet
{
my $self = shift;
my $parameter = shift;
my $an = $self->parent;
my $valid = 0;
my $debug = 3;
my $subnet = defined $parameter->{subnet} ? $parameter->{subnet} : 0;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { subnet => $subnet }});
if ($subnet)
{
# We have something. Is it an IPv4 address?
if ($an->Validate->is_ipv4({ip => $subnet}))
{
# It is. Try converting it to a CIDR notation. If we get an empty string back, it isn't valid.
my $cidr = $an->Convert->cidr({subnet => $subnet});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { cidr => $cidr }});
if ($cidr)
{
# It's valid.
$valid = 1;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
}
else
{
# OK, maybe it's a CIDR notation?
my $ip = $an->Convert->cidr({cidr => $subnet});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { ip => $ip }});
if ($ip)
{
# There we go.
$valid = 1;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
}
}
}
}
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { valid => $valid }});
return($valid);
}
=head2 is_uuid =head2 is_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 >>'.
@ -326,3 +543,6 @@ sub is_uuid
return($valid); return($valid);
} }
1;

@ -99,6 +99,22 @@ elsif ($an->data->{cgi}{step}{value} eq "step1")
$body = config_step1($an); $body = config_step1($an);
} }
} }
elsif ($an->data->{cgi}{step}{value} eq "step2")
{
# Sanity check step1.
my $sane = sanity_check_step2($an);
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { sane => $sane }});
if ($sane)
{
# Step 1 was sanem show step 2.
$body = config_step3($an);
}
else
{
# No good
$body = config_step2($an);
}
}
else else
{ {
$body = get_network_details_form($an); $body = get_network_details_form($an);
@ -167,13 +183,12 @@ sub config_step2
foreach my $bcn (1..$bcn_count) foreach my $bcn (1..$bcn_count)
{ {
push @{$links}, "bcn_link".$bcn; push @{$links}, "bcn_link".$bcn;
my $this_bcn_key = "bcn".$bcn;
my $this_ip_key = "bcn".$bcn."_ip"; my $this_ip_key = "bcn".$bcn."_ip";
my $this_subnet_key = "bcn".$bcn."_subnet"; my $this_subnet_key = "bcn".$bcn."_subnet";
my $this_iface1_key = "bcn".$bcn."_iface1_mac"; my $this_iface1_key = "bcn".$bcn."_iface1_mac";
my $this_iface2_key = "bcn".$bcn."_iface2_mac"; my $this_iface2_key = "bcn".$bcn."_iface2_mac";
$cgi .= $this_ip_key.",".$this_subnet_key.",".$this_iface1_key.",".$this_iface2_key.","; $cgi .= $this_ip_key.",".$this_subnet_key.",".$this_iface1_key.",".$this_iface2_key.",";
my $this_ip = generate_ip($an, "bcn", 1, $an->data->{cgi}{sequence}{value}); my $this_ip = generate_ip($an, "bcn", $bcn, $an->data->{cgi}{sequence}{value});
my $this_ip_class = $an->data->{cgi}{$this_ip_key}{alert} ? "input_alert" : "input_clear"; my $this_ip_class = $an->data->{cgi}{$this_ip_key}{alert} ? "input_alert" : "input_clear";
my $this_subnet_class = $an->data->{cgi}{$this_subnet_key}{alert} ? "input_alert" : "input_clear"; my $this_subnet_class = $an->data->{cgi}{$this_subnet_key}{alert} ? "input_alert" : "input_clear";
my $this_iface1_class = $an->data->{cgi}{$this_iface1_key}{alert} ? "input_alert" : "input_clear"; my $this_iface1_class = $an->data->{cgi}{$this_iface1_key}{alert} ? "input_alert" : "input_clear";
@ -210,17 +225,17 @@ sub config_step2
}}); }});
} }
# IFN
my $ifn_count = $an->data->{cgi}{ifn_count}{value} ? $an->data->{cgi}{ifn_count}{value} : 1; my $ifn_count = $an->data->{cgi}{ifn_count}{value} ? $an->data->{cgi}{ifn_count}{value} : 1;
foreach my $ifn (1..$ifn_count) foreach my $ifn (1..$ifn_count)
{ {
push @{$links}, "ifn_link".$ifn; push @{$links}, "ifn_link".$ifn;
my $this_ifn_key = "ifn".$ifn;
my $this_ip_key = "ifn".$ifn."_ip"; my $this_ip_key = "ifn".$ifn."_ip";
my $this_subnet_key = "ifn".$ifn."_subnet"; my $this_subnet_key = "ifn".$ifn."_subnet";
my $this_iface1_key = "ifn".$ifn."_iface1_mac"; my $this_iface1_key = "ifn".$ifn."_iface1_mac";
my $this_iface2_key = "ifn".$ifn."_iface2_mac"; my $this_iface2_key = "ifn".$ifn."_iface2_mac";
$cgi .= $this_ip_key.",".$this_subnet_key.",".$this_iface1_key.",".$this_iface2_key.","; $cgi .= $this_ip_key.",".$this_subnet_key.",".$this_iface1_key.",".$this_iface2_key.",";
my $this_ip = generate_ip($an, "ifn", 1, $an->data->{cgi}{sequence}{value}); my $this_ip = generate_ip($an, "ifn", $ifn, $an->data->{cgi}{sequence}{value});
my $this_ip_class = $an->data->{cgi}{$this_ip_key}{alert} ? "input_alert" : "input_clear"; my $this_ip_class = $an->data->{cgi}{$this_ip_key}{alert} ? "input_alert" : "input_clear";
my $this_subnet_class = $an->data->{cgi}{$this_subnet_key}{alert} ? "input_alert" : "input_clear"; my $this_subnet_class = $an->data->{cgi}{$this_subnet_key}{alert} ? "input_alert" : "input_clear";
my $this_iface1_class = $an->data->{cgi}{$this_iface1_key}{alert} ? "input_alert" : "input_clear"; my $this_iface1_class = $an->data->{cgi}{$this_iface1_key}{alert} ? "input_alert" : "input_clear";
@ -260,6 +275,79 @@ sub config_step2
else else
{ {
### Show the single iface per network form. ### Show the single iface per network form.
# BCN
my $bcn_count = $an->data->{cgi}{bcn_count}{value} ? $an->data->{cgi}{bcn_count}{value} : 1;
foreach my $bcn (1..$bcn_count)
{
push @{$links}, "bcn_link".$bcn;
my $this_ip_key = "bcn".$bcn."_ip";
my $this_subnet_key = "bcn".$bcn."_subnet";
my $this_iface1_key = "bcn".$bcn."_iface1_mac";
$cgi .= $this_ip_key.",".$this_subnet_key.",".$this_iface1_key.",";
my $this_ip = generate_ip($an, "bcn", $bcn, $an->data->{cgi}{sequence}{value});
my $this_ip_class = $an->data->{cgi}{$this_ip_key}{alert} ? "input_alert" : "input_clear";
my $this_subnet_class = $an->data->{cgi}{$this_subnet_key}{alert} ? "input_alert" : "input_clear";
my $this_iface1_class = $an->data->{cgi}{$this_iface1_key}{alert} ? "input_alert" : "input_clear";
# Build the interface select boxes...
my $this_iface1_form = $an->Template->select_form({
name => $this_iface1_key,
options => $interface_options,
blank => 1,
selected => defined $an->data->{cgi}{$this_iface1_key}{value} ? $an->data->{cgi}{$this_iface1_key}{value} : "",
class => $an->data->{cgi}{$this_iface1_key}{alert} ? "input_alert" : "input_clear",
});
# Assemble the form
$interface_form .= $an->Template->get({file => "main.html", name => "single_interface_form", variables => {
field => $an->Words->string({key => "striker_0018", variables => { number => $bcn }}),
description => "#!string!striker_0019!#",
ip_key => $this_ip_key,
ip_value => defined $an->data->{cgi}{$this_ip_key}{value} ? $an->data->{cgi}{$this_ip_key}{value} : $this_ip,
ip_class => $this_ip_class,
subnet_key => $this_subnet_key,
subnet_value => defined $an->data->{cgi}{$this_subnet_key}{value} ? $an->data->{cgi}{$this_subnet_key}{value} : $an->data->{'default'}{bcn}{netmask},
subnet_class => $this_subnet_class,
iface1_select => $this_iface1_form,
}});
}
# IFN
my $ifn_count = $an->data->{cgi}{ifn_count}{value} ? $an->data->{cgi}{ifn_count}{value} : 1;
foreach my $ifn (1..$ifn_count)
{
push @{$links}, "ifn_link".$ifn;
my $this_ip_key = "ifn".$ifn."_ip";
my $this_subnet_key = "ifn".$ifn."_subnet";
my $this_iface1_key = "ifn".$ifn."_iface1_mac";
$cgi .= $this_ip_key.",".$this_subnet_key.",".$this_iface1_key.",";
my $this_ip = generate_ip($an, "ifn", $ifn, $an->data->{cgi}{sequence}{value});
my $this_ip_class = $an->data->{cgi}{$this_ip_key}{alert} ? "input_alert" : "input_clear";
my $this_subnet_class = $an->data->{cgi}{$this_subnet_key}{alert} ? "input_alert" : "input_clear";
my $this_iface1_class = $an->data->{cgi}{$this_iface1_key}{alert} ? "input_alert" : "input_clear";
# Build the interface select boxes...
my $this_iface1_form = $an->Template->select_form({
name => $this_iface1_key,
options => $interface_options,
blank => 1,
selected => defined $an->data->{cgi}{$this_iface1_key}{value} ? $an->data->{cgi}{$this_iface1_key}{value} : "",
class => $an->data->{cgi}{$this_iface1_key}{alert} ? "input_alert" : "input_clear",
});
# Assemble the form
$interface_form .= $an->Template->get({file => "main.html", name => "single_interface_form", variables => {
field => $an->Words->string({key => "striker_0022", variables => { number => $ifn }}),
description => "#!string!striker_0023!#",
ip_key => $this_ip_key,
ip_value => defined $an->data->{cgi}{$this_ip_key}{value} ? $an->data->{cgi}{$this_ip_key}{value} : $this_ip,
ip_class => $this_ip_class,
subnet_key => $this_subnet_key,
subnet_value => defined $an->data->{cgi}{$this_subnet_key}{value} ? $an->data->{cgi}{$this_subnet_key}{value} : $an->data->{'default'}{ifn}{netmask},
subnet_class => $this_subnet_class,
iface1_select => $this_iface1_form,
}});
}
} }
### TODO: Add a form for Gateway, DNS and which interface to use ### TODO: Add a form for Gateway, DNS and which interface to use
@ -343,6 +431,8 @@ sub config_step2
extra => "", extra => "",
}}); }});
# Get the table that shows the current interface states. # Get the table that shows the current interface states.
my $interface_states = get_network_details_form($an); my $interface_states = get_network_details_form($an);
@ -354,6 +444,7 @@ sub config_step2
prefix => $an->data->{cgi}{prefix}{value}, prefix => $an->data->{cgi}{prefix}{value},
domain => $an->data->{cgi}{domain}{value}, domain => $an->data->{cgi}{domain}{value},
sequence => $an->data->{cgi}{sequence}{value}, sequence => $an->data->{cgi}{sequence}{value},
bcn_count => $an->data->{cgi}{bcn_count}{value},
ifn_count => $an->data->{cgi}{ifn_count}{value}, ifn_count => $an->data->{cgi}{ifn_count}{value},
interface_form => $interface_form, interface_form => $interface_form,
interface_states => $interface_states, interface_states => $interface_states,
@ -362,7 +453,7 @@ sub config_step2
gateway_form => $say_gateway, gateway_form => $say_gateway,
dns_form => $say_dns, dns_form => $say_dns,
hostname_form => $say_hostname, hostname_form => $say_hostname,
cgi_list => $cgi."gateway,hostname,striker_user,striker_password", cgi_list => $cgi."organization,prefix,domain,sequence,bcn_count,ifn_count,gateway,hostname,dns,striker_user,striker_password",
}}); }});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { step2_body => $step2_body }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { step2_body => $step2_body }});
@ -374,64 +465,182 @@ sub sanity_check_step2
{ {
my ($an) = @_; my ($an) = @_;
# This will flip if we run into a problem. We start by running through step1's sanity checks again. # This will flip if we run into a problem.
# This should only fail is someone was passing raw data to us and screwed something up. my $sane = 1;
my $sane = sanity_check_step1($an);
# Do we have a host name, striker user and password? # Do we have a host name, striker user and password?
if ((not defined $an->data->{cgi}{hostname}{value}) or (not $an->data->{cgi}{hostname}{value})) if (not $an->Validate->form_field({name => "hostname", type => "domain_name"}))
{ {
$an->data->{cgi}{hostname}{alert} = 1;
$sane = 0; $sane = 0;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane, "cgi::hostname::alert" => $an->data->{cgi}{hostname}{alert} }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane }});
} }
# The user name
if ((not defined $an->data->{cgi}{striker_user}{value}) or (not $an->data->{cgi}{striker_user}{value})) if ((not defined $an->data->{cgi}{striker_user}{value}) or (not $an->data->{cgi}{striker_user}{value}))
{ {
$an->data->{cgi}{striker_user}{alert} = 1; $an->data->{cgi}{striker_user}{alert} = 1;
$sane = 0; $sane = 0;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane, "cgi::striker_user::alert" => $an->data->{cgi}{striker_user}{alert} }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane, "cgi::striker_user::alert" => $an->data->{cgi}{striker_user}{alert} }});
} }
if ((not defined $an->data->{cgi}{striker_password}{value}) or (not $an->data->{cgi}{striker_password}{value}))
# The password
if ((not defined $an->data->{cgi}{striker_password}{value}) or (not $an->data->{cgi}{striker_password}{value}) or (length($an->data->{cgi}{striker_password}{value}) < 6))
{ {
$an->data->{cgi}{striker_password}{alert} = 1; $an->data->{cgi}{striker_password}{alert} = 1;
$sane = 0; $sane = 0;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane, "cgi::striker_password::alert" => $an->data->{cgi}{striker_password}{alert} }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane, "cgi::striker_password::alert" => $an->data->{cgi}{striker_password}{alert} }});
} }
# Now it gets a bit tricker as we'll need to loop through the BCNs and IFNs. # The gateway
my $bcn_count = $an->data->{cgi}{bcn_count}{value} ? $an->data->{cgi}{bcn_count}{value} : 1; if (not $an->Validate->form_field({name => "gateway", type => "ipv4"}))
foreach my $bcn (1..$bcn_count)
{ {
my $this_bcn_key = "bcn".$bcn; $sane = 0;
my $this_ip_key = "bcn".$bcn."_ip"; $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane }});
my $this_subnet_key = "bcn".$bcn."_subnet"; }
my $this_iface1_key = "bcn".$bcn."_iface1_mac";
my $this_iface2_key = "bcn".$bcn."_iface2_mac";
# If I only have the iface1, we'll create a non-bonded interface (even if the option for a # DNS can be multiple entries, comma-separated.
# bond was presented to the user). So to be sane, we need a valid IP, subnet if ((not defined $an->data->{cgi}{dns}{value}) or (not $an->data->{cgi}{dns}{value}))
{
$an->data->{cgi}{dns}{alert} = 1;
$sane = 0;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane, "cgi::dns::alert" => $an->data->{cgi}{dns}{alert} }});
}
else
{
foreach my $ip (split/,/, $an->data->{cgi}{dns}{value})
{
$ip =~ s/^\s+//;
$ip =~ s/\s+$//;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { ip => $ip }});
if (not $an->Validate->is_ipv4({ip => $ip}))
{
$an->data->{cgi}{dns}{alert} = 1;
$sane = 0;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane, "cgi::dns::alert" => $an->data->{cgi}{dns}{alert} }});
}
}
}
# Look for interfaces and sanity check them.
my $links = [];
foreach my $network ("bcn", "ifn")
{
my $count_key = $network."_count";
my $network_count = $an->data->{cgi}{$count_key}{value} ? $an->data->{cgi}{$count_key}{value} : 1;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
network => $network,
count_key => $count_key,
network_count => $network_count,
}});
foreach my $count (1..$network_count)
{
push @{$links}, $network."_link".$count;
my $this_ip_key = $network.$count."_ip";
my $this_subnet_key = $network.$count."_subnet";
my $this_iface1_key = $network.$count."_iface1_mac";
my $this_iface2_key = $network.$count."_iface2_mac";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
count => $count,
this_ip_key => $this_ip_key,
this_subnet_key => $this_subnet_key,
this_iface1_key => $this_iface1_key,
this_iface2_key => $this_iface2_key,
"cgi::${this_ip_key}::value" => $an->data->{cgi}{$this_ip_key}{value},
"cgi::${this_subnet_key}::value" => $an->data->{cgi}{$this_subnet_key}{value},
"cgi::${this_iface1_key}::value" => $an->data->{cgi}{$this_iface1_key}{value},
"cgi::${this_iface2_key}::value" => $an->data->{cgi}{$this_iface2_key}{value},
}});
# Is the IP sane?
if (not $an->Validate->form_field({name => $this_ip_key, type => "ipv4"}))
{
# Nope
$sane = 0;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane }});
} }
my $ifn_count = $an->data->{cgi}{ifn_count}{value} ? $an->data->{cgi}{ifn_count}{value} : 1;
foreach my $ifn (1..$ifn_count) # What about the subnet?
if (not $an->Validate->form_field({name => $this_subnet_key, type => "subnet"}))
{ {
my $this_ifn_key = "ifn".$ifn; $sane = 0;
my $this_ip_key = "ifn".$ifn."_ip"; $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane }});
my $this_subnet_key = "ifn".$ifn."_subnet"; }
my $this_iface1_key = "ifn".$ifn."_iface1_mac";
my $this_iface2_key = "ifn".$ifn."_iface2_mac"; # Interface 1 must be set
if (not $an->Validate->form_field({name => $this_iface1_key, type => "mac"}))
{
$sane = 0;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane }});
}
else
{
# Valid MAC. Has it been assigned elsewhere?
my $mac = $an->data->{cgi}{$this_iface1_key}{value};
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { mac => $mac }});
if ((not exists $an->data->{network}{$mac}{set_as}) or (not $an->data->{network}{$mac}{set_as}))
{
$an->data->{network}{$mac}{set_as} = $this_iface1_key;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "network::${mac}::set_as" => $an->data->{network}{$mac}{set_as} }});
}
else
{
# Conflict! Set the alert for this interface and the conflicting one.
my $conflict_key = $an->data->{network}{$mac}{set_as};
$an->data->{cgi}{$conflict_key}{alert} = 1;
$an->data->{cgi}{$this_iface1_key}{alert} = 1;
$sane = 0;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => {
sane => $sane,
"cgi::${conflict_key}::alert" => $an->data->{cgi}{$conflict_key}{alert},
"cgi::${this_iface1_key}::alert" => $an->data->{cgi}{$this_iface1_key}{alert},
}});
}
}
# Interface 2 doesn't have to be set.
if ((defined $an->data->{cgi}{$this_iface2_key}{value}) && ($an->data->{cgi}{$this_iface2_key}{value}))
{
if (not $an->Validate->form_field({name => $this_iface2_key, type => "mac"}))
{
$sane = 0;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane }});
}
else
{
# Valid MAC. Has it been assigned elsewhere?
my $mac = $an->data->{cgi}{$this_iface2_key}{value};
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { mac => $mac }});
if ((not exists $an->data->{network}{$mac}{set_as}) or (not $an->data->{network}{$mac}{set_as}))
{
$an->data->{network}{$mac}{set_as} = $this_iface2_key;
}
else
{
# Conflict! Set the alert for this interface and the conflicting one.
my $conflict_key = $an->data->{network}{$mac}{set_as};
$an->data->{cgi}{$conflict_key}{alert} = 1;
$an->data->{cgi}{$this_iface2_key}{alert} = 1;
$sane = 0;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => {
sane => $sane,
"cgi::${conflict_key}::alert" => $an->data->{cgi}{$conflict_key}{alert},
"cgi::${this_iface2_key}::alert" => $an->data->{cgi}{$this_iface2_key}{alert},
}});
}
}
}
}
} }
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { sane => $sane }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { sane => $sane }});
return($sane); return($sane);
} }
# This sanity-checks step 1 and returns '1' if there was a problem. # This sanity-checks step 1 and returns '1' if there was a problem.
sub sanity_check_step1 sub sanity_check_step1
{ {
my ($an) = @_; my ($an) = @_;
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0131", variables => { function => "sanity_check_step1()" }}); $an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0131", variables => { function => "sanity_check_step1()" }});
# This will flip if we run into a problem. # This will flip if we run into a problem.
my $sane = 1; my $sane = 1;
@ -535,7 +744,7 @@ sub sanity_check_step1
get_network_details($an); get_network_details($an);
my $required_interfaces_for_single = 1 + $an->data->{cgi}{ifn_count}{value}; my $required_interfaces_for_single = 1 + $an->data->{cgi}{ifn_count}{value};
my $interface_count = keys %{$an->data->{interfaces}}; my $interface_count = keys %{$an->data->{interfaces}};
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
required_interfaces_for_single => $required_interfaces_for_single, required_interfaces_for_single => $required_interfaces_for_single,
interface_count => $interface_count, interface_count => $interface_count,
}}); }});
@ -557,7 +766,7 @@ sub sanity_check_step1
} }
else else
{ {
# Record the answer. # Sane, Record the answers.
$an->Database->insert_or_update_variables({ $an->Database->insert_or_update_variables({
variable_name => "form::config_step1::ifn_count::value", variable_name => "form::config_step1::ifn_count::value",
variable_value => $an->data->{cgi}{ifn_count}{value}, variable_value => $an->data->{cgi}{ifn_count}{value},
@ -607,7 +816,7 @@ sub config_step1
variable_source_uuid => $an->Get->host_uuid, variable_source_uuid => $an->Get->host_uuid,
variable_source_table => "hosts", variable_source_table => "hosts",
}); });
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
organization => $organization, organization => $organization,
prefix => $prefix, prefix => $prefix,
domain => $domain, domain => $domain,
@ -620,7 +829,7 @@ sub config_step1
$an->data->{cgi}{domain}{value} = $domain ne "" ? $domain : ""; $an->data->{cgi}{domain}{value} = $domain ne "" ? $domain : "";
$an->data->{cgi}{sequence}{value} = $sequence ne "" ? $sequence : 1; $an->data->{cgi}{sequence}{value} = $sequence ne "" ? $sequence : 1;
$an->data->{cgi}{ifn_count}{value} = $ifn_count ne "" ? $ifn_count : 1; $an->data->{cgi}{ifn_count}{value} = $ifn_count ne "" ? $ifn_count : 1;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
'cgi::organization::value' => $an->data->{cgi}{organization}{value}, 'cgi::organization::value' => $an->data->{cgi}{organization}{value},
'cgi::prefix::value' => $an->data->{cgi}{prefix}{value}, 'cgi::prefix::value' => $an->data->{cgi}{prefix}{value},
'cgi::domain::value' => $an->data->{cgi}{domain}{value}, 'cgi::domain::value' => $an->data->{cgi}{domain}{value},
@ -711,7 +920,7 @@ sub get_network_details
# Now read the network.xml # Now read the network.xml
my $file = $an->data->{path}{directories}{html}."/status/network.xml"; my $file = $an->data->{path}{directories}{html}."/status/network.xml";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { file => $file }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { file => $file }});
# Parse... # Parse...
my $xml = XML::Simple->new(); my $xml = XML::Simple->new();
@ -743,7 +952,7 @@ sub get_network_details
speed => $data->{interface}{$interface}{speed}, speed => $data->{interface}{$interface}{speed},
'state' => $data->{interface}{$interface}{'state'}, 'state' => $data->{interface}{$interface}{'state'},
}; };
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
"interfaces::${interface}::bond" => $an->data->{interfaces}{$interface}{bond}, "interfaces::${interface}::bond" => $an->data->{interfaces}{$interface}{bond},
"interfaces::${interface}::bridge" => $an->data->{interfaces}{$interface}{bridge}, "interfaces::${interface}::bridge" => $an->data->{interfaces}{$interface}{bridge},
"interfaces::${interface}::duplex" => $an->data->{interfaces}{$interface}{duplex}, "interfaces::${interface}::duplex" => $an->data->{interfaces}{$interface}{duplex},
@ -788,15 +997,12 @@ sub get_network_details_form
{ {
$interface_list .= "$interface,"; $interface_list .= "$interface,";
$network .= $an->Template->get({file => "main.html", name => "network_entry", variables => { $network .= $an->Template->get({file => "main.html", name => "network_entry", variables => {
#mac => $data->{interface}{$interface}{mac},
mac => "", mac => "",
mac_id => $interface."_mac", mac_id => $interface."_mac",
name => $interface, name => $interface,
name_id => $interface."_name", name_id => $interface."_name",
#speed => $data->{interface}{$interface}{speed},
speed => "", speed => "",
speed_id => $interface."_speed", speed_id => $interface."_speed",
#'link' => $data->{interface}{$interface}{'link'},
'link' => "", 'link' => "",
link_id => $interface."_link", link_id => $interface."_link",
order => "", order => "",
@ -815,7 +1021,7 @@ sub get_network_details_form
sub generate_ip sub generate_ip
{ {
my ($an, $network, $network_sequence, $device_sequence) = @_; my ($an, $network, $network_sequence, $device_sequence) = @_;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
network => $network, network => $network,
network_sequence => $network_sequence, network_sequence => $network_sequence,
device_sequence => $device_sequence, device_sequence => $device_sequence,
@ -827,7 +1033,7 @@ sub generate_ip
# The subnet's second octet will be '+X' where 'X' is the sequence. # The subnet's second octet will be '+X' where 'X' is the sequence.
my $default_ip = $an->data->{'default'}{$network}{subnet}; my $default_ip = $an->data->{'default'}{$network}{subnet};
my $default_netmark = $an->data->{'default'}{$network}{netmask}; my $default_netmark = $an->data->{'default'}{$network}{netmask};
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
default_ip => $default_ip, default_ip => $default_ip,
default_netmark => $default_netmark, default_netmark => $default_netmark,
}}); }});
@ -836,7 +1042,7 @@ sub generate_ip
{ {
# 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);
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
ip_octet1 => $ip_octet1, ip_octet1 => $ip_octet1,
ip_octet2 => $ip_octet2, ip_octet2 => $ip_octet2,
ip_octet3 => $ip_octet3, ip_octet3 => $ip_octet3,
@ -850,7 +1056,7 @@ sub generate_ip
$ip_octet3 = $an->data->{'default'}{bcn}{striker_octet3}; $ip_octet3 = $an->data->{'default'}{bcn}{striker_octet3};
$ip_octet4 = $device_sequence; $ip_octet4 = $device_sequence;
$ip = $ip_octet1.".".$ip_octet2.".".$ip_octet3.".".$ip_octet4; $ip = $ip_octet1.".".$ip_octet2.".".$ip_octet3.".".$ip_octet4;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
"s1:ip_octet2" => $ip_octet2, "s1:ip_octet2" => $ip_octet2,
"s2:ip_octet3" => $ip_octet3, "s2:ip_octet3" => $ip_octet3,
"s3:ip_octet4" => $ip_octet4, "s3:ip_octet4" => $ip_octet4,
@ -864,6 +1070,6 @@ sub generate_ip
$ip = "#!error!#"; $ip = "#!error!#";
} }
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ip => $ip }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { ip => $ip }});
return($ip); return($ip);
} }

@ -61,7 +61,7 @@ This is the AN::Tools master 'words' file.
<key name="striker_0031">Striker user name</key> <key name="striker_0031">Striker user name</key>
<key name="striker_0032">This is the user name that you will log into Striker as and the name of the user that owns the database.</key> <key name="striker_0032">This is the user name that you will log into Striker as and the name of the user that owns the database.</key>
<key name="striker_0033">Striker password</key> <key name="striker_0033">Striker password</key>
<key name="striker_0034"><![CDATA[This will be the password used to log into this Striker and connect to its database.<br /><b>NOTE</b>: This password needs to be stored in plain text. Do not use a password you use elsewhere.]]></key> <key name="striker_0034"><![CDATA[This will be the password used to log into this Striker and connect to its database. It must be 6+ characters long.<br /><b>NOTE</b>: This password needs to be stored in plain text. Do not use a password you use elsewhere.]]></key>
<key name="striker_0035">Gateway</key> <key name="striker_0035">Gateway</key>
<key name="striker_0036">This is the network gateway used to access the outside world.</key> <key name="striker_0036">This is the network gateway used to access the outside world.</key>
<key name="striker_0037">DNS</key> <key name="striker_0037">DNS</key>

@ -25,7 +25,7 @@ input[type=text].input_clear, input[type=number].input_clear, select.input_clear
} }
input[type=text].input_alert, input[type=number].input_alert, select.input_alert { input[type=text].input_alert, input[type=number].input_alert, select.input_alert {
border: 2px solid red; border: 1px solid #ff3f3f;
} }
input[type=text], input[type=number] { input[type=text], input[type=number] {

@ -199,6 +199,7 @@
<input type="submit" name="next" id="next" value="#!string!striker_0013!#"> <input type="submit" name="next" id="next" value="#!string!striker_0013!#">
</td> </td>
</tr> </tr>
<input type="hidden" name="bcn_count" id="bcn_count" value="#!variable!bcn_count!#">
<input type="hidden" name="step" id="step" value="step2"> <input type="hidden" name="step" id="step" value="step2">
<input type="hidden" name="cgi_list" id="cgi_list" value="organization,prefix,domain,sequence,next,step,#!variable!cgi_list!#"> <input type="hidden" name="cgi_list" id="cgi_list" value="organization,prefix,domain,sequence,next,step,#!variable!cgi_list!#">
</form> </form>
@ -274,10 +275,59 @@
</table> </table>
<!-- end bonded_interface_form --> <!-- end bonded_interface_form -->
<!-- start single_interface_form -->
<table>
<tr>
<td colspan="5" class="form_group_header1">
#!variable!field!#
</td>
</tr>
<tr>
<td colspan="5" class="form_group_header2">
#!variable!description!#
</td>
</tr>
<tr>
<td>
#!string!striker_0024!#
</td>
<td>
<input type="text" name="#!variable!ip_key!#" id="#!variable!ip_key!#" value="#!variable!ip_value!#" placeholder="#!string!striker_0024!#" class="#!variable!ip_class!#">
</td>
<td>
&nbsp;
</td>
<td>
#!string!striker_0028!#
</td>
<td>
#!variable!iface1_select!#
</td>
</tr>
<tr>
<td>
#!string!striker_0025!#
</td>
<td>
<input type="text" name="#!variable!subnet_key!#" id="#!variable!subnet_key!#" value="#!variable!subnet_value!#" placeholder="#!string!striker_0025!#" class="#!variable!subnet_class!#">
</td>
<td>
&nbsp;
</td>
<td>
&nbsp;
</td>
<td>
&nbsp;
</td>
</tr>
</table>
<!-- end single_interface_form -->
<!-- start network_header --> <!-- start network_header -->
<table id="network_status" class="data_table_nowrap"> <table id="network_status" class="data_table_nowrap">
<tr> <tr>
<td colspan="4" class="column_header"> <td colspan="5" class="column_header">
#!string!header_0001!# #!string!header_0001!#
</td> </td>
</tr> </tr>

Loading…
Cancel
Save