From 9d16e280cdd3d51cebaa584989e910815217d41d Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 7 Jul 2024 21:07:24 -0700 Subject: [PATCH] Enhancement: support pfsense v2 api (#3716) --- docs/widgets/services/pfsense.md | 1 + src/utils/config/service-helpers.js | 5 ++++- src/widgets/pfsense/component.jsx | 13 ++++++++++--- src/widgets/pfsense/widget.js | 14 +++++++++++--- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/docs/widgets/services/pfsense.md b/docs/widgets/services/pfsense.md index 8f32a718d..adf98f4b2 100644 --- a/docs/widgets/services/pfsense.md +++ b/docs/widgets/services/pfsense.md @@ -26,5 +26,6 @@ widget: headers: # optional, or username/password Authorization: client_id client_token wan: igb0 + version: v2 # optional, defaults to v1 fields: ["load", "memory", "temp", "wanStatus"] # optional ``` diff --git a/src/utils/config/service-helpers.js b/src/utils/config/service-helpers.js index 93b5b1b6f..75d31add0 100644 --- a/src/utils/config/service-helpers.js +++ b/src/utils/config/service-helpers.js @@ -399,7 +399,7 @@ export function cleanServiceGroups(groups) { expandOneStreamToTwoRows, showEpisodeNumber, - // glances, pihole + // glances, pihole, pfsense version, // glances @@ -509,6 +509,9 @@ export function cleanServiceGroups(groups) { if (type === "unifi") { if (site) cleanedService.widget.site = site; } + if (type === "pfsense") { + if (version) cleanedService.widget.version = version; + } if (type === "proxmox") { if (node) cleanedService.widget.node = node; } diff --git a/src/widgets/pfsense/component.jsx b/src/widgets/pfsense/component.jsx index 0e961dbc4..54ae1bfdc 100644 --- a/src/widgets/pfsense/component.jsx +++ b/src/widgets/pfsense/component.jsx @@ -9,8 +9,12 @@ export default function Component({ service }) { const { widget } = service; - const { data: systemData, error: systemError } = useWidgetAPI(widget, "system"); - const { data: interfaceData, error: interfaceError } = useWidgetAPI(widget, "interface"); + const version = widget.version ?? 1; + const { data: systemData, error: systemError } = useWidgetAPI(widget, version === 1 ? "system" : "systemv2"); + const { data: interfaceData, error: interfaceError } = useWidgetAPI( + widget, + version === 1 ? "interface" : "interfacev2", + ); const showWanIP = widget.fields?.filter((f) => f !== "wanIP").length <= 4 && widget.fields?.includes("wanIP"); const showDiskUsage = widget.fields?.filter((f) => f !== "disk").length <= 4 && widget.fields?.includes("disk"); @@ -37,7 +41,10 @@ export default function Component({ service }) { return ( - +