From 057d5eca8f82c66866220913a361e086aa017002 Mon Sep 17 00:00:00 2001
From: aidenpwnz <hidden>
Date: Fri, 2 Sep 2022 12:13:15 +0200
Subject: [PATCH 1/2] FEAT: NGINX Proxy Manager

---
 src/components/services/widget.jsx            |  4 +-
 .../services/widgets/service/npm.jsx          | 79 +++++++++++++++++++
 2 files changed, 82 insertions(+), 1 deletion(-)
 create mode 100644 src/components/services/widgets/service/npm.jsx

diff --git a/src/components/services/widget.jsx b/src/components/services/widget.jsx
index 926f1156..ca313588 100644
--- a/src/components/services/widget.jsx
+++ b/src/components/services/widget.jsx
@@ -11,6 +11,7 @@ import Jellyfin from "./widgets/service/jellyfin";
 import Speedtest from "./widgets/service/speedtest";
 import Traefik from "./widgets/service/traefik";
 import Jellyseerr from "./widgets/service/jellyseerr";
+import Npm from "./widgets/service/npm";
 
 const widgetMappings = {
   docker: Docker,
@@ -25,7 +26,8 @@ const widgetMappings = {
   rutorrent: Rutorrent,
   speedtest: Speedtest,
   traefik: Traefik,
-  jellyseerr: Jellyseerr
+  jellyseerr: Jellyseerr,
+  npm: Npm,
 };
 
 export default function Widget({ service }) {
diff --git a/src/components/services/widgets/service/npm.jsx b/src/components/services/widgets/service/npm.jsx
new file mode 100644
index 00000000..921cd69b
--- /dev/null
+++ b/src/components/services/widgets/service/npm.jsx
@@ -0,0 +1,79 @@
+import useSWR from "swr";
+
+import Widget from "../widget";
+import Block from "../block";
+import { useState } from "react";
+
+export default function Npm({ service }) {
+  const config = service.widget;
+  const { url } = config;
+
+  const [token, setToken] = useState();
+
+  const fetcher = async (reqUrl) => {
+    const { url, email, password } = config;
+    const urlConstructed = `${url}/api/tokens`;
+    const body = { identity: email, secret: password };
+
+    if (!token) {
+      const res = await fetch(urlConstructed, {
+        method: "POST",
+        body: JSON.stringify(body),
+        headers: {
+          "Content-Type": "application/json",
+        },
+      })
+        .then((response) => response.json())
+        .then(
+          async (data) =>
+            await fetch(reqUrl, {
+              method: "GET",
+              headers: {
+                "Content-Type": "application/json",
+                Authorization: "Bearer " + data.token,
+              },
+            })
+        );
+      return res.json();
+    } else {
+      const resp = await fetch(reqUrl, {
+        method: "GET",
+        headers: {
+          "Content-Type": "application/json",
+          Authorization: "Bearer " + token,
+        },
+      });
+      return resp.json();
+    }
+  };
+
+  const { data: infoData, error: infoError } = useSWR(`${url}/api/nginx/proxy-hosts`, fetcher);
+
+  console.log(infoData);
+
+  if (infoError) {
+    return <Widget error="NGINX Proxy Manager API Error" />;
+  }
+
+  if (!infoData) {
+    return (
+      <Widget>
+        <Block label="Running" />
+        <Block label="Stopped" />
+        <Block label="Total" />
+      </Widget>
+    );
+  }
+
+  const enabled = infoData.filter((c) => c.enabled === 1).length;
+  const disabled = infoData.filter((c) => c.enabled === 0).length;
+  const total = infoData.length;
+
+  return (
+    <Widget>
+      <Block label="Enabled" value={enabled} />
+      <Block label="Disabled" value={disabled} />
+      <Block label="Total" value={total} />
+    </Widget>
+  );
+}

From 13afe82fa5c11380625fd419fc9f4f079545426e Mon Sep 17 00:00:00 2001
From: aidenpwnz <aidenpwnz@proton.me>
Date: Fri, 2 Sep 2022 16:48:28 +0200
Subject: [PATCH 2/2] FEAT: NGINX Proxy Manager

---
 .../services/widgets/service/npm.jsx          | 58 +++++++------------
 src/skeleton/services.yaml                    |  5 ++
 2 files changed, 27 insertions(+), 36 deletions(-)

diff --git a/src/components/services/widgets/service/npm.jsx b/src/components/services/widgets/service/npm.jsx
index 921cd69b..222bf1bd 100644
--- a/src/components/services/widgets/service/npm.jsx
+++ b/src/components/services/widgets/service/npm.jsx
@@ -2,49 +2,35 @@ import useSWR from "swr";
 
 import Widget from "../widget";
 import Block from "../block";
-import { useState } from "react";
 
 export default function Npm({ service }) {
   const config = service.widget;
   const { url } = config;
 
-  const [token, setToken] = useState();
-
   const fetcher = async (reqUrl) => {
-    const { url, email, password } = config;
-    const urlConstructed = `${url}/api/tokens`;
-    const body = { identity: email, secret: password };
+    const { url, username, password } = config;
+    const loginUrl = `${url}/api/tokens`;
+    const body = { identity: username, secret: password };
 
-    if (!token) {
-      const res = await fetch(urlConstructed, {
-        method: "POST",
-        body: JSON.stringify(body),
-        headers: {
-          "Content-Type": "application/json",
-        },
-      })
-        .then((response) => response.json())
-        .then(
-          async (data) =>
-            await fetch(reqUrl, {
-              method: "GET",
-              headers: {
-                "Content-Type": "application/json",
-                Authorization: "Bearer " + data.token,
-              },
-            })
-        );
-      return res.json();
-    } else {
-      const resp = await fetch(reqUrl, {
-        method: "GET",
-        headers: {
-          "Content-Type": "application/json",
-          Authorization: "Bearer " + token,
-        },
-      });
-      return resp.json();
-    }
+    const res = await fetch(loginUrl, {
+      method: "POST",
+      body: JSON.stringify(body),
+      headers: {
+        "Content-Type": "application/json",
+      },
+    })
+      .then((response) => response.json())
+      .then(
+        async (data) =>
+          await fetch(reqUrl, {
+            method: "GET",
+            headers: {
+              "Content-Type": "application/json",
+              Authorization: "Bearer " + data.token,
+            },
+          })
+      );
+    return res.json();
   };
 
   const { data: infoData, error: infoError } = useSWR(`${url}/api/nginx/proxy-hosts`, fetcher);
diff --git a/src/skeleton/services.yaml b/src/skeleton/services.yaml
index 169082a0..5ee3ca14 100644
--- a/src/skeleton/services.yaml
+++ b/src/skeleton/services.yaml
@@ -5,6 +5,11 @@
     - My First Service:
         href: http://localhosdt/
         description: Homepage is awesome
+        widget:
+          type: npm # npm for NGINX Proxy Manager
+          url: http://localhost:81 # no slash at the end
+          username: aidenpwnz@proton.me # your email
+          password: AidenProxy1994! # your password
 
 - My Second Group:
     - My Second Service: