@ -38,7 +38,7 @@ $anvil->data->{form}{back_link} = "";
$anvil->data->{form}{refresh_link} = "";
$anvil->data->{form}{refresh_link} = "";
# Read in any CGI variables, if needed.
# Read in any CGI variables, if needed.
$anvil->Get->cgi({debug => 2} );
$anvil->Get->cgi();
# If we're being asked to get a file, do so now.
# If we're being asked to get a file, do so now.
if ($anvil->data->{cgi}{upload_file}{file_handle})
if ($anvil->data->{cgi}{upload_file}{file_handle})
@ -850,7 +850,7 @@ sub process_sync_page
name => $name,
name => $name,
user => $user,
user => $user,
ping => $ping,
ping => $ping,
password => $anvil->Log->secure ? $password : $anvil->Words->string({key => "log_0186"} ),
password => $anvil->Log->is_secure($password ),
}});
}});
# Store it by name.
# Store it by name.
@ -865,7 +865,7 @@ sub process_sync_page
"peers::${host}::name" => $anvil->data->{peers}{$host}{name},
"peers::${host}::name" => $anvil->data->{peers}{$host}{name},
"peers::${host}::ping" => $anvil->data->{peers}{$host}{ping},
"peers::${host}::ping" => $anvil->data->{peers}{$host}{ping},
"peers::${host}::uuid" => $anvil->data->{peers}{$host}{uuid},
"peers::${host}::uuid" => $anvil->data->{peers}{$host}{uuid},
"peers::${host}::password" => $anvil->Log->secure ? $anvil->data->{peers}{$host}{password} : $anvil->Words->string({key => "log_0186" }),
"peers::${host}::password" => $anvil->Log->is_secure($anvil->data->{peers}{$host}{password }),
}});
}});
}
}
@ -885,7 +885,7 @@ sub process_sync_page
user => $user,
user => $user,
ping => $ping,
ping => $ping,
uuid => $uuid,
uuid => $uuid,
password => $anvil->Log->secure ? $password : $anvil->Words->string({key => "log_0186"} ),
password => $anvil->Log->is_secure($password ),
}});
}});
$anvil->data->{cgi}{new_peer_password}{value} = "" if not defined $anvil->data->{cgi}{new_peer_password}{value};
$anvil->data->{cgi}{new_peer_password}{value} = "" if not defined $anvil->data->{cgi}{new_peer_password}{value};
@ -979,17 +979,25 @@ sub add_sync_peer
my $password = $anvil->data->{cgi}{new_peer_password}{value};
my $password = $anvil->data->{cgi}{new_peer_password}{value};
my $name = $anvil->data->{sys}{database}{name};
my $name = $anvil->data->{sys}{database}{name};
my $ping = $anvil->data->{cgi}{new_peer_ping}{value} eq "on" ? 1 : 0;
my $ping = $anvil->data->{cgi}{new_peer_ping}{value} eq "on" ? 1 : 0;
my $port = 5432;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
my $ssh_tcp = 22;
user => $user,
host => $host,
password => $anvil->Log->is_secure($password),
name => $name,
ping => $ping,
}});
my $pgsql_port = 5432;
my $ssh_port = 22;
my $peer_uuid = "";
my $peer_uuid = "";
my $peer_host = "";
my $peer_host = "";
my $use_ip = ""; # This will contain the local IP to use for the peer to setup comms with us
my $use_ip = ""; # This will contain the local IP to use for the peer to setup comms with us
if ($host =~ /,ssh=(\d+)$/)
if ($host =~ /,ssh=(\d+)$/)
{
{
$ssh_tcp = $1;
$ssh_por t = $1;
$host =~ s/,ssh=\d+$//;
$host =~ s/,ssh=\d+$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
ssh_tcp => $ssh_tcp ,
ssh_por t => $ssh_por t,
host => $host,
host => $host,
}});
}});
}
}
@ -997,10 +1005,10 @@ sub add_sync_peer
{
{
$user = $1;
$user = $1;
$host = $2;
$host = $2;
$port = $3;
$pgsql_p ort = $3;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
host => $host,
host => $host,
port => $port,
pgsql_p ort => $pgsql_ port,
user => $user,
user => $user,
}});
}});
}
}
@ -1016,12 +1024,18 @@ sub add_sync_peer
elsif ($host =~ /^(.*?):(\d+)$/)
elsif ($host =~ /^(.*?):(\d+)$/)
{
{
$host = $1;
$host = $1;
$port = $2;
$pgsql_p ort = $2;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
host => $host,
host => $host,
port => $port,
pgsql_p ort => $pgsql_ port,
}});
}});
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
ssh_port => $ssh_port,
host => $host,
pgsql_port => $pgsql_port,
user => $user,
}});
# Is the host a domain or IP?
# Is the host a domain or IP?
# If so, and 'bi-directional' is set, verify we can ssh into the peer.
# If so, and 'bi-directional' is set, verify we can ssh into the peer.
@ -1030,23 +1044,25 @@ sub add_sync_peer
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
is_domain => $is_domain,
is_domain => $is_domain,
is_ipv4 => $is_ipv4,
is_ipv4 => $is_ipv4,
port => $port,
pgsql_p ort => $pgsql_ port,
}});
}});
if (((not $is_domain) && (not $is_ipv4)) or ($port < 1) or ($port > 65536))
if (((not $is_domain) && (not $is_ipv4)) or ($pgsql_p ort < 1) or ($pgsql_ port > 65536))
{
{
# Bad host.
# 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"}) }});
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "striker_warning_0002"}) }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"form::error_massage" => $anvil->data->{form}{error_massage},
}});
}
}
else
else
{
{
# Can we connect to the peer?
# Can we connect to the peer?
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 ($output, $error, $return_code) = $anvil->Remote->call({
my ($output, $error, $return_code) = $anvil->Remote->call({
debug => 2,
shell_call => $anvil->data->{path}{exe}{dmidecode}." --string system-uuid",
password => $password,
password => $password,
target => $ssh_tcp != 22 ? $host.":".$ssh_tcp : $host,
target => $host,
shell_call => $shell_call,
port => $ssh_port,
});
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
output => $output,
@ -1071,8 +1087,10 @@ sub add_sync_peer
else
else
{
{
my ($error, $output, $return_code) = $anvil->Remote->call({
my ($error, $output, $return_code) = $anvil->Remote->call({
debug => 2,
password => $password,
password => $password,
target => $ssh_tcp != 22 ? $host.":".$ssh_tcp : $host,
target => $host,
port => $ssh_port,
shell_call => $anvil->data->{path}{exe}{hostnamectl}." --static",
shell_call => $anvil->data->{path}{exe}{hostnamectl}." --static",
return_code => $return_code,
return_code => $return_code,
});
});
@ -1096,6 +1114,9 @@ sub add_sync_peer
{
{
# Can't do bi-directional
# Can't do bi-directional
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "striker_warning_0008", variables => { host => $host }}) }});
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "striker_warning_0008", variables => { host => $host }}) }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"form::error_massage" => $anvil->data->{form}{error_massage},
}});
}
}
}
}
}
}
@ -1108,7 +1129,10 @@ sub add_sync_peer
{
{
my $pgpass_file = "/tmp/.pgpass";
my $pgpass_file = "/tmp/.pgpass";
$password =~ s/:/\:/g;
$password =~ s/:/\:/g;
my $body = $host.":".$port.":".$name.":".$user.":".$password;
my $body = $host.":".$pgsql_port.":".$name.":".$user.":".$password;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 1, list => {
body => $body,
}});
$anvil->Storage->write_file({
$anvil->Storage->write_file({
file => $pgpass_file,
file => $pgpass_file,
body => $body,
body => $body,
@ -1118,7 +1142,7 @@ sub add_sync_peer
});
});
# This will return '1' only, if it works.
# This will return '1' only, if it works.
my ($db_access, $return_code) = $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\""});
my ($db_access, $return_code) = $anvil->System->call({shell_call => "PGPASSFILE=\"".$pgpass_file."\" ".$anvil->data->{path}{exe}{psql}." --host ".$host." --port ".$pgsql_p ort." --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, return_code => $return_code }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { db_access => $db_access, return_code => $return_code }});
if ($db_access ne "1")
if ($db_access ne "1")
{
{
@ -1147,10 +1171,10 @@ sub add_sync_peer
if ($anvil->data->{cgi}{confirm}{value})
if ($anvil->data->{cgi}{confirm}{value})
{
{
# OK, save the job!
# OK, save the job!
my $job_command = $anvil->data->{path}{exe}{'striker-manage-peers'}." --add --host-uuid ".$peer_uuid." --host ".$host." --port ".$port." --ping ".$ping;
my $job_command = $anvil->data->{path}{exe}{'striker-manage-peers'}." --add --host-uuid ".$peer_uuid." --host ".$host." --port ".$pgsql_p ort." --ping ".$ping;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
job_command => $job_command,
job_command => $job_command,
password => $anvil->Log->secure ? $password : $anvil->Words->string({key => "log_0186"} ),
password => $anvil->Log->is_secure($password ),
}});
}});
# The job data will always contain the password for the peer, but also contain the
# The job data will always contain the password for the peer, but also contain the
@ -1169,8 +1193,10 @@ sub add_sync_peer
my $sql_port = $anvil->data->{database}{$host_uuid}{port};
my $sql_port = $anvil->data->{database}{$host_uuid}{port};
my $job_command = $anvil->data->{path}{exe}{'striker-manage-peers'}." --add --host-uuid ".$host_uuid." --host ".$use_ip." --port ".$sql_port." --ping ".$ping;
my $job_command = $anvil->data->{path}{exe}{'striker-manage-peers'}." --add --host-uuid ".$host_uuid." --host ".$use_ip." --port ".$sql_port." --ping ".$ping;
$job_data .= "\npeer_job_command=".$job_command;
$job_data .= "\npeer_job_command=".$job_command;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, list => { job_command => $job_command }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 1, list => { job_data => $job_data }});
job_command => $job_command,
job_data => $anvil->Log->is_secure($job_data),
}});
}
}
# Store the job
# Store the job
@ -1202,10 +1228,11 @@ sub add_sync_peer
{
{
# Show the screen the confirm the addition.
# Show the screen the confirm the addition.
$anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "confirm-new-peer", variables => {
$anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "confirm-new-peer", variables => {
access => $user."@".$host.":".$port,
access => $user."@".$host.":".$pgsql_p ort,
ping => $anvil->data->{cgi}{new_peer_ping}{value} ? "#!string!unit_0001!#" : "#!string!unit_0002!#",
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!#",
bidirectional => $anvil->data->{cgi}{new_peer_bidirection}{value} ? "#!string!unit_0001!#" : "#!string!unit_0002!#",
}});
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "form::body" => $anvil->data->{form}{body} }});
}
}
}
}
@ -1516,7 +1543,6 @@ ORDER BY
striker_user => $anvil->data->{cgi}{striker_user}{value},
striker_user => $anvil->data->{cgi}{striker_user}{value},
striker_password => $anvil->data->{cgi}{striker_password}{value},
striker_password => $anvil->data->{cgi}{striker_password}{value},
networks => $networks,
networks => $networks,
cgi_list => $cgi."step",
show_name => 1,
show_name => 1,
}});
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { step3_body => $step3_body }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { step3_body => $step3_body }});
@ -1893,7 +1919,6 @@ ORDER BY
gateway_form => $say_gateway,
gateway_form => $say_gateway,
dns_form => $say_dns,
dns_form => $say_dns,
hostname_form => $say_hostname,
hostname_form => $say_hostname,
cgi_list => $cgi."organization,prefix,domain,sequence,bcn_count,ifn_count,gateway,hostname,dns,striker_user,striker_password",
}});
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { step2_body => $step2_body }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { step2_body => $step2_body }});
@ -2620,7 +2645,6 @@ sub config_step1
domain_form => $say_domain,
domain_form => $say_domain,
sequence_form => $say_sequence,
sequence_form => $say_sequence,
ifn_count_form => $say_ifn_count,
ifn_count_form => $say_ifn_count,
cgi_list => "organization,prefix,domain,sequence,ifn_count",
}});
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { step1_body => $step1_body }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { step1_body => $step1_body }});