* Started reworking the jquery to read through the network.json file and parse the form, instead of looping through the form and reading the json file repeatedly.

* Made System->get_ips() smarter; it pulls DNS data from the route interface only.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent 0272ba8b80
commit 97441831e6
  1. 2
      Anvil/Tools.pm
  2. 19
      Anvil/Tools/System.pm
  3. 95
      html/skins/alteeve/config.js

@ -749,7 +749,7 @@ sub _set_defaults
switch_octet3 => "3", switch_octet3 => "3",
striker_octet3 => "4", striker_octet3 => "4",
}, },
dns => "8.8.8.8, 8.8.4.4", dns => "8.8.8.8, 4.4.4.4",
# IFN starts at 10.(80+)/16 # IFN starts at 10.(80+)/16
ifn => { ifn => {
subnet => "10.100.0.0", subnet => "10.100.0.0",

@ -630,12 +630,27 @@ sub get_ips
# If I got a route, get the DNS. # If I got a route, get the DNS.
if ($route_interface) if ($route_interface)
{ {
# I want to build the DNS list from only the interface that is used for routing.
my $in_interface = "";
my $dns_list = ""; my $dns_list = "";
my $dns_hash = {}; my $dns_hash = {};
my $ip_route = $anvil->System->call({debug => $debug, shell_call => $anvil->data->{path}{exe}{nmcli}." dev show"}); my $ip_route = $anvil->System->call({debug => $debug, shell_call => $anvil->data->{path}{exe}{nmcli}." dev show"});
foreach my $line (split/\n/, $ip_route) foreach my $line (split/\n/, $ip_route)
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }});
if ($line =~ /GENERAL.DEVICE:\s+(.*)$/)
{
$in_interface = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { in_interface => $in_interface }});
}
if (not $line)
{
$in_interface = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { in_interface => $in_interface }});
}
next if $in_interface ne $route_interface;
if ($line =~ /IP4.DNS\[(\d+)\]:\s+(.*)/i) if ($line =~ /IP4.DNS\[(\d+)\]:\s+(.*)/i)
{ {
my $order = $1; my $order = $1;
@ -648,13 +663,13 @@ sub get_ips
foreach my $order (sort {$a cmp $b} keys %{$dns_hash}) foreach my $order (sort {$a cmp $b} keys %{$dns_hash})
{ {
$dns_list .= $dns_hash->{$order}.","; $dns_list .= $dns_hash->{$order}.", ";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"s1:dns_hash->{$order}" => $dns_hash->{$order}, "s1:dns_hash->{$order}" => $dns_hash->{$order},
"s2:dns_list" => $dns_list, "s2:dns_list" => $dns_list,
}}); }});
} }
$dns_list =~ s/,$//; $dns_list =~ s/, $//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { dns_list => $dns_list }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { dns_list => $dns_list }});
$anvil->data->{sys}{network}{interface}{$route_interface}{default_gateway} = 1; $anvil->data->{sys}{network}{interface}{$route_interface}{default_gateway} = 1;

@ -42,7 +42,7 @@ $( window ).on( "load", function()
// Clears the URL to remove everything off after '?'. // Clears the URL to remove everything off after '?'.
//var newURL = location.href.split("?")[0]; //var newURL = location.href.split("?")[0];
//window.history.pushState('object', document.title, newURL); //window.history.pushState('object', document.title, newURL);
console.log('onload fired.'); //console.log('onload fired.');
/* /*
if($("#interface_list").val()) { if($("#interface_list").val()) {
@ -54,42 +54,75 @@ $( window ).on( "load", function()
} }
*/ */
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) { $.getJSON('/status/network.json', { get_param: 'value' }, function(data) {
$.each(data.ips, function(index, element) { $.each(data.ips, function(index, element) {
var on_interface = element.on; console.log('- entry: ['+index+'], on: ['+element.on+'], address: ['+element.address+'], subnet: ['+element.subnet+'].');
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+'].'); console.log('- gateway: ['+element.gateway+'], dns: ['+element.dns+'], default gateway: ['+element.default_gateway+'].');
// If this is the default gateway, see about setting the Gateway IP and DNS.
if (element.default_gateway == '1') { if (element.default_gateway == '1') {
if ($("#gateway").val() == '') { console.log('This is the default gateway interface.');
console.log('- Form value for gateway......: ['+$("#gateway").val()+'] and dns: ['+$("#dns").val()+'].');
console.log('- Default values for gateway..: ['+$("#gateway_default").val()+'] and dns: ['+$("#dns_default").val()+'].');
console.log('- Interface values for gateway: ['+element.gateway+'] and dns: ['+element.dns+'].');
if (($("#gateway").val() == '') && (element.gateway)) {
$("#gateway").val(element.gateway); $("#gateway").val(element.gateway);
}; }
if ($("#dns").val() == '') { if (($("#dns").val() == '') && (element.dns)) {
$("#dns").var(element.dns); $("#dns").val(element.dns);
}; }
}; }
};
});
}); });
var default_ip = $("#"+network_name+"_ip_default").val();
console.log(network+' IP not set. Setting to: ['+default_ip+']'); // If DNS or gateway are blank still and we have default values, set them.
$("#"+network_name+"_ip").val(default_ip); console.log('Form value for gateway......: ['+$("#gateway").val()+'] and dns: ['+$("#dns").val()+'].');
}; console.log('Interface values for gateway: ['+$("#gateway_default").val()+'] and dns: ['+$("#dns_default").val()+'].');
}; if (($("#gateway").val() == '') && ($("#gateway_default").val())) {
}; $("#gateway").val($("#gateway_default").val());
}
if (($("#dns").val() == '') && ($("#dns_default").val())) {
$("#dns").val($("#dns_default").val());
}
}); });
//jQuery.each("bcn sn ifn".split(" "), function(index, network) {
// jQuery.each("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;
// var ip_set = $("#"+network_name+"_ip").val();
// console.log('i: ['+i+'], Network: ['+network_name+'], IP set: ['+ip_set+'], default: ['+$("#"+network_name+"_ip_default").val()+'].');
// if (ip_set == '') {
// console.log('Reading /status/network.json');
// $.ajax({dataType:"json",url:"/status/network.json",data:{get_param:"value"},async:false}), function(data) {
// console.log('Read for: ['+network_name+'].');
// $.each(data.ips, function(index, element) {
// var on_interface = element.on;
// console.log('on_interface: ['+on_interface+'], network_name: ['+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(on_interface.match(new RegExp(network_name))) {
// 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);
// };
// };
// };
// });
}) })

Loading…
Cancel
Save