* Moved the network default values into the main defaults hash.

* Fixed a bug in Database->insert_or_update_network_interfaces where independent interfaces (not under a bridge or a bond) were not being saved.
* Continued working on improving Striker's network config jquery/form functions.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent 38f81fd8eb
commit 0272ba8b80
  1. 30
      Anvil/Tools.pm
  2. 4
      Anvil/Tools/Database.pm
  3. 2
      anvil.conf
  4. 181
      cgi-bin/home
  5. 48
      html/skins/alteeve/config.js
  6. 1
      html/skins/alteeve/main.html
  7. 7
      tools/anvil-update-states

@ -723,9 +723,6 @@ sub _set_defaults
host_uuid => "",
language => "en_CA",
log_file => "/var/log/anvil.log",
network => {
},
password => {
algorithm => "sha512",
hash_count => 500000,
@ -736,8 +733,35 @@ sub _set_defaults
stty => "",
},
use_base2 => 1,
user => "admin",
};
$anvil->data->{defaults} = {
## Network stuff... The second octet auto-increments to handle N-number of netowrks. As such,
## we need to use a wider spread between the BCNs, SNs and IFNs than we had
## in v2.
network => {
# BCN starts at 10.(0+n)/16
bcn => {
subnet => "10.0.0.0",
netmask => "255.255.0.0",
pdu_octet3 => "1",
ups_octet3 => "2",
switch_octet3 => "3",
striker_octet3 => "4",
},
dns => "8.8.8.8, 8.8.4.4",
# IFN starts at 10.(80+)/16
ifn => {
subnet => "10.100.0.0",
netmask => "255.255.0.0",
striker_octet3 => "4",
},
# SN starts at 10.(40+n)/16
sn => {
subnet => "10.50.0.0",
netmask => "255.255.0.0",
},
},
database => {
locking => {
reap_age => 300,

@ -2858,8 +2858,8 @@ sub insert_or_update_network_interfaces
my $uuid = defined $parameter->{uuid} ? $parameter->{uuid} : "";
my $file = defined $parameter->{file} ? $parameter->{file} : "";
my $line = defined $parameter->{line} ? $parameter->{line} : "";
my $network_interface_bond_uuid = defined $parameter->{network_interface_bond_uuid} ? $parameter->{network_interface_bond_uuid} : 'NULL';
my $network_interface_bridge_uuid = defined $parameter->{network_interface_bridge_uuid} ? $parameter->{network_interface_bridge_uuid} : 'NULL';
my $network_interface_bond_uuid = $parameter->{network_interface_bond_uuid} ? $parameter->{network_interface_bond_uuid} : 'NULL';
my $network_interface_bridge_uuid = $parameter->{network_interface_bridge_uuid} ? $parameter->{network_interface_bridge_uuid} : 'NULL';
my $network_interface_duplex = defined $parameter->{network_interface_duplex} ? $parameter->{network_interface_duplex} : "unknown";
my $network_interface_host_uuid = defined $parameter->{network_interface_host_uuid} ? $parameter->{network_interface_host_uuid} : $anvil->Get->host_uuid;
my $network_interface_link_state = defined $parameter->{network_interface_link_state} ? $parameter->{network_interface_link_state} : "unknown";

@ -80,8 +80,6 @@ sys::database::schema = /usr/sbin/anvil/anvil.sql
#sys::database::maximum_batch_size = 25000
### Apache stuff
#sys::apache::user = admin
# By default, we try to determine the host type using the host name. The rules used for this can be seen in
# 'perldoc Anvil::Tools::System -> determine_host_type'. If you are using non-standard host names, or for some
# other reason want to statically assign the host type, you can do so with this variable. Note that this sets

@ -60,21 +60,6 @@ $| = 1;
### Setup some variables.
$anvil->data->{form}{error_massage} = "&nbsp;";
## Network stuff... The second octet auto-increments to handle N-number of netowrks. As such, we need to use
## a wider spread between the BCNs, SNs and IFNs than we had in v2.
# BCN starts at 10.(0+n)/16
$anvil->data->{'default'}{bcn}{subnet} = "10.0.0.0";
$anvil->data->{'default'}{bcn}{netmask} = "255.255.0.0";
$anvil->data->{'default'}{bcn}{pdu_octet3} = "1";
$anvil->data->{'default'}{bcn}{ups_octet3} = "2";
$anvil->data->{'default'}{bcn}{switch_octet3} = "3";
$anvil->data->{'default'}{bcn}{striker_octet3} = "4";
# SN starts at 10.(40+n)/16
$anvil->data->{'default'}{sn}{subnet} = "10.40.0.0";
$anvil->data->{'default'}{sn}{netmask} = "255.255.0.0";
# IFN starts at 10.(80+)/16
$anvil->data->{'default'}{ifn}{subnet} = "10.80.0.0";
$anvil->data->{'default'}{ifn}{netmask} = "255.255.0.0";
# Read in any CGI variables, if needed.
$anvil->Get->cgi();
@ -497,7 +482,7 @@ ORDER BY
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->{'default'}{bcn}{netmask},
subnet_value => defined $anvil->data->{cgi}{$this_subnet_key}{value} ? $anvil->data->{cgi}{$this_subnet_key}{value} : $anvil->data->{'default'}{network}{bcn}{netmask},
subnet_class => $this_subnet_class,
iface1_select => $this_iface1_form,
iface2_select => $this_iface2_form,
@ -545,7 +530,7 @@ ORDER BY
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->{'default'}{ifn}{netmask},
subnet_value => defined $anvil->data->{cgi}{$this_subnet_key}{value} ? $anvil->data->{cgi}{$this_subnet_key}{value} : $anvil->data->{'default'}{network}{ifn}{netmask},
subnet_class => $this_subnet_class,
iface1_select => $this_iface1_form,
iface2_select => $this_iface2_form,
@ -587,7 +572,7 @@ ORDER BY
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->{'default'}{bcn}{netmask},
subnet_value => defined $anvil->data->{cgi}{$this_subnet_key}{value} ? $anvil->data->{cgi}{$this_subnet_key}{value} : $anvil->data->{'default'}{network}{bcn}{netmask},
subnet_class => $this_subnet_class,
iface1_select => $this_iface1_form,
}});
@ -625,7 +610,7 @@ ORDER BY
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->{'default'}{ifn}{netmask},
subnet_value => defined $anvil->data->{cgi}{$this_subnet_key}{value} ? $anvil->data->{cgi}{$this_subnet_key}{value} : $anvil->data->{'default'}{network}{ifn}{netmask},
subnet_class => $this_subnet_class,
iface1_select => $this_iface1_form,
}});
@ -634,28 +619,29 @@ ORDER BY
### TODO: Add a form for Gateway, DNS and which interface to use
# Gateway
my $say_default_gateway = "";
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} : $say_default_gateway,
class => $gateway_class,
extra => "",
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 => "",
}});
# DNS
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} : "8.8.8.8, 8.8.4.4",
class => $dns_class,
extra => "",
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 => "",
}});
# Which interface gets the route?
@ -678,43 +664,42 @@ ORDER BY
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 => {
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,
class => $hostname_class,
extra => "",
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 => "",
}});
# Admin user
my $say_default_striker_user = "striker";
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!#",
value => defined $anvil->data->{cgi}{striker_user}{value} ? $anvil->data->{cgi}{striker_user}{value} : $say_default_striker_user,
class => $striker_user_class,
extra => "",
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!#",
value => defined $anvil->data->{cgi}{striker_user}{value} ? $anvil->data->{cgi}{striker_user}{value} : $anvil->data->{sys}{user},
default_value => "",
class => $striker_user_class,
extra => "",
}});
# Password
my $say_default_striker_password = "";
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} : $say_default_striker_password,
class => $striker_password_class,
extra => "",
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 => "",
}});
# Get the table that shows the current interface states.
my $interface_states = get_network_details_form($anvil);
@ -1305,35 +1290,38 @@ sub config_step1
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 => {
name => "organization",
id => "organization",
field => "#!string!striker_0003!#",
description => "#!string!striker_0004!#",
value => defined $anvil->data->{cgi}{organization}{value} ? $anvil->data->{cgi}{organization}{value} : "",
class => $organization_class,
extra => "",
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 => "",
}});
$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 => {
name => "prefix",
id => "prefix",
field => "#!string!striker_0005!#",
description => "#!string!striker_0006!#",
value => defined $anvil->data->{cgi}{prefix}{value} ? $anvil->data->{cgi}{prefix}{value} : "",
class => $prefix_class,
extra => "maxlength=\"5\"",
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\"",
}});
$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 => {
name => "domain",
id => "domain",
field => "#!string!striker_0007!#",
description => "#!string!striker_0008!#",
value => defined $anvil->data->{cgi}{domain}{value} ? $anvil->data->{cgi}{domain}{value} : "",
class => $domain_class,
extra => "maxlength=\"255\"",
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\"",
}});
$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";
@ -1504,7 +1492,8 @@ sub get_network_details_form
sub generate_ip
{
my ($anvil, $network, $network_sequence, $device_sequence) = @_;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
my $debug = 2;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
network => $network,
network_sequence => $network_sequence,
device_sequence => $device_sequence,
@ -1514,9 +1503,9 @@ sub generate_ip
my $ip = "";
# The subnet's second octet will be '+X' where 'X' is the sequence.
my $default_ip = $anvil->data->{'default'}{$network}{subnet};
my $default_netmark = $anvil->data->{'default'}{$network}{netmask};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
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 => {
default_ip => $default_ip,
default_netmark => $default_netmark,
}});
@ -1525,7 +1514,7 @@ sub generate_ip
{
# Valid values.
my ($ip_octet1, $ip_octet2, $ip_octet3, $ip_octet4) = (split/\./, $default_ip);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
ip_octet1 => $ip_octet1,
ip_octet2 => $ip_octet2,
ip_octet3 => $ip_octet3,
@ -1536,10 +1525,10 @@ sub generate_ip
{
# We can work with this.
$ip_octet2 += $network_sequence;
$ip_octet3 = $anvil->data->{'default'}{$network}{striker_octet3};
$ip_octet3 = $anvil->data->{defaults}{network}{$network}{striker_octet3};
$ip_octet4 = $device_sequence;
$ip = $ip_octet1.".".$ip_octet2.".".$ip_octet3.".".$ip_octet4;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"s1:ip_octet2" => $ip_octet2,
"s2:ip_octet3" => $ip_octet3,
"s3:ip_octet4" => $ip_octet4,
@ -1553,6 +1542,6 @@ sub generate_ip
$ip = "#!error!#";
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { ip => $ip }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { ip => $ip }});
return($ip);
}

@ -54,16 +54,42 @@ $( window ).on( "load", function()
}
*/
if($("#bcn_count").val()) {
var bcn_count = $("#bcn_count").val();
console.log('BCN Count: ['+bcn_count+'].');
for (var i = 1; i <= bcn_count; i++) {
console.log('BCN IP set: ['+$("#bcn"+i+"_ip").val()+'], default: ['+$("#bcn"+i+"_ip_default").val()+'].');
if ($("#bcn"+i+"_ip").val() == '') {
var default_ip = $("#bcn"+i+"_ip_default").val();
console.log('BCN IP not set. Setting to: ['+default_ip+']');
$("#bcn"+i+"_ip").val(default_ip)
}
jQuery.each("bcn sn ifn".split(" "), function(index, network) {
console.log('Network: ['+network+'].');
if($("#"+network+"_count").val()) {
var count = $("#"+network+"_count").val();
console.log(network+' count: ['+count+'].');
for (var i = 1; i <= count; i++) {
var network_name = network+i;
console.log('Network: ['+network_name+'], BCN IP set: ['+$("#"+network_name+"_ip").val()+'], default: ['+$("#"+network_name+"_ip_default").val()+'].');
if ($("#"+network_name+"_ip").val() == '') {
var set_ip = '';
var set_subnet = '';
var set_gateway = '';
var set_dns = '';
$.getJSON('/status/network.json', { get_param: 'value' }, function(data) {
$.each(data.ips, function(index, element) {
var on_interface = element.on;
if(on_interface.match(new RegExp(network_name))) {
console.log('entry: ['+index+'], on: ['+element.on+'], address: ['+element.address+'], subnet: ['+element.subnet+'].');
console.log('- gateway: ['+element.gateway+'], dns: ['+element.dns+'], default gateway: ['+element.default_gateway+'].');
if (element.default_gateway == '1') {
if ($("#gateway").val() == '') {
$("#gateway").val(element.gateway);
};
if ($("#dns").val() == '') {
$("#dns").var(element.dns);
};
};
};
});
});
var default_ip = $("#"+network_name+"_ip_default").val();
console.log(network+' IP not set. Setting to: ['+default_ip+']');
$("#"+network_name+"_ip").val(default_ip);
};
};
};
}
});
})

@ -495,6 +495,7 @@
<!-- start input_text_form -->
#!variable!description!#<br />
<input type="text" name="#!variable!name!#" id="#!variable!id!#" value="#!variable!value!#" placeholder="#!variable!field!#" class="#!variable!class!#" #!variable!extra!#>
<input type="hidden" name="#!variable!name!#_default" id="#!variable!id!#_default" value="#!variable!default_value!#" >
<!-- end input_text_form -->
<!-- start input_number_form -->

@ -360,11 +360,14 @@ sub report_network
if (($type eq $processing) && ($type eq "interface"))
{
my $say_bond_uuid = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "bond_by_name::${bond_master}" => $anvil->data->{bond_by_name}{$bond_master} }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bond_master => $bond_master }});
if (($bond_master) && ($anvil->data->{bond_by_name}{$bond_master}))
{
$say_bond_uuid = $anvil->data->{bond_by_name}{$bond_master};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_bond_uuid => $say_bond_uuid }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"bond_by_name::${bond_master}" => $anvil->data->{bond_by_name}{$bond_master},
say_bond_uuid => $say_bond_uuid,
}});
}
my $network_interface_uuid = $anvil->Database->insert_or_update_network_interfaces({
debug => 2,

Loading…
Cancel
Save