diff --git a/css/style.css b/css/style.css new file mode 100644 index 0000000..fa23b42 --- /dev/null +++ b/css/style.css @@ -0,0 +1,26 @@ +/* +Copyright (C) 2016 Alex + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +/* http://stackoverflow.com/questions/17206631/why-are-bootstrap-tabs-displaying-tab-pane-divs-with-incorrect-widths-when-using */ +/* bootstrap hack: fix content width inside hidden tabs */ +.tab-content > .tab-pane:not(.active), +.pill-content > .pill-pane:not(.active) { + display: block; + height: 0; + overflow-y: hidden; +} +/* bootstrap hack end */ diff --git a/index.php b/index.php index 56da34b..6bc3a46 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,5 @@ - + + @@ -102,9 +176,28 @@ function drawChart() { + + +
+ + +
+
+
+
-
+
+
+
+
+
+
+
@@ -143,7 +236,7 @@ function drawChart() { - @@ -176,7 +269,7 @@ function drawChart() { - @@ -209,7 +302,7 @@ function drawChart() { - @@ -243,7 +336,7 @@ function drawChart() { - diff --git a/vnstat.php b/vnstat.php index e792da3..57f34cb 100644 --- a/vnstat.php +++ b/vnstat.php @@ -101,7 +101,9 @@ function get_vnstat_data($path, $type, $interface) { $hourlyGraph = array(); $hourly = array(); + $dailyGraph = array(); $daily = array(); + $monthlyGraph = array(); $monthly = array(); $top10 = array(); @@ -127,6 +129,15 @@ function get_vnstat_data($path, $type, $interface) { $hourly[$data[1]]['act'] = 1; break; case "d": // Daily + // Set-up the daily graph data + $dailyGraph[$data[1]]['time'] = $data[2]; + $dailyGraph[$data[1]]['label'] = date("jS", $data[2]); + $dailyGraph[$data[1]]['rx'] = kbytes_to_string(($data[3] * 1024 + $data[5]), true, $byte_formatter); + $dailyGraph[$data[1]]['tx'] = kbytes_to_string(($data[4] * 1024 + $data[6]), true, $byte_formatter); + $dailyGraph[$data[1]]['total'] = kbytes_to_string(($data[3] * 1024 + $data[5]) + ($data[4] * 1024 + $data[6]), true, $byte_formatter); + $dailyGraph[$data[1]]['totalUnformatted'] = (($data[3] * 1024 + $data[5]) + ($data[4] * 1024 + $data[6])); + $dailyGraph[$data[1]]['act'] = 1; + $daily[$data[1]]['time'] = $data[2]; $daily[$data[1]]['label'] = date("d/m/Y", $data[2]); $daily[$data[1]]['rx'] = kbytes_to_string($data[3] * 1024 + $data[5]); @@ -135,6 +146,15 @@ function get_vnstat_data($path, $type, $interface) { $daily[$data[1]]['act'] = $data[7]; break; case "m": // Monthly + // Set-up the monthly graph data + $monthlyGraph[$data[1]]['time'] = $data[2]; + $monthlyGraph[$data[1]]['label'] = date("F", ($data[2] - ($data[2] % 3600))); + $monthlyGraph[$data[1]]['rx'] = kbytes_to_string(($data[3] * 1024 + $data[5]), true, $byte_formatter); + $monthlyGraph[$data[1]]['tx'] = kbytes_to_string(($data[4] * 1024 + $data[6]), true, $byte_formatter); + $monthlyGraph[$data[1]]['total'] = kbytes_to_string((($data[3] * 1024 + $data[5]) + ($data[4] * 1024 + $data[6])), true, $byte_formatter); + $monthlyGraph[$data[1]]['totalUnformatted'] = ($data[3] + $data[4]); + $monthlyGraph[$data[1]]['act'] = 1; + $monthly[$data[1]]['time'] = $data[2]; $monthly[$data[1]]['label'] = date("F", $data[2]); $monthly[$data[1]]['rx'] = kbytes_to_string($data[3] * 1024 + $data[5]); @@ -163,11 +183,21 @@ function get_vnstat_data($path, $type, $interface) { if ($item1['time'] == $item2['time']) return 0; return $item1['time'] < $item2['time'] ? -1 : 1; }); + + usort($dailyGraph, function ($item1, $item2) { + if ($item1['time'] == $item2['time']) return 0; + return $item1['time'] > $item2['time'] ? -1 : 1; + }); usort($daily, function ($item1, $item2) { if ($item1['time'] == $item2['time']) return 0; return $item1['time'] > $item2['time'] ? -1 : 1; }); + + usort($monthlyGraph, function ($item1, $item2) { + if ($item1['time'] == $item2['time']) return 0; + return $item1['time'] > $item2['time'] ? -1 : 1; + }); usort($monthly, function ($item1, $item2) { if ($item1['time'] == $item2['time']) return 0; @@ -185,8 +215,12 @@ function get_vnstat_data($path, $type, $interface) { return $hourlyGraph; case "hourly": return $hourly; + case "dailyGraph": + return $dailyGraph; case "daily": return $daily; + case "monthlyGraph": + return $monthlyGraph; case "monthly": return $monthly; case "top10":