diff --git a/ajax/bandwidth/get_bandwidth.php b/ajax/bandwidth/get_bandwidth.php
index 48cd5156..ea0c103e 100644
--- a/ajax/bandwidth/get_bandwidth.php
+++ b/ajax/bandwidth/get_bandwidth.php
@@ -2,12 +2,12 @@
require_once '../../includes/config.php';
require_once RASPI_CONFIG.'/raspap.php';
-// For privacy require authentication.
session_start();
header('X-Frame-Options: DENY');
header("Content-Security-Policy: default-src 'none'; connect-src 'self'");
require_once '../../includes/authenticate.php';
+
$interface = filter_input(INPUT_GET, 'inet', FILTER_SANITIZE_SPECIAL_CHARS);
if (empty($interface)) {
// Use first interface if inet parameter not provided.
@@ -37,15 +37,12 @@ $timeunits = filter_input(INPUT_GET, 'tu');
if ($timeunits === 'm') {
// months
$jsonData = $jsonobj['interfaces'][0]['traffic']['months'];
-//} elseif ($timeunits === 'h') {
-// $jsonData = $jsonobj['interfaces'][0]['traffic']['hours'];
} else {
// default: days
$jsonData = $jsonobj['interfaces'][0]['traffic']['days'];
}
$datasizeunits = filter_input(INPUT_GET, 'dsu');
-
header('X-Content-Type-Options: nosniff');
header('Content-Type: application/json');
echo '[ ';
@@ -54,11 +51,6 @@ for ($i = count($jsonData) - 1; $i >= 0; --$i) {
if ($timeunits === 'm') {
$dt = DateTime::createFromFormat('Y n', $jsonData[$i]['date']['year'].' '.
$jsonData[$i]['date']['month']);
-// } elseif ($timeunits === 'h') {
-// $dt = DateTime::createFromFormat('Y n j G i', $jsonData[$i]['date']['year'].' '.
-// $jsonData[$i]['date']['month'].' '.
-// $jsonData[$i]['date']['day'].' '.
-// $i.' 00');
} else {
$dt = DateTime::createFromFormat('Y n j', $jsonData[$i]['date']['year'].' '.
$jsonData[$i]['date']['month'].' '.
@@ -82,9 +74,6 @@ for ($i = count($jsonData) - 1; $i >= 0; --$i) {
if ($timeunits === 'm') {
echo '{ "date": "' , $dt->format('Y-m') , '", "rx": "' , $datareceived ,
'", "tx": "' , $datasend , '" }';
-// } elseif ($timeunits === 'h') {
-// echo '{ "date": "' , $dt->format('Y-m-d H:i') , '", "rx": ' , $datareceived ,
-// ', "tx": ' , $datasend , ' }';
} else {
echo '{ "date": "' , $dt->format('Y-m-d') , '", "rx": "' , $datareceived ,
'", "tx": "' , $datasend , '" }';
diff --git a/includes/vnstat.php b/includes/vnstat.php
index a0035b9f..86762ad8 100644
--- a/includes/vnstat.php
+++ b/includes/vnstat.php
@@ -19,19 +19,18 @@ function DisplayVnstat(&$extraFooterScripts)
-
+
-
+
-
-
+
+
-
-
php echo _("Hourly traffic amount today"); ?
-
-
-
-
-*/
-?>
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
diff --git a/js/bandwidthcharts.js b/js/bandwidthcharts.js
index df9178c4..bbb82da4 100644
--- a/js/bandwidthcharts.js
+++ b/js/bandwidthcharts.js
@@ -18,8 +18,8 @@
/**
* Create a bootstrap data table.
*/
- function CreateDataTable(placeholder) {
- $("#"+placeholder).append('
');
+ function CreateDataTable(placeholder, timeunits) {
+ $("#"+placeholder).append('');
}
/**
@@ -27,11 +27,13 @@
* construct the proper barchart.
*/
function ShowBandwidthChartHandler(e) {
- // Remove all charts
- $("#divBandwidthdaily").empty();
- $("#divBandwidthweekly").empty();
- $("#divBandwidthmonthly").empty();
- // Construct ajax uri for getting proper data.
+ // Remove all morrisjs charts
+ $("#divChartBandwidthdaily").empty();
+ $("#divChartBandwidthmonthly").empty();
+ // Remove all datatables
+ $("#divTableBandwidthdaily").empty();
+ $("#divTableBandwidthmonthly").empty();
+ // Construct ajax uri for getting the proper data.
var timeunit = $("ul#tabbarBandwidth li.active a").attr("href").substr(1);
var uri = 'ajax/bandwidth/get_bandwidth.php?';
uri += 'inet=';
@@ -41,9 +43,9 @@
var datasizeunits = 'mb';
uri += '&dsu='+encodeURIComponent(datasizeunits);
// Init. chart
- var barchart = CreateBarChart('divBandwidth'+timeunit, datasizeunits);
- // Init. datatable
- var datatable = CreateDataTable('divBandwidth'+timeunit);
+ var barchart = CreateBarChart('divChartBandwidth'+timeunit, datasizeunits);
+ // Init. datatable html
+ var datatable = CreateDataTable('divTableBandwidth'+timeunit, timeunit);
// Get data for chart
$.ajax({
url: uri,
@@ -54,10 +56,11 @@
}).done(function(jsondata) {
$("#divLoaderBandwidth"+timeunit).addClass("hidden");
barchart.setData(jsondata);
- $('#tableBandwidth').DataTable({
- "searching": false,
+ $('#tableBandwidth'+timeunit).DataTable({
+ searching: false,
+ paging: false,
data: jsondata,
- "columns": [
+ columns: [
{ "data": "date" },
{ "data": "rx", "title": "received "+datasizeunits },
{ "data": "tx", "title": "send "+datasizeunits }]
@@ -71,10 +74,12 @@
});
}
- $('#tabbarBandwidth a[data-toggle="tab"]').on('shown.bs.tab', ShowBandwidthChartHandler);
- $('#cbxInterfacedaily').on('change', ShowBandwidthChartHandler);
- $('#cbxInterfaceweekly').on('change', ShowBandwidthChartHandler);
- $('#cbxInterfacemonthly').on('change', ShowBandwidthChartHandler);
- ShowBandwidthChartHandler();
+ $( document ).ready(function() {
+ $('#tabbarBandwidth a[data-toggle="tab"]').on('shown.bs.tab', ShowBandwidthChartHandler);
+ $('#cbxInterfacedaily').on('change', ShowBandwidthChartHandler);
+ $('#cbxInterfaceweekly').on('change', ShowBandwidthChartHandler);
+ $('#cbxInterfacemonthly').on('change', ShowBandwidthChartHandler);
+ ShowBandwidthChartHandler();
+ });
})(jQuery);
\ No newline at end of file