From 4995dcb80dc6dfdde6d747e4331b5e8409078424 Mon Sep 17 00:00:00 2001 From: Ben Smithurst Date: Sat, 4 Jan 2025 15:59:11 +0000 Subject: [PATCH 01/15] add setting to scan for new interfaces --- .../src/opnsense/service/templates/OPNsense/Vnstat/vnstat.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/vnstat/src/opnsense/service/templates/OPNsense/Vnstat/vnstat.conf b/net/vnstat/src/opnsense/service/templates/OPNsense/Vnstat/vnstat.conf index 8745f976d3..abc9958d3f 100644 --- a/net/vnstat/src/opnsense/service/templates/OPNsense/Vnstat/vnstat.conf +++ b/net/vnstat/src/opnsense/service/templates/OPNsense/Vnstat/vnstat.conf @@ -9,6 +9,8 @@ Interface {{ interfaces|join('+') }} {% endif %} +# scan for new interfaces and add to DB +AlwaysAddNewInterfaces 1 # location of the database directory DatabaseDir "/var/lib/vnstat" From c8697dc8dfb0e154a6510c39b2804247267b1fd3 Mon Sep 17 00:00:00 2001 From: Ben Smithurst Date: Sat, 4 Jan 2025 16:01:44 +0000 Subject: [PATCH 02/15] allow single interface only --- .../mvc/app/controllers/OPNsense/Vnstat/forms/general.xml | 2 +- .../src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml index cd1f8ded82..6fe12c58e1 100644 --- a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml +++ b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml @@ -8,7 +8,7 @@ general.interface - select_multiple + dropdown Set the interface to listen on. diff --git a/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml b/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml index fa94d7dc05..29ee4d5f89 100644 --- a/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml +++ b/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml @@ -9,7 +9,7 @@ N - Y + N From 2903e6376f1a55eb19448ef21a2c535227fe4595 Mon Sep 17 00:00:00 2001 From: Ben Smithurst Date: Sat, 4 Jan 2025 16:49:00 +0000 Subject: [PATCH 03/15] multiple interface support --- .../OPNsense/Vnstat/Api/ServiceController.php | 40 +++++++++++++------ .../OPNsense/Vnstat/forms/general.xml | 10 ++++- .../app/models/OPNsense/Vnstat/General.xml | 4 ++ .../opnsense/scripts/OPNsense/Vnstat/stats.sh | 11 +++++ .../conf/actions.d/actions_vnstat.conf | 16 ++++---- 5 files changed, 59 insertions(+), 22 deletions(-) create mode 100644 net/vnstat/src/opnsense/scripts/OPNsense/Vnstat/stats.sh diff --git a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php index a8fbebb7c2..623f5c155c 100644 --- a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php +++ b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php @@ -32,6 +32,7 @@ use OPNsense\Base\ApiMutableServiceControllerBase; use OPNsense\Core\Backend; +use OPNsense\Core\Config; use OPNsense\Vnstat\General; /** @@ -51,9 +52,7 @@ class ServiceController extends ApiMutableServiceControllerBase */ public function hourlyAction() { - $backend = new Backend(); - $response = $backend->configdRun("vnstat hourly"); - return array("response" => $response); + return $this->getStatsForDisplayInterfaces('hourly'); } /** @@ -62,9 +61,7 @@ public function hourlyAction() */ public function dailyAction() { - $backend = new Backend(); - $response = $backend->configdRun("vnstat daily"); - return array("response" => $response); + return $this->getStatsForDisplayInterfaces('daily'); } /** @@ -73,9 +70,7 @@ public function dailyAction() */ public function monthlyAction() { - $backend = new Backend(); - $response = $backend->configdRun("vnstat monthly"); - return array("response" => $response); + return $this->getStatsForDisplayInterfaces('monthly'); } /** @@ -84,9 +79,7 @@ public function monthlyAction() */ public function yearlyAction() { - $backend = new Backend(); - $response = $backend->configdRun("vnstat yearly"); - return array("response" => $response); + return $this->getStatsForDisplayInterfaces('yearly'); } /** @@ -99,4 +92,27 @@ public function resetdbAction() $response = $backend->configdRun("vnstat resetdb"); return array("response" => $response); } + + private function getStatsForDisplayInterfaces(string $type) { + $config = Config::getInstance()->toArray(); + $backend = new Backend(); + + if (!isset($config['OPNsense']['vnstat']['general']['interface_display'])) { + // no interface configured, use script default (i.e. don't specify interface) + $response = $backend->configdRun("vnstat $type"); + return array("response" => $response); + } + + // loop over configured interfaces, combining the output + $result = ''; + foreach (explode(',', $config['OPNsense']['vnstat']['general']['interface_display']) as $interface) { + // map the OPNsense interface name to the kernel interface name that vnstat uses + if (isset($config['interfaces'][$interface]['if'])) { + $result .= $backend->configdpRun("vnstat", [ $type, $config['interfaces'][$interface]['if'] ]); + } + } + return array("response" => $result); + } } + +// vim:set ts=4 sw=4 et: diff --git a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml index 6fe12c58e1..232f1e2bfe 100644 --- a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml +++ b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml @@ -7,8 +7,14 @@ general.interface - + dropdown - Set the interface to listen on. + Set the default interface. + + + general.interface_display + + select_multiple + Set the interface(s) to display stats for. diff --git a/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml b/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml index 29ee4d5f89..c329862415 100644 --- a/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml +++ b/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml @@ -11,5 +11,9 @@ N N + + N + Y + diff --git a/net/vnstat/src/opnsense/scripts/OPNsense/Vnstat/stats.sh b/net/vnstat/src/opnsense/scripts/OPNsense/Vnstat/stats.sh new file mode 100644 index 0000000000..611f53bc0a --- /dev/null +++ b/net/vnstat/src/opnsense/scripts/OPNsense/Vnstat/stats.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +type="$1" +interface="$2" + +if [ -z "$interface" ]; then + # Interface not specified, use default interface for backward compatibility + interface=`awk '/^Interface/ { print $2 }' < /usr/local/etc/vnstat.conf` +fi + +vnstat -$type $interface diff --git a/net/vnstat/src/opnsense/service/conf/actions.d/actions_vnstat.conf b/net/vnstat/src/opnsense/service/conf/actions.d/actions_vnstat.conf index 4a4fcbd64e..4b31f7a46d 100644 --- a/net/vnstat/src/opnsense/service/conf/actions.d/actions_vnstat.conf +++ b/net/vnstat/src/opnsense/service/conf/actions.d/actions_vnstat.conf @@ -23,26 +23,26 @@ type:script_output message:request Vnstat status [hourly] -command:/usr/local/bin/vnstat -h -parameters: +command:/usr/local/opnsense/scripts/OPNsense/Vnstat/stats.sh h +parameters:%s type:script_output message:request Vnstat hourly status [daily] -command:/usr/local/bin/vnstat -d -parameters: +command:/usr/local/opnsense/scripts/OPNsense/Vnstat/stats.sh d +parameters:%s type:script_output message:request Vnstat daily status [monthly] -command:/usr/local/bin/vnstat -m -parameters: +command:/usr/local/opnsense/scripts/OPNsense/Vnstat/stats.sh m +parameters:%s type:script_output message:request Vnstat monthly status [yearly] -command:/usr/local/bin/vnstat -y -parameters: +command:/usr/local/opnsense/scripts/OPNsense/Vnstat/stats.sh y +parameters:%s type:script_output message:request Vnstat yearly status From 0d849eff07ff077523647464f0a35b4d71cbdfc0 Mon Sep 17 00:00:00 2001 From: Ben Smithurst Date: Sat, 4 Jan 2025 16:49:19 +0000 Subject: [PATCH 04/15] remove vim marker --- .../app/controllers/OPNsense/Vnstat/Api/ServiceController.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php index 623f5c155c..05f4606b26 100644 --- a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php +++ b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php @@ -114,5 +114,3 @@ private function getStatsForDisplayInterfaces(string $type) { return array("response" => $result); } } - -// vim:set ts=4 sw=4 et: From b59f9b0d094702963cfbdf2b0d3e1599277e7541 Mon Sep 17 00:00:00 2001 From: Ben Smithurst Date: Sat, 4 Jan 2025 17:10:50 +0000 Subject: [PATCH 05/15] use configdpRun for consistency here --- .../app/controllers/OPNsense/Vnstat/Api/ServiceController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php index 05f4606b26..c65d177f14 100644 --- a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php +++ b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php @@ -99,7 +99,7 @@ private function getStatsForDisplayInterfaces(string $type) { if (!isset($config['OPNsense']['vnstat']['general']['interface_display'])) { // no interface configured, use script default (i.e. don't specify interface) - $response = $backend->configdRun("vnstat $type"); + $response = $backend->configdpRun("vnstat", [ $type ]); return array("response" => $response); } From 81b8215b38101dee0dafd597b3debc9c12a2ba6f Mon Sep 17 00:00:00 2001 From: Ben Smithurst Date: Sun, 5 Jan 2025 11:00:40 +0000 Subject: [PATCH 06/15] revert interface option changes --- .../app/controllers/OPNsense/Vnstat/forms/general.xml | 10 ++-------- .../mvc/app/models/OPNsense/Vnstat/General.xml | 6 +----- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml index 232f1e2bfe..cd1f8ded82 100644 --- a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml +++ b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml @@ -7,14 +7,8 @@ general.interface - - dropdown - Set the default interface. - - - general.interface_display - + select_multiple - Set the interface(s) to display stats for. + Set the interface to listen on. diff --git a/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml b/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml index c329862415..fa94d7dc05 100644 --- a/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml +++ b/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml @@ -8,12 +8,8 @@ Y - N - N - - N Y - + From ced7a585faa68e11614ccfadb4a4e8fce7a2a152 Mon Sep 17 00:00:00 2001 From: Ben Smithurst Date: Sun, 5 Jan 2025 11:05:42 +0000 Subject: [PATCH 07/15] define new separate_stats option --- .../app/controllers/OPNsense/Vnstat/forms/general.xml | 9 ++++++++- .../opnsense/mvc/app/models/OPNsense/Vnstat/General.xml | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml index cd1f8ded82..8ed4613c05 100644 --- a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml +++ b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml @@ -9,6 +9,13 @@ general.interface select_multiple - Set the interface to listen on. + Set the interface(s) to display stats for. + + + general.separate_stats + + checkbox + If checked, separate stats are shown for each configured interface. If unchecked + a single set of stats is shown containing the sum of traffic on all configured interfaces. diff --git a/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml b/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml index fa94d7dc05..5511a725e9 100644 --- a/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml +++ b/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml @@ -11,5 +11,9 @@ N Y + + 0 + Y + From 371b95db32a251023c6babfd77c8410ddbef2ec7 Mon Sep 17 00:00:00 2001 From: Ben Smithurst Date: Sun, 5 Jan 2025 11:12:40 +0000 Subject: [PATCH 08/15] handle the separate_stats option --- .../OPNsense/Vnstat/Api/ServiceController.php | 16 ++++++++-------- .../opnsense/scripts/OPNsense/Vnstat/stats.sh | 0 2 files changed, 8 insertions(+), 8 deletions(-) mode change 100644 => 100755 net/vnstat/src/opnsense/scripts/OPNsense/Vnstat/stats.sh diff --git a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php index c65d177f14..42796dd264 100644 --- a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php +++ b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php @@ -52,7 +52,7 @@ class ServiceController extends ApiMutableServiceControllerBase */ public function hourlyAction() { - return $this->getStatsForDisplayInterfaces('hourly'); + return $this->getStats('hourly'); } /** @@ -61,7 +61,7 @@ public function hourlyAction() */ public function dailyAction() { - return $this->getStatsForDisplayInterfaces('daily'); + return $this->getStats('daily'); } /** @@ -70,7 +70,7 @@ public function dailyAction() */ public function monthlyAction() { - return $this->getStatsForDisplayInterfaces('monthly'); + return $this->getStats('monthly'); } /** @@ -79,7 +79,7 @@ public function monthlyAction() */ public function yearlyAction() { - return $this->getStatsForDisplayInterfaces('yearly'); + return $this->getStats('yearly'); } /** @@ -93,19 +93,19 @@ public function resetdbAction() return array("response" => $response); } - private function getStatsForDisplayInterfaces(string $type) { + private function getStats(string $type) { $config = Config::getInstance()->toArray(); $backend = new Backend(); - if (!isset($config['OPNsense']['vnstat']['general']['interface_display'])) { - // no interface configured, use script default (i.e. don't specify interface) + if (empty($config['OPNsense']['vnstat']['general']['separate_stats'])) { + // separate stats are not wanted, just get totals $response = $backend->configdpRun("vnstat", [ $type ]); return array("response" => $response); } // loop over configured interfaces, combining the output $result = ''; - foreach (explode(',', $config['OPNsense']['vnstat']['general']['interface_display']) as $interface) { + foreach (explode(',', $config['OPNsense']['vnstat']['general']['interface']) as $interface) { // map the OPNsense interface name to the kernel interface name that vnstat uses if (isset($config['interfaces'][$interface]['if'])) { $result .= $backend->configdpRun("vnstat", [ $type, $config['interfaces'][$interface]['if'] ]); diff --git a/net/vnstat/src/opnsense/scripts/OPNsense/Vnstat/stats.sh b/net/vnstat/src/opnsense/scripts/OPNsense/Vnstat/stats.sh old mode 100644 new mode 100755 From c217fbbaacf07ab846ab16a03918458f79512812 Mon Sep 17 00:00:00 2001 From: Ben Smithurst Date: Sun, 5 Jan 2025 11:17:11 +0000 Subject: [PATCH 09/15] rewrite to avoid needing the stats script --- .../src/opnsense/scripts/OPNsense/Vnstat/stats.sh | 11 ----------- .../service/conf/actions.d/actions_vnstat.conf | 8 ++++---- 2 files changed, 4 insertions(+), 15 deletions(-) delete mode 100755 net/vnstat/src/opnsense/scripts/OPNsense/Vnstat/stats.sh diff --git a/net/vnstat/src/opnsense/scripts/OPNsense/Vnstat/stats.sh b/net/vnstat/src/opnsense/scripts/OPNsense/Vnstat/stats.sh deleted file mode 100755 index 611f53bc0a..0000000000 --- a/net/vnstat/src/opnsense/scripts/OPNsense/Vnstat/stats.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -type="$1" -interface="$2" - -if [ -z "$interface" ]; then - # Interface not specified, use default interface for backward compatibility - interface=`awk '/^Interface/ { print $2 }' < /usr/local/etc/vnstat.conf` -fi - -vnstat -$type $interface diff --git a/net/vnstat/src/opnsense/service/conf/actions.d/actions_vnstat.conf b/net/vnstat/src/opnsense/service/conf/actions.d/actions_vnstat.conf index 4b31f7a46d..b4eb008864 100644 --- a/net/vnstat/src/opnsense/service/conf/actions.d/actions_vnstat.conf +++ b/net/vnstat/src/opnsense/service/conf/actions.d/actions_vnstat.conf @@ -23,25 +23,25 @@ type:script_output message:request Vnstat status [hourly] -command:/usr/local/opnsense/scripts/OPNsense/Vnstat/stats.sh h +command:vnstat -h parameters:%s type:script_output message:request Vnstat hourly status [daily] -command:/usr/local/opnsense/scripts/OPNsense/Vnstat/stats.sh d +command:vnstat -d parameters:%s type:script_output message:request Vnstat daily status [monthly] -command:/usr/local/opnsense/scripts/OPNsense/Vnstat/stats.sh m +command:vnstat -m parameters:%s type:script_output message:request Vnstat monthly status [yearly] -command:/usr/local/opnsense/scripts/OPNsense/Vnstat/stats.sh y +command:vnvstat -y parameters:%s type:script_output message:request Vnstat yearly status From aac8ec421a67551b10150893dd8edd191d999609 Mon Sep 17 00:00:00 2001 From: Ben Smithurst Date: Sun, 5 Jan 2025 11:18:50 +0000 Subject: [PATCH 10/15] fix typo, add back full path to vnstat --- .../opnsense/service/conf/actions.d/actions_vnstat.conf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/vnstat/src/opnsense/service/conf/actions.d/actions_vnstat.conf b/net/vnstat/src/opnsense/service/conf/actions.d/actions_vnstat.conf index b4eb008864..89a149bf57 100644 --- a/net/vnstat/src/opnsense/service/conf/actions.d/actions_vnstat.conf +++ b/net/vnstat/src/opnsense/service/conf/actions.d/actions_vnstat.conf @@ -23,25 +23,25 @@ type:script_output message:request Vnstat status [hourly] -command:vnstat -h +command:/usr/local/bin/vnstat -h parameters:%s type:script_output message:request Vnstat hourly status [daily] -command:vnstat -d +command:/usr/local/bin/vnstat -d parameters:%s type:script_output message:request Vnstat daily status [monthly] -command:vnstat -m +command:/usr/local/bin/vnstat -m parameters:%s type:script_output message:request Vnstat monthly status [yearly] -command:vnvstat -y +command:/usr/local/bin/vnstat -y parameters:%s type:script_output message:request Vnstat yearly status From 5f53d28b33e8f5f4b204fd08e2c9dc2081d78ec8 Mon Sep 17 00:00:00 2001 From: Ben Smithurst Date: Sun, 5 Jan 2025 11:23:37 +0000 Subject: [PATCH 11/15] improve comments, add basic phpdoc --- .../OPNsense/Vnstat/Api/ServiceController.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php index 42796dd264..41505caa43 100644 --- a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php +++ b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php @@ -93,20 +93,26 @@ public function resetdbAction() return array("response" => $response); } + /** + * Get stats of the given type + * @param string $type Which type of statistics to return (hourly, daily, weekly, or monthly) + * @return array + */ private function getStats(string $type) { $config = Config::getInstance()->toArray(); $backend = new Backend(); if (empty($config['OPNsense']['vnstat']['general']['separate_stats'])) { - // separate stats are not wanted, just get totals + // Separate stats are not wanted, just get totals - that's the default in vnstat itself, + // no need to specify anything here. $response = $backend->configdpRun("vnstat", [ $type ]); return array("response" => $response); } - // loop over configured interfaces, combining the output + // Loop over configured interfaces, concatenating the output of each. $result = ''; foreach (explode(',', $config['OPNsense']['vnstat']['general']['interface']) as $interface) { - // map the OPNsense interface name to the kernel interface name that vnstat uses + // Map the OPNsense interface name to the kernel interface name that vnstat uses. if (isset($config['interfaces'][$interface]['if'])) { $result .= $backend->configdpRun("vnstat", [ $type, $config['interfaces'][$interface]['if'] ]); } From 17978c930bf48b28c448c55ac73c515150edb9ea Mon Sep 17 00:00:00 2001 From: Ben Smithurst Date: Sun, 5 Jan 2025 11:24:57 +0000 Subject: [PATCH 12/15] tweak help text --- .../mvc/app/controllers/OPNsense/Vnstat/forms/general.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml index 8ed4613c05..0710114baa 100644 --- a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml +++ b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/forms/general.xml @@ -15,7 +15,7 @@ general.separate_stats checkbox - If checked, separate stats are shown for each configured interface. If unchecked + If checked, separate stats are shown for each configured interface. If unchecked, a single set of stats is shown containing the sum of traffic on all configured interfaces. From 790583aded1ade251ab75c42a7c212acb00c4df3 Mon Sep 17 00:00:00 2001 From: Ben Smithurst Date: Sun, 5 Jan 2025 11:27:59 +0000 Subject: [PATCH 13/15] run "make style-model" --- .../src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml b/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml index 5511a725e9..3f4c844954 100644 --- a/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml +++ b/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml @@ -4,15 +4,15 @@ 0.0.1 - 0 + 0 Y N - Y + Y - 0 + 0 Y From f733359b01f41f0b97bb665a8fb4f3aed6b71d43 Mon Sep 17 00:00:00 2001 From: Ben Smithurst Date: Sun, 5 Jan 2025 14:01:48 +0000 Subject: [PATCH 14/15] default to true for separate_stats --- .../src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml b/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml index 3f4c844954..ed4ac8d518 100644 --- a/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml +++ b/net/vnstat/src/opnsense/mvc/app/models/OPNsense/Vnstat/General.xml @@ -12,7 +12,7 @@ Y - 0 + 1 Y From 2bd53550aee7c1b7bceb0a085284e28aa6eb9573 Mon Sep 17 00:00:00 2001 From: Ben Smithurst Date: Sun, 5 Jan 2025 14:08:34 +0000 Subject: [PATCH 15/15] update config check to handle the default being true --- .../app/controllers/OPNsense/Vnstat/Api/ServiceController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php index 41505caa43..bbf502baa9 100644 --- a/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php +++ b/net/vnstat/src/opnsense/mvc/app/controllers/OPNsense/Vnstat/Api/ServiceController.php @@ -102,7 +102,7 @@ private function getStats(string $type) { $config = Config::getInstance()->toArray(); $backend = new Backend(); - if (empty($config['OPNsense']['vnstat']['general']['separate_stats'])) { + if (isset($config['OPNsense']['vnstat']['general']['separate_stats']) && !$config['OPNsense']['vnstat']['general']['separate_stats']) { // Separate stats are not wanted, just get totals - that's the default in vnstat itself, // no need to specify anything here. $response = $backend->configdpRun("vnstat", [ $type ]);