An open source, self-hosted, real-time port monitoring and discovery tool.
feat: show the ability to add TrueNAS API key on UI
Mostafa Wahiedc51a9a7df6bb
diff --git a/frontend/src/App.jsx b/frontend/src/App.jsxindex 77b4a9d..9768ba1 100644--- a/frontend/src/App.jsx+++ b/frontend/src/App.jsx@@ -432,7 +432,7 @@ export default function App() {vms: scanData.vms,parentId: server.parentId,platform_type: server.platform_type || scanData.platform,- enhancedFeaturesEnabled: true,+ enhancedFeaturesEnabled: scanData.enhancedFeaturesEnabled ?? true,};} else {const errorData = await scanResponse@@ -493,7 +493,7 @@ export default function App() {vms: scanData.vms,parentId: server.parentId,platform_type: server.platform_type || scanData.platform,- enhancedFeaturesEnabled: true,+ enhancedFeaturesEnabled: scanData.enhancedFeaturesEnabled ?? true,};} else {const errorData = await scanResponse.json().catch(() => ({@@ -1305,7 +1305,7 @@ export default function App() {vms: scanData.vms,parentId: serverData.parentId,platform_type: serverData.platform_type || scanData.platform,- enhancedFeaturesEnabled: true,+ enhancedFeaturesEnabled: scanData.enhancedFeaturesEnabled ?? true,};setGroups((currentGroups) =>@@ -1530,6 +1530,7 @@ export default function App() {platformName={server.platformName}systemInfo={server.systemInfo}vms={server.vms}+ enhancedFeaturesEnabled={server.enhancedFeaturesEnabled}infoCardLayout={infoCardLayout}onInfoCardLayoutChange={setInfoCardLayout}portLayout={portLayout}diff --git a/frontend/src/components/server/ServerSection.jsx b/frontend/src/components/server/ServerSection.jsxindex 30b516d..f01b4f9 100644--- a/frontend/src/components/server/ServerSection.jsx+++ b/frontend/src/components/server/ServerSection.jsx@@ -57,6 +57,7 @@ function ServerSectionComponent({platformName,systemInfo,vms,+ enhancedFeaturesEnabled,portLayout,onPortLayoutChange,isExpanded,@@ -217,6 +218,8 @@ function ServerSectionComponent({const hasSystemInfo = systemInfo && Object.keys(systemInfo).length > 0;const hasVMs = vms && vms.length > 0;+ const isTrueNAS = platformName?.toLowerCase().includes("truenas");+ const showVMSection = hasVMs || (isTrueNAS && enhancedFeaturesEnabled === false);const getHostDisplay = () => {if (!serverUrl) {@@ -263,7 +266,7 @@ function ServerSectionComponent({</div></div>- {(hasSystemInfo || hasVMs) && (+ {(hasSystemInfo || showVMSection) && (<div><div className="flex items-center justify-end mb-4"><div className="flex items-center space-x-1 bg-slate-100 dark:bg-slate-900 rounded-lg p-1">@@ -332,7 +335,7 @@ function ServerSectionComponent({</AccordionContent></AccordionItem>)}- {hasVMs && (+ {showVMSection && (<AccordionItemvalue="vms"className="border rounded-xl bg-white dark:bg-slate-800/50 border-slate-200 dark:border-slate-700/50 shadow-sm"@@ -340,11 +343,11 @@ function ServerSectionComponent({<AccordionTrigger className="px-6 py-4 text-lg font-semibold text-slate-900 dark:text-slate-100 hover:no-underline"><div className="flex items-center"><VmIcon className="h-5 w-5 mr-3 text-slate-600 dark:text-slate-400" />- Virtual Machines ({vms.length})+ Virtual Machines {hasVMs && `(${vms.length})`}</div></AccordionTrigger><AccordionContent className="px-6 pb-6">- <VMsCard vms={vms} />+ <VMsCard vms={vms} enhancedFeaturesEnabled={enhancedFeaturesEnabled} /></AccordionContent></AccordionItem>)}diff --git a/frontend/src/components/server/TrueNASApiKeyEmptyState.jsx b/frontend/src/components/server/TrueNASApiKeyEmptyState.jsxnew file mode 100644index 0000000..446feb4--- /dev/null+++ b/frontend/src/components/server/TrueNASApiKeyEmptyState.jsx@@ -0,0 +1,73 @@+import React, { useState } from "react";+import { Key, Server, Box, BarChart3 } from "lucide-react";+import { Button } from "@/components/ui/button";+import { TrueNASApiKeyModal } from "./TrueNASApiKeyModal";++/**+ * Empty state card shown when TrueNAS API key is not configured+ * Encourages users to add API key to unlock enhanced features+ */+export function TrueNASApiKeyEmptyState() {+ const [isModalOpen, setIsModalOpen] = useState(false);++ return (+ <>+ <div className="bg-gradient-to-br from-indigo-50 to-blue-50 dark:from-indigo-950/30 dark:to-blue-950/30 rounded-xl border-2 border-dashed border-indigo-200 dark:border-indigo-800/50 p-8">+ <div className="flex flex-col items-center text-center space-y-4">++ <div className="relative">+ <div className="absolute inset-0 bg-indigo-400/20 dark:bg-indigo-600/20 blur-xl rounded-full"></div>+ <div className="relative bg-white dark:bg-slate-800 rounded-full p-4 shadow-lg">+ <Key className="h-8 w-8 text-indigo-600 dark:text-indigo-400" />+ </div>+ </div>+++ <div className="space-y-2">+ <h3 className="text-lg font-semibold text-slate-900 dark:text-slate-100">+ Enhanced TrueNAS Features Available+ </h3>+ <p className="text-sm text-slate-600 dark:text-slate-400 max-w-md">+ Add a TrueNAS API key to unlock advanced monitoring capabilities+ </p>+ </div>+++ <div className="flex flex-col gap-2.5 w-full max-w-xs">+ <div className="flex items-center justify-center space-x-2 p-3 bg-white dark:bg-slate-800/50 rounded-lg border border-slate-200 dark:border-slate-700">+ <Server className="h-4 w-4 text-indigo-600 dark:text-indigo-400 flex-shrink-0" />+ <span className="text-xs font-medium text-slate-700 dark:text-slate-300">+ Virtual Machines+ </span>+ </div>+ <div className="flex items-center justify-center space-x-2 p-3 bg-white dark:bg-slate-800/50 rounded-lg border border-slate-200 dark:border-slate-700">+ <Box className="h-4 w-4 text-indigo-600 dark:text-indigo-400 flex-shrink-0" />+ <span className="text-xs font-medium text-slate-700 dark:text-slate-300">+ LXC Containers+ </span>+ </div>+ <div className="flex items-center justify-center space-x-2 p-3 bg-white dark:bg-slate-800/50 rounded-lg border border-slate-200 dark:border-slate-700">+ <BarChart3 className="h-4 w-4 text-indigo-600 dark:text-indigo-400 flex-shrink-0" />+ <span className="text-xs font-medium text-slate-700 dark:text-slate-300">+ Enhanced System Info+ </span>+ </div>+ </div>+++ <Button+ onClick={() => setIsModalOpen(true)}+ className="mt-2 bg-indigo-600 hover:bg-indigo-700 text-white dark:bg-indigo-500 dark:hover:bg-indigo-600"+ >+ Setup Guide+ </Button>+ </div>+ </div>++ <TrueNASApiKeyModal+ isOpen={isModalOpen}+ onClose={() => setIsModalOpen(false)}+ />+ </>+ );+}diff --git a/frontend/src/components/server/TrueNASApiKeyModal.jsx b/frontend/src/components/server/TrueNASApiKeyModal.jsxnew file mode 100644index 0000000..dceed31--- /dev/null+++ b/frontend/src/components/server/TrueNASApiKeyModal.jsx@@ -0,0 +1,159 @@+import React, { useState } from "react";+import {+ Dialog,+ DialogContent,+ DialogHeader,+ DialogTitle,+ DialogDescription,+} from "@/components/ui/dialog";+import { Button } from "@/components/ui/button";+import { Key, Check } from "lucide-react";++/**+ * Modal component that provides step-by-step instructions+ * for setting up TrueNAS API key to unlock enhanced features+ */+export function TrueNASApiKeyModal({ isOpen, onClose }) {+ const [copiedEnvVar, setCopiedEnvVar] = useState(false);++ const handleCopyEnvVar = () => {+ const text = "TRUENAS_API_KEY";++ if (navigator.clipboard && navigator.clipboard.writeText) {+ navigator.clipboard.writeText(text)+ .then(() => {+ setCopiedEnvVar(true);+ setTimeout(() => setCopiedEnvVar(false), 2000);+ })+ .catch((err) => {+ console.warn("Clipboard API failed, trying fallback", err);+ fallbackCopy(text);+ });+ } else {+ fallbackCopy(text);+ }+ };++ const fallbackCopy = (text) => {+ try {+ const textArea = document.createElement("textarea");+ textArea.value = text;+ textArea.style.position = "fixed";+ textArea.style.left = "-999999px";+ textArea.style.top = "-999999px";+ document.body.appendChild(textArea);+ textArea.focus();+ textArea.select();+ const successful = document.execCommand("copy");+ document.body.removeChild(textArea);++ if (successful) {+ setCopiedEnvVar(true);+ setTimeout(() => setCopiedEnvVar(false), 2000);+ }+ } catch (err) {+ console.error("All copy methods failed", err);+ }+ };++ const handleKeyDown = (e) => {+ if (e.key === "Escape") {+ onClose();+ }+ };++ return (+ <Dialog open={isOpen} onOpenChange={onClose}>+ <DialogContent+ className="sm:max-w-2xl max-h-[85vh] overflow-y-auto"+ onKeyDown={handleKeyDown}+ >+ <DialogHeader>+ <div className="flex items-center space-x-2">+ <Key className="h-5 w-5 text-indigo-600 dark:text-indigo-400" />+ <DialogTitle>Setup TrueNAS API Key</DialogTitle>+ </div>+ <DialogDescription>+ Enable VMs, LXC containers, and enhanced system information.+ </DialogDescription>+ </DialogHeader>++ <div className="space-y-5 py-4">++ <div className="space-y-2.5">+ <div className="flex items-center space-x-2">+ <div className="flex items-center justify-center w-6 h-6 rounded-full bg-indigo-100 dark:bg-indigo-900/50 text-indigo-700 dark:text-indigo-300 font-semibold text-xs">+ 1+ </div>+ <h3 className="font-semibold text-slate-900 dark:text-slate-100 text-sm">+ Generate API Key in TrueNAS+ </h3>+ </div>+ <div className="ml-8 text-sm text-slate-600 dark:text-slate-400 space-y-1.5">+ <div>Navigate to: <span className="font-mono text-xs bg-slate-100 dark:bg-slate-800 px-1.5 py-0.5 rounded">System Settings → API Keys</span></div>+ <div>Click <span className="font-semibold">Add</span>, give it a name, then copy the generated key</div>+ </div>+ </div>+++ <div className="space-y-2.5">+ <div className="flex items-center space-x-2">+ <div className="flex items-center justify-center w-6 h-6 rounded-full bg-indigo-100 dark:bg-indigo-900/50 text-indigo-700 dark:text-indigo-300 font-semibold text-xs">+ 2+ </div>+ <h3 className="font-semibold text-slate-900 dark:text-slate-100 text-sm">+ Add to portracker+ </h3>+ </div>+ <div className="ml-8 space-y-2.5">+ <div className="text-sm text-slate-600 dark:text-slate-400">+ <span className="font-semibold">Apps</span> → <span className="font-semibold">portracker</span> → <span className="font-semibold">Edit</span> → <span className="font-semibold">Environment Variables</span> → <span className="font-semibold">Add</span>+ </div>+ <div className="p-2.5 bg-slate-50 dark:bg-slate-800/50 rounded-lg border border-slate-200 dark:border-slate-700">+ <div className="space-y-1.5 text-xs">+ <div className="flex items-center justify-between">+ <span className="text-slate-500 dark:text-slate-400">Name:</span>+ <div+ onClick={handleCopyEnvVar}+ className="inline-flex items-center space-x-1.5 px-2 py-1 bg-white dark:bg-slate-700 border border-slate-200 dark:border-slate-600 rounded hover:bg-slate-50 dark:hover:bg-slate-600 transition-colors cursor-pointer"+ >+ <code className="font-mono text-xs text-slate-800 dark:text-slate-200 select-all">+ TRUENAS_API_KEY+ </code>+ {copiedEnvVar && (+ <Check className="h-3 w-3 text-green-600 dark:text-green-400 flex-shrink-0" />+ )}+ </div>+ </div>+ <div className="flex items-center justify-between">+ <span className="text-slate-500 dark:text-slate-400">Value:</span>+ <span className="text-slate-500 dark:text-slate-400 italic">[paste your key]</span>+ </div>+ </div>+ </div>+ <div className="text-xs text-slate-500 dark:text-slate-500 italic">+ Click <span className="font-semibold not-italic">Update</span> and wait for restart+ </div>+ </div>+ </div>+++ <div className="p-2.5 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg">+ <p className="text-xs text-blue-800 dark:text-blue-400">+ <span className="font-semibold">🔒 Secure:</span> API key is read-only. Refresh portracker UI to see VMs.+ </p>+ </div>+ </div>++ <div className="flex justify-end pt-2">+ <Button+ onClick={onClose}+ className="bg-indigo-600 hover:bg-indigo-700 text-white dark:bg-indigo-500 dark:hover:bg-indigo-600"+ >+ Got it+ </Button>+ </div>+ </DialogContent>+ </Dialog>+ );+}diff --git a/frontend/src/components/server/VMsCard.jsx b/frontend/src/components/server/VMsCard.jsxindex 04fdd84..9b04002 100644--- a/frontend/src/components/server/VMsCard.jsx+++ b/frontend/src/components/server/VMsCard.jsx@@ -1,5 +1,6 @@import { Server, Zap, HardDrive, Box } from "lucide-react";import { formatBytes } from "@/lib/utils";+import { TrueNASApiKeyEmptyState } from "./TrueNASApiKeyEmptyState";function VMItem({ vm }) {const status = typeof vm.status === 'string' ? vm.status : (vm.status?.state || 'unknown');@@ -54,7 +55,11 @@ function VMItem({ vm }) {);}-export function VMsCard({ vms }) {+export function VMsCard({ vms, enhancedFeaturesEnabled }) {+ if (enhancedFeaturesEnabled === false) {+ return <TrueNASApiKeyEmptyState />;+ }+if (!vms || vms.length === 0) return null;return (