From 42f6971da7840a68db1fd08da4d6548066cf5b82 Mon Sep 17 00:00:00 2001 From: tigattack <10629864+tigattack@users.noreply.github.com> Date: Thu, 25 Sep 2025 01:07:11 +0100 Subject: [PATCH] fix(frontend): variable unused --- frontend/src/pages/Hosts.jsx | 563 ----------------------------------- 1 file changed, 563 deletions(-) diff --git a/frontend/src/pages/Hosts.jsx b/frontend/src/pages/Hosts.jsx index 3a5e49d..a2f2c8c 100644 --- a/frontend/src/pages/Hosts.jsx +++ b/frontend/src/pages/Hosts.jsx @@ -9,11 +9,8 @@ import { ChevronDown, Clock, Columns, - Copy, ExternalLink, - Eye, Eye as EyeIcon, - EyeOff, EyeOff as EyeOffIcon, Filter, GripVertical, @@ -35,7 +32,6 @@ import { dashboardAPI, formatRelativeTime, hostGroupsAPI, - settingsAPI, } from "../utils/api"; import { OSIcon } from "../utils/osIcons.jsx"; @@ -232,565 +228,6 @@ const AddHostModal = ({ isOpen, onClose, onSuccess }) => { ); }; -// Credentials Modal Component -const CredentialsModal = ({ host, isOpen, onClose }) => { - const apiIdId = useId(); - const apiKeyId = useId(); - const [showApiKey, setShowApiKey] = useState(false); - const [activeTab, setActiveTab] = useState( - host?.isNewHost ? "quick" : "credentials", - ); - - // Update active tab when host changes - React.useEffect(() => { - if (host?.isNewHost) { - setActiveTab("quick"); - } else { - setActiveTab("credentials"); - } - }, [host?.isNewHost]); - - const copyToClipboard = async (text, label) => { - try { - // Try modern clipboard API first - if (navigator.clipboard && window.isSecureContext) { - await navigator.clipboard.writeText(text); - alert(`${label} copied to clipboard!`); - return; - } - - // Fallback for older browsers or non-secure contexts - 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(); - - try { - const successful = document.execCommand("copy"); - if (successful) { - alert(`${label} copied to clipboard!`); - } else { - throw new Error("Copy command failed"); - } - } catch { - // If all else fails, show the text in a prompt - prompt(`Copy this ${label.toLowerCase()}:`, text); - } finally { - document.body.removeChild(textArea); - } - } catch (err) { - console.error("Failed to copy to clipboard:", err); - // Show the text in a prompt as last resort - prompt(`Copy this ${label.toLowerCase()}:`, text); - } - }; - - // Fetch server URL from settings - const { data: settings } = useQuery({ - queryKey: ["settings"], - queryFn: () => settingsAPI.get().then((res) => res.data), - enabled: isOpen, // Only fetch when modal is open - }); - - const serverUrl = - settings?.server_url || window.location.origin.replace(":3000", ":3001"); - - const getSetupCommands = () => { - // Get current time for crontab scheduling - const now = new Date(); - const currentMinute = now.getMinutes(); - const currentHour = now.getHours(); - - return { - oneLine: `curl -sSL ${serverUrl}/api/v1/hosts/install | bash -s -- ${serverUrl} "${host?.api_id}" "${host?.api_key}"`, - - download: `# Download and setup PatchMon agent -curl -o /tmp/patchmon-agent.sh ${serverUrl}/api/v1/hosts/agent/download -sudo mkdir -p /etc/patchmon -sudo mv /tmp/patchmon-agent.sh /usr/local/bin/patchmon-agent.sh -sudo chmod +x /usr/local/bin/patchmon-agent.sh`, - - configure: `# Configure API credentials -sudo /usr/local/bin/patchmon-agent.sh configure "${host?.api_id}" "${host?.api_key}"`, - - test: `# Test the configuration -sudo /usr/local/bin/patchmon-agent.sh test`, - - initialUpdate: `# Send initial package data -sudo /usr/local/bin/patchmon-agent.sh update`, - - crontab: `# Add to crontab for hourly updates starting at current time (run as root) -echo "${currentMinute} * * * * /usr/local/bin/patchmon-agent.sh update >/dev/null 2>&1" | sudo crontab -`, - - fullSetup: `#!/bin/bash -# Complete PatchMon Agent Setup Script -# Run this on the target host: ${host?.friendly_name} - -echo "๐Ÿ”„ Setting up PatchMon agent..." - -# Download and install agent -echo "๐Ÿ“ฅ Downloading agent script..." -curl -o /tmp/patchmon-agent.sh ${serverUrl}/api/v1/hosts/agent/download -sudo mkdir -p /etc/patchmon -sudo mv /tmp/patchmon-agent.sh /usr/local/bin/patchmon-agent.sh -sudo chmod +x /usr/local/bin/patchmon-agent.sh - -# Configure credentials -echo "๐Ÿ”‘ Configuring API credentials..." -sudo /usr/local/bin/patchmon-agent.sh configure "${host?.api_id}" "${host?.api_key}" - -# Test configuration -echo "๐Ÿงช Testing configuration..." -sudo /usr/local/bin/patchmon-agent.sh test - -# Send initial update -echo "๐Ÿ“Š Sending initial package data..." -sudo /usr/local/bin/patchmon-agent.sh update - -# Setup crontab starting at current time -echo "โฐ Setting up hourly crontab starting at ${currentHour.toString().padStart(2, "0")}:${currentMinute.toString().padStart(2, "0")}..." -echo "${currentMinute} * * * * /usr/local/bin/patchmon-agent.sh update >/dev/null 2>&1" | sudo crontab - - -echo "โœ… PatchMon agent setup complete!" -echo " - Agent installed: /usr/local/bin/patchmon-agent.sh" -echo " - Config directory: /etc/patchmon/" -echo " - Updates: Every hour via crontab (starting at ${currentHour.toString().padStart(2, "0")}:${currentMinute.toString().padStart(2, "0")})" -echo " - View logs: tail -f /var/log/patchmon-agent.log"`, - }; - }; - - if (!isOpen || !host) return null; - - const commands = getSetupCommands(); - - return ( -
-
-
-

- Host Setup - {host.friendly_name} -

- -
- - {/* Tabs */} -
- - - - -
- - {/* Tab Content */} - {activeTab === "quick" && ( -
-
-

- ๐Ÿš€ One-Line Installation -

-

- Copy and paste this single command on{" "} - {host.friendly_name} to install and configure - the PatchMon agent automatically. -

-
- -
-
- Installation Command -
-
-
- - {commands.oneLine} - - -
-
-

- This command will download, install, configure, and set up - automatic updates for the PatchMon agent. -

-
- -
-

- ๐Ÿ“‹ What This Command Does -

-
    -
  • โ€ข Downloads the PatchMon installation script
  • -
  • - โ€ข Installs the agent to{" "} - /usr/local/bin/patchmon-agent.sh -
  • -
  • - โ€ข Configures API credentials for{" "} - {host.friendly_name} -
  • -
  • โ€ข Tests the connection to PatchMon server
  • -
  • โ€ข Sends initial package data
  • -
  • โ€ข Sets up hourly automatic updates via crontab
  • -
-
- -
-

- โš ๏ธ Requirements -

-
    -
  • - โ€ข Must be run as root (use sudo) -
  • -
  • โ€ข Requires internet connection to download agent
  • -
  • - โ€ข Requires curl and bash to be - installed -
  • -
  • โ€ข Host must be able to reach the PatchMon server
  • -
-
-
- )} - - {activeTab === "credentials" && ( -
-
- -
- - -
-
- -
- -
- - - -
-
- -
-

- โš ๏ธ Security Note -

-

- Keep these credentials secure. They provide access to update - package information for {host.friendly_name}{" "} - only. -

-
-
- )} - - {activeTab === "setup" && ( -
-
-

- ๐Ÿ“‹ Step-by-Step Setup -

-

- Follow these commands on {host.friendly_name}{" "} - to install and configure the PatchMon agent. -

-
- - {/* Step 1: Download & Install */} -
-
- Step 1: Download & Install Agent -
-
-
- - {commands.download} - - -
-
-
- - {/* Step 2: Configure */} -
-
- Step 2: Configure API Credentials -
-
-
- {commands.configure} - -
-
-
- - {/* Step 3: Test */} -
-
- Step 3: Test Configuration -
-
-
- {commands.test} - -
-
-
- - {/* Step 4: Initial Update */} -
-
- Step 4: Send Initial Package Data -
-

- This will automatically detect and send system information (OS, - IP, architecture) along with package data. -

-
-
- {commands.initialUpdate} - -
-
-
- - {/* Step 5: Crontab */} -
-
- Step 5: Setup Hourly Updates -
-
-
- {commands.crontab} - -
-
-

- This sets up automatic package updates every hour at the top of - the hour. -

-
-
- )} - - {activeTab === "script" && ( -
-
-

- ๐Ÿš€ Automated Setup -

-

- Copy this complete setup script to{" "} - {host.friendly_name} and run it to - automatically install and configure everything. -

-
- -
-
-
- Complete Setup Script -
- -
-
-
{commands.fullSetup}
-
-
-

- Usage: -

-

1. Copy the script above

-

- 2. Save it to a file on {host.friendly_name} (e.g.,{" "} - setup-patchmon.sh) -

-

- 3. Run:{" "} - - chmod +x setup-patchmon.sh && sudo ./setup-patchmon.sh - -

-
-
-
- )} - -
- - Download Agent Script - - -
-
-
- ); -}; - const Hosts = () => { const hostGroupFilterId = useId(); const statusFilterId = useId();