From fa1792cd5f825c5aca043ca7863070547ea3d44d Mon Sep 17 00:00:00 2001 From: KillahBee Date: Fri, 20 Jan 2023 11:43:19 -0500 Subject: [PATCH] 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 15af1c0dc..55edf803d 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 10ca2b9c3..7dc9f9e6a 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 000000000..696396152 --- /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 000000000..e8dd9888e --- /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 d87f0b685..5b09416fc 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 349f9f93d..f5d34eb4f 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,