From fa1792cd5f825c5aca043ca7863070547ea3d44d Mon Sep 17 00:00:00 2001 From: KillahBee Date: Fri, 20 Jan 2023 11:43:19 -0500 Subject: [PATCH 1/3] adding cloudflare widget --- public/locales/en/common.json | 4 ++++ src/utils/proxy/handlers/credentialed.js | 3 +++ src/widgets/cloudflared/component.jsx | 30 ++++++++++++++++++++++++ src/widgets/cloudflared/widget.js | 18 ++++++++++++++ src/widgets/components.js | 1 + src/widgets/widgets.js | 2 ++ 6 files changed, 58 insertions(+) create mode 100644 src/widgets/cloudflared/component.jsx create mode 100644 src/widgets/cloudflared/widget.js diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 15af1c0d..55edf803 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -429,5 +429,9 @@ "temp_tool": "Tool temp", "temp_bed": "Bed temp", "job_completion": "Completion" + }, + "cloudflared" { + "origin_ip": "Origin IP", + "status": "Status" } } \ No newline at end of file diff --git a/src/utils/proxy/handlers/credentialed.js b/src/utils/proxy/handlers/credentialed.js index 10ca2b9c..7dc9f9e6 100644 --- a/src/utils/proxy/handlers/credentialed.js +++ b/src/utils/proxy/handlers/credentialed.js @@ -40,6 +40,9 @@ export default async function credentialedProxyHandler(req, res, map) { headers.Authorization = `Token ${widget.key}`; } else if (widget.type === "miniflux") { headers["X-Auth-Token"] = `${widget.key}`; + } else if (widget.type === "cloudflared") { + headers["X-Auth-Email"] = `${widget.email}`; + headers["X-Auth-Key"] = `${widget.key}`; } else { headers["X-API-Key"] = `${widget.key}`; } diff --git a/src/widgets/cloudflared/component.jsx b/src/widgets/cloudflared/component.jsx new file mode 100644 index 00000000..69639615 --- /dev/null +++ b/src/widgets/cloudflared/component.jsx @@ -0,0 +1,30 @@ +import Container from "components/services/widget/container"; +import Block from "components/services/widget/block"; +import useWidgetAPI from "utils/proxy/use-widget-api"; + +export default function Component({ service }) { + const { t } = useTranslation(); + const { widget } = service; + + const { data: statsData, error: statsError } = useWidgetAPI(widget, "cfd_tunnel"); + + if (statsError) { + return ; + } + + if (!statsData) { + return ( + + + + + ); + } + + return ( + + + + + ); +} \ No newline at end of file diff --git a/src/widgets/cloudflared/widget.js b/src/widgets/cloudflared/widget.js new file mode 100644 index 00000000..e8dd9888 --- /dev/null +++ b/src/widgets/cloudflared/widget.js @@ -0,0 +1,18 @@ +import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; + +const widget = { + api: "https://api.cloudflare.com/client/v4/accounts/{accountid}/{endpoint}/{tunnelid}?", + proxyHandler: credentialedProxyHandler, + + mappings: { + "cfd_tunnel": { + endpoint: "cfd_tunnel", + validate: [ + "origin_ip", + "status", + ], + }, + }, +}; + +export default widget; diff --git a/src/widgets/components.js b/src/widgets/components.js index d87f0b68..5b09416f 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -6,6 +6,7 @@ const components = { autobrr: dynamic(() => import("./autobrr/component")), bazarr: dynamic(() => import("./bazarr/component")), changedetectionio: dynamic(() => import("./changedetectionio/component")), + cloudflared: dynamic(() => import("./cloudflared/component")), coinmarketcap: dynamic(() => import("./coinmarketcap/component")), deluge: dynamic(() => import("./deluge/component")), downloadstation: dynamic(() => import("./downloadstation/component")), diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 349f9f93..f5d34eb4 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -3,6 +3,7 @@ import authentik from "./authentik/widget"; import autobrr from "./autobrr/widget"; import bazarr from "./bazarr/widget"; import changedetectionio from "./changedetectionio/widget"; +import cloudflared from "./cloudflared/widget"; import coinmarketcap from "./coinmarketcap/widget"; import deluge from "./deluge/widget"; import downloadstation from "./downloadstation/widget"; @@ -61,6 +62,7 @@ const widgets = { autobrr, bazarr, changedetectionio, + cloudflared, coinmarketcap, deluge, diskstation: downloadstation, From 2836ee1f3b4791eabfb1bc8e399b8fb79aec2929 Mon Sep 17 00:00:00 2001 From: KillahBee Date: Mon, 23 Jan 2023 11:59:58 -0500 Subject: [PATCH 2/3] cloudflared widget working locally --- src/widgets/cloudflared/component.jsx | 5 ++--- src/widgets/cloudflared/widget.js | 4 ---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/widgets/cloudflared/component.jsx b/src/widgets/cloudflared/component.jsx index 69639615..06131358 100644 --- a/src/widgets/cloudflared/component.jsx +++ b/src/widgets/cloudflared/component.jsx @@ -3,7 +3,6 @@ import Block from "components/services/widget/block"; import useWidgetAPI from "utils/proxy/use-widget-api"; export default function Component({ service }) { - const { t } = useTranslation(); const { widget } = service; const { data: statsData, error: statsError } = useWidgetAPI(widget, "cfd_tunnel"); @@ -23,8 +22,8 @@ export default function Component({ service }) { return ( - - + + ); } \ No newline at end of file diff --git a/src/widgets/cloudflared/widget.js b/src/widgets/cloudflared/widget.js index e8dd9888..78716934 100644 --- a/src/widgets/cloudflared/widget.js +++ b/src/widgets/cloudflared/widget.js @@ -7,10 +7,6 @@ const widget = { mappings: { "cfd_tunnel": { endpoint: "cfd_tunnel", - validate: [ - "origin_ip", - "status", - ], }, }, }; From 89c6528f245eda1974f47a2324ce4fddef1b6033 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 23 Jan 2023 10:31:08 -0800 Subject: [PATCH 3/3] cloudflare widget validation, handle multiple connections, fix translation file error, capitalize status --- public/locales/en/common.json | 2 +- src/widgets/cloudflared/component.jsx | 6 ++++-- src/widgets/cloudflared/widget.js | 6 +++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 55edf803..5477092a 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -430,7 +430,7 @@ "temp_bed": "Bed temp", "job_completion": "Completion" }, - "cloudflared" { + "cloudflared": { "origin_ip": "Origin IP", "status": "Status" } diff --git a/src/widgets/cloudflared/component.jsx b/src/widgets/cloudflared/component.jsx index 06131358..2cbcd45b 100644 --- a/src/widgets/cloudflared/component.jsx +++ b/src/widgets/cloudflared/component.jsx @@ -20,10 +20,12 @@ export default function Component({ service }) { ); } + const originIP = statsData.result.connections?.origin_ip ?? statsData.result.connections[0]?.origin_ip; + return ( - - + + ); } \ No newline at end of file diff --git a/src/widgets/cloudflared/widget.js b/src/widgets/cloudflared/widget.js index 78716934..1bb8819f 100644 --- a/src/widgets/cloudflared/widget.js +++ b/src/widgets/cloudflared/widget.js @@ -1,12 +1,16 @@ import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; const widget = { - api: "https://api.cloudflare.com/client/v4/accounts/{accountid}/{endpoint}/{tunnelid}?", + api: "https://api.cloudflare.com/client/v4/accounts/{accountid}/{endpoint}/{tunnelid}", proxyHandler: credentialedProxyHandler, mappings: { "cfd_tunnel": { endpoint: "cfd_tunnel", + validate: [ + "success", + "result" + ] }, }, };