From 86259a4783f5848cf7424ad4aeaa6bfde5cb3ce2 Mon Sep 17 00:00:00 2001 From: Digimer Date: Sun, 10 Jun 2018 00:27:08 -0400 Subject: [PATCH] * Got the network.xml and network.json files fixed and parsable. * Moved config JS to config.js. Signed-off-by: Digimer --- cgi-bin/home | 22 +++++++++++++++-- html/skins/alteeve/config.html | 19 ++++++++++++++ html/skins/alteeve/config.js | 45 ++++++++++++++++++++++++++++++++++ html/skins/alteeve/main.html | 1 + html/skins/alteeve/main.js | 35 -------------------------- tools/anvil-update-states | 9 ++----- 6 files changed, 87 insertions(+), 44 deletions(-) create mode 100644 html/skins/alteeve/config.html create mode 100644 html/skins/alteeve/config.js diff --git a/cgi-bin/home b/cgi-bin/home index f3de81b2..4227e7fc 100755 --- a/cgi-bin/home +++ b/cgi-bin/home @@ -1387,7 +1387,7 @@ sub get_network_details my $xml = XML::Simple->new(); my $data = ""; my $network = ""; - eval { $data = $xml->XMLin($file, KeyAttr => { interface => 'name', key => 'name' }, ForceArray => [ 'interface', 'key' ]) }; + eval { $data = $xml->XMLin($file, KeyAttr => { interface => 'name', key => 'name', ip => 'address' }, ForceArray => [ 'interface', 'key' ]) }; if ($@) { chomp $@; @@ -1413,7 +1413,7 @@ sub get_network_details speed => $data->{interface}{$interface}{speed}, 'state' => $data->{interface}{$interface}{'state'}, }; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "interfaces::${interface}::bond" => $anvil->data->{interfaces}{$interface}{bond}, "interfaces::${interface}::bridge" => $anvil->data->{interfaces}{$interface}{bridge}, "interfaces::${interface}::duplex" => $anvil->data->{interfaces}{$interface}{duplex}, @@ -1426,6 +1426,24 @@ sub get_network_details "interfaces::${interface}::state" => $anvil->data->{interfaces}{$interface}{'state'}, }}); } + foreach my $address (sort {$a cmp $b} keys %{$data->{ip}}) + { + # 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}, + }}); + } } return(0); diff --git a/html/skins/alteeve/config.html b/html/skins/alteeve/config.html new file mode 100644 index 00000000..05ef7dcf --- /dev/null +++ b/html/skins/alteeve/config.html @@ -0,0 +1,19 @@ + + + + + + + + + + + + + #!string!brand_0001!# - #!string!brand_0003!# + + + + + + diff --git a/html/skins/alteeve/config.js b/html/skins/alteeve/config.js new file mode 100644 index 00000000..1976dcb6 --- /dev/null +++ b/html/skins/alteeve/config.js @@ -0,0 +1,45 @@ +$.ajaxSetup({ + cache: false +}); +$(function() { + var say_up = $('#network_link_state').data('up'); + var say_down = $('#network_link_state').data('down'); + var say_speed_suffix = $('#network_link_speed').data('mbps'); + //console.log('say_up: ['+say_up+'], say_down: ['+say_down+'], say_speed_suffix: ['+say_speed_suffix+']'); + if($("#network_status").length) { + //console.log('network.json status file exists.'); + setInterval(function() { + $.getJSON('/status/network.json', { get_param: 'value' }, function(data) { + $.each(data.networks, function(index, element) { + + //console.log('entry: ['+index+'], name: ['+element.name+'], mac: ['+element.mac+'], link: ['+element.link+'], up order: ['+element.order+']'); + + var link = say_up; + if (element.link == 0) { + link = say_down; + } + $("#"+element.name+"_mac").text(element.mac); + $("#"+element.name+"_link").text(link); + $("#"+element.name+"_speed").text(element.speed+' '+say_speed_suffix); + $("#"+element.name+"_order").text(element.order); + }); + }); + }, 1000); + } + else + { + //alert('network status strings not loaded.'); + } + if($("#disk_status").length) { + //alert('disk status exists.'); + //$("#bar").text('B'); + } +}); + +$( window ).on( "load", function() +{ + // NOTE: Disabled for now. Clears the URL to remove everything off after '?'. +// var newURL = location.href.split("?")[0]; +// window.history.pushState('object', document.title, newURL); + console.log('onload fired.'); +}) diff --git a/html/skins/alteeve/main.html b/html/skins/alteeve/main.html index a9a32f2f..729e9b7a 100644 --- a/html/skins/alteeve/main.html +++ b/html/skins/alteeve/main.html @@ -602,6 +602,7 @@ +
#!string!header_0001!# diff --git a/html/skins/alteeve/main.js b/html/skins/alteeve/main.js index 9b0f1122..37c4de10 100644 --- a/html/skins/alteeve/main.js +++ b/html/skins/alteeve/main.js @@ -2,43 +2,8 @@ $.ajaxSetup({ cache: false }); $(function() { - var say_up = $('#network_link_state').data('up'); - var say_down = $('#network_link_state').data('down'); - var say_speed_suffix = $('#network_link_speed').data('mbps'); - //console.log('say_up: ['+say_up+'], say_down: ['+say_down+'], say_speed_suffix: ['+say_speed_suffix+']'); - if($("#network_status").length) { - //alert('network status exists.'); - setInterval(function() { - $.getJSON('/status/network.json', { get_param: 'value' }, function(data) { - $.each(data.networks, function(index, element) { - - console.log('entry: ['+index+'], name: ['+element.name+'], mac: ['+element.mac+'], link: ['+element.link+'], up order: ['+element.order+']'); - - var link = say_up; - if (element.link == 0) { - link = say_down; - } - $("#"+element.name+"_mac").text(element.mac); - $("#"+element.name+"_link").text(link); - $("#"+element.name+"_speed").text(element.speed+' '+say_speed_suffix); - $("#"+element.name+"_order").text(element.order); - }); - }); - }, 1000); - } - else - { - //alert('network status strings not loaded.'); - } - if($("#disk_status").length) { - //alert('disk status exists.'); - //$("#bar").text('B'); - } }); $( window ).on( "load", function() { - // NOTE: Disabled for now. Clears the URL to remove everything off after '?'. - //var newURL = location.href.split("?")[0]; - //window.history.pushState('object', document.title, newURL); }) diff --git a/tools/anvil-update-states b/tools/anvil-update-states index 58b6d688..db4432f3 100755 --- a/tools/anvil-update-states +++ b/tools/anvil-update-states @@ -575,13 +575,8 @@ ORDER BY } $network_json =~ s/,$//s; - $network_json .= "]\n"; + $network_json .= "],\n"; $network_json .= "\"ips\":[\n"; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_json => $network_json }}); - - $network_xml .= "\n"; - $network_xml .= "\n"; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_xml => $network_xml }}); # Now record the IPs. $query = " @@ -651,7 +646,7 @@ WHERE $network_json .= "]}\n"; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_json => $network_json }}); - $network_xml .= "\n"; + $network_xml .= "\n"; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_xml => $network_xml }}); # Write the JSON file.