From f2e0ea0ebb9bb430ece43139a4ff3c8a69e87667 Mon Sep 17 00:00:00 2001
From: spasecookee <58440408+spasecookee@users.noreply.github.com>
Date: Mon, 5 Aug 2024 12:42:26 -0600
Subject: [PATCH 1/3] Added most-recent result and new 24.7 widget
OPNSense 24.7 has a new widget format, which is provided here. There is also a new "most-recent" result displayed in the widget.
---
.../Speedtest/Api/ServiceController.php | 5 ++
.../OPNsense/speedtest/opn_speedtest.py | 22 +++++
.../conf/actions.d/actions_speedtest.conf | 6 ++
.../www/js/widgets/Metadata/Speedtest.xml | 16 ++++
.../src/opnsense/www/js/widgets/Speedtest.js | 80 +++++++++++++++++++
.../www/widgets/widgets/speedtest.widget.php | 14 ++--
6 files changed, 138 insertions(+), 5 deletions(-)
create mode 100644 net-mgmt/speedtest-community/src/opnsense/www/js/widgets/Metadata/Speedtest.xml
create mode 100644 net-mgmt/speedtest-community/src/opnsense/www/js/widgets/Speedtest.js
diff --git a/net-mgmt/speedtest-community/src/opnsense/mvc/app/controllers/OPNsense/Speedtest/Api/ServiceController.php b/net-mgmt/speedtest-community/src/opnsense/mvc/app/controllers/OPNsense/Speedtest/Api/ServiceController.php
index 8ecabb5..ca7732c 100644
--- a/net-mgmt/speedtest-community/src/opnsense/mvc/app/controllers/OPNsense/Speedtest/Api/ServiceController.php
+++ b/net-mgmt/speedtest-community/src/opnsense/mvc/app/controllers/OPNsense/Speedtest/Api/ServiceController.php
@@ -56,6 +56,11 @@ public function showlogAction()
{
return (new Backend())->configdRun("speedtest showlog");
}
+
+ public function showrecentAction()
+ {
+ return (new Backend())->configdRun("speedtest showrecent");
+ }
public function deletelogAction()
{
diff --git a/net-mgmt/speedtest-community/src/opnsense/scripts/OPNsense/speedtest/opn_speedtest.py b/net-mgmt/speedtest-community/src/opnsense/scripts/OPNsense/speedtest/opn_speedtest.py
index 6afe8d5..7a0372d 100755
--- a/net-mgmt/speedtest-community/src/opnsense/scripts/OPNsense/speedtest/opn_speedtest.py
+++ b/net-mgmt/speedtest-community/src/opnsense/scripts/OPNsense/speedtest/opn_speedtest.py
@@ -79,6 +79,28 @@ def is_int (n):
print(json.dumps(array[:50]))
quit()
+ # parameter r or recent - returning the last 1 entries from csv
+ if arg=='r' or arg == 'recent':
+ f = open(csvfile, 'r', encoding="utf-8")
+ data = csv.reader(f,dialect='excel')
+ header = next(data)
+ row=[]
+ for row in data:
+ #from timestamp to visual form
+ row[0]=datetime.fromtimestamp(float(row[0])).isoformat()
+ f.close()
+ out = {
+ 'date': str(row[0]),
+ 'server': row[2] + " " + row[3],
+ 'download': row[5],
+ 'upload': row[6],
+ 'latency': row[7],
+ 'url': row[8]
+ }
+ print(json.dumps(out))
+ quit()
+
+
# parameter s or stat - return statistics
if arg=='s' or arg=='stat':
latencyarray = []
diff --git a/net-mgmt/speedtest-community/src/opnsense/service/conf/actions.d/actions_speedtest.conf b/net-mgmt/speedtest-community/src/opnsense/service/conf/actions.d/actions_speedtest.conf
index 99ea7b1..1af356e 100644
--- a/net-mgmt/speedtest-community/src/opnsense/service/conf/actions.d/actions_speedtest.conf
+++ b/net-mgmt/speedtest-community/src/opnsense/service/conf/actions.d/actions_speedtest.conf
@@ -29,6 +29,12 @@ parameters:
type:script_output
message: Shows speedtest log (last 50 entries)
+[showrecent]
+command:/usr/local/bin/python3 /usr/local/opnsense/scripts/OPNsense/speedtest/opn_speedtest.py recent
+parameters:
+type:script_output
+message: Shows speedtest most recent log entry
+
[deletelog]
command:/bin/rm /usr/local/opnsense/scripts/OPNsense/speedtest/speedtest.csv
parameters:
diff --git a/net-mgmt/speedtest-community/src/opnsense/www/js/widgets/Metadata/Speedtest.xml b/net-mgmt/speedtest-community/src/opnsense/www/js/widgets/Metadata/Speedtest.xml
new file mode 100644
index 0000000..8b04b43
--- /dev/null
+++ b/net-mgmt/speedtest-community/src/opnsense/www/js/widgets/Metadata/Speedtest.xml
@@ -0,0 +1,16 @@
+
+
+ Speedtest.js
+
+ /api/speedtest/service/showrecent
+ /api/speedtest/service/showstat
+
+
+ Speedtest
+ Most Recent
+ Avg. Latency
+ Avg. Download
+ Avg. Upload
+
+
+
\ No newline at end of file
diff --git a/net-mgmt/speedtest-community/src/opnsense/www/js/widgets/Speedtest.js b/net-mgmt/speedtest-community/src/opnsense/www/js/widgets/Speedtest.js
new file mode 100644
index 0000000..36908ea
--- /dev/null
+++ b/net-mgmt/speedtest-community/src/opnsense/www/js/widgets/Speedtest.js
@@ -0,0 +1,80 @@
+
+/*
+ * Copyright (C) 2024 Deciso B.V.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+/*
+ * Copyright (C) 2024 Deciso B.V.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import BaseTableWidget from "./BaseTableWidget.js";
+
+export default class ETProTelemetry extends BaseTableWidget {
+ constructor() {
+ super();
+ this.tickTimeout = 3600;
+ }
+ getGridOptions() {
+ return {
+ };
+ }
+ getMarkup() {
+ let $container = $('
');
+ let $Speedtesttable = this.createTable('speedtest-table', {
+ headerPosition: 'left',
+ });
+ $container.append($Speedtesttable);
+ return $container;
+ }
+
+ async onWidgetTick() {
+ const status_data = await this.ajaxCall('/api/speedtest/service/showstat');
+ const recent_data = await this.ajaxCall('/api/speedtest/service/showrecent');
+ $('#speedtest_most_recent').html(`${recent_data['date']} Down: ${recent_data['download']} Mbps
(up: ${recent_data['upload']} Mbps, latency: ${recent_data['latency']} ms)`);
+ $('#speedtest_avg_latency').html(`${status_data['latency']['avg']} ms (min: ${status_data['latency']['min']}, max: ${status_data['latency']['max']})`);
+ $('#speedtest_avg_download').html(`${status_data['download']['avg']} Mbps (min: ${status_data['download']['min']}, max: ${status_data['download']['max']})`);
+ $('#speedtest_avg_upload').html(`${status_data['upload']['avg']} Mbps (min: ${status_data['upload']['min']}, max: ${status_data['upload']['max']})`);
+ }
+
+ async onMarkupRendered() {
+ let rows = [];
+ rows.push([[this.translations['most_recent']], $('').prop('outerHTML')]);
+ rows.push([[this.translations['avg_latency']], $('').prop('outerHTML')]);
+ rows.push([[this.translations['avg_download']], $('').prop('outerHTML')]);
+ rows.push([[this.translations['avg_upload']], $('').prop('outerHTML')]);
+
+ super.updateTable('speedtest-table', rows);
+ }
+}
+
diff --git a/net-mgmt/speedtest-community/src/www/widgets/widgets/speedtest.widget.php b/net-mgmt/speedtest-community/src/www/widgets/widgets/speedtest.widget.php
index 39b2a24..a37932c 100644
--- a/net-mgmt/speedtest-community/src/www/widgets/widgets/speedtest.widget.php
+++ b/net-mgmt/speedtest-community/src/www/widgets/widgets/speedtest.widget.php
@@ -28,17 +28,21 @@
?>
From 330614ab3fd08910c4cc1b6f7a2c400093bb853e Mon Sep 17 00:00:00 2001
From: spasecookee <58440408+spasecookee@users.noreply.github.com>
Date: Fri, 9 Aug 2024 18:19:20 -0600
Subject: [PATCH 2/3] Added a hyperlink to the widget title
The old widget's title liked to the speedtest page. This adds it back.
---
.../speedtest-community/src/opnsense/www/js/widgets/Speedtest.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/net-mgmt/speedtest-community/src/opnsense/www/js/widgets/Speedtest.js b/net-mgmt/speedtest-community/src/opnsense/www/js/widgets/Speedtest.js
index 36908ea..4cf2c35 100644
--- a/net-mgmt/speedtest-community/src/opnsense/www/js/widgets/Speedtest.js
+++ b/net-mgmt/speedtest-community/src/opnsense/www/js/widgets/Speedtest.js
@@ -68,6 +68,7 @@ export default class ETProTelemetry extends BaseTableWidget {
}
async onMarkupRendered() {
+ $(`#${this.id}-title`).html(`${this.translations['title']}`);
let rows = [];
rows.push([[this.translations['most_recent']], $('').prop('outerHTML')]);
rows.push([[this.translations['avg_latency']], $('').prop('outerHTML')]);
From 1c9d39c0faf5e6358ad9f55fe46ae9c4bbf7b8cd Mon Sep 17 00:00:00 2001
From: spasecookee <58440408+spasecookee@users.noreply.github.com>
Date: Sun, 1 Sep 2024 10:00:25 -0600
Subject: [PATCH 3/3] Fixed syntax errors
Class name was incorrect.
incorrect use of import (old-style widget)
Widget is loading again in 24.7.3
---
.../src/opnsense/www/js/widgets/Speedtest.js | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/net-mgmt/speedtest-community/src/opnsense/www/js/widgets/Speedtest.js b/net-mgmt/speedtest-community/src/opnsense/www/js/widgets/Speedtest.js
index 4cf2c35..e49e179 100644
--- a/net-mgmt/speedtest-community/src/opnsense/www/js/widgets/Speedtest.js
+++ b/net-mgmt/speedtest-community/src/opnsense/www/js/widgets/Speedtest.js
@@ -38,9 +38,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-import BaseTableWidget from "./BaseTableWidget.js";
-
-export default class ETProTelemetry extends BaseTableWidget {
+export default class Speedtest extends BaseTableWidget {
constructor() {
super();
this.tickTimeout = 3600;