$.ajaxSetup({ cache: false }); $(function() { }); $( window ).on( "load", function() { // NOTE: Disabled for now. Breaks viewing the source. // Clears the URL to remove everything off after '?'. //var newURL = location.href.split("?")[0]; //window.history.pushState('object', document.title, newURL); // Show the list of unconfigured (and configured) hosts on the main page. if ($('#unconfigured_hosts').length) { // Toggle the table with the list of hosts that can be configured. $("#toggle_unconfigured_icon").click(function(){ $("#unconfigured_hosts").toggle(); }); $("#toggle_unconfigured_text").click(function(){ $("#unconfigured_hosts").toggle(); }); // Walk through the network.json file and use it to pre-fill the form. setInterval(function() { $.getJSON('/status/all_status.json', function(data) { //console.log('read /status/all_status.json'); var show_none = 1; var say_none = $('#unconfigured_hosts').data('none'); var say_yes = $('#unconfigured_hosts').data('yes'); var say_no = $('#unconfigured_hosts').data('no'); var say_unconfigured = $('#unconfigured_hosts').data('unconfigured'); var say_configured = $('#unconfigured_hosts').data('configured'); var say_type = $('#unconfigured_hosts').data('type'); var say_accessible = $('#unconfigured_hosts').data('accessible'); var say_at_ip = $('#unconfigured_hosts').data('at-ip'); // Open the table var body = ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; $.each(data.hosts, function(index, element) { if (element.type === 'dashboard') { // Skip return true; }; if (element.configured != 1) { show_none = 0; if (element.matched_ip_address) { //console.log('Show: ['+element.short_name+'], connect via: ['+element.matched_ip_address+']'); body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; } else { //console.log('Show: ['+element.short_name+'], not accessible from here'); body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; } } }); if (show_none) { body += ''; body += ''; body += '' ; } // Now show configured ones (in case the user wants to reconfigure a host) show_none = 1; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; $.each(data.hosts, function(index, element) { if (element.type === 'dashboard') { // Skip return true; }; if (element.configured == 1) { show_none = 0; if (element.matched_ip_address) { //console.log('Show: ['+element.short_name+'], connect via: ['+element.matched_ip_address+']'); body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; } else { //console.log('Show: ['+element.short_name+'], not accessible from here'); body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; } } }); if (show_none) { body += ''; body += ''; body += '' ; } // Close the table body += '
'+say_unconfigured+'   '+say_type+'   '+say_accessible+'   '+say_at_ip+'
'+element.short_name+'   '+element.type+'   '+say_yes+'   '+element.matched_ip_address+'
'+element.short_name+'   '+element.type+'   '+say_no+'   --
<'+say_none+'>
'+say_configured+'   '+say_type+'   '+say_accessible+'   '+say_at_ip+'
'+element.short_name+'   '+element.type+'   '+say_yes+'   '+element.matched_ip_address+'
'+element.short_name+'   '+element.type+'   '+say_no+'   --
<'+say_none+'>
'; // clear + append can't be the best way to do this... $("#unconfigured_hosts").empty(); $("#unconfigured_hosts").append(body); }); }, 1000); }; // Run in we're showing a specific hosts' network. if ($('#network_interface_table').length) { var host_name = $('#network_interface_table').data('host-name'); var say_title = $('#network_interface_table').data('title'); var say_mac_address = $('#network_interface_table').data('mac-address'); var say_name = $('#network_interface_table').data('name'); var say_state = $('#network_interface_table').data('state'); var say_speed = $('#network_interface_table').data('speed'); var say_up_order = $('#network_interface_table').data('up-order'); var say_up = $('#network_interface_table').data('up'); var say_down = $('#network_interface_table').data('down'); //console.log('showing network info for: ['+host_name+']'); setInterval(function() { $.getJSON('/status/all_status.json', function(data) { //console.log('read all_status.json: ['+data+']'); // Build the HTML var body = ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; $.each(data.hosts, function(i, host) { //console.log('This is: ['+host.name+']'); if (host.name != host_name) { // Skip return true; }; //console.log('Found it!'); $.each(host.network_interfaces, function(j, nic) { // Only real interfaces have a 'changed_order' value. if (nic.changed_order) { var say_link_state = say_down; if (nic.link_state == 1) { say_link_state = say_up; } body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; body += ''; } }); }); body += '
'+say_title+'
'+say_mac_address+''+say_name+''+say_state+''+say_speed+''+say_up_order+'
'+nic.mac_address+''+nic.name+''+say_link_state+''+nic.say_speed+''+nic.changed_order+'
'; // clear + append can't be the best way to do this... $("#network_interface_table").empty(); $("#network_interface_table").append(body); }); }, 1000); }; })