* Got the network.xml and network.json files fixed and parsable.

* Moved config JS to config.js.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent 66b5c815d0
commit 86259a4783
  1. 22
      cgi-bin/home
  2. 19
      html/skins/alteeve/config.html
  3. 45
      html/skins/alteeve/config.js
  4. 1
      html/skins/alteeve/main.html
  5. 35
      html/skins/alteeve/main.js
  6. 9
      tools/anvil-update-states

@ -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}})
{
# <ip address="192.168.122.201" on="ifn1_bond1" subnet="255.255.0.0" gateway="192.168.122.1" default_gateway="1" dns="8.8.8.8,8.8.4.4"
$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},
}});
}
}
return(0);

@ -0,0 +1,19 @@
<!-- start header -->
<!DOCTYPE html>
<html lang="#!variable!language!#">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- Disable caching during development. -->
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" /> <title>#!string!brand_0001!# - #!string!brand_0003!#</title>
<link rel="stylesheet" href="#!data!skin::url!#/main.css" media="screen" />
<script type="text/javascript" src="/jquery-latest.js"></script>
<script type="text/javascript" src="#!data!skin::url!#/main.js"></script>
</head>
<!-- end header -->

@ -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.');
})

@ -602,6 +602,7 @@
<!-- start network_header -->
<table id="network_status" class="data_table_nowrap">
<script type="text/javascript" src="#!data!skin::url!#/config.js"></script>
<tr>
<td colspan="5" class="column_header">
#!string!header_0001!#

@ -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);
})

@ -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 .= "</network>\n";
$network_xml .= "<ips>\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 .= "</ips>\n";
$network_xml .= "</network>\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_xml => $network_xml }});
# Write the JSON file.

Loading…
Cancel
Save