From 9da341f84ccb032f3cab8823b31faea6a973f7f7 Mon Sep 17 00:00:00 2001 From: Muhammad Ibrahim Date: Fri, 14 Nov 2025 23:57:43 +0000 Subject: [PATCH] auto-enrolment enhancements --- agents/direct_host_auto_enroll.sh | 16 +- backend/src/routes/hostRoutes.js | 7 +- frontend/src/pages/settings/Integrations.jsx | 190 +++++++++---------- 3 files changed, 112 insertions(+), 101 deletions(-) diff --git a/agents/direct_host_auto_enroll.sh b/agents/direct_host_auto_enroll.sh index 17ece1e..5735f09 100755 --- a/agents/direct_host_auto_enroll.sh +++ b/agents/direct_host_auto_enroll.sh @@ -16,6 +16,9 @@ SCRIPT_VERSION="1.0.0" # Usage: # curl -s "https://patchmon.example.com/api/v1/auto-enrollment/script?type=direct-host&token_key=KEY&token_secret=SECRET" | sh # +# With custom friendly name: +# curl -s "https://patchmon.example.com/api/v1/auto-enrollment/script?type=direct-host&token_key=KEY&token_secret=SECRET" | FRIENDLY_NAME="My Server" sh +# # Requirements: # - Run as root or with sudo # - Auto-enrollment token from PatchMon @@ -28,6 +31,7 @@ AUTO_ENROLLMENT_KEY="${AUTO_ENROLLMENT_KEY:-}" AUTO_ENROLLMENT_SECRET="${AUTO_ENROLLMENT_SECRET:-}" CURL_FLAGS="${CURL_FLAGS:--s}" FORCE_INSTALL="${FORCE_INSTALL:-false}" +FRIENDLY_NAME="${FRIENDLY_NAME:-}" # Optional: Custom friendly name for the host # ===== COLOR OUTPUT ===== RED='\033[0;31m' @@ -77,7 +81,7 @@ fi # Check for required commands for cmd in curl; do - if ! command -v $cmd &> /dev/null; then + if ! command -v $cmd >/dev/null 2>&1; then error "Required command '$cmd' not found. Please install it first." fi done @@ -91,7 +95,14 @@ info "Gathering host information..." # Get hostname hostname=$(hostname) -friendly_name="$hostname" + +# Use FRIENDLY_NAME env var if provided, otherwise use hostname +if [ -n "$FRIENDLY_NAME" ]; then + friendly_name="$FRIENDLY_NAME" + info "Using custom friendly name: $friendly_name" +else + friendly_name="$hostname" +fi # Try to get machine_id (optional, for tracking) machine_id="" @@ -132,6 +143,7 @@ case "$arch_raw" in esac info "Hostname: $hostname" +info "Friendly Name: $friendly_name" info "IP Address: $ip_address" info "OS: $os_info" info "Architecture: $architecture" diff --git a/backend/src/routes/hostRoutes.js b/backend/src/routes/hostRoutes.js index 6e09e21..618c783 100644 --- a/backend/src/routes/hostRoutes.js +++ b/backend/src/routes/hostRoutes.js @@ -551,8 +551,11 @@ router.post( updated_at: new Date(), }; - // Update machine_id if provided and current one is a placeholder - if (req.body.machineId && host.machine_id.startsWith("pending-")) { + // Update machine_id if provided and current one is a placeholder or null + if ( + req.body.machineId && + (host.machine_id === null || host.machine_id.startsWith("pending-")) + ) { updateData.machine_id = req.body.machineId; } diff --git a/frontend/src/pages/settings/Integrations.jsx b/frontend/src/pages/settings/Integrations.jsx index 87f0220..3940645 100644 --- a/frontend/src/pages/settings/Integrations.jsx +++ b/frontend/src/pages/settings/Integrations.jsx @@ -35,6 +35,8 @@ const Integrations = () => { const [server_url, setServerUrl] = useState(""); const [force_proxmox_install, setForceProxmoxInstall] = useState(false); const [usage_type, setUsageType] = useState("proxmox-lxc"); + const [selected_script_type, setSelectedScriptType] = useState("proxmox-lxc"); + const [curl_flags, setCurlFlags] = useState("-s"); // Form state const [form_data, setFormData] = useState({ @@ -50,14 +52,9 @@ const Integrations = () => { const [copy_success, setCopySuccess] = useState({}); - // Helper functions to build enrollment URLs with optional force flag - const getProxmoxUrl = () => { - const baseUrl = `${server_url}/api/v1/auto-enrollment/script?type=proxmox-lxc&token_key=${new_token.token_key}&token_secret=${new_token.token_secret}`; - return force_proxmox_install ? `${baseUrl}&force=true` : baseUrl; - }; - - const getDirectHostUrl = () => { - const baseUrl = `${server_url}/api/v1/auto-enrollment/script?type=direct-host&token_key=${new_token.token_key}&token_secret=${new_token.token_secret}`; + // Helper function to build enrollment URL with optional force flag and selected type + const getEnrollmentUrl = (scriptType = selected_script_type) => { + const baseUrl = `${server_url}/api/v1/auto-enrollment/script?type=${scriptType}&token_key=${new_token.token_key}&token_secret=${new_token.token_secret}`; return force_proxmox_install ? `${baseUrl}&force=true` : baseUrl; }; @@ -116,9 +113,12 @@ const Integrations = () => { try { const response = await api.get("/settings"); setServerUrl(response.data.server_url || window.location.origin); + // Set curl flags based on SSL settings + setCurlFlags(response.data.ignore_ssl_self_signed ? "-sk" : "-s"); } catch (error) { console.error("Failed to load server URL:", error); setServerUrl(window.location.origin); + setCurlFlags("-s"); } }; @@ -599,12 +599,12 @@ const Integrations = () => {

- Proxmox LXC Auto-Enrollment + Auto-enrollment

- Automatically discover and enroll LXC containers from - Proxmox hosts. + Automatically discover and enroll hosts from Proxmox or + direct enrollment.

{

- API Credentials + Scoped credentials

- Programmatic access to PatchMon data using Basic - Authentication. + Programmatic access to PatchMon data with granular + scope-based permissions.

{
-
+

{activeTab === "gethomepage" ? "Create GetHomepage API Key" @@ -1060,6 +1060,7 @@ const Integrations = () => { onClick={() => { setShowCreateModal(false); setUsageType("proxmox-lxc"); + setSelectedScriptType("proxmox-lxc"); }} className="text-secondary-400 hover:text-secondary-600 dark:hover:text-secondary-200" > @@ -1067,28 +1068,35 @@ const Integrations = () => {

-
- {activeTab === "auto-enrollment" && ( - - )} + {/* Tabs for Auto-enrollment modal */} + {activeTab === "auto-enrollment" && ( +
+ + +
+ )} +
- )} - {(new_token.metadata?.integration_type === "proxmox-lxc" || - usage_type === "proxmox-lxc") && ( -
-
- Direct Host Auto-Enrollment Command -
-

- Run this command on individual hosts to enroll them - directly: -

- -
- - -
-

- 💡 Run this on individual hosts for easy enrollment - without Proxmox. -

+ {/* Usage hint for direct-host */} + {selected_script_type === "direct-host" && ( +

+ 💡 Tip: Specify a custom name:{" "} + + FRIENDLY_NAME="My Server" sh + +

+ )}
)} @@ -1765,6 +1760,7 @@ const Integrations = () => { setNewToken(null); setShowSecret(false); setUsageType("proxmox-lxc"); + setSelectedScriptType("proxmox-lxc"); }} className="w-full btn-primary py-2 px-4 rounded-md" >