Skip to content

Commit

Permalink
General cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxudo committed Aug 19, 2024
1 parent c6741f8 commit a9b7610
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 226 deletions.
18 changes: 9 additions & 9 deletions migrations/2018_02_20_000001_network_add_dns.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class NetworkAddDns extends Migration
public function up()
{
$capsule = new Capsule();

$capsule::schema()->table($this->tableName, function (Blueprint $table) {
$table->string('ipv4dns')->nullable();
$table->string('vlans')->nullable();
Expand Down Expand Up @@ -40,14 +40,14 @@ public function down()
{
$capsule = new Capsule();
$capsule::schema()->table($this->tableName, function (Blueprint $table) {
$table->dropColumn('ipv4dns');
$table->dropColumn('vlans');
$table->dropColumn('activemtu');
$table->dropColumn('validmturange');
$table->dropColumn('currentmedia');
$table->dropColumn('activemedia');
$table->dropColumn('searchdomain');
$table->dropColumn('externalip');
$table->dropColumn('ipv4dns');
$table->dropColumn('vlans');
$table->dropColumn('activemtu');
$table->dropColumn('validmturange');
$table->dropColumn('currentmedia');
$table->dropColumn('activemedia');
$table->dropColumn('searchdomain');
$table->dropColumn('externalip');
});
}
}
2 changes: 1 addition & 1 deletion migrations/2019_03_18_000001_network_rewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class NetworkRewrite extends Migration
public function up()
{
$capsule = new Capsule();

$capsule::schema()->table($this->tableName, function (Blueprint $table) {
$table->string('ipv4switchmacaddress')->nullable();
$table->string('ipv4destaddresses')->nullable();
Expand Down
7 changes: 3 additions & 4 deletions migrations/2022_08_29_000001_network_ supported_channels.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ class NetworkSupportedChannels extends Migration
public function up()
{
$capsule = new Capsule();

$capsule::schema()->table($this->tableName, function (Blueprint $table) {
// This doesn't work on some versions of MySQL
// $table->string('supported_channels', 1024)->nullable()->change();
$table->dropColumn('supported_channels');
});

$capsule::schema()->table($this->tableName, function (Blueprint $table) {
$table->text('supported_channels')->nullable();
});

}

public function down()
Expand All @@ -30,7 +29,7 @@ public function down()
$capsule::schema()->table($this->tableName, function (Blueprint $table) {
$table->dropColumn('supported_channels');
});

$capsule::schema()->table($this->tableName, function (Blueprint $table) {
$table->string('supported_channels')->nullable();
});
Expand Down
18 changes: 8 additions & 10 deletions network_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
**/
class Network_controller extends Module_controller
{

/*** Protect methods with auth! ****/
public function __construct()
{
// Store module path
$this->module_path = dirname(__FILE__);

// Add local config
configAppendFile(__DIR__ . '/config.php', 'network');
}
Expand Down Expand Up @@ -46,7 +45,7 @@ public function routers()
}

$router_arr = array();

// See if we're being parsed a request object
if (array_key_exists('req', $_GET)) {
$router_arr = (array) json_decode($_GET['req']);
Expand All @@ -60,7 +59,7 @@ public function routers()
$router_arr = [];
}
}

$out = array();
$reportdata = new \Model();

Expand Down Expand Up @@ -119,16 +118,15 @@ public function get_tab_data($serial_number = '')
$obj->view('json', array('msg' => 'Not authorized'));
return;
}

$queryobj = new Network_model();


$sql = "SELECT service, bsd_interface, `order`, status, ethernet, clientid, searchdomain, ipv4conf, ipv4ip, ipv4dns, ipv4mask, ipv4router, ipv4switchmacaddress, ipv4destaddresses, ipv6clientid, ipv6conf, ipv6ip, ipv6prefixlen, ipv6router, ipv6switchmacaddress, ipv6destaddresses, vpnservername, vpnserveraddress, overrideprimary, ipv6vpnservername, ipv6vpnserveraddress, ipv6coverrideprimary, dhcp_domain_name, dhcp_domain_name_servers, dhcp_routers, dhcp_server_identifier, dhcp_subnet_mask, location, netbiosname, workgroup, vlans, activemtu, validmturange, currentmedia, activemedia, externalip, supported_channels, supported_phymodes, wireless_card_type, firmware_version, country_code, wireless_locale, airdrop_channel, airdrop_supported, wow_supported
FROM network
WHERE serial_number = '$serial_number'";
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter()."
AND serial_number = '$serial_number'";

$queryobj = new Network_model();
$network_tab = $queryobj->query($sql);

$network = new Network_model;
$obj->view('json', array('msg' => current(array('msg' => $network_tab))));
}
} // END class Network_controller
29 changes: 18 additions & 11 deletions scripts/networkinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import plistlib
import re
import platform

from Foundation import CFPreferencesCopyAppValue

Expand Down Expand Up @@ -47,17 +48,19 @@ def get_network_info():
if device['service'] == "Wi-Fi" or device['service'] == "AirPort":

try:
cmd = ['/usr/libexec/airportd', 'info']
proc = subprocess.Popen(cmd, shell=False, bufsize=-1,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(output, unused_error) = proc.communicate()
output = output.decode("utf-8", errors="ignore")
# If less than macOS 13 (Darwin 22), use legacy method to get wifi data
if getDarwinVersion() < 22:
output = bashCommand(['/usr/libexec/airportd', 'info']).decode("utf-8", errors="ignore")
else:
output = bashCommand(['/usr/bin/wdutil', 'info']).decode("utf-8", errors="ignore")

for line in output.split('\n'):
if "Active PHY: " in line:
device['activemedia'] = line.replace("Active PHY: ","").strip()
break
elif " PHY Mode : " in line:
device['activemedia'] = "802."+(line.replace(" PHY Mode : ","").strip())
break
except Exception:
pass

Expand Down Expand Up @@ -169,11 +172,8 @@ def get_network_info():

def get_network_locations():
'''Uses system profiler to get info about the network locations'''
cmd = ['/usr/sbin/system_profiler', 'SPNetworkLocationDataType', '-xml']
proc = subprocess.Popen(cmd, shell=False, bufsize=-1,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(output, unused_error) = proc.communicate()
output = bashCommand(['/usr/sbin/system_profiler', 'SPNetworkLocationDataType', '-xml'])

try:
try:
plist = plistlib.readPlistFromString(output)
Expand Down Expand Up @@ -273,9 +273,11 @@ def get_tunnel_info(ifconfig_data):
if "inet" in utun_line and "inet6" not in utun_line:
utun['ipv4ip'] = ''.join(re.sub('inet ','',utun_line.strip()).split(' ')[0]).strip()
utun['service'] = adapter
# utun['status'] = 1
elif "inet6" in utun_line and "fe80::" not in utun_line:
utun['ipv6ip'] = ''.join(re.sub('inet6 ','',utun_line.strip()).split(' ')[0]).strip()
utun['service'] = adapter
# utun['status'] = 1
elif "ether" in utun_line:
utun['ethernet'] = re.sub('ether ','',utun_line.strip()).split(' ')[0].strip().upper()

Expand Down Expand Up @@ -351,6 +353,11 @@ def get_airport_info():
device['wireless_locale'] = obj[item]
return device

def getDarwinVersion():
"""Returns the Darwin version."""
darwin_version_tuple = platform.release().split('.')
return int(darwin_version_tuple[0])

def get_pref_value(key, domain):

value = CFPreferencesCopyAppValue(key, domain)
Expand Down
35 changes: 0 additions & 35 deletions views/network_listing.php

This file was deleted.

18 changes: 18 additions & 0 deletions views/network_listing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
i18n_title: network.report
table:
- column: machine.computer_name
i18n_header: listing.computername
formatter: clientDetail
tab_link: network-tab
- column: reportdata.serial_number
i18n_header: serial
- {i18n_header: username, column: reportdata.long_username}
- {i18n_header: network.service, column: network.service}
- {i18n_header: network.status, column: network.status, formatter: binaryEnabledDisabled}
- {i18n_header: network.ethernet, column: network.ethernet}
- {i18n_header: network.ip_address, column: network.ipv4ip}
- {i18n_header: network.dns, column: network.ipv4dns}
- {i18n_header: network.router, column: network.ipv4router}
- {i18n_header: network.externalip, column: network.externalip}
- {i18n_header: network.mask, column: network.ipv4mask}
- {i18n_header: network.activemedia, column: network.activemedia}
142 changes: 64 additions & 78 deletions views/network_location_widget.php
Original file line number Diff line number Diff line change
@@ -1,78 +1,64 @@
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-globe"></i>
<span data-i18n="network.widget.network_location"></span>
<list-link data-url="/show/listing/network/network"></list-link>
</h3>
</div>
<div id="ip-panel" class="panel-body text-center">
<svg id="network-plot" style="width:100%; height: 300px"></svg>
</div>
</div><!-- /panel -->
</div><!-- /col -->

<script>
$(document).on('appReady', function() {
function isnotzero(point)
{
return point.cnt > 0;
}
var url = appUrl + '/module/reportdata/ip'
var chart;
d3.json(url, function(err, data){
var height = 300;
var width = 350;
// Filter data
data = data.filter(isnotzero);
nv.addGraph(function() {
var chart = nv.models.pieChart()
.x(function(d) { return d.key })
.y(function(d) { return d.cnt })
.showLabels(false);
chart.title("" + d3.sum(data, function(d){
return d.cnt;
}));
chart.pie.donut(true);
d3.select("#network-plot")
.datum(data)
.transition().duration(1200)
.style('height', height)
.call(chart);
// Adjust title (count) depending on active slices
chart.dispatch.on('stateChange.legend', function (newState) {
var disabled = newState.disabled;
chart.title("" + d3.sum(data, function(d, i){
return d.cnt * !disabled[i];
}));
});
return chart;
});
});
});
</script>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-globe"></i>
<span data-i18n="network.widget.network_location"></span>
<list-link data-url="/show/listing/network/network"></list-link>
</h3>
</div>
<div id="ip-panel" class="panel-body text-center">
<svg id="network-plot" style="width:100%; height: 300px"></svg>
</div>
</div><!-- /panel -->
</div><!-- /col -->

<script>
$(document).on('appReady', function() {
function isnotzero(point)
{
return point.cnt > 0;
}
var url = appUrl + '/module/reportdata/ip'
var chart;
d3.json(url, function(err, data){
var height = 300;
var width = 350;
// Filter data
data = data.filter(isnotzero);
nv.addGraph(function() {
var chart = nv.models.pieChart()
.x(function(d) { return d.key })
.y(function(d) { return d.cnt })
.showLabels(false);
chart.title("" + d3.sum(data, function(d){
return d.cnt;
}));
chart.pie.donut(true);
d3.select("#network-plot")
.datum(data)
.transition().duration(1200)
.style('height', height)
.call(chart);
// Adjust title (count) depending on active slices
chart.dispatch.on('stateChange.legend', function (newState) {
var disabled = newState.disabled;
chart.title("" + d3.sum(data, function(d, i){
return d.cnt * !disabled[i];
}));
});
return chart;
});
});
});
</script>
Loading

0 comments on commit a9b7610

Please sign in to comment.