You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2164 lines
94 KiB
2164 lines
94 KiB
8 years ago
|
#!/usr/bin/perl
|
||
|
#
|
||
7 years ago
|
# Exit codes;
|
||
|
# 0 == OK
|
||
|
# 1 == Host UUID not available yet.
|
||
|
#
|
||
7 years ago
|
# TODO:
|
||
|
# * Make the BCN count a thing, remove Striker user and make it statically 'admin'.
|
||
|
#
|
||
7 years ago
|
|
||
8 years ago
|
use strict;
|
||
|
use warnings;
|
||
7 years ago
|
use Anvil::Tools;
|
||
8 years ago
|
use Data::Dumper;
|
||
7 years ago
|
use NetAddr::IP;
|
||
8 years ago
|
|
||
7 years ago
|
# Turn off buffering
|
||
|
$| = 1;
|
||
|
|
||
8 years ago
|
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0];
|
||
|
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0];
|
||
|
if (($running_directory =~ /^\./) && ($ENV{PWD}))
|
||
|
{
|
||
|
$running_directory =~ s/^\./$ENV{PWD}/;
|
||
|
}
|
||
8 years ago
|
|
||
6 years ago
|
my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1});
|
||
8 years ago
|
|
||
7 years ago
|
### NOTE: We'll print the headers only when we need to. If we print them hear, it will block cookies being set.
|
||
8 years ago
|
|
||
7 years ago
|
# Set the log level to 2. Setting 3 slows he program down a LOT.
|
||
8 years ago
|
|
||
7 years ago
|
# Read the config and then connect to the database.
|
||
7 years ago
|
$anvil->Storage->read_config();
|
||
7 years ago
|
|
||
7 years ago
|
### Setup some variables.
|
||
|
$anvil->data->{skin}{url} = $anvil->data->{path}{urls}{skins}."/".$anvil->Template->skin;
|
||
|
$anvil->data->{form}{body} = "";
|
||
6 years ago
|
$anvil->data->{form}{error_massage} = "";
|
||
7 years ago
|
$anvil->data->{form}{back_link} = "";
|
||
|
$anvil->data->{form}{refresh_link} = "";
|
||
|
|
||
|
# Read in any CGI variables, if needed.
|
||
|
$anvil->Get->cgi();
|
||
|
|
||
|
# If the system hasn't initialized, there may be no host.uuid, and we'll need a better error to show the
|
||
|
# user.
|
||
|
if (not -e $anvil->data->{path}{data}{host_uuid})
|
||
7 years ago
|
{
|
||
7 years ago
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0002"}) }});
|
||
|
print_and_exit($anvil);
|
||
7 years ago
|
}
|
||
|
|
||
6 years ago
|
$anvil->Database->connect({
|
||
7 years ago
|
sql_file => $anvil->data->{sys}{database}{schema},
|
||
7 years ago
|
test_table => "network_interfaces",
|
||
|
});
|
||
6 years ago
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132", variables => { "sys::db_connections" => $anvil->data->{sys}{db_connections} }});
|
||
|
if (not $anvil->data->{sys}{db_connections})
|
||
7 years ago
|
{
|
||
|
# No databases, exit.
|
||
7 years ago
|
print $anvil->Words->string({key => "error_0003"});
|
||
7 years ago
|
$anvil->nice_exit({exit_code => 2});
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
7 years ago
|
# If any jobs are pending/running, show the "unavailable" option.
|
||
7 years ago
|
my $available = check_availability($anvil);
|
||
|
my $configured = $available ? check_if_configured($anvil) : 0;
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
|
||
|
available => $available,
|
||
|
configured => $configured,
|
||
|
}});
|
||
7 years ago
|
if (not $available)
|
||
7 years ago
|
{
|
||
7 years ago
|
# Set the body to 'say::maintenance'.
|
||
7 years ago
|
$anvil->data->{form}{body} = $anvil->data->{say}{maintenance};
|
||
7 years ago
|
}
|
||
7 years ago
|
elsif (not $configured)
|
||
7 years ago
|
{
|
||
7 years ago
|
# If there is no user account yet, then the system is new and needs to be reconfigured.
|
||
7 years ago
|
configure_striker($anvil);
|
||
7 years ago
|
}
|
||
7 years ago
|
else
|
||
7 years ago
|
{
|
||
7 years ago
|
# Normal operation
|
||
7 years ago
|
process_task($anvil);
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
# Build the page to display
|
||
7 years ago
|
my $refresh_button = "";
|
||
|
if ($anvil->data->{form}{refresh_link})
|
||
|
{
|
||
|
$refresh_button = $anvil->Template->get({file => "main.html", name => "refresh_button_on", variables => { url => $anvil->data->{form}{refresh_link} }});
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$refresh_button = $anvil->Template->get({file => "main.html", name => "refresh_button_off"});
|
||
|
}
|
||
|
|
||
7 years ago
|
print_and_exit($anvil);
|
||
|
|
||
|
|
||
|
#############################################################################################################
|
||
|
# Functions #
|
||
|
#############################################################################################################
|
||
|
|
||
|
sub print_and_exit
|
||
7 years ago
|
{
|
||
7 years ago
|
my ($anvil) = @_;
|
||
|
|
||
|
# Time for the header
|
||
|
my $header = $anvil->Template->get({file => "main.html", name => "header", variables => { language => $anvil->Words->language }});
|
||
|
|
||
|
my $back_button = "";
|
||
|
if ($anvil->data->{form}{back_link})
|
||
7 years ago
|
{
|
||
7 years ago
|
my $url = $THIS_FILE;
|
||
|
if ($anvil->data->{form}{back_link} ne "?")
|
||
|
{
|
||
|
# Turn on the back button,
|
||
|
$url = $anvil->data->{form}{back_link};
|
||
|
}
|
||
|
$back_button = $anvil->Template->get({file => "main.html", name => "back_button_on", variables => { url => $url }});
|
||
7 years ago
|
}
|
||
7 years ago
|
else
|
||
|
{
|
||
|
# Back is disabled.
|
||
|
$back_button = $anvil->Template->get({file => "main.html", name => "back_button_off"});
|
||
|
}
|
||
|
my $left_buttons = $anvil->Template->get({file => "main.html", name => "button_bar_left", variables => {
|
||
|
back_button => $back_button,
|
||
|
refresh_button => $refresh_button,
|
||
|
}});
|
||
7 years ago
|
|
||
7 years ago
|
my $right_buttons = $anvil->Template->get({file => "main.html", name => "button_bar_right", variables => {
|
||
|
anvil_button => $anvil->data->{sys}{users}{user_name} ? $anvil->Template->get({file => "main.html", name => "anvil_button_on"}) : $anvil->Template->get({file => "main.html", name => "anvil_button_off"}),
|
||
|
striker_button => $anvil->data->{sys}{users}{user_name} ? $anvil->Template->get({file => "main.html", name => "striker_button_on"}) : $anvil->Template->get({file => "main.html", name => "striker_button_off"}),
|
||
|
configure_button => $anvil->data->{sys}{users}{user_name} ? $anvil->Template->get({file => "main.html", name => "configure_button_on"}) : $anvil->Template->get({file => "main.html", name => "configure_button_off"}),
|
||
|
user_button => $anvil->data->{sys}{users}{user_name} ? $anvil->Template->get({file => "main.html", name => "user_button_on"}) : $anvil->Template->get({file => "main.html", name => "user_button_off"}),
|
||
|
}});
|
||
|
my $footer = $anvil->Template->get({file => "main.html", name => "footer", variables => {
|
||
|
user => $anvil->data->{sys}{users}{user_name} ? "#!string!message_0034!#" : " ",
|
||
|
}});
|
||
7 years ago
|
|
||
7 years ago
|
# Display the page.
|
||
|
my $body = $anvil->Template->get({debug => 3, file => "main.html", name => "master", variables => {
|
||
|
header => $header,
|
||
|
skin_url => $anvil->data->{path}{urls}{skins}."/".$anvil->Template->skin,
|
||
6 years ago
|
center_top_bar => $anvil->data->{form}{error_massage} ? $anvil->data->{form}{error_massage} : " ",
|
||
7 years ago
|
right_top_bar => $right_buttons,
|
||
|
left_top_bar => $left_buttons,
|
||
|
center_body => $anvil->data->{form}{body},
|
||
|
left_bottom_bar => " ",
|
||
|
center_bottom_bar => " ",
|
||
|
right_bottom_bar => " ",
|
||
|
footer => $footer,
|
||
|
}});
|
||
7 years ago
|
|
||
7 years ago
|
print $anvil->Template->get({file => "shared.html", name => "http_headers"})."\n";
|
||
|
print "$body";
|
||
7 years ago
|
|
||
7 years ago
|
$anvil->nice_exit({exit_code => 0});
|
||
|
|
||
|
return(0);
|
||
|
}
|
||
7 years ago
|
|
||
|
# This handles all the daily tasks of Striker.
|
||
|
sub process_task
|
||
|
{
|
||
|
my ($anvil) = @_;
|
||
|
|
||
7 years ago
|
# Is the user trying to log in?
|
||
|
my $logged_in = 0;
|
||
|
if ((defined $anvil->data->{cgi}{login}) && ($anvil->data->{cgi}{login}{value}))
|
||
|
{
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "cgi::login::value" => $anvil->data->{cgi}{login}{value} }});
|
||
|
|
||
|
# Woot!
|
||
7 years ago
|
my $failed = $anvil->Account->login({debug => 3});
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { failed => $failed }});
|
||
|
if (not $failed)
|
||
|
{
|
||
|
$logged_in = 1;
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { logged_in => $logged_in }});
|
||
|
}
|
||
|
}
|
||
7 years ago
|
elsif ((defined $anvil->data->{cgi}{logout}) && ($anvil->data->{cgi}{logout}{value}))
|
||
|
{
|
||
|
# Bye now!
|
||
|
$anvil->Account->logout({debug => 3});
|
||
|
}
|
||
7 years ago
|
else
|
||
|
{
|
||
|
# Is the user logged in?
|
||
|
# 0 - The cookies were read, the account was validated and the user's details were loaded.
|
||
|
# 1 - No cookie was found or read. The user needs to log in
|
||
|
# 2 - There was a problem reading the user's UUID (it wasn't found in the database), so the
|
||
7 years ago
|
# cookies were deleted (via C<< Account->logout() >>. The user needs to log back in.
|
||
7 years ago
|
# 3 - There user's hash is invalid, it is probably expired. The user has been logged out and
|
||
|
# needs to log back in.
|
||
7 years ago
|
my $cookie_problem = $anvil->Account->read_cookies({debug => 3});
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { cookie_problem => $cookie_problem }});
|
||
7 years ago
|
if (not $cookie_problem)
|
||
|
{
|
||
|
$logged_in = 1;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { logged_in => $logged_in }});
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
|
# Show the login screen, if the user isn't logged in.
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { logged_in => $logged_in }});
|
||
7 years ago
|
if (not $logged_in)
|
||
|
{
|
||
7 years ago
|
$anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "striker-login", variables => {
|
||
7 years ago
|
user => $anvil->data->{cgi}{username}{value},
|
||
|
password => "",
|
||
|
}});
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "form::body" => $anvil->data->{form}{body} }});
|
||
|
return(0);
|
||
7 years ago
|
}
|
||
|
|
||
|
# If we're here, the user is logged in!
|
||
7 years ago
|
if ($anvil->data->{cgi}{striker}{value})
|
||
|
{
|
||
7 years ago
|
$anvil->data->{form}{back_link} = "?striker=true";
|
||
|
$anvil->data->{cgi}{task}{value} = "" if not defined $anvil->data->{cgi}{task}{value};
|
||
|
$anvil->data->{cgi}{action}{value} = "" if not defined $anvil->data->{cgi}{action}{value};
|
||
7 years ago
|
if ($anvil->data->{cgi}{task}{value} eq "sync")
|
||
|
{
|
||
7 years ago
|
process_sync_page($anvil);
|
||
7 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
# The 'back' goes home
|
||
|
$anvil->data->{form}{back_link} = "?";
|
||
|
$anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "striker-setup"});
|
||
|
}
|
||
7 years ago
|
}
|
||
|
elsif (0)
|
||
|
{
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
# Load the main page.
|
||
7 years ago
|
$anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "striker-welcome"});
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
|
# $anvil->data->{sys}{users}{user_name} = $user_name;
|
||
|
# $anvil->data->{sys}{users}{user_uuid} = $user_uuid;
|
||
|
# $anvil->data->{sys}{users}{user_password_hash} = $user_password_hash,
|
||
|
# $anvil->data->{sys}{users}{user_salt} = $user_salt,
|
||
|
# $anvil->data->{sys}{users}{user_algorithm} = $user_algorithm,
|
||
|
# $anvil->data->{sys}{users}{user_hash_count} = $user_hash_count,
|
||
|
# $anvil->data->{sys}{users}{user_language} = $user_language,
|
||
|
# $anvil->data->{sys}{users}{user_is_admin} = $user_is_admin,
|
||
|
# $anvil->data->{sys}{users}{user_is_experienced} = $user_is_experienced,
|
||
|
# $anvil->data->{sys}{users}{user_is_trusted} = $user_is_trusted,
|
||
7 years ago
|
|
||
7 years ago
|
return(0);
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
# This handles tasks related to setting up peer Strikers.
|
||
|
sub process_sync_page
|
||
|
{
|
||
|
my ($anvil) = @_;
|
||
|
|
||
7 years ago
|
# Setup some CGI values we might use.
|
||
|
$anvil->data->{cgi}{new_peer_access}{value} = "" if not defined $anvil->data->{cgi}{new_peer_access}{value};
|
||
|
$anvil->data->{cgi}{new_peer_password}{value} = "" if not defined $anvil->data->{cgi}{new_peer_password}{value};
|
||
|
$anvil->data->{cgi}{save}{value} = "" if not defined $anvil->data->{cgi}{save}{value};
|
||
|
$anvil->data->{cgi}{confirm}{value} = "" if not defined $anvil->data->{cgi}{confirm}{value};
|
||
|
|
||
|
# This handles checkboxes
|
||
|
if (defined $anvil->data->{cgi}{new_peer_ping}{value})
|
||
|
{
|
||
7 years ago
|
$anvil->data->{cgi}{new_peer_ping}{value} = "" if $anvil->data->{cgi}{new_peer_ping}{value} ne "on";
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "cgi::new_peer_ping::value" => $anvil->data->{cgi}{new_peer_ping}{value} }});
|
||
7 years ago
|
}
|
||
|
else
|
||
|
{
|
||
7 years ago
|
$anvil->data->{cgi}{new_peer_ping}{value} = "";
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "cgi::new_peer_ping::value" => $anvil->data->{cgi}{new_peer_ping}{value} }});
|
||
|
}
|
||
|
if (defined $anvil->data->{cgi}{new_peer_bidirection}{value})
|
||
|
{
|
||
7 years ago
|
$anvil->data->{cgi}{new_peer_bidirection}{value} = "" if $anvil->data->{cgi}{new_peer_bidirection}{value} ne "on";
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "cgi::new_peer_bidirection::value" => $anvil->data->{cgi}{new_peer_bidirection}{value} }});
|
||
7 years ago
|
}
|
||
|
else
|
||
|
{
|
||
7 years ago
|
$anvil->data->{cgi}{new_peer_bidirection}{value} = "";
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "cgi::new_peer_bidirection::value" => $anvil->data->{cgi}{new_peer_bidirection}{value} }});
|
||
|
}
|
||
|
|
||
7 years ago
|
# Are we adding a new peer?
|
||
7 years ago
|
if (($anvil->data->{cgi}{new_peer_access}{value}) && ($anvil->data->{cgi}{new_peer_password}{value} ne ""))
|
||
7 years ago
|
{
|
||
7 years ago
|
add_sync_peer($anvil);
|
||
7 years ago
|
|
||
|
if ($anvil->data->{form}{body})
|
||
|
{
|
||
|
# We're done
|
||
|
return(0);
|
||
|
}
|
||
7 years ago
|
}
|
||
|
elsif ($anvil->data->{cgi}{action}{value} eq "remove")
|
||
|
{
|
||
|
#remove_sync_peer($anvil);
|
||
|
}
|
||
|
|
||
7 years ago
|
my $host_uuid = $anvil->Get->host_uuid;
|
||
7 years ago
|
$anvil->System->get_ips();
|
||
|
|
||
|
# We'll want to show the user way to access the local machine. For that, we'll loop through our own IPs.
|
||
7 years ago
|
my $inbound_table = "";
|
||
7 years ago
|
foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{sys}{network}{interface}})
|
||
|
{
|
||
|
next if (($interface !~ /^bcn/) && ($interface !~ /^ifn/));
|
||
|
next if not $anvil->Validate->is_ipv4({ip => $anvil->data->{sys}{network}{interface}{$interface}{ip}});
|
||
|
next if not $anvil->Validate->is_subnet({subnet => $anvil->data->{sys}{network}{interface}{$interface}{subnet}});
|
||
|
my ($network_type, $network_number) = ($interface =~ /^(.*?)(\d+)_/);
|
||
|
|
||
7 years ago
|
my $database_user = $anvil->data->{database}{$host_uuid}{user} ? $anvil->data->{database}{$host_uuid}{user} : $anvil->data->{sys}{database}{user};
|
||
7 years ago
|
my $database_port = $anvil->data->{database}{$host_uuid}{port};
|
||
|
my $network_key = $network_type eq "bcn" ? "striker_0018" : "striker_0022";
|
||
|
my $say_network = $anvil->Words->string({key => $network_key, variables => { number => $network_number }});
|
||
7 years ago
|
|
||
|
# The user 'admin' and the port 5432 are default, so only show them if they're non-standard.
|
||
|
my $access_string = $database_user."\@".$anvil->data->{sys}{network}{interface}{$interface}{ip}.":".$database_port;
|
||
|
if (($database_port eq "5432") && ($database_user eq "admin"))
|
||
|
{
|
||
|
$access_string = $anvil->data->{sys}{network}{interface}{$interface}{ip};
|
||
|
}
|
||
|
elsif ($database_port eq "5432")
|
||
|
{
|
||
|
$access_string = $database_user."\@".$anvil->data->{sys}{network}{interface}{$interface}{ip};
|
||
|
}
|
||
|
elsif ($database_user eq "admin")
|
||
|
{
|
||
|
$access_string = $anvil->data->{sys}{network}{interface}{$interface}{ip}.":".$database_port;
|
||
|
}
|
||
7 years ago
|
$inbound_table .= $anvil->Template->get({file => "striker.html", name => "striker-sync-inbound", variables => {
|
||
7 years ago
|
access => $access_string,
|
||
7 years ago
|
note => $say_network,
|
||
|
}});
|
||
|
}
|
||
|
|
||
|
# This needs to be loaded into a hash by target, the sorted. We'll build the table on sort.
|
||
|
my $peer_table = "";
|
||
|
foreach my $uuid (keys %{$anvil->data->{database}})
|
||
|
{
|
||
7 years ago
|
next if not $anvil->Validate->is_uuid({uuid => $uuid});
|
||
7 years ago
|
next if $uuid eq $host_uuid;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { uuid => $uuid }});
|
||
7 years ago
|
|
||
|
my $host = $anvil->data->{database}{$uuid}{host} ? $anvil->data->{database}{$uuid}{host} : ""; # This should fail
|
||
|
my $port = $anvil->data->{database}{$uuid}{port} ? $anvil->data->{database}{$uuid}{port} : 5432;
|
||
|
my $name = $anvil->data->{database}{$uuid}{name} ? $anvil->data->{database}{$uuid}{name} : $anvil->data->{sys}{database}{name};
|
||
|
my $user = $anvil->data->{database}{$uuid}{user} ? $anvil->data->{database}{$uuid}{user} : $anvil->data->{sys}{database}{user};
|
||
7 years ago
|
my $ping = $anvil->data->{database}{$uuid}{ping} ? $anvil->data->{database}{$uuid}{ping} : 1;
|
||
7 years ago
|
my $password = $anvil->data->{database}{$uuid}{password} ? $anvil->data->{database}{$uuid}{password} : "";
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||
7 years ago
|
host => $host,
|
||
|
port => $port,
|
||
|
name => $name,
|
||
|
user => $user,
|
||
7 years ago
|
ping => $ping,
|
||
7 years ago
|
password => $anvil->Log->secure ? $password : $anvil->Words->string({key => "log_0186"}),
|
||
7 years ago
|
}});
|
||
7 years ago
|
|
||
|
# Store it by name.
|
||
|
$anvil->data->{peers}{$host}{port} = $port;
|
||
|
$anvil->data->{peers}{$host}{name} = $name;
|
||
|
$anvil->data->{peers}{$host}{user} = $user;
|
||
|
$anvil->data->{peers}{$host}{ping} = $ping;
|
||
|
$anvil->data->{peers}{$host}{password} = $password;
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||
|
"peers::${host}::port" => $anvil->data->{peers}{$host}{port},
|
||
|
"peers::${host}::name" => $anvil->data->{peers}{$host}{name},
|
||
|
"peers::${host}::ping" => $anvil->data->{peers}{$host}{ping},
|
||
|
"peers::${host}::password" => $anvil->Log->secure ? $anvil->data->{peers}{$host}{password} : $anvil->Words->string({key => "log_0186"}),
|
||
|
}});
|
||
|
}
|
||
|
|
||
|
# Now peers are sortable by host name.
|
||
|
foreach my $host (sort {$a cmp $b} keys %{$anvil->data->{peers}})
|
||
|
{
|
||
|
my $port = $anvil->data->{peers}{$host}{port};
|
||
|
my $name = $anvil->data->{peers}{$host}{name};
|
||
|
my $user = $anvil->data->{peers}{$host}{user};
|
||
|
my $ping = $anvil->data->{peers}{$host}{ping};
|
||
|
my $password = $anvil->data->{peers}{$host}{password};
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||
|
host => $host,
|
||
|
port => $port,
|
||
|
name => $name,
|
||
|
user => $user,
|
||
|
ping => $ping,
|
||
|
password => $anvil->Log->secure ? $password : $anvil->Words->string({key => "log_0186"}),
|
||
|
}});
|
||
|
|
||
7 years ago
|
$anvil->data->{cgi}{new_peer_password}{value} = "" if not defined $anvil->data->{cgi}{new_peer_password}{value};
|
||
7 years ago
|
$peer_table .= $anvil->Template->get({file => "striker.html", name => "striker-sync-entry", variables => {
|
||
|
access => $port eq 5432 ? $user."\@".$host : $user."\@".$host.":".$port,
|
||
7 years ago
|
password => $anvil->data->{cgi}{new_peer_password}{value},
|
||
7 years ago
|
ping_checked => $ping ? "checked" : "",
|
||
|
}});
|
||
7 years ago
|
}
|
||
|
|
||
|
# Build the menu.
|
||
7 years ago
|
$anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "striker-sync", variables => {
|
||
7 years ago
|
inbound_table => $inbound_table,
|
||
|
peer_table => $peer_table,
|
||
|
new_peer_access => defined $anvil->data->{cgi}{new_peer_access}{value} ? $anvil->data->{cgi}{new_peer_access}{value} : "",
|
||
|
new_peer_password => defined $anvil->data->{cgi}{new_peer_password}{value} ? $anvil->data->{cgi}{new_peer_password}{value} : "",
|
||
7 years ago
|
}});
|
||
7 years ago
|
|
||
|
return(0);
|
||
|
}
|
||
|
|
||
7 years ago
|
# This adds a new peer to anvil.conf.
|
||
|
sub add_sync_peer
|
||
|
{
|
||
|
my ($anvil) = @_;
|
||
|
|
||
|
# Break up the user, host and port. If anything goes wrong, we'll set an error and send it back.
|
||
|
my $user = $anvil->data->{sys}{database}{user};
|
||
|
my $host = $anvil->data->{cgi}{new_peer_access}{value};
|
||
|
my $name = $anvil->data->{sys}{database}{name};
|
||
|
my $port = 5432;
|
||
|
my $ssh_tcp = 22;
|
||
|
my $peer_uuid = "";
|
||
|
my $peer_host = "";
|
||
7 years ago
|
if ($host =~ /,ssh=(\d+)$/)
|
||
7 years ago
|
{
|
||
7 years ago
|
$ssh_tcp = $1;
|
||
|
$host =~ s/,ssh=\d+$//;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||
7 years ago
|
ssh_tcp => $ssh_tcp,
|
||
|
host => $host,
|
||
7 years ago
|
}});
|
||
|
}
|
||
7 years ago
|
if ($host =~ /^(.*?)\@(.*?):(\d+)$/)
|
||
7 years ago
|
{
|
||
|
$user = $1;
|
||
|
$host = $2;
|
||
|
$port = $3;
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||
|
host => $host,
|
||
|
port => $port,
|
||
|
user => $user,
|
||
|
}});
|
||
|
}
|
||
7 years ago
|
elsif ($host =~ /^(.*?)\@(.*?)$/)
|
||
7 years ago
|
{
|
||
|
$user = $1;
|
||
|
$host = $2;
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||
|
host => $host,
|
||
|
user => $user,
|
||
|
}});
|
||
|
}
|
||
7 years ago
|
elsif ($host =~ /^(.*?):(\d+)$/)
|
||
7 years ago
|
{
|
||
|
$host = $1;
|
||
|
$port = $2;
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||
|
host => $host,
|
||
|
port => $port,
|
||
|
}});
|
||
|
}
|
||
|
|
||
|
# Is the host a domain or IP?
|
||
|
# If so, and 'bi-directional' is set, verify we can ssh into the peer.
|
||
7 years ago
|
my $is_domain = $anvil->Validate->is_domain_name({name => $host});
|
||
|
my $is_ipv4 = $anvil->Validate->is_ipv4({ip => $host});
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||
|
is_domain => $is_domain,
|
||
|
is_ipv4 => $is_ipv4,
|
||
|
port => $port,
|
||
|
}});
|
||
|
if (((not $is_domain) && (not $is_ipv4)) or ($port < 1) or ($port > 65536))
|
||
7 years ago
|
{
|
||
|
# Bad host.
|
||
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "striker_warning_0002"}) }});
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
# Can we connect to the peer?
|
||
7 years ago
|
my $shell_call = $anvil->data->{path}{exe}{dmidecode}." --string system-uuid";
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
|
||
|
|
||
|
my ($error, $output) = $anvil->Remote->call({
|
||
|
debug => 2,
|
||
7 years ago
|
password => $anvil->data->{cgi}{new_peer_password}{value},
|
||
|
target => $ssh_tcp != 22 ? $host.":".$ssh_tcp : $host,
|
||
7 years ago
|
shell_call => $shell_call,
|
||
7 years ago
|
});
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { error => $error }});
|
||
7 years ago
|
if ($error)
|
||
|
{
|
||
|
# No access
|
||
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "striker_warning_0003"}) }});
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
# We got the peer's UUID. Get the hostname as well.
|
||
7 years ago
|
$peer_uuid = lc($output->[0]);
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { peer_uuid => $peer_uuid }});
|
||
|
|
||
7 years ago
|
if (not $anvil->Validate->is_uuid({uuid => $peer_uuid}))
|
||
|
{
|
||
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "striker_warning_0005", variables => { uuid => $peer_uuid }}) }});
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
my ($error, $output) = $anvil->Remote->call({
|
||
|
debug => 2,
|
||
|
password => $anvil->data->{cgi}{new_peer_password}{value},
|
||
|
target => $ssh_tcp != 22 ? $host.":".$ssh_tcp : $host,
|
||
|
shell_call => $anvil->data->{path}{exe}{hostnamectl}." --static",
|
||
|
});
|
||
|
|
||
|
$peer_host = $output->[0];
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { peer_host => $peer_host }});
|
||
|
}
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
# Now, verify we can access the peer database. This will involve writting out a .pgpass file, then making a local system call.
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "form::error_massage" => $anvil->data->{form}{error_massage} }});
|
||
|
if (not $anvil->data->{form}{error_massage})
|
||
|
{
|
||
|
my $pgpass_file = "/tmp/.pgpass";
|
||
|
my $password = $anvil->data->{cgi}{new_peer_password}{value};
|
||
|
$password =~ s/:/\:/g;
|
||
|
my $body = $host.":".$port.":".$name.":".$user.":".$password;
|
||
|
$anvil->Storage->write_file({
|
||
6 years ago
|
file => $pgpass_file,
|
||
|
body => $body,
|
||
|
mode => "0600",
|
||
|
secure => 1,
|
||
|
overwrite => 1,
|
||
7 years ago
|
});
|
||
|
|
||
|
# This will return '1' only, if it works.
|
||
|
my $db_access = $anvil->System->call({shell_call => "PGPASSFILE=\"".$pgpass_file."\" ".$anvil->data->{path}{exe}{psql}." --host ".$host." --port ".$port." --dbname ".$name." --username ".$user." --no-password --tuples-only --no-align --command \"SELECT 1\""});
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { db_access => $db_access }});
|
||
|
if ($db_access ne "1")
|
||
|
{
|
||
|
# Failed to connect.
|
||
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "striker_warning_0004"}) }});
|
||
|
}
|
||
|
|
||
|
# Delete the pgpass file.
|
||
6 years ago
|
unlink $pgpass_file;
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
7 years ago
|
# If an error was set, clear the 'save' and 'confirm' values.
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "form::error_massage" => $anvil->data->{form}{error_massage} }});
|
||
|
if ($anvil->data->{form}{error_massage})
|
||
7 years ago
|
{
|
||
7 years ago
|
$anvil->data->{cgi}{save}{value} = "";
|
||
|
$anvil->data->{cgi}{confirm}{value} = "";
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||
|
"cgi::save::value" => $anvil->data->{cgi}{save}{value},
|
||
|
"cgi::confirm::value" => $anvil->data->{cgi}{confirm}{value},
|
||
7 years ago
|
}});
|
||
|
}
|
||
|
else
|
||
|
{
|
||
7 years ago
|
# Things look good. Is the save confirmed?
|
||
|
if ($anvil->data->{cgi}{confirm}{value})
|
||
|
{
|
||
|
# OK, save!
|
||
6 years ago
|
|
||
7 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
# Show the screen the confirm the addition.
|
||
|
$anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "confirm-new-peer", variables => {
|
||
|
access => $user."@".$host.":".$port,
|
||
|
ping => $anvil->data->{cgi}{new_peer_ping}{value} ? "#!string!unit_0001!#" : "#!string!unit_0002!#",
|
||
|
bidirectional => $anvil->data->{cgi}{new_peer_bidirection}{value} ? "#!string!unit_0001!#" : "#!string!unit_0002!#",
|
||
|
}});
|
||
|
}
|
||
7 years ago
|
}
|
||
|
|
||
|
return(0);
|
||
|
}
|
||
|
|
||
7 years ago
|
# This shows the menus for configuring Striker.
|
||
|
sub configure_striker
|
||
|
{
|
||
|
my ($anvil) = @_;
|
||
|
|
||
7 years ago
|
# This will be true when the dashboard is unconfigured.
|
||
|
if (not $anvil->data->{cgi}{step}{value})
|
||
7 years ago
|
{
|
||
7 years ago
|
$anvil->data->{form}{body} = config_step1($anvil);
|
||
7 years ago
|
}
|
||
7 years ago
|
elsif ($anvil->data->{cgi}{step}{value} eq "step1")
|
||
7 years ago
|
{
|
||
7 years ago
|
# Sanity check step1.
|
||
|
my $sane = sanity_check_step1($anvil);
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { sane => $sane }});
|
||
7 years ago
|
if ($sane)
|
||
|
{
|
||
|
# Step 1 was sane, show step 2.
|
||
7 years ago
|
$anvil->data->{form}{body} = config_step2($anvil);
|
||
7 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
# No good
|
||
7 years ago
|
$anvil->data->{form}{body} = config_step1($anvil);
|
||
7 years ago
|
}
|
||
7 years ago
|
}
|
||
7 years ago
|
elsif ($anvil->data->{cgi}{step}{value} eq "step2")
|
||
|
{
|
||
|
# Sanity check step1.
|
||
|
my $sane = sanity_check_step2($anvil);
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { sane => $sane }});
|
||
|
if ($sane)
|
||
|
{
|
||
|
# Step 2 was sane, show step 3.
|
||
7 years ago
|
$anvil->data->{form}{body} = config_step3($anvil);
|
||
7 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
# No good
|
||
7 years ago
|
$anvil->data->{form}{body} = config_step2($anvil);
|
||
7 years ago
|
}
|
||
|
}
|
||
|
elsif ($anvil->data->{cgi}{step}{value} eq "step3")
|
||
7 years ago
|
{
|
||
7 years ago
|
# User has confirmed, update the system!
|
||
7 years ago
|
$anvil->data->{form}{body} = save_job($anvil);
|
||
7 years ago
|
}
|
||
|
else
|
||
|
{
|
||
7 years ago
|
$anvil->data->{form}{body} = get_network_details_form($anvil);
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
7 years ago
|
return(0);
|
||
7 years ago
|
}
|
||
8 years ago
|
|
||
7 years ago
|
# This checks to see if the local machine has been configured after initial install. If not, it will present
|
||
|
# the configuration menu.
|
||
|
sub check_if_configured
|
||
|
{
|
||
|
my ($anvil) = @_;
|
||
|
|
||
|
my ($configured, $variable_uuid, $modified_date) = $anvil->Database->read_variable({
|
||
|
variable_name => "system::configured",
|
||
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
|
variable_source_table => "hosts",
|
||
|
});
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
|
||
7 years ago
|
configured => $configured,
|
||
|
variable_uuid => $variable_uuid,
|
||
|
modified_date => $modified_date,
|
||
|
}});
|
||
|
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { configured => $configured }});
|
||
7 years ago
|
return($configured);
|
||
|
}
|
||
8 years ago
|
|
||
7 years ago
|
# This checks to see if anything is running that requires Striker being unavailable. If not, this returns
|
||
|
# '1'. If there is a job pending/running, it returns '0'
|
||
|
sub check_availability
|
||
7 years ago
|
{
|
||
|
my ($anvil) = @_;
|
||
|
|
||
7 years ago
|
my $debug = 3;
|
||
7 years ago
|
my $available = 1;
|
||
7 years ago
|
my $query = "
|
||
7 years ago
|
SELECT
|
||
|
job_progress,
|
||
|
modified_date,
|
||
|
extract(epoch from modified_date)
|
||
|
FROM
|
||
|
jobs
|
||
|
WHERE
|
||
|
job_name = 'configure::network'
|
||
|
AND
|
||
|
job_progress != 100
|
||
|
AND
|
||
|
job_host_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->Get->host_uuid)."
|
||
|
;";
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
|
||
7 years ago
|
|
||
7 years ago
|
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
|
||
|
my $count = @{$results};
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
|
||
7 years ago
|
results => $results,
|
||
|
count => $count,
|
||
|
}});
|
||
7 years ago
|
if ($count)
|
||
|
{
|
||
|
# We're waiting for the network configuration
|
||
7 years ago
|
my $percent = $results->[0]->[0];
|
||
|
my $timestamp = $results->[0]->[1];
|
||
|
my $unixtime = $results->[0]->[2];
|
||
|
my $seconds_ago = $anvil->Convert->add_commas({number => (time - $unixtime)});
|
||
|
$available = 0;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
|
||
7 years ago
|
available => $available,
|
||
|
percent => $percent,
|
||
|
seconds_ago => $seconds_ago,
|
||
|
timestamp => $timestamp,
|
||
|
unixtime => $unixtime,
|
||
|
}});
|
||
7 years ago
|
|
||
7 years ago
|
$anvil->data->{say}{maintenance} = $anvil->Template->get({file => "striker.html", name => "striker-offline", variables => {
|
||
7 years ago
|
title_id => "",
|
||
|
message_id => "",
|
||
|
title => "#!string!striker_0046!#",
|
||
7 years ago
|
description => $anvil->Words->string({key => "striker_0047", variables => { percent => $percent, timestamp => $timestamp, seconds_ago => $seconds_ago }}),
|
||
7 years ago
|
}});
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { 'say::maintenance' => $anvil->data->{say}{maintenance} }});
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { available => $available }});
|
||
7 years ago
|
return($available);
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
# This requests the job to reconfigure the network be run
|
||
|
sub save_job
|
||
7 years ago
|
{
|
||
|
my ($anvil) = @_;
|
||
|
|
||
7 years ago
|
# Record the job!
|
||
|
my ($job_uuid) = $anvil->Database->insert_or_update_jobs({
|
||
|
debug => 2,
|
||
|
file => $THIS_FILE,
|
||
|
line => __LINE__,
|
||
7 years ago
|
job_command => "anvil-configure-striker",
|
||
7 years ago
|
job_data => "form::config_step2",
|
||
|
job_name => "configure::network",
|
||
|
job_title => "job_0001",
|
||
|
job_description => "job_0002",
|
||
|
});
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }});
|
||
7 years ago
|
|
||
7 years ago
|
# TODO: Check that a job_uuid was returned and warn of a problem if not.
|
||
|
my $say_title = "#!string!striker_0044!#";
|
||
|
my $say_desciption = "#!string!striker_0045!#";
|
||
7 years ago
|
|
||
7 years ago
|
# We don't need to store anything as hidden variables, we'll read it back from the database later.
|
||
|
my $job_recorded_body = $anvil->Template->get({file => "main.html", name => "network_job_recorded", variables => {
|
||
|
title_id => "",
|
||
|
message_id => "",
|
||
|
title => $say_title,
|
||
|
description => $say_desciption,
|
||
|
}});
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { job_recorded_body => $job_recorded_body }});
|
||
|
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }});
|
||
|
return($job_recorded_body);
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
# This shows the user what is about to be done and asks the user to confirm.
|
||
|
sub config_step3
|
||
|
{
|
||
7 years ago
|
my ($anvil) = @_;
|
||
7 years ago
|
|
||
|
# Read in all the variables from the database. We don't care what was passed, the data in the
|
||
|
# database has been tested and is more valid than, say, a manipulated URL.
|
||
|
my $cgi = "";
|
||
7 years ago
|
my $nets = {};
|
||
7 years ago
|
my $query = "
|
||
|
SELECT
|
||
|
variable_name,
|
||
|
variable_value
|
||
|
FROM
|
||
|
variables
|
||
|
WHERE
|
||
|
(variable_section = 'config_step1' OR variable_section = 'config_step2')
|
||
|
AND
|
||
|
variable_source_table = 'hosts'
|
||
|
AND
|
||
7 years ago
|
variable_source_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->Get->host_uuid)."
|
||
7 years ago
|
ORDER BY
|
||
|
variable_name ASC;";
|
||
7 years ago
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }});
|
||
7 years ago
|
|
||
7 years ago
|
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
|
||
7 years ago
|
my $count = @{$results};
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||
7 years ago
|
results => $results,
|
||
|
count => $count,
|
||
|
}});
|
||
|
foreach my $row (@{$results})
|
||
|
{
|
||
7 years ago
|
my $variable_name = $row->[0];
|
||
|
my $variable_value = $row->[1];
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||
7 years ago
|
variable_name => $variable_name,
|
||
|
variable_value => $variable_value,
|
||
|
}});
|
||
|
|
||
|
if ($variable_name =~ /form::config_step2::(.*?)::value/)
|
||
|
{
|
||
7 years ago
|
my $variable = $1;
|
||
|
$cgi .= $variable.",";
|
||
7 years ago
|
$anvil->data->{cgi}{$variable}{value} = $variable_value;
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "cgi::${variable}::value" => $anvil->data->{cgi}{$variable}{value} }});
|
||
7 years ago
|
|
||
|
if (($variable =~ /^(bcn\d+)_/) or ($variable =~ /^(ifn\d+)_/))
|
||
|
{
|
||
|
my $this_net = $1;
|
||
|
$nets->{$this_net} = 1;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "nets->this_net" => $nets->{$this_net} }});
|
||
7 years ago
|
}
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
#foreach my $key (sort {$a cmp $b} keys %ENV) { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "ENV{$key}" => $ENV{$key} }}); }
|
||
7 years ago
|
|
||
|
# Get the list of current IPs so that we can warn the user if committing the changes will require
|
||
|
# reconnecting.
|
||
7 years ago
|
$anvil->System->get_ips;
|
||
7 years ago
|
my $matched_ip = 0;
|
||
|
my $server_ip = $ENV{SERVER_ADDR};
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { server_ip => $server_ip }});
|
||
7 years ago
|
|
||
7 years ago
|
# We'll need ot show how networks will be configured. This depends on;
|
||
|
# 1. Is it a bonded or single interface?
|
||
|
# 2. Is it the interface with the gateway?
|
||
|
# 3. If no gateway or DNS was specified, alert that there will be no outside access.
|
||
7 years ago
|
get_network_details($anvil);
|
||
7 years ago
|
my $networks = "";
|
||
|
foreach my $this_net (sort {$a cmp $b} keys %{$nets})
|
||
|
{
|
||
|
my $ip_key = $this_net."_ip";
|
||
|
my $subnet_key = $this_net."_subnet";
|
||
7 years ago
|
my $iface1_key = $this_net."_link1_mac_to_set";
|
||
|
my $iface2_key = $this_net."_link2_mac_to_set";
|
||
7 years ago
|
my $ip = $anvil->data->{cgi}{$ip_key}{value};
|
||
|
my $subnet = $anvil->data->{cgi}{$subnet_key}{value};
|
||
|
my $iface1_mac = $anvil->data->{cgi}{$iface1_key}{value};
|
||
|
my $iface2_mac = ((defined $anvil->data->{cgi}{$iface2_key}{value}) && ($anvil->data->{cgi}{$iface2_key}{value})) ? $anvil->data->{cgi}{$iface2_key}{value} : "";
|
||
7 years ago
|
my $template = $iface2_mac ? "step3_bonded_interface" : "step3_single_interface";
|
||
7 years ago
|
my $gateway = $anvil->data->{cgi}{gateway_interface}{value} eq $this_net ? 1 : 0;
|
||
7 years ago
|
my $link_number = ($this_net =~ /n(\d+)$/)[0];
|
||
|
my $column = $this_net =~ /^bcn/ ? "striker_0018" : "striker_0022";
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||
7 years ago
|
"s1:nets->this_net" => $nets->{$this_net},
|
||
|
"s2:ip" => $ip,
|
||
|
"s3:subnet" => $subnet,
|
||
|
"s4:iface1_mac" => $iface1_mac,
|
||
|
"s5:iface2_mac" => $iface2_mac,
|
||
|
"s6:template" => $template,
|
||
|
"s7:gateway" => $gateway,
|
||
|
"s8:link_number" => $link_number,
|
||
|
}});
|
||
|
|
||
|
# Add to the networks template.
|
||
|
my $say_ip = $ip."/".$subnet;
|
||
7 years ago
|
if (($gateway) && ($anvil->data->{cgi}{gateway}{value}))
|
||
7 years ago
|
{
|
||
7 years ago
|
$template .= "_with_gateway";
|
||
7 years ago
|
$anvil->data->{cgi}{dns}{value} = "--" if not $anvil->data->{cgi}{dns}{value};
|
||
7 years ago
|
}
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { template => $template }});
|
||
7 years ago
|
$networks .= $anvil->Template->get({file => "config.html", name => $template, variables => {
|
||
7 years ago
|
column => $anvil->Words->string({key => $column, variables => { number => $link_number }}),
|
||
7 years ago
|
ip_address => $say_ip,
|
||
7 years ago
|
ip => $ip,
|
||
|
subnet => $subnet,
|
||
7 years ago
|
primary => $iface1_mac,
|
||
|
backup => $iface2_mac,
|
||
7 years ago
|
gateway => $anvil->data->{cgi}{gateway}{value},
|
||
|
dns => $anvil->data->{cgi}{dns}{value},
|
||
7 years ago
|
}})."\n";
|
||
|
|
||
|
# Does this interface's IP match the active one?
|
||
|
if ($server_ip eq $ip)
|
||
|
{
|
||
|
# Yup! No need to warn the user
|
||
|
$matched_ip = 1;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { matched_ip => $matched_ip }});
|
||
7 years ago
|
}
|
||
|
}
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { networks => $networks }});
|
||
7 years ago
|
|
||
|
# If the IP is going to change, warn the user.
|
||
|
if (not $matched_ip)
|
||
7 years ago
|
{
|
||
7 years ago
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "striker_warning_0001"}) }});
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
# We don't need to store anything as hidden variables, we'll read it back from the database later.
|
||
7 years ago
|
my $step3_body = $anvil->Template->get({file => "config.html", name => "config_step3", variables => {
|
||
7 years ago
|
step1_welcome_title_id => "",
|
||
|
step1_welcome_message_id => "",
|
||
7 years ago
|
organization => $anvil->data->{cgi}{organization}{value},
|
||
|
prefix => $anvil->data->{cgi}{prefix}{value},
|
||
7 years ago
|
hostname => $anvil->data->{cgi}{hostname}{value},
|
||
7 years ago
|
striker_user => $anvil->data->{cgi}{striker_user}{value},
|
||
|
striker_password => $anvil->data->{cgi}{striker_password}{value},
|
||
7 years ago
|
networks => $networks,
|
||
7 years ago
|
cgi_list => $cgi."step",
|
||
7 years ago
|
show_name => 1,
|
||
7 years ago
|
}});
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { step3_body => $step3_body }});
|
||
7 years ago
|
|
||
|
return($step3_body);
|
||
|
}
|
||
|
|
||
7 years ago
|
# This is step2 where the user maps their network.
|
||
|
sub config_step2
|
||
|
{
|
||
7 years ago
|
my ($anvil) = @_;
|
||
7 years ago
|
|
||
7 years ago
|
# If I am coming from stage 1, load any values from the database, if they exist.
|
||
7 years ago
|
if ($anvil->data->{cgi}{step}{value} eq "step1")
|
||
7 years ago
|
{
|
||
|
# First load. See if we can read old data. We don't know for sure what variables will have
|
||
|
# been set, so we'll load anything from the group 'config_step2'.
|
||
|
my $query = "
|
||
|
SELECT
|
||
|
variable_name,
|
||
|
variable_value
|
||
|
FROM
|
||
|
variables
|
||
|
WHERE
|
||
|
variable_section = 'config_step2'
|
||
|
AND
|
||
|
variable_source_table = 'hosts'
|
||
|
AND
|
||
7 years ago
|
variable_source_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->Get->host_uuid)."
|
||
7 years ago
|
ORDER BY
|
||
|
variable_name ASC;";
|
||
7 years ago
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0124", variables => { query => $query }});
|
||
7 years ago
|
|
||
7 years ago
|
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
|
||
7 years ago
|
my $count = @{$results};
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
|
||
7 years ago
|
results => $results,
|
||
|
count => $count,
|
||
|
}});
|
||
|
foreach my $row (@{$results})
|
||
|
{
|
||
7 years ago
|
my $variable_name = $row->[0];
|
||
|
my $variable_value = $row->[1];
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||
7 years ago
|
variable_name => $variable_name,
|
||
|
variable_value => $variable_value,
|
||
|
}});
|
||
|
|
||
|
if ($variable_name =~ /form::config_step2::(.*?)::value/)
|
||
|
{
|
||
7 years ago
|
my $variable = $1;
|
||
7 years ago
|
$anvil->data->{cgi}{$variable}{value} = $variable_value;
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "cgi::${variable}::value" => $anvil->data->{cgi}{$variable}{value} }});
|
||
7 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
# We need to decide how many IFNs there is, decide if we have enough NICs and then build the form
|
||
|
# either complaining about insufficient NICs or a list of interfaces (single or bond, depending on
|
||
|
# iface count), the IPs to assign and mapping MACs to ifaces. We'll also offer an option to
|
||
|
# "blind-map" as we did in v2.
|
||
7 years ago
|
get_network_details($anvil);
|
||
|
my $required_interfaces_for_single = 1 + $anvil->data->{cgi}{ifn_count}{value};
|
||
7 years ago
|
my $required_interfaces_for_bonds = 2 * $required_interfaces_for_single;
|
||
7 years ago
|
my $interface_count = keys %{$anvil->data->{interfaces}};
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
|
||
7 years ago
|
required_interfaces_for_single => $required_interfaces_for_single,
|
||
|
required_interfaces_for_bonds => $required_interfaces_for_bonds,
|
||
|
interface_count => $interface_count,
|
||
|
}});
|
||
|
|
||
7 years ago
|
my $interface_options = [];
|
||
7 years ago
|
foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{interfaces}})
|
||
7 years ago
|
{
|
||
7 years ago
|
my $this_mac = $anvil->data->{interfaces}{$interface}{mac};
|
||
7 years ago
|
push @{$interface_options}, $this_mac."#!#".$this_mac." (".$interface.")";
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
my $problem = 0;
|
||
|
my $interface_form = "";
|
||
7 years ago
|
my $cgi = "";
|
||
7 years ago
|
my $links = [];
|
||
7 years ago
|
if ($interface_count >= $required_interfaces_for_bonds)
|
||
7 years ago
|
{
|
||
7 years ago
|
### Show the bonded ifaces form.
|
||
|
# BCN
|
||
7 years ago
|
my $bcn_count = $anvil->data->{cgi}{bcn_count}{value} ? $anvil->data->{cgi}{bcn_count}{value} : 1;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bcn_count => $bcn_count }});
|
||
7 years ago
|
foreach my $bcn (1..$bcn_count)
|
||
|
{
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bcn => $bcn }});
|
||
7 years ago
|
push @{$links}, "bcn_link".$bcn;
|
||
7 years ago
|
my $this_ip_key = "bcn".$bcn."_ip";
|
||
|
my $this_subnet_key = "bcn".$bcn."_subnet";
|
||
7 years ago
|
my $this_iface1_key = "bcn".$bcn."_link1_mac_to_set";
|
||
|
my $this_iface2_key = "bcn".$bcn."_link2_mac_to_set";
|
||
7 years ago
|
$cgi .= $this_ip_key.",".$this_subnet_key.",".$this_iface1_key.",".$this_iface2_key.",";
|
||
7 years ago
|
my $this_ip = generate_ip($anvil, "bcn", $bcn, $anvil->data->{cgi}{sequence}{value});
|
||
7 years ago
|
my $this_ip_class = $anvil->data->{cgi}{$this_ip_key}{alert} ? "input_alert" : "input_clear";
|
||
|
my $this_subnet_class = $anvil->data->{cgi}{$this_subnet_key}{alert} ? "input_alert" : "input_clear";
|
||
|
my $this_iface1_class = $anvil->data->{cgi}{$this_iface1_key}{alert} ? "input_alert" : "input_clear";
|
||
|
my $this_iface2_class = $anvil->data->{cgi}{$this_iface2_key}{alert} ? "input_alert" : "input_clear";
|
||
7 years ago
|
|
||
|
# Build the interface select boxes...
|
||
7 years ago
|
my $this_iface1_form = $anvil->Template->select_form({
|
||
7 years ago
|
name => $this_iface1_key,
|
||
|
options => $interface_options,
|
||
|
blank => 1,
|
||
7 years ago
|
selected => defined $anvil->data->{cgi}{$this_iface1_key}{value} ? $anvil->data->{cgi}{$this_iface1_key}{value} : "",
|
||
|
class => $anvil->data->{cgi}{$this_iface1_key}{alert} ? "input_alert" : "input_clear",
|
||
7 years ago
|
});
|
||
7 years ago
|
my $this_iface2_form = $anvil->Template->select_form({
|
||
7 years ago
|
name => $this_iface2_key,
|
||
|
options => $interface_options,
|
||
|
blank => 1,
|
||
7 years ago
|
selected => defined $anvil->data->{cgi}{$this_iface2_key}{value} ? $anvil->data->{cgi}{$this_iface2_key}{value} : "",
|
||
|
class => $anvil->data->{cgi}{$this_iface2_key}{alert} ? "input_alert" : "input_clear",
|
||
7 years ago
|
});
|
||
|
|
||
|
# Assemble the form
|
||
7 years ago
|
$interface_form .= $anvil->Template->get({file => "config.html", name => "bonded_interface_form", variables => {
|
||
7 years ago
|
field => $anvil->Words->string({key => "striker_0018", variables => { number => $bcn }}),
|
||
|
description => "#!string!striker_0019!#",
|
||
|
ip_key => $this_ip_key,
|
||
|
ip_value => defined $anvil->data->{cgi}{$this_ip_key}{value} ? $anvil->data->{cgi}{$this_ip_key}{value} : "",
|
||
|
ip_value_default => $this_ip,
|
||
|
ip_class => $this_ip_class,
|
||
|
subnet_key => $this_subnet_key,
|
||
|
subnet_value => defined $anvil->data->{cgi}{$this_subnet_key}{value} ? $anvil->data->{cgi}{$this_subnet_key}{value} : "",
|
||
|
subnet_value_default => $anvil->data->{defaults}{network}{bcn}{netmask},
|
||
|
subnet_class => $this_subnet_class,
|
||
|
iface1_select => $this_iface1_form,
|
||
|
iface2_select => $this_iface2_form,
|
||
7 years ago
|
}});
|
||
|
}
|
||
7 years ago
|
|
||
7 years ago
|
# IFN
|
||
7 years ago
|
my $ifn_count = $anvil->data->{cgi}{ifn_count}{value} ? $anvil->data->{cgi}{ifn_count}{value} : 1;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ifn_count => $ifn_count }});
|
||
7 years ago
|
foreach my $ifn (1..$ifn_count)
|
||
|
{
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ifn => $ifn }});
|
||
7 years ago
|
push @{$links}, "ifn_link".$ifn;
|
||
7 years ago
|
my $this_ip_key = "ifn".$ifn."_ip";
|
||
|
my $this_subnet_key = "ifn".$ifn."_subnet";
|
||
7 years ago
|
my $this_iface1_key = "ifn".$ifn."_link1_mac_to_set";
|
||
|
my $this_iface2_key = "ifn".$ifn."_link2_mac_to_set";
|
||
7 years ago
|
$cgi .= $this_ip_key.",".$this_subnet_key.",".$this_iface1_key.",".$this_iface2_key.",";
|
||
7 years ago
|
my $this_ip = generate_ip($anvil, "ifn", $ifn, $anvil->data->{cgi}{sequence}{value});
|
||
7 years ago
|
my $this_ip_class = $anvil->data->{cgi}{$this_ip_key}{alert} ? "input_alert" : "input_clear";
|
||
|
my $this_subnet_class = $anvil->data->{cgi}{$this_subnet_key}{alert} ? "input_alert" : "input_clear";
|
||
|
my $this_iface1_class = $anvil->data->{cgi}{$this_iface1_key}{alert} ? "input_alert" : "input_clear";
|
||
|
my $this_iface2_class = $anvil->data->{cgi}{$this_iface2_key}{alert} ? "input_alert" : "input_clear";
|
||
7 years ago
|
|
||
|
# Build the interface select boxes...
|
||
7 years ago
|
my $this_iface1_form = $anvil->Template->select_form({
|
||
7 years ago
|
name => $this_iface1_key,
|
||
|
options => $interface_options,
|
||
|
blank => 1,
|
||
7 years ago
|
selected => defined $anvil->data->{cgi}{$this_iface1_key}{value} ? $anvil->data->{cgi}{$this_iface1_key}{value} : "",
|
||
|
class => $anvil->data->{cgi}{$this_iface1_key}{alert} ? "input_alert" : "input_clear",
|
||
7 years ago
|
});
|
||
7 years ago
|
my $this_iface2_form = $anvil->Template->select_form({
|
||
7 years ago
|
name => $this_iface2_key,
|
||
|
options => $interface_options,
|
||
|
blank => 1,
|
||
7 years ago
|
selected => defined $anvil->data->{cgi}{$this_iface2_key}{value} ? $anvil->data->{cgi}{$this_iface2_key}{value} : "",
|
||
|
class => $anvil->data->{cgi}{$this_iface2_key}{alert} ? "input_alert" : "input_clear",
|
||
7 years ago
|
});
|
||
|
|
||
|
# Assemble the form
|
||
7 years ago
|
$interface_form .= $anvil->Template->get({file => "config.html", name => "bonded_interface_form", variables => {
|
||
7 years ago
|
field => $anvil->Words->string({key => "striker_0022", variables => { number => $ifn }}),
|
||
|
description => "#!string!striker_0023!#",
|
||
|
ip_key => $this_ip_key,
|
||
|
ip_value => defined $anvil->data->{cgi}{$this_ip_key}{value} ? $anvil->data->{cgi}{$this_ip_key}{value} : "",
|
||
|
ip_value_default => $this_ip,
|
||
|
ip_class => $this_ip_class,
|
||
|
subnet_key => $this_subnet_key,
|
||
|
subnet_value => defined $anvil->data->{cgi}{$this_subnet_key}{value} ? $anvil->data->{cgi}{$this_subnet_key}{value} : "",
|
||
|
subnet_value_default => $anvil->data->{defaults}{network}{ifn}{netmask},
|
||
|
subnet_class => $this_subnet_class,
|
||
|
iface1_select => $this_iface1_form,
|
||
|
iface2_select => $this_iface2_form,
|
||
7 years ago
|
}});
|
||
|
}
|
||
7 years ago
|
}
|
||
|
else
|
||
|
{
|
||
7 years ago
|
### Show the single iface per network form.
|
||
7 years ago
|
# BCN
|
||
7 years ago
|
my $bcn_count = $anvil->data->{cgi}{bcn_count}{value} ? $anvil->data->{cgi}{bcn_count}{value} : 1;
|
||
7 years ago
|
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";
|
||
7 years ago
|
my $this_iface1_key = "bcn".$bcn."_link1_mac_to_set";
|
||
7 years ago
|
$cgi .= $this_ip_key.",".$this_subnet_key.",".$this_iface1_key.",";
|
||
7 years ago
|
my $this_ip = generate_ip($anvil, "bcn", $bcn, $anvil->data->{cgi}{sequence}{value});
|
||
7 years ago
|
my $this_ip_class = $anvil->data->{cgi}{$this_ip_key}{alert} ? "input_alert" : "input_clear";
|
||
|
my $this_subnet_class = $anvil->data->{cgi}{$this_subnet_key}{alert} ? "input_alert" : "input_clear";
|
||
|
my $this_iface1_class = $anvil->data->{cgi}{$this_iface1_key}{alert} ? "input_alert" : "input_clear";
|
||
7 years ago
|
|
||
|
# Build the interface select boxes...
|
||
7 years ago
|
my $this_iface1_form = $anvil->Template->select_form({
|
||
7 years ago
|
name => $this_iface1_key,
|
||
|
options => $interface_options,
|
||
|
blank => 1,
|
||
7 years ago
|
selected => defined $anvil->data->{cgi}{$this_iface1_key}{value} ? $anvil->data->{cgi}{$this_iface1_key}{value} : "",
|
||
|
class => $anvil->data->{cgi}{$this_iface1_key}{alert} ? "input_alert" : "input_clear",
|
||
7 years ago
|
});
|
||
|
|
||
|
# Assemble the form
|
||
7 years ago
|
$interface_form .= $anvil->Template->get({file => "config.html", name => "single_interface_form", variables => {
|
||
7 years ago
|
field => $anvil->Words->string({key => "striker_0018", variables => { number => $bcn }}),
|
||
|
description => "#!string!striker_0019!#",
|
||
|
ip_key => $this_ip_key,
|
||
|
ip_value => defined $anvil->data->{cgi}{$this_ip_key}{value} ? $anvil->data->{cgi}{$this_ip_key}{value} : "",
|
||
|
ip_value_default => $this_ip,
|
||
|
ip_class => $this_ip_class,
|
||
|
subnet_key => $this_subnet_key,
|
||
|
subnet_value => defined $anvil->data->{cgi}{$this_subnet_key}{value} ? $anvil->data->{cgi}{$this_subnet_key}{value} : $anvil->data->{defaults}{network}{bcn}{netmask},
|
||
|
subnet_value_default => $anvil->data->{defaults}{network}{bcn}{netmask},
|
||
|
subnet_class => $this_subnet_class,
|
||
|
iface1_select => $this_iface1_form,
|
||
7 years ago
|
}});
|
||
|
}
|
||
|
|
||
|
# IFN
|
||
7 years ago
|
my $ifn_count = $anvil->data->{cgi}{ifn_count}{value} ? $anvil->data->{cgi}{ifn_count}{value} : 1;
|
||
7 years ago
|
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";
|
||
7 years ago
|
my $this_iface1_key = "ifn".$ifn."_link1_mac_to_set";
|
||
7 years ago
|
$cgi .= $this_ip_key.",".$this_subnet_key.",".$this_iface1_key.",";
|
||
7 years ago
|
my $this_ip = generate_ip($anvil, "ifn", $ifn, $anvil->data->{cgi}{sequence}{value});
|
||
7 years ago
|
my $this_ip_class = $anvil->data->{cgi}{$this_ip_key}{alert} ? "input_alert" : "input_clear";
|
||
|
my $this_subnet_class = $anvil->data->{cgi}{$this_subnet_key}{alert} ? "input_alert" : "input_clear";
|
||
|
my $this_iface1_class = $anvil->data->{cgi}{$this_iface1_key}{alert} ? "input_alert" : "input_clear";
|
||
7 years ago
|
|
||
|
# Build the interface select boxes...
|
||
7 years ago
|
my $this_iface1_form = $anvil->Template->select_form({
|
||
7 years ago
|
name => $this_iface1_key,
|
||
|
options => $interface_options,
|
||
|
blank => 1,
|
||
7 years ago
|
selected => defined $anvil->data->{cgi}{$this_iface1_key}{value} ? $anvil->data->{cgi}{$this_iface1_key}{value} : "",
|
||
|
class => $anvil->data->{cgi}{$this_iface1_key}{alert} ? "input_alert" : "input_clear",
|
||
7 years ago
|
});
|
||
|
|
||
|
# Assemble the form
|
||
7 years ago
|
$interface_form .= $anvil->Template->get({file => "config.html", name => "single_interface_form", variables => {
|
||
7 years ago
|
field => $anvil->Words->string({key => "striker_0022", variables => { number => $ifn }}),
|
||
|
description => "#!string!striker_0023!#",
|
||
|
ip_key => $this_ip_key,
|
||
|
ip_value => defined $anvil->data->{cgi}{$this_ip_key}{value} ? $anvil->data->{cgi}{$this_ip_key}{value} : "",
|
||
|
ip_value_default => $this_ip,
|
||
|
ip_class => $this_ip_class,
|
||
|
subnet_key => $this_subnet_key,
|
||
|
subnet_value => defined $anvil->data->{cgi}{$this_subnet_key}{value} ? $anvil->data->{cgi}{$this_subnet_key}{value} : $anvil->data->{defaults}{network}{ifn}{netmask},
|
||
|
subnet_value_default => $anvil->data->{defaults}{network}{ifn}{netmask},
|
||
|
subnet_class => $this_subnet_class,
|
||
|
iface1_select => $this_iface1_form,
|
||
7 years ago
|
}});
|
||
|
}
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
### TODO: Add a form for Gateway, DNS and which interface to use
|
||
|
# Gateway
|
||
7 years ago
|
my $gateway_class = $anvil->data->{cgi}{gateway}{alert} ? "input_alert" : "input_clear";
|
||
|
my $say_gateway = $anvil->Template->get({file => "main.html", name => "input_text_form", variables => {
|
||
|
name => "gateway",
|
||
|
id => "gateway",
|
||
|
field => "#!string!striker_0035!#",
|
||
|
description => "#!string!striker_0036!#",
|
||
|
value => defined $anvil->data->{cgi}{gateway}{value} ? $anvil->data->{cgi}{gateway}{value} : "",
|
||
|
default_value => "",
|
||
|
class => $gateway_class,
|
||
|
extra => "",
|
||
7 years ago
|
}});
|
||
|
|
||
|
# DNS
|
||
7 years ago
|
my $dns_class = $anvil->data->{cgi}{dns}{alert} ? "input_alert" : "input_clear";
|
||
|
my $say_dns = $anvil->Template->get({file => "main.html", name => "input_text_form", variables => {
|
||
|
name => "dns",
|
||
|
id => "dns",
|
||
|
field => "#!string!striker_0037!#",
|
||
|
description => "#!string!striker_0038!#",
|
||
|
value => defined $anvil->data->{cgi}{dns}{value} ? $anvil->data->{cgi}{dns}{value} : "",
|
||
|
default_value => $anvil->data->{defaults}{network}{dns},
|
||
|
class => $dns_class,
|
||
|
extra => "",
|
||
7 years ago
|
}});
|
||
|
|
||
|
# Which interface gets the route?
|
||
7 years ago
|
my $default_dg_iface = defined $anvil->data->{cgi}{dg_iface}{value} ? $anvil->data->{cgi}{dg_iface}{value} : "ifn_link1";
|
||
|
my $dg_iface_select = $anvil->Template->select_form({
|
||
7 years ago
|
name => "dg_iface",
|
||
|
options => $links,
|
||
|
blank => 0,
|
||
|
selected => $default_dg_iface,
|
||
7 years ago
|
class => $anvil->data->{cgi}{dg_iface}{alert} ? "input_alert" : "input_clear",
|
||
7 years ago
|
});
|
||
7 years ago
|
my $dg_iface_class = $anvil->data->{cgi}{dg_iface}{alert} ? "input_alert" : "input_clear";
|
||
|
my $say_dg_iface = $anvil->Template->get({file => "main.html", name => "input_select_form", variables => {
|
||
7 years ago
|
field => "#!string!striker_0039!#",
|
||
|
description => "#!string!striker_0040!#",
|
||
|
'select' => "",
|
||
|
}});
|
||
|
|
||
7 years ago
|
# Hostname
|
||
7 years ago
|
my $say_default_hostname = $anvil->data->{cgi}{prefix}{value}."-striker0".$anvil->data->{cgi}{sequence}{value}.".".$anvil->data->{cgi}{domain}{value};
|
||
|
my $hostname_class = $anvil->data->{cgi}{hostname}{alert} ? "input_alert" : "input_clear";
|
||
|
my $say_hostname = $anvil->Template->get({file => "main.html", name => "input_text_form", variables => {
|
||
7 years ago
|
name => "hostname",
|
||
|
id => "hostname",
|
||
|
field => "#!string!striker_0016!#",
|
||
|
description => "#!string!striker_0017!#",
|
||
|
value => defined $anvil->data->{cgi}{hostname}{value} ? $anvil->data->{cgi}{hostname}{value} : $say_default_hostname,
|
||
|
default_value => "",
|
||
|
class => $hostname_class,
|
||
|
extra => "",
|
||
7 years ago
|
}});
|
||
|
|
||
7 years ago
|
# Admin user
|
||
7 years ago
|
my $striker_user_class = $anvil->data->{cgi}{striker_user}{alert} ? "input_alert" : "input_clear";
|
||
|
my $say_striker_user = $anvil->Template->get({file => "main.html", name => "input_text_form", variables => {
|
||
|
name => "striker_user",
|
||
|
id => "striker_user",
|
||
|
field => "#!string!striker_0031!#",
|
||
|
description => "#!string!striker_0032!#",
|
||
7 years ago
|
value => defined $anvil->data->{cgi}{striker_user}{value} ? $anvil->data->{cgi}{striker_user}{value} : $anvil->data->{sys}{user}{name},
|
||
7 years ago
|
default_value => "",
|
||
|
class => $striker_user_class,
|
||
|
extra => "",
|
||
7 years ago
|
}});
|
||
|
|
||
|
# Password
|
||
7 years ago
|
my $striker_password_class = $anvil->data->{cgi}{striker_password}{alert} ? "input_alert" : "input_clear";
|
||
|
my $say_striker_password = $anvil->Template->get({file => "main.html", name => "input_text_form", variables => {
|
||
|
name => "striker_password",
|
||
|
id => "striker_password",
|
||
|
field => "#!string!striker_0033!#",
|
||
|
description => "#!string!striker_0034!#",
|
||
|
value => defined $anvil->data->{cgi}{striker_password}{value} ? $anvil->data->{cgi}{striker_password}{value} : "",
|
||
|
default_value => "",
|
||
|
class => $striker_password_class,
|
||
|
extra => "",
|
||
7 years ago
|
}});
|
||
|
|
||
|
# Get the table that shows the current interface states.
|
||
7 years ago
|
my $interface_states = get_network_details_form($anvil);
|
||
7 years ago
|
|
||
|
# Store the previous CGI variables and display the new fields.
|
||
7 years ago
|
my $step2_body = $anvil->Template->get({file => "config.html", name => "config_step2", variables => {
|
||
7 years ago
|
step1_welcome_title_id => "",
|
||
|
step1_welcome_message_id => "",
|
||
7 years ago
|
organization => $anvil->data->{cgi}{organization}{value},
|
||
|
prefix => $anvil->data->{cgi}{prefix}{value},
|
||
|
domain => $anvil->data->{cgi}{domain}{value},
|
||
|
sequence => $anvil->data->{cgi}{sequence}{value},
|
||
|
bcn_count => $anvil->data->{cgi}{bcn_count}{value},
|
||
|
ifn_count => $anvil->data->{cgi}{ifn_count}{value},
|
||
7 years ago
|
interface_form => $interface_form,
|
||
7 years ago
|
interface_states => $interface_states,
|
||
|
striker_user_form => $say_striker_user,
|
||
|
striker_password_form => $say_striker_password,
|
||
7 years ago
|
gateway_form => $say_gateway,
|
||
|
dns_form => $say_dns,
|
||
7 years ago
|
hostname_form => $say_hostname,
|
||
7 years ago
|
cgi_list => $cgi."organization,prefix,domain,sequence,bcn_count,ifn_count,gateway,hostname,dns,striker_user,striker_password",
|
||
7 years ago
|
}});
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { step2_body => $step2_body }});
|
||
7 years ago
|
|
||
7 years ago
|
return($step2_body);
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
# This sanity-checks step 2 and returns '1' if there was a problem.
|
||
|
sub sanity_check_step2
|
||
|
{
|
||
7 years ago
|
my ($anvil) = @_;
|
||
7 years ago
|
|
||
7 years ago
|
# This will flip if we run into a problem.
|
||
|
my $sane = 1;
|
||
7 years ago
|
|
||
|
# Do we have a host name, striker user and password?
|
||
7 years ago
|
if (not $anvil->Validate->form_field({name => "hostname", type => "domain_name"}))
|
||
7 years ago
|
{
|
||
7 years ago
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0012"}) }});
|
||
|
$anvil->data->{cgi}{hostname}{alert} = 1;
|
||
|
$sane = 0;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane }});
|
||
7 years ago
|
}
|
||
7 years ago
|
else
|
||
|
{
|
||
|
# Record the answer.
|
||
7 years ago
|
$anvil->Database->insert_or_update_variables({
|
||
7 years ago
|
variable_name => "form::config_step2::hostname::value",
|
||
7 years ago
|
variable_value => $anvil->data->{cgi}{hostname}{value},
|
||
7 years ago
|
variable_default => "",
|
||
|
variable_description => "striker_0017",
|
||
|
variable_section => "config_step2",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
update_value_only => 1,
|
||
|
});
|
||
|
}
|
||
7 years ago
|
|
||
|
# The user name
|
||
7 years ago
|
if ((not defined $anvil->data->{cgi}{striker_user}{value}) or (not $anvil->data->{cgi}{striker_user}{value}))
|
||
7 years ago
|
{
|
||
7 years ago
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0013"}) }});
|
||
7 years ago
|
$anvil->data->{cgi}{striker_user}{alert} = 1;
|
||
7 years ago
|
$sane = 0;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane, "cgi::striker_user::alert" => $anvil->data->{cgi}{striker_user}{alert} }});
|
||
7 years ago
|
}
|
||
7 years ago
|
else
|
||
|
{
|
||
|
# Record the answer.
|
||
7 years ago
|
$anvil->Database->insert_or_update_variables({
|
||
7 years ago
|
variable_name => "form::config_step2::striker_user::value",
|
||
7 years ago
|
variable_value => $anvil->data->{cgi}{striker_user}{value},
|
||
7 years ago
|
variable_default => "",
|
||
|
variable_description => "striker_0032",
|
||
|
variable_section => "config_step2",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
update_value_only => 1,
|
||
|
});
|
||
|
}
|
||
7 years ago
|
|
||
|
# The password
|
||
7 years ago
|
if ((not defined $anvil->data->{cgi}{striker_password}{value}) or (not $anvil->data->{cgi}{striker_password}{value}) or (length($anvil->data->{cgi}{striker_password}{value}) < 6))
|
||
7 years ago
|
{
|
||
7 years ago
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0014"}) }});
|
||
7 years ago
|
$anvil->data->{cgi}{striker_password}{alert} = 1;
|
||
7 years ago
|
$sane = 0;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane, "cgi::striker_password::alert" => $anvil->data->{cgi}{striker_password}{alert} }});
|
||
7 years ago
|
}
|
||
7 years ago
|
else
|
||
7 years ago
|
{
|
||
7 years ago
|
# Record the answer.
|
||
7 years ago
|
$anvil->Database->insert_or_update_variables({
|
||
7 years ago
|
variable_name => "form::config_step2::striker_password::value",
|
||
7 years ago
|
variable_value => $anvil->data->{cgi}{striker_password}{value},
|
||
7 years ago
|
variable_default => "",
|
||
|
variable_description => "striker_0034",
|
||
|
variable_section => "config_step2",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
update_value_only => 1,
|
||
|
});
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
# DNS can be multiple entries, comma-separated. It can also be blank, if the user doesn't need Internet access.
|
||
|
my $dns_ok = 1;
|
||
7 years ago
|
if ((defined $anvil->data->{cgi}{dns}{value}) and ($anvil->data->{cgi}{dns}{value}))
|
||
7 years ago
|
{
|
||
7 years ago
|
foreach my $ip (split/,/, $anvil->data->{cgi}{dns}{value})
|
||
7 years ago
|
{
|
||
|
$ip =~ s/^\s+//;
|
||
|
$ip =~ s/\s+$//;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { ip => $ip }});
|
||
|
if (not $anvil->Validate->is_ipv4({ip => $ip}))
|
||
7 years ago
|
{
|
||
7 years ago
|
$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;
|
||
|
$sane = 0;
|
||
|
$dns_ok = 0;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane, dns_ok => $dns_ok, "cgi::dns::alert" => $anvil->data->{cgi}{dns}{alert} }});
|
||
7 years ago
|
}
|
||
|
}
|
||
7 years ago
|
}
|
||
|
if ($dns_ok)
|
||
|
{
|
||
|
# Record the answer.
|
||
7 years ago
|
$anvil->Database->insert_or_update_variables({
|
||
7 years ago
|
variable_name => "form::config_step2::dns::value",
|
||
7 years ago
|
variable_value => $anvil->data->{cgi}{dns}{value},
|
||
7 years ago
|
variable_default => "",
|
||
|
variable_description => "striker_0038",
|
||
|
variable_section => "config_step2",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
update_value_only => 1,
|
||
|
});
|
||
7 years ago
|
}
|
||
|
|
||
|
# Look for interfaces and sanity check them.
|
||
7 years ago
|
my $networks = {};
|
||
7 years ago
|
foreach my $network ("bcn", "ifn")
|
||
7 years ago
|
{
|
||
7 years ago
|
my $count_key = $network."_count";
|
||
7 years ago
|
my $network_count = $anvil->data->{cgi}{$count_key}{value} ? $anvil->data->{cgi}{$count_key}{value} : 1;
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
|
||
7 years ago
|
network => $network,
|
||
|
count_key => $count_key,
|
||
|
network_count => $network_count,
|
||
|
}});
|
||
|
foreach my $count (1..$network_count)
|
||
|
{
|
||
7 years ago
|
my $this_network = $network.$count;
|
||
|
my $this_ip_key = $this_network."_ip";
|
||
|
my $this_subnet_key = $this_network."_subnet";
|
||
7 years ago
|
my $this_iface1_key = $this_network."_link1_mac_to_set";
|
||
|
my $this_iface2_key = $this_network."_link2_mac_to_set";
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
|
||
7 years ago
|
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,
|
||
7 years ago
|
"cgi::${this_ip_key}::value" => $anvil->data->{cgi}{$this_ip_key}{value},
|
||
|
"cgi::${this_subnet_key}::value" => $anvil->data->{cgi}{$this_subnet_key}{value},
|
||
|
"cgi::${this_iface1_key}::value" => $anvil->data->{cgi}{$this_iface1_key}{value},
|
||
|
"cgi::${this_iface2_key}::value" => $anvil->data->{cgi}{$this_iface2_key}{value},
|
||
7 years ago
|
}});
|
||
|
|
||
7 years ago
|
# This will be used to tell the user which interface has a problem, if one exists.
|
||
|
my $network_key = $network =~ /^bcn/ ? "striker_0018" : "striker_0022";
|
||
|
my $say_network = $anvil->Words->string({key => $network_key, variables => { number => $count }});
|
||
|
|
||
7 years ago
|
# Is the IP sane?
|
||
7 years ago
|
my $ip_ok = 1;
|
||
7 years ago
|
if (not $anvil->Validate->form_field({name => $this_ip_key, type => "ipv4"}))
|
||
7 years ago
|
{
|
||
|
# Nope
|
||
7 years ago
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0016", variables => { network => $say_network}}) }});
|
||
|
$anvil->data->{cgi}{$this_ip_key}{alert} = 1;
|
||
|
$sane = 0;
|
||
|
$ip_ok = 0;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane, ip_ok => $ip_ok }});
|
||
7 years ago
|
}
|
||
7 years ago
|
else
|
||
|
{
|
||
|
# Save the IP
|
||
7 years ago
|
$anvil->Database->insert_or_update_variables({
|
||
7 years ago
|
variable_name => "form::config_step2::${this_ip_key}::value",
|
||
7 years ago
|
variable_value => $anvil->data->{cgi}{$this_ip_key}{value},
|
||
7 years ago
|
variable_default => "",
|
||
|
variable_description => "striker_0024",
|
||
|
variable_section => "config_step2",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
update_value_only => 1,
|
||
|
});
|
||
|
}
|
||
7 years ago
|
|
||
|
# What about the subnet?
|
||
7 years ago
|
if (not $anvil->Validate->form_field({name => $this_subnet_key, type => "subnet"}))
|
||
7 years ago
|
{
|
||
7 years ago
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0016", variables => { network => $say_network }}) }});
|
||
|
$anvil->data->{cgi}{$this_subnet_key}{alert} = 1;
|
||
|
$sane = 0;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane }});
|
||
7 years ago
|
}
|
||
7 years ago
|
elsif ($ip_ok)
|
||
|
{
|
||
|
# We'll use the dotted-decimal subnet. If it already is, great. If not, convert it.
|
||
7 years ago
|
my $say_subnet = $anvil->data->{cgi}{$this_subnet_key}{value} =~ /^\d{1,2}$/ ? $anvil->Convert->cide({cidr => $anvil->data->{cgi}{$this_subnet_key}{value}}) : $anvil->data->{cgi}{$this_subnet_key}{value};
|
||
|
my $full_ip = $anvil->data->{cgi}{$this_ip_key}{value}."/".$anvil->data->{cgi}{$this_subnet_key}{value};
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_subnet => $say_subnet, full_ip => $full_ip }});
|
||
7 years ago
|
|
||
|
$networks->{$this_network} = $full_ip;
|
||
7 years ago
|
|
||
|
# Save the subnet
|
||
7 years ago
|
$anvil->Database->insert_or_update_variables({
|
||
7 years ago
|
variable_name => "form::config_step2::${this_subnet_key}::value",
|
||
7 years ago
|
variable_value => $anvil->data->{cgi}{$this_subnet_key}{value},
|
||
7 years ago
|
variable_default => "",
|
||
|
variable_description => "striker_0025",
|
||
|
variable_section => "config_step2",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
update_value_only => 1,
|
||
|
});
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
|
# Interface 1 must be set
|
||
7 years ago
|
if (not $anvil->Validate->form_field({name => $this_iface1_key, type => "mac"}))
|
||
7 years ago
|
{
|
||
7 years ago
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0017", variables => { network => $say_network, 'link' => "1" }}) }});
|
||
|
$anvil->data->{cgi}{$this_iface1_key}{alert} = 1;
|
||
|
$sane = 0;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane }});
|
||
7 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
# Valid MAC. Has it been assigned elsewhere?
|
||
7 years ago
|
my $mac = $anvil->data->{cgi}{$this_iface1_key}{value};
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { mac => $mac }});
|
||
|
if ((not exists $anvil->data->{network}{$mac}{set_as}) or (not $anvil->data->{network}{$mac}{set_as}))
|
||
7 years ago
|
{
|
||
7 years ago
|
$anvil->data->{network}{$mac}{set_as} = $this_iface1_key;
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "network::${mac}::set_as" => $anvil->data->{network}{$mac}{set_as} }});
|
||
7 years ago
|
|
||
|
# Record the answer.
|
||
7 years ago
|
$anvil->Database->insert_or_update_variables({
|
||
7 years ago
|
variable_name => "form::config_step2::${this_iface1_key}::value",
|
||
7 years ago
|
variable_value => $anvil->data->{cgi}{$this_iface1_key}{value},
|
||
7 years ago
|
variable_default => "",
|
||
|
variable_description => "striker_0029",
|
||
|
variable_section => "config_step2",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
update_value_only => 1,
|
||
|
});
|
||
7 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
# Conflict! Set the alert for this interface and the conflicting one.
|
||
7 years ago
|
my $conflict_key = $anvil->data->{network}{$mac}{set_as};
|
||
7 years ago
|
$anvil->data->{cgi}{$conflict_key}{alert} = 1;
|
||
|
$anvil->data->{cgi}{$this_iface1_key}{alert} = 1;
|
||
7 years ago
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0018"}) }});
|
||
|
$sane = 0;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => {
|
||
7 years ago
|
sane => $sane,
|
||
7 years ago
|
"cgi::${conflict_key}::alert" => $anvil->data->{cgi}{$conflict_key}{alert},
|
||
|
"cgi::${this_iface1_key}::alert" => $anvil->data->{cgi}{$this_iface1_key}{alert},
|
||
7 years ago
|
}});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
# Interface 2 doesn't have to be set.
|
||
7 years ago
|
if ((defined $anvil->data->{cgi}{$this_iface2_key}{value}) && ($anvil->data->{cgi}{$this_iface2_key}{value}))
|
||
7 years ago
|
{
|
||
7 years ago
|
if (not $anvil->Validate->form_field({name => $this_iface2_key, type => "mac"}))
|
||
7 years ago
|
{
|
||
7 years ago
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0017", variables => { network => $say_network, 'link' => "2" }}) }});
|
||
|
$anvil->data->{cgi}{$this_iface2_key}{alert} = 1;
|
||
|
$sane = 0;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane }});
|
||
7 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
# Valid MAC. Has it been assigned elsewhere?
|
||
7 years ago
|
my $mac = $anvil->data->{cgi}{$this_iface2_key}{value};
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { mac => $mac }});
|
||
|
if ((not exists $anvil->data->{network}{$mac}{set_as}) or (not $anvil->data->{network}{$mac}{set_as}))
|
||
7 years ago
|
{
|
||
7 years ago
|
$anvil->data->{network}{$mac}{set_as} = $this_iface2_key;
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "network::${mac}::set_as" => $anvil->data->{network}{$mac}{set_as} }});
|
||
7 years ago
|
|
||
|
# Record the answer.
|
||
7 years ago
|
$anvil->Database->insert_or_update_variables({
|
||
7 years ago
|
variable_name => "form::config_step2::${this_iface2_key}::value",
|
||
7 years ago
|
variable_value => $anvil->data->{cgi}{$this_iface2_key}{value},
|
||
7 years ago
|
variable_default => "",
|
||
|
variable_description => "striker_0030",
|
||
|
variable_section => "config_step2",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
update_value_only => 1,
|
||
|
});
|
||
7 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
# Conflict! Set the alert for this interface and the conflicting one.
|
||
7 years ago
|
my $conflict_key = $anvil->data->{network}{$mac}{set_as};
|
||
7 years ago
|
$anvil->data->{cgi}{$conflict_key}{alert} = 1;
|
||
|
$anvil->data->{cgi}{$this_iface2_key}{alert} = 1;
|
||
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0018"}) }});
|
||
|
$sane = 0;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => {
|
||
7 years ago
|
sane => $sane,
|
||
7 years ago
|
"cgi::${conflict_key}::alert" => $anvil->data->{cgi}{$conflict_key}{alert},
|
||
|
"cgi::${this_iface2_key}::alert" => $anvil->data->{cgi}{$this_iface2_key}{alert},
|
||
7 years ago
|
}});
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
# The gateway, this has to be after the interfaces so that we can match it to an interface (and error
|
||
|
# if not)
|
||
7 years ago
|
if (not $anvil->Validate->form_field({name => "gateway", type => "ipv4", empty_ok => 1}))
|
||
7 years ago
|
{
|
||
7 years ago
|
$anvil->data->{cgi}{gateway}{alert} = 1;
|
||
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0019"}) }});
|
||
|
$sane = 0;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane }});
|
||
7 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
# Convert the gateway strings to binary.
|
||
7 years ago
|
my $gateway = defined $anvil->data->{cgi}{gateway}{value} ? $anvil->data->{cgi}{gateway}{value} : "";
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { gateway => $gateway }});
|
||
7 years ago
|
|
||
|
# If there is no gateway, that's OK, there just won't be any Internet access.
|
||
7 years ago
|
my $gateway_interface = "";
|
||
7 years ago
|
if ($gateway)
|
||
7 years ago
|
{
|
||
7 years ago
|
# Match this gateway to one of the interfaces.
|
||
|
foreach my $this_network (sort {$a cmp $b} keys %{$networks})
|
||
|
{
|
||
|
my ($this_ip, $this_subnet) = ($networks->{$this_network} =~ /^(.*?)\/(.*)$/);
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
|
||
7 years ago
|
"s1:this_network" => $this_network,
|
||
|
"s2:networks->$this_network" => $networks->{$this_network},
|
||
|
"s3:this_ip" => $this_ip,
|
||
|
"s4:this_subnet" => $this_subnet,
|
||
|
}});
|
||
|
|
||
|
my $first = NetAddr::IP->new("$this_ip/$this_subnet");
|
||
|
my $second = NetAddr::IP->new("$gateway/$this_subnet");
|
||
7 years ago
|
|
||
7 years ago
|
if ($second->within($first))
|
||
|
{
|
||
|
$gateway_interface = $this_network;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { gateway_interface => $gateway_interface }});
|
||
7 years ago
|
}
|
||
|
}
|
||
|
if (not $gateway_interface)
|
||
7 years ago
|
{
|
||
7 years ago
|
# Explain the problem
|
||
7 years ago
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0004"}) }});
|
||
7 years ago
|
$anvil->data->{cgi}{gateway}{alert} = 1;
|
||
|
$sane = 0;
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane, "cgi::gateway::alert" => $anvil->data->{cgi}{gateway}{alert} }});
|
||
7 years ago
|
}
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
# If no alert was raised, record the values.
|
||
7 years ago
|
if (not $anvil->data->{cgi}{gateway}{alert})
|
||
7 years ago
|
{
|
||
|
# Record the answer.
|
||
7 years ago
|
$anvil->Database->insert_or_update_variables({
|
||
7 years ago
|
variable_name => "form::config_step2::gateway::value",
|
||
7 years ago
|
variable_value => $anvil->data->{cgi}{gateway}{value},
|
||
7 years ago
|
variable_default => "",
|
||
|
variable_description => "striker_0036",
|
||
|
variable_section => "config_step2",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
update_value_only => 1,
|
||
|
});
|
||
|
|
||
|
# Record the gateway interface
|
||
7 years ago
|
$anvil->Database->insert_or_update_variables({
|
||
7 years ago
|
variable_name => "form::config_step2::gateway_interface::value",
|
||
|
variable_value => $gateway_interface,
|
||
|
variable_default => "",
|
||
|
variable_description => "",
|
||
|
variable_section => "config_step2",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
update_value_only => 1,
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { sane => $sane }});
|
||
7 years ago
|
return($sane);
|
||
|
}
|
||
|
|
||
7 years ago
|
# This sanity-checks step 1 and returns '1' if there was a problem.
|
||
|
sub sanity_check_step1
|
||
|
{
|
||
7 years ago
|
my ($anvil) = @_;
|
||
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0131", variables => { function => "sanity_check_step1()" }});
|
||
7 years ago
|
|
||
7 years ago
|
# This will flip if we run into a problem.
|
||
7 years ago
|
my $sane = 1;
|
||
|
|
||
7 years ago
|
# Organization just needs *something*
|
||
7 years ago
|
if ((not defined $anvil->data->{cgi}{organization}{value}) or (not $anvil->data->{cgi}{organization}{value}))
|
||
7 years ago
|
{
|
||
7 years ago
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0020", variables => { field => "striker_0003" }}) }});
|
||
7 years ago
|
$anvil->data->{cgi}{organization}{alert} = 1;
|
||
7 years ago
|
$sane = 0;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane, "cgi::organization::alert" => $anvil->data->{cgi}{organization}{alert} }});
|
||
7 years ago
|
}
|
||
7 years ago
|
else
|
||
|
{
|
||
|
# Record the answer.
|
||
7 years ago
|
$anvil->Database->insert_or_update_variables({
|
||
7 years ago
|
variable_name => "form::config_step1::organization::value",
|
||
7 years ago
|
variable_value => $anvil->data->{cgi}{organization}{value},
|
||
7 years ago
|
variable_default => "",
|
||
|
variable_description => "striker_0004",
|
||
|
variable_section => "config_step1",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
update_value_only => 1,
|
||
|
});
|
||
|
}
|
||
7 years ago
|
|
||
|
# The prefix needs to be alphanumeric and be between 1 ~ 5 chatacters.
|
||
7 years ago
|
if ((not $anvil->Validate->is_alphanumeric({string => $anvil->data->{cgi}{prefix}{value}})) or (length($anvil->data->{cgi}{prefix}{value}) > 5))
|
||
7 years ago
|
{
|
||
7 years ago
|
$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;
|
||
|
$sane = 0;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane, "cgi::prefix::alert" => $anvil->data->{cgi}{prefix}{alert} }});
|
||
7 years ago
|
}
|
||
7 years ago
|
else
|
||
|
{
|
||
|
# Record the answer.
|
||
7 years ago
|
$anvil->Database->insert_or_update_variables({
|
||
7 years ago
|
variable_name => "form::config_step1::prefix::value",
|
||
7 years ago
|
variable_value => $anvil->data->{cgi}{prefix}{value},
|
||
7 years ago
|
variable_default => "",
|
||
|
variable_description => "striker_0006",
|
||
|
variable_section => "config_step1",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
update_value_only => 1,
|
||
|
});
|
||
|
}
|
||
7 years ago
|
|
||
|
# We can use Validate to check the domain.
|
||
7 years ago
|
if (not $anvil->Validate->form_field({name => "domain", type => "domain_name"}))
|
||
7 years ago
|
{
|
||
7 years ago
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "error_0020", variables => { field => "striker_0007" }}) }});
|
||
|
$anvil->data->{cgi}{domain}{alert} = 1;
|
||
|
$sane = 0;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane }});
|
||
7 years ago
|
}
|
||
7 years ago
|
else
|
||
|
{
|
||
|
# Record the answer.
|
||
7 years ago
|
$anvil->Database->insert_or_update_variables({
|
||
7 years ago
|
variable_name => "form::config_step1::domain::value",
|
||
7 years ago
|
variable_value => $anvil->data->{cgi}{domain}{value},
|
||
7 years ago
|
variable_default => "",
|
||
|
variable_description => "striker_0008",
|
||
|
variable_section => "config_step1",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
update_value_only => 1,
|
||
|
});
|
||
|
}
|
||
7 years ago
|
|
||
|
# The sequence and IFN count need to be integers.
|
||
7 years ago
|
if (not $anvil->Validate->is_positive_integer({number => $anvil->data->{cgi}{sequence}{value}}))
|
||
7 years ago
|
{
|
||
7 years ago
|
$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" }}) }});
|
||
7 years ago
|
$anvil->data->{cgi}{sequence}{alert} = 1;
|
||
7 years ago
|
$sane = 0;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane, "cgi::sequence::alert" => $anvil->data->{cgi}{sequence}{alert} }});
|
||
7 years ago
|
}
|
||
7 years ago
|
else
|
||
|
{
|
||
|
# Record the answer.
|
||
7 years ago
|
$anvil->Database->insert_or_update_variables({
|
||
7 years ago
|
variable_name => "form::config_step1::sequence::value",
|
||
7 years ago
|
variable_value => $anvil->data->{cgi}{sequence}{value},
|
||
7 years ago
|
variable_default => "",
|
||
|
variable_description => "striker_0010",
|
||
|
variable_section => "config_step1",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
update_value_only => 1,
|
||
|
});
|
||
|
}
|
||
|
|
||
7 years ago
|
if (not $anvil->Validate->is_positive_integer({number => $anvil->data->{cgi}{ifn_count}{value}}))
|
||
7 years ago
|
{
|
||
7 years ago
|
$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" }}) }});
|
||
7 years ago
|
$anvil->data->{cgi}{ifn_count}{alert} = 1;
|
||
7 years ago
|
$sane = 0;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { sane => $sane, "cgi::ifn_count::alert" => $anvil->data->{cgi}{ifn_count}{alert} }});
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
# Make sure we have enough interfaces.
|
||
7 years ago
|
get_network_details($anvil);
|
||
|
my $required_interfaces_for_single = 1 + $anvil->data->{cgi}{ifn_count}{value};
|
||
|
my $interface_count = keys %{$anvil->data->{interfaces}};
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
|
||
7 years ago
|
required_interfaces_for_single => $required_interfaces_for_single,
|
||
|
interface_count => $interface_count,
|
||
|
}});
|
||
|
|
||
|
if ($interface_count < $required_interfaces_for_single)
|
||
|
{
|
||
|
# Build the error message.
|
||
7 years ago
|
my $say_message = $anvil->Words->string({key => "error_0001", variables => {
|
||
7 years ago
|
interface_count => $interface_count,
|
||
|
required_interfaces_for_single => $required_interfaces_for_single,
|
||
|
}});
|
||
|
|
||
|
# Not enough interfaces found.
|
||
7 years ago
|
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $say_message }});
|
||
7 years ago
|
$anvil->data->{cgi}{ifn_count}{alert} = 1;
|
||
7 years ago
|
$sane = 0;
|
||
7 years ago
|
}
|
||
7 years ago
|
else
|
||
|
{
|
||
7 years ago
|
# Sane, Record the answers.
|
||
7 years ago
|
$anvil->Database->insert_or_update_variables({
|
||
7 years ago
|
variable_name => "form::config_step1::ifn_count::value",
|
||
7 years ago
|
variable_value => $anvil->data->{cgi}{ifn_count}{value},
|
||
7 years ago
|
variable_default => "",
|
||
|
variable_description => "striker_0012",
|
||
|
variable_section => "config_step1",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
update_value_only => 1,
|
||
|
});
|
||
|
}
|
||
7 years ago
|
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { sane => $sane }});
|
||
7 years ago
|
return($sane);
|
||
|
}
|
||
|
|
||
7 years ago
|
# This is step 1 in asking the user how to configure Striker.
|
||
|
sub config_step1
|
||
|
{
|
||
7 years ago
|
my ($anvil) = @_;
|
||
7 years ago
|
|
||
7 years ago
|
if (not $anvil->data->{cgi}{'next'}{value})
|
||
7 years ago
|
{
|
||
7 years ago
|
# First load. See if we can read old data.
|
||
7 years ago
|
my ($organization) = $anvil->Database->read_variable({
|
||
7 years ago
|
variable_name => "form::config_step1::organization::value",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
});
|
||
7 years ago
|
my ($prefix) = $anvil->Database->read_variable({
|
||
7 years ago
|
variable_name => "form::config_step1::prefix::value",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
});
|
||
7 years ago
|
my ($domain) = $anvil->Database->read_variable({
|
||
7 years ago
|
variable_name => "form::config_step1::domain::value",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
});
|
||
7 years ago
|
my ($sequence) = $anvil->Database->read_variable({
|
||
7 years ago
|
variable_name => "form::config_step1::sequence::value",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
});
|
||
7 years ago
|
my ($ifn_count) = $anvil->Database->read_variable({
|
||
7 years ago
|
variable_name => "form::config_step1::ifn_count::value",
|
||
7 years ago
|
variable_source_uuid => $anvil->Get->host_uuid,
|
||
7 years ago
|
variable_source_table => "hosts",
|
||
|
});
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
|
||
7 years ago
|
organization => $organization,
|
||
|
prefix => $prefix,
|
||
|
domain => $domain,
|
||
|
sequence => $sequence,
|
||
|
ifn_count => $ifn_count,
|
||
|
}});
|
||
|
|
||
7 years ago
|
$anvil->data->{cgi}{organization}{value} = $organization ne "" ? $organization : "";
|
||
|
$anvil->data->{cgi}{prefix}{value} = $prefix ne "" ? $prefix : "";
|
||
|
$anvil->data->{cgi}{domain}{value} = $domain ne "" ? $domain : "";
|
||
|
$anvil->data->{cgi}{sequence}{value} = $sequence ne "" ? $sequence : 1;
|
||
|
$anvil->data->{cgi}{ifn_count}{value} = $ifn_count ne "" ? $ifn_count : 1;
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
|
||
|
'cgi::organization::value' => $anvil->data->{cgi}{organization}{value},
|
||
|
'cgi::prefix::value' => $anvil->data->{cgi}{prefix}{value},
|
||
|
'cgi::domain::value' => $anvil->data->{cgi}{domain}{value},
|
||
|
'cgi::sequence::value' => $anvil->data->{cgi}{sequence}{value},
|
||
|
'cgi::ifn_count::value' => $anvil->data->{cgi}{ifn_count}{value},
|
||
7 years ago
|
}});
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
7 years ago
|
my $organization_class = $anvil->data->{cgi}{organization}{alert} ? "input_alert" : "input_clear";
|
||
|
my $say_organization = $anvil->Template->get({file => "main.html", name => "input_text_form", variables => {
|
||
7 years ago
|
name => "organization",
|
||
|
id => "organization",
|
||
|
field => "#!string!striker_0003!#",
|
||
|
description => "#!string!striker_0004!#",
|
||
|
value => defined $anvil->data->{cgi}{organization}{value} ? $anvil->data->{cgi}{organization}{value} : "",
|
||
|
default_value => "",
|
||
|
class => $organization_class,
|
||
|
extra => "",
|
||
7 years ago
|
}});
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_organization => $say_organization }});
|
||
|
my $prefix_class = $anvil->data->{cgi}{prefix}{alert} ? "input_alert" : "input_clear";
|
||
|
my $say_prefix = $anvil->Template->get({file => "main.html", name => "input_text_form", variables => {
|
||
7 years ago
|
name => "prefix",
|
||
|
id => "prefix",
|
||
|
field => "#!string!striker_0005!#",
|
||
|
description => "#!string!striker_0006!#",
|
||
|
value => defined $anvil->data->{cgi}{prefix}{value} ? $anvil->data->{cgi}{prefix}{value} : "",
|
||
|
default_value => "",
|
||
|
class => $prefix_class,
|
||
|
extra => "maxlength=\"5\"",
|
||
7 years ago
|
}});
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_prefix => $say_prefix }});
|
||
|
my $domain_class = $anvil->data->{cgi}{domain}{alert} ? "input_alert" : "input_clear";
|
||
|
my $say_domain = $anvil->Template->get({file => "main.html", name => "input_text_form", variables => {
|
||
7 years ago
|
name => "domain",
|
||
|
id => "domain",
|
||
|
field => "#!string!striker_0007!#",
|
||
|
description => "#!string!striker_0008!#",
|
||
|
value => defined $anvil->data->{cgi}{domain}{value} ? $anvil->data->{cgi}{domain}{value} : "",
|
||
|
default_value => "",
|
||
|
class => $domain_class,
|
||
|
extra => "maxlength=\"255\"",
|
||
7 years ago
|
}});
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_domain => $say_domain }});
|
||
|
my $sequence_class = $anvil->data->{cgi}{sequence}{alert} ? "input_alert" : "input_clear";
|
||
|
my $say_sequence = $anvil->Template->get({file => "main.html", name => "input_number_form", variables => {
|
||
7 years ago
|
name => "sequence",
|
||
|
id => "sequence",
|
||
|
field => "#!string!striker_0009!#",
|
||
|
description => "#!string!striker_0010!#",
|
||
7 years ago
|
value => defined $anvil->data->{cgi}{sequence}{value} ? $anvil->data->{cgi}{sequence}{value} : "",
|
||
7 years ago
|
class => $sequence_class,
|
||
7 years ago
|
extra => "min=\"1\" max=\"24\"",
|
||
7 years ago
|
}});
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_domain => $say_domain }});
|
||
|
my $ifn_count_class = $anvil->data->{cgi}{ifn_count}{alert} ? "input_alert" : "input_clear";
|
||
|
my $say_ifn_count = $anvil->Template->get({file => "main.html", name => "input_number_form", variables => {
|
||
7 years ago
|
name => "ifn_count",
|
||
|
id => "ifn_count",
|
||
7 years ago
|
field => "#!string!striker_0011!#",
|
||
|
description => "#!string!striker_0012!#",
|
||
7 years ago
|
value => defined $anvil->data->{cgi}{ifn_count}{value} ? $anvil->data->{cgi}{ifn_count}{value} : "",
|
||
7 years ago
|
class => $ifn_count_class,
|
||
7 years ago
|
extra => "min=\"1\" max=\"24\"",
|
||
7 years ago
|
}});
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_ifn_count => $say_ifn_count }});
|
||
7 years ago
|
|
||
7 years ago
|
my $step1_body = $anvil->Template->get({file => "config.html", name => "config_step1", variables => {
|
||
7 years ago
|
step1_welcome_title_id => "",
|
||
|
step1_welcome_message_id => "",
|
||
7 years ago
|
organization_form => $say_organization,
|
||
|
prefix_form => $say_prefix,
|
||
7 years ago
|
domain_form => $say_domain,
|
||
|
sequence_form => $say_sequence,
|
||
7 years ago
|
ifn_count_form => $say_ifn_count,
|
||
7 years ago
|
cgi_list => "organization,prefix,domain,sequence,ifn_count",
|
||
7 years ago
|
}});
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { step1_body => $step1_body }});
|
||
7 years ago
|
|
||
|
return($step1_body);
|
||
|
}
|
||
|
|
||
7 years ago
|
# This reads the network status XML file and loads the data into $anvil->data->{network}{{...}.
|
||
8 years ago
|
sub get_network_details
|
||
|
{
|
||
7 years ago
|
my ($anvil) = @_;
|
||
8 years ago
|
|
||
7 years ago
|
### TODO: Daemonize this or solve selinux issues
|
||
|
### Refresh the network.xml
|
||
7 years ago
|
#$anvil->System->call({shell_call => $anvil->data->{path}{exe}{'anvil-update-states'}});
|
||
7 years ago
|
|
||
|
# Now read the network.xml
|
||
7 years ago
|
my $file = $anvil->data->{path}{directories}{html}."/status/network.xml";
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { file => $file }});
|
||
7 years ago
|
|
||
|
# Parse...
|
||
|
my $xml = XML::Simple->new();
|
||
|
my $data = "";
|
||
|
my $network = "";
|
||
7 years ago
|
eval { $data = $xml->XMLin($file, KeyAttr => { interface => 'name', key => 'name', ip => 'address' }, ForceArray => [ 'interface', 'key' ] ) };
|
||
7 years ago
|
if ($@)
|
||
|
{
|
||
|
chomp $@;
|
||
|
my $error = "[ Error ] - The was a problem reading: [$file]. The error was:\n";
|
||
|
$error .= "===========================================================\n";
|
||
|
$error .= $@."\n";
|
||
|
$error .= "===========================================================\n";
|
||
7 years ago
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", raw => $error});
|
||
7 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
foreach my $interface (sort {$a cmp $b} keys %{$data->{interface}})
|
||
|
{
|
||
7 years ago
|
$anvil->data->{interfaces}{$interface} = {
|
||
7 years ago
|
bond => $data->{interface}{$interface}{bond},
|
||
|
bridge => $data->{interface}{$interface}{bridge},
|
||
|
duplex => $data->{interface}{$interface}{duplex},
|
||
|
'link' => $data->{interface}{$interface}{'link'},
|
||
|
mac => $data->{interface}{$interface}{mac},
|
||
|
media => $data->{interface}{$interface}{media},
|
||
|
mtu => $data->{interface}{$interface}{mtu},
|
||
|
order => $data->{interface}{$interface}{order},
|
||
|
speed => $data->{interface}{$interface}{speed},
|
||
|
'state' => $data->{interface}{$interface}{'state'},
|
||
7 years ago
|
};
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||
7 years ago
|
"interfaces::${interface}::bond" => $anvil->data->{interfaces}{$interface}{bond},
|
||
|
"interfaces::${interface}::bridge" => $anvil->data->{interfaces}{$interface}{bridge},
|
||
|
"interfaces::${interface}::duplex" => $anvil->data->{interfaces}{$interface}{duplex},
|
||
|
"interfaces::${interface}::link" => $anvil->data->{interfaces}{$interface}{'link'},
|
||
|
"interfaces::${interface}::mac" => $anvil->data->{interfaces}{$interface}{mac},
|
||
|
"interfaces::${interface}::media" => $anvil->data->{interfaces}{$interface}{media},
|
||
|
"interfaces::${interface}::mtu" => $anvil->data->{interfaces}{$interface}{mtu},
|
||
|
"interfaces::${interface}::order" => $anvil->data->{interfaces}{$interface}{order},
|
||
|
"interfaces::${interface}::speed" => $anvil->data->{interfaces}{$interface}{speed},
|
||
|
"interfaces::${interface}::state" => $anvil->data->{interfaces}{$interface}{'state'},
|
||
7 years ago
|
}});
|
||
|
}
|
||
7 years ago
|
### TODO: Sort out how to read the XML using the proper KeyAttr to avoid this mess...
|
||
|
# If there is only one IP, the details will be stored directly under the 'ip' key. If two or
|
||
|
# more exist, each ip address will be the key after 'ip'.
|
||
|
if (exists $data->{ip}{address})
|
||
7 years ago
|
{
|
||
7 years ago
|
# Only one entry. Fix the hash.
|
||
|
my $address = $data->{ip}{address};
|
||
|
my $on = $data->{ip}{on};
|
||
|
my $subnet = $data->{ip}{subnet};
|
||
|
my $gateway = $data->{ip}{gateway};
|
||
|
my $default_gateway = $data->{ip}{default_gateway};
|
||
|
my $dns = $data->{ip}{dns};
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||
|
address => $address,
|
||
|
on => $on,
|
||
|
subnet => $subnet,
|
||
|
gateway => $gateway,
|
||
|
default_gateway => $default_gateway,
|
||
|
dns => $dns,
|
||
|
}});
|
||
|
|
||
7 years ago
|
$anvil->data->{ip}{$address} = {
|
||
7 years ago
|
on => $on,
|
||
|
subnet => $subnet,
|
||
|
gateway => $gateway,
|
||
|
default_gateway => $default_gateway,
|
||
|
dns => $dns,
|
||
7 years ago
|
};
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||
|
"ip::${address}::on" => $anvil->data->{ip}{$address}{on},
|
||
|
"ip::${address}::subnet" => $anvil->data->{ip}{$address}{subnet},
|
||
|
"ip::${address}::gateway" => $anvil->data->{ip}{$address}{gateway},
|
||
|
"ip::${address}::default_gateway" => $anvil->data->{ip}{$address}{default_gateway},
|
||
|
"ip::${address}::dns" => $anvil->data->{ip}{$address}{dns},
|
||
|
}});
|
||
|
}
|
||
7 years ago
|
else
|
||
|
{
|
||
|
foreach my $address (sort {$a cmp $b} keys %{$data->{ip}})
|
||
|
{
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { address => $address }});
|
||
|
$anvil->data->{ip}{$address} = {
|
||
|
on => $data->{ip}{$address}{on},
|
||
|
subnet => $data->{ip}{$address}{subnet},
|
||
|
gateway => $data->{ip}{$address}{gateway},
|
||
|
default_gateway => $data->{ip}{$address}{default_gateway},
|
||
|
dns => $data->{ip}{$address}{dns},
|
||
|
};
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
|
||
|
"ip::${address}::on" => $anvil->data->{ip}{$address}{on},
|
||
|
"ip::${address}::subnet" => $anvil->data->{ip}{$address}{subnet},
|
||
|
"ip::${address}::gateway" => $anvil->data->{ip}{$address}{gateway},
|
||
|
"ip::${address}::default_gateway" => $anvil->data->{ip}{$address}{default_gateway},
|
||
|
"ip::${address}::dns" => $anvil->data->{ip}{$address}{dns},
|
||
|
}});
|
||
|
}
|
||
|
}
|
||
7 years ago
|
}
|
||
|
|
||
|
return(0);
|
||
|
}
|
||
|
|
||
|
sub get_network_details_form
|
||
|
{
|
||
7 years ago
|
my ($anvil) = @_;
|
||
7 years ago
|
|
||
7 years ago
|
my $file = $anvil->data->{path}{directories}{html}."/status/network.xml";
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { file => $file }});
|
||
8 years ago
|
my $xml = XML::Simple->new();
|
||
|
my $data = "";
|
||
|
my $network = "";
|
||
|
eval { $data = $xml->XMLin($file, KeyAttr => { interface => 'name', key => 'name' }, ForceArray => [ 'interface', 'key' ]) };
|
||
|
if ($@)
|
||
|
{
|
||
|
chomp $@;
|
||
|
my $error = "[ Error ] - The was a problem reading: [$file]. The error was:\n";
|
||
|
$error .= "===========================================================\n";
|
||
|
$error .= $@."\n";
|
||
|
$error .= "===========================================================\n";
|
||
7 years ago
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", raw => $error});
|
||
8 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
my $interface_list = "";
|
||
7 years ago
|
$network = $anvil->Template->get({file => "config.html", name => "network_header"});
|
||
8 years ago
|
foreach my $interface (sort {$a cmp $b} keys %{$data->{interface}})
|
||
|
{
|
||
|
$interface_list .= "$interface,";
|
||
7 years ago
|
$network .= $anvil->Template->get({file => "config.html", name => "network_entry", variables => {
|
||
7 years ago
|
mac => "",
|
||
|
mac_id => $interface."_mac",
|
||
|
name => $interface,
|
||
|
name_id => $interface."_name",
|
||
|
speed => "",
|
||
|
speed_id => $interface."_speed",
|
||
|
'link' => "",
|
||
|
link_id => $interface."_link",
|
||
|
order => "",
|
||
|
order_id => $interface."_order",
|
||
8 years ago
|
}});
|
||
|
}
|
||
|
$interface_list =~ s/,$//;
|
||
7 years ago
|
$network .= $anvil->Template->get({file => "config.html", name => "network_footer", variables => { interface_list => $interface_list }});
|
||
8 years ago
|
}
|
||
|
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { network => $network }});
|
||
8 years ago
|
return($network);
|
||
|
}
|
||
7 years ago
|
|
||
|
# This is a rudimentary function for generating default Striker IPs.
|
||
|
sub generate_ip
|
||
|
{
|
||
7 years ago
|
my ($anvil, $network, $network_sequence, $device_sequence) = @_;
|
||
7 years ago
|
my $debug = 2;
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
|
||
7 years ago
|
network => $network,
|
||
|
network_sequence => $network_sequence,
|
||
|
device_sequence => $device_sequence,
|
||
|
}});
|
||
|
|
||
|
# An empty string is returned if we can't make a sane guess at what should be set.
|
||
|
my $ip = "";
|
||
|
|
||
|
# The subnet's second octet will be '+X' where 'X' is the sequence.
|
||
7 years ago
|
my $default_ip = $anvil->data->{defaults}{network}{$network}{subnet};
|
||
|
my $default_netmark = $anvil->data->{defaults}{network}{$network}{netmask};
|
||
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
|
||
7 years ago
|
default_ip => $default_ip,
|
||
|
default_netmark => $default_netmark,
|
||
|
}});
|
||
|
|
||
7 years ago
|
if (($anvil->Validate->is_ipv4({ip => $default_ip})) && ($anvil->Validate->is_ipv4({ip => $default_netmark})))
|
||
7 years ago
|
{
|
||
|
# Valid values.
|
||
|
my ($ip_octet1, $ip_octet2, $ip_octet3, $ip_octet4) = (split/\./, $default_ip);
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
|
||
7 years ago
|
ip_octet1 => $ip_octet1,
|
||
|
ip_octet2 => $ip_octet2,
|
||
|
ip_octet3 => $ip_octet3,
|
||
|
ip_octet4 => $ip_octet4,
|
||
|
}});
|
||
|
|
||
|
if ($default_netmark eq "255.255.0.0")
|
||
|
{
|
||
|
# We can work with this.
|
||
|
$ip_octet2 += $network_sequence;
|
||
7 years ago
|
$ip_octet3 = $anvil->data->{defaults}{network}{$network}{striker_octet3};
|
||
7 years ago
|
$ip_octet4 = $device_sequence;
|
||
|
$ip = $ip_octet1.".".$ip_octet2.".".$ip_octet3.".".$ip_octet4;
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
|
||
7 years ago
|
"s1:ip_octet2" => $ip_octet2,
|
||
|
"s2:ip_octet3" => $ip_octet3,
|
||
|
"s3:ip_octet4" => $ip_octet4,
|
||
|
"s4:ip" => $ip,
|
||
|
}});
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
# Something wrong with our defaults.
|
||
|
$ip = "#!error!#";
|
||
|
}
|
||
|
|
||
7 years ago
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { ip => $ip }});
|
||
7 years ago
|
return($ip);
|
||
|
}
|