Skip to content

Commit 9df86f8

Browse files
committed
Merge branch 'master' of https://github.com/cardil/linux-dash into cardil-master
2 parents 21d26f5 + c2d6cc9 commit 9df86f8

File tree

7 files changed

+95
-54
lines changed

7 files changed

+95
-54
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ <h3>
243243
<div class="widget-header">
244244
<i class="icon-list"></i>
245245
<h3>
246-
DNS Leases
246+
DHCP Leases
247247
</h3>
248248
<div id="refresh-dnsmasqleases" class="btn icon-refresh js-refresh-info"></div>
249249
</div><!-- /widget-header -->

js/dashboard.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ dashboard.getLoadAverage = function () {
417417
}
418418

419419
dashboard.getDnsmasqLeases = function () {
420-
$.get("sh/dnsmasq-leases.php", function (data) {
420+
$.get("sh/dhcp-leases.php", function (data) {
421421
var table = $("#dnsmasqleases_dashboard");
422422
var ex = document.getElementById("dnsmasqleases_dashboard");
423423
if ($.fn.DataTable.fnIsDataTable(ex)) {
@@ -448,6 +448,7 @@ dashboard.getBandwidth = function () {
448448
$.ajax({
449449
url: 'sh/bandwidth.php',
450450
cache: false,
451+
dataType: 'json',
451452
success: function (data) {
452453
$('#bw-tx').text(data.tx);
453454
$('#bw-rx').text(data.rx);

sh/bandwidth.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
$tx_path = 'cat /sys/class/net/eth0/statistics/tx_bytes';
44
$rx_path = 'cat /sys/class/net/eth0/statistics/rx_bytes';
55

6-
$tx_start = shell_exec($tx_path);
7-
$rx_start = shell_exec($rx_path);
6+
$tx_start = intval(shell_exec($tx_path));
7+
$rx_start = intval(shell_exec($rx_path));
88

99
sleep(2);
1010

11-
$tx_end = shell_exec($tx_path);
12-
$rx_end = shell_exec($rx_path);
11+
$tx_end = intval(shell_exec($tx_path));
12+
$rx_end = intval(shell_exec($rx_path));
1313

14-
$result['tx'] = ($tx_end - $tx_start)/2;
15-
$result['rx'] = ($rx_end - $rx_start)/2;
14+
$result['tx'] = ($tx_end - $tx_start);
15+
$result['rx'] = ($rx_end - $rx_start);
1616

1717
echo json_encode($result);

sh/dhcp-leases.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
// define the path to the DNSMasq Lease file
4+
$dnsmasq_lease_file = "/var/lib/misc/dnsmasq.leases";
5+
6+
// build the results
7+
$results = array();
8+
9+
// check if DNS MASQ file exists
10+
if (file_exists($dnsmasq_lease_file)) {
11+
12+
// get the contents of the lease file
13+
$data = file_get_contents($dnsmasq_lease_file);
14+
15+
// separate it into lines
16+
$data = explode("\n", $data);
17+
18+
// strip any blank lines
19+
$data = array_filter($data, function ($v) {
20+
return $v;
21+
});
22+
23+
// step through the data
24+
foreach ($data as $l) {
25+
// explode each line of the data
26+
$l = explode(" ", $l);
27+
28+
// remove the last field (I don't know what it is - for most of the
29+
// lines it's simply "*", in other cases it's the host MAC address)
30+
unset($l[4]);
31+
32+
// convert the timestamp to a readable date/time
33+
$l[0] = date("m/j/Y H:i:s", $l[0]);
34+
35+
// add the line to the results
36+
$results[] = $l;
37+
}
38+
} else {
39+
$fh=fopen("/var/lib/dhcp/dhcpd.leases","r");
40+
41+
while ($dat=fgets($fh)) {
42+
if (preg_match("/lease.+{/",$dat)) {
43+
$active=false;
44+
$ip = preg_split("/ /",$dat);$ip=$ip[1];
45+
$expires = '';
46+
$dat=fgets($fh);
47+
while (!preg_match("/hardware ethernet/",$dat) && !preg_match("/ends/",$dat)) {
48+
$dat=fgets($fh);
49+
}
50+
if (preg_match("/ends/",$dat)) {
51+
$expires = preg_replace("/.*ends\\s+\\d+\\s+(.+);.*/", '\1', $dat);
52+
$ts = strtotime($expires);
53+
$expires = date("m/j/Y H:i:s", $ts);
54+
}
55+
$dat=fgets($fh);
56+
while (!preg_match("/hardware ethernet/",$dat)) {
57+
if (preg_match("/binding state active/",$dat)) {
58+
$active=true;
59+
}
60+
$dat=fgets($fh);
61+
}
62+
$mac = preg_split("/ |;/",$dat); $mac=$mac[4];
63+
$host = '';
64+
$dat=fgets($fh);
65+
while (trim($dat) != "}" && !preg_match("/client-hostname/",$dat)) {
66+
$dat=fgets($fh);
67+
}
68+
if (preg_match("/client-hostname/",$dat)) {
69+
$host = preg_replace("/.*\"(.+)\".*/", '\1', $dat);
70+
}
71+
72+
if ($active) {
73+
$results[$ip] = array($expires, $mac, $ip, $host);
74+
}
75+
}
76+
}
77+
sort($results);
78+
$results = array_values($results);
79+
80+
}
81+
82+
// output the results
83+
echo json_encode($results);

sh/dnsmasq-leases.php

Lines changed: 0 additions & 43 deletions
This file was deleted.

sh/numberofcores.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
);
88

99
// get value via /proc/cpuinfo
10-
$numOfCores = shell_exec('/bin/grep -c ^processor /proc/cpuinfo');
10+
$numOfCores = shell_exec('LC_ALL=C /bin/grep -c ^processor /proc/cpuinfo');
1111
$numOfCores = filter_var(
1212
$numOfCores[0],
1313
FILTER_VALIDATE_INT,

sh/where.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
$binaries = explode(" ", "php node mysql vim python ruby java apache2 nginx openssl vsftpd make");
1313
}
1414

15-
putenv('PATH=/usr/local/sbin:/usr/sbin:/sbin:' . getenv('PATH'));
15+
$path = 'PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:' . getenv('PATH');
1616
$data = array();
1717
foreach ($binaries as $b) {
1818
$which = array();
19-
exec('command -v ' . escapeshellarg($b), $which, $return_var);
19+
exec($path . ' command -v ' . escapeshellarg($b), $which, $return_var);
2020
$data[] = array($b, $return_var ? "Not Installed" : $which[0]);
2121
}
2222

0 commit comments

Comments
 (0)