From cfe4486b1f0859963d940c7507ac3898e5d6d1a9 Mon Sep 17 00:00:00 2001 From: Dinesh Reddy J Date: Mon, 10 Apr 2023 15:03:13 +0530 Subject: [PATCH] added Ngrok widget --- src/utils/proxy/handlers/credentialed.js | 6 +-- src/widgets/components.js | 1 + src/widgets/ngrok/component.jsx | 50 ++++++++++++++++++++++++ src/widgets/ngrok/widget.js | 14 +++++++ src/widgets/widgets.js | 2 + 5 files changed, 70 insertions(+), 3 deletions(-) create mode 100755 src/widgets/ngrok/component.jsx create mode 100755 src/widgets/ngrok/widget.js diff --git a/src/utils/proxy/handlers/credentialed.js b/src/utils/proxy/handlers/credentialed.js index 56bbb151..76f0eba8 100644 --- a/src/utils/proxy/handlers/credentialed.js +++ b/src/utils/proxy/handlers/credentialed.js @@ -39,9 +39,9 @@ export default async function credentialedProxyHandler(req, res, map) { headers.Authorization = `Bearer ${widget.key}`; } else if (widget.type === "proxmox") { headers.Authorization = `PVEAPIToken=${widget.username}=${widget.password}`; - } else if (widget.type === "proxmoxbackupserver") { - delete headers["Content-Type"]; - headers.Authorization = `PBSAPIToken=${widget.username}:${widget.password}`; + } else if (widget.type === "ngrok") { + headers.Authorization = `Bearer ${widget.key}`; + headers["Ngrok-Version"] = 2; } else if (widget.type === "autobrr") { headers["X-API-Token"] = `${widget.key}`; } else if (widget.type === "tubearchivist") { diff --git a/src/widgets/components.js b/src/widgets/components.js index aa54e246..f101baf0 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -41,6 +41,7 @@ const components = { navidrome: dynamic(() => import("./navidrome/component")), nextcloud: dynamic(() => import("./nextcloud/component")), nextdns: dynamic(() => import("./nextdns/component")), + ngrok: dynamic(() => import("./ngrok/component")), npm: dynamic(() => import("./npm/component")), nzbget: dynamic(() => import("./nzbget/component")), octoprint: dynamic(() => import("./octoprint/component")), diff --git a/src/widgets/ngrok/component.jsx b/src/widgets/ngrok/component.jsx new file mode 100755 index 00000000..cf0c3676 --- /dev/null +++ b/src/widgets/ngrok/component.jsx @@ -0,0 +1,50 @@ +import { useTranslation } from "next-i18next"; + +import Container from "components/services/widget/container"; +import useWidgetAPI from "utils/proxy/use-widget-api"; + + +function displayUrl(url , index){ + return ( + +
+ {url} +
+
+ ); +} + + +export default function Component({ service }) { + const { t } = useTranslation(); + const { widget } = service; + const { + data: ngrokData, + error: ngrokError + } = useWidgetAPI(widget, "tunnels",{ + refreshInterval: 30000, + }); + + if (ngrokError) { + return ; + } + + if (ngrokData){ + if(ngrokData.tunnels.length === 0){ + return ( +
+ {t("No Active Tunnels")} +
+ ); + } + + let runningTunnels = ngrokData.tunnels.length; + if(runningTunnels > 5) runningTunnels = 5; + + return ( +
+ {ngrokData.tunnels.slice(0, runningTunnels).map((tunnel, index) => displayUrl(tunnel.public_url, index))} +
+ ); +} +} diff --git a/src/widgets/ngrok/widget.js b/src/widgets/ngrok/widget.js new file mode 100755 index 00000000..ef8a6239 --- /dev/null +++ b/src/widgets/ngrok/widget.js @@ -0,0 +1,14 @@ +import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; + +const widget = { + api: "https://api.ngrok.com/{{endpoint}}", + proxyHandler: credentialedProxyHandler, + + mapping: { + "tunnels": { + endpoint: "tunnels" + }, + }, +}; + +export default widget; diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index ab2d44b2..c221e273 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -35,6 +35,7 @@ import mylar from "./mylar/widget"; import navidrome from "./navidrome/widget"; import nextcloud from "./nextcloud/widget"; import nextdns from "./nextdns/widget"; +import ngrok from "./ngrok/widget" import npm from "./npm/widget"; import nzbget from "./nzbget/widget"; import octoprint from "./octoprint/widget"; @@ -113,6 +114,7 @@ const widgets = { navidrome, nextcloud, nextdns, + ngrok, npm, nzbget, octoprint,