Skip to content

An open source, self-hosted, real-time port monitoring and discovery tool.

fix: priortize https connection for TrueNAS API key, correct VMs card to include both VMs and LXC containers.

Mostafa Wahiedf5573c5ec794
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ef1fd86..47c04d5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,6 @@
# Changelog
-All notable changes to Portracker will be documented in this file.
+All notable changes to portracker will be documented in this file.
## [1.1.0] - 2025-08-23
diff --git a/backend/collectors/truenas_collector.js b/backend/collectors/truenas_collector.js
index 46de30e..49b6eeb 100644
--- a/backend/collectors/truenas_collector.js
+++ b/backend/collectors/truenas_collector.js
@@ -1217,7 +1217,27 @@ class TrueNASCollector extends BaseCollector {
this.log(`Collected ${truenasApps.length} TrueNAS native apps`);
}
if (enhancedData.vms && enhancedData.vms.length > 0) {
- results.vms = enhancedData.vms.map((vm) => ({
+ const realVMs = enhancedData.vms.map((vm) => ({
+ type: "vm",
+ id: vm.id,
+ name: vm.name,
+ status: vm.status,
+ vcpus: vm.vcpus,
+ memory: vm.memory,
+ autostart: vm.autostart,
+ platform: "truenas",
+ platform_data: {
+ vnc_enabled: vm.vnc_enabled,
+ vnc_port: vm.vnc_port,
+ devices: vm.devices || [],
+ orig_data: vm,
+ },
+ }));
+ results.vms.push(...realVMs);
+ this.log(`Collected ${realVMs.length} TrueNAS virtual machines`);
+ }
+ if (enhancedData.containers && enhancedData.containers.length > 0) {
+ const lxcContainers = enhancedData.containers.map((vm) => ({
type: "vm",
id: vm.id,
name: vm.name,
@@ -1227,6 +1247,7 @@ class TrueNASCollector extends BaseCollector {
autostart: vm.autostart,
platform: "truenas",
platform_data: {
+ container_type: "lxc",
aliases: vm.aliases,
image: vm.image,
os: vm.image?.os || "unknown",
@@ -1235,7 +1256,8 @@ class TrueNASCollector extends BaseCollector {
orig_data: vm,
},
}));
- this.log(`Collected ${results.vms.length} virtual machines`);
+ results.vms.push(...lxcContainers);
+ this.log(`Collected ${lxcContainers.length} TrueNAS LXC containers`);
}
this.logInfo("Enhanced features collection completed successfully");
} catch (err) {
@@ -1766,11 +1788,17 @@ class TrueNASCollector extends BaseCollector {
);
}
try {
- const vms = await this.client.call("virt.instance.query");
+ const vms = await this.client.call("vm.query");
results.vms = vms || [];
} catch (err) {
this.logWarn("VM API query failed:", err.message.substring(0, 50));
}
+ try {
+ const containers = await this.client.call("virt.instance.query");
+ results.containers = containers || [];
+ } catch (err) {
+ this.logWarn("LXC Container API query failed:", err.message.substring(0, 50));
+ }
} catch (err) {
this.logError(
"Overall enhanced features collection failed:",
diff --git a/backend/index.js b/backend/index.js
index 33b9cad..5707e2f 100644
--- a/backend/index.js
+++ b/backend/index.js
@@ -625,7 +625,7 @@ app.get("/api/ports", async (req, res) => {
* New peer-based endpoint to replace remote API connectivity.
*/
app.get("/api/all-ports", async (req, res) => {
- const debug = req.query.debug === "true";
+ const debug = req.query.debug === "true" || process.env.DEBUG === 'true';
if (Object.prototype.hasOwnProperty.call(req.query, 'debug')) logger.setDebugEnabled(debug);
logger.debug(`GET /api/all-ports called with debug=${debug}`);
@@ -699,7 +699,7 @@ async function getLocalPortsUsingCollectors(options = {}) {
*/
app.get("/api/servers/:id/scan", async (req, res) => {
const serverId = req.params.id;
- const currentDebug = req.query.debug === "true";
+ const currentDebug = req.query.debug === "true" || process.env.DEBUG === 'true';
if (Object.prototype.hasOwnProperty.call(req.query, 'debug')) logger.setDebugEnabled(currentDebug);
diff --git a/backend/lib/tn-ws.js b/backend/lib/tn-ws.js
index 093f54a..ebad654 100644
--- a/backend/lib/tn-ws.js
+++ b/backend/lib/tn-ws.js
@@ -20,9 +20,10 @@ function debugWS(message, ...args) {
* Get TrueNAS WebSocket URLs to try
* @param {object} options - Options object
* @param {boolean} options.appDebugEnabled - Whether application-level debug is enabled
+ * @param {boolean} options.requireSecure - Whether to prioritize secure connections (for API key usage)
*/
async function getTrueNASWebSocketURLs(options = {}) {
- const { appDebugEnabled = false } = options;
+ const { appDebugEnabled = false, requireSecure = false } = options;
try {
if (appDebugEnabled) {
debugWS("Attempting to auto-discover TrueNAS UI configuration...");
@@ -39,7 +40,7 @@ async function getTrueNASWebSocketURLs(options = {}) {
}
}
- const urls = generateWebSocketURLs(uiConfig, { appDebugEnabled });
+ const urls = generateWebSocketURLs(uiConfig, { appDebugEnabled, requireSecure });
if (appDebugEnabled) {
debugWS(`Will try ${urls.length} WebSocket URLs: ${urls.join(", ")}`);
}
@@ -51,7 +52,7 @@ async function getTrueNASWebSocketURLs(options = {}) {
`Error during auto-discovery: ${err.message}, using fallback URLs`
);
}
- return generateWebSocketURLs(null, { appDebugEnabled });
+ return generateWebSocketURLs(null, { appDebugEnabled, requireSecure });
}
}
@@ -77,7 +78,7 @@ async function connectWs(options = {}) {
throw new Error("No API key provided for WebSocket authentication");
}
- const urls = await getTrueNASWebSocketURLs({ appDebugEnabled, host, port });
+ const urls = await getTrueNASWebSocketURLs({ appDebugEnabled, host, port, requireSecure: true });
let ws,
i = 0;
let pingInterval = null;
diff --git a/backend/lib/truenas-auto-discover.js b/backend/lib/truenas-auto-discover.js
index 0df7308..e81df59 100644
--- a/backend/lib/truenas-auto-discover.js
+++ b/backend/lib/truenas-auto-discover.js
@@ -237,10 +237,11 @@ function detectHostAddresses() {
* @param {Object|null} uiConfig Discovered UI configuration
* @param {object} [options={}] - Options object
* @param {boolean} [options.appDebugEnabled=false] - Whether application-level debug is enabled
+ * @param {boolean} [options.requireSecure=false] - Whether to prioritize secure connections (wss) over insecure (ws)
* @returns {Array<string>} Array of WebSocket URLs to try
*/
function generateWebSocketURLs(uiConfig = null, options = {}) {
- const { appDebugEnabled = false } = options;
+ const { appDebugEnabled = false, requireSecure = false } = options;
const urls = [];
const explicitBase = process.env.TRUENAS_WS_BASE;
@@ -264,20 +265,42 @@ function generateWebSocketURLs(uiConfig = null, options = {}) {
uiConfig
);
}
- for (const host of hostAddresses) {
- if (uiConfig.httpsEnabled && uiConfig.httpsPort) {
- const url = `wss://${host}:${uiConfig.httpsPort}/websocket`;
- urls.push(url);
- if (appDebugEnabled) {
- debugDiscovery(`Added discovered HTTPS WebSocket: ${url}`);
+
+ if (requireSecure) {
+ for (const host of hostAddresses) {
+ if (uiConfig.httpsEnabled && uiConfig.httpsPort) {
+ const url = `wss://${host}:${uiConfig.httpsPort}/websocket`;
+ urls.push(url);
+ if (appDebugEnabled) {
+ debugDiscovery(`Added discovered HTTPS WebSocket (secure): ${url}`);
+ }
}
}
+ for (const host of hostAddresses) {
+ if (uiConfig.httpPort) {
+ const url = `ws://${host}:${uiConfig.httpPort}/websocket`;
+ urls.push(url);
+ if (appDebugEnabled) {
+ debugDiscovery(`Added discovered HTTP WebSocket (fallback): ${url}`);
+ }
+ }
+ }
+ } else {
+ for (const host of hostAddresses) {
+ if (uiConfig.httpsEnabled && uiConfig.httpsPort) {
+ const url = `wss://${host}:${uiConfig.httpsPort}/websocket`;
+ urls.push(url);
+ if (appDebugEnabled) {
+ debugDiscovery(`Added discovered HTTPS WebSocket: ${url}`);
+ }
+ }
- if (uiConfig.httpPort) {
- const url = `ws://${host}:${uiConfig.httpPort}/websocket`;
- urls.push(url);
- if (appDebugEnabled) {
- debugDiscovery(`Added discovered HTTP WebSocket: ${url}`);
+ if (uiConfig.httpPort) {
+ const url = `ws://${host}:${uiConfig.httpPort}/websocket`;
+ urls.push(url);
+ if (appDebugEnabled) {
+ debugDiscovery(`Added discovered HTTP WebSocket: ${url}`);
+ }
}
}
}
@@ -287,7 +310,13 @@ function generateWebSocketURLs(uiConfig = null, options = {}) {
if (appDebugEnabled) {
debugDiscovery("No UI config discovered, using generic fallback ports");
}
- const commonPorts = [
+
+ const commonPorts = requireSecure ? [
+ { port: 443, protocol: "wss" },
+ { port: 8443, protocol: "wss" },
+ { port: 80, protocol: "ws" },
+ { port: 8080, protocol: "ws" },
+ ] : [
{ port: 443, protocol: "wss" },
{ port: 80, protocol: "ws" },
{ port: 8443, protocol: "wss" },
diff --git a/frontend/src/components/server/VMsCard.jsx b/frontend/src/components/server/VMsCard.jsx
index f5dcf40..04fdd84 100644
--- a/frontend/src/components/server/VMsCard.jsx
+++ b/frontend/src/components/server/VMsCard.jsx
@@ -1,9 +1,11 @@
-import { Server, Zap, HardDrive } from "lucide-react";
+import { Server, Zap, HardDrive, Box } from "lucide-react";
import { formatBytes } from "@/lib/utils";
function VMItem({ vm }) {
- const isRunning = vm.status && vm.status.toLowerCase() === "running";
+ const status = typeof vm.status === 'string' ? vm.status : (vm.status?.state || 'unknown');
+ const isRunning = status.toLowerCase() === "running";
const statusColor = isRunning ? "bg-green-500" : "bg-red-500";
+ const isLXC = vm.platform_data?.container_type === "lxc";
return (
<div className="border border-slate-200 dark:border-slate-700 rounded-lg p-4 hover:shadow-md transition-all duration-200 hover:border-slate-300 dark:hover:border-slate-600">
@@ -11,14 +13,25 @@ function VMItem({ vm }) {
<div className="flex items-center space-x-3">
<div className="flex items-center space-x-2">
<span className={`w-2.5 h-2.5 rounded-full ${statusColor}`}></span>
- <Server className="h-6 w-6 text-slate-500 dark:text-slate-400" />
+ {isLXC ? (
+ <Box className="h-6 w-6 text-slate-500 dark:text-slate-400" />
+ ) : (
+ <Server className="h-6 w-6 text-slate-500 dark:text-slate-400" />
+ )}
</div>
<div>
- <h4 className="font-medium text-sm text-slate-900 dark:text-slate-100">
- {vm.name}
- </h4>
+ <div className="flex items-center space-x-2">
+ <h4 className="font-medium text-sm text-slate-900 dark:text-slate-100">
+ {vm.name}
+ </h4>
+ {isLXC && (
+ <span className="inline-flex items-center px-1.5 py-0.5 bg-slate-100 dark:bg-slate-700 text-slate-600 dark:text-slate-300 rounded text-[10px] font-medium uppercase tracking-wide">
+ LXC
+ </span>
+ )}
+ </div>
<p className="text-xs text-slate-500 dark:text-slate-400 capitalize">
- {vm.status || "Unknown"}
+ {status}
</p>
</div>
</div>