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,