diff --git a/agents/patchmon_install.sh b/agents/patchmon_install.sh index 315f117..c41ba0b 100644 --- a/agents/patchmon_install.sh +++ b/agents/patchmon_install.sh @@ -311,6 +311,37 @@ else mkdir -p /etc/patchmon fi +# Check if agent is already configured and working (before we overwrite anything) +info "๐ Checking if agent is already configured..." + +if [[ -f /etc/patchmon/config.yml ]] && [[ -f /etc/patchmon/credentials.yml ]]; then + if [[ -f /usr/local/bin/patchmon-agent ]]; then + info "๐ Found existing agent configuration" + info "๐งช Testing existing configuration with ping..." + + if /usr/local/bin/patchmon-agent ping >/dev/null 2>&1; then + success "โ Agent is already configured and ping successful" + info "๐ Existing configuration is working - skipping installation" + info "" + info "If you want to reinstall, remove the configuration files first:" + info " sudo rm -f /etc/patchmon/config.yml /etc/patchmon/credentials.yml" + echo "" + exit 0 + else + warning "โ ๏ธ Agent configuration exists but ping failed" + warning "โ ๏ธ Will move existing configuration and reinstall" + echo "" + fi + else + warning "โ ๏ธ Configuration files exist but agent binary is missing" + warning "โ ๏ธ Will move existing configuration and reinstall" + echo "" + fi +else + success "โ Agent not yet configured - proceeding with installation" + echo "" +fi + # Step 2: Create configuration files info "๐ Creating configuration files..." @@ -426,33 +457,6 @@ if [[ -f "/etc/patchmon/logs/patchmon-agent.log" ]]; then fi # Step 4: Test the configuration -# Check if this machine is already enrolled -info "๐ Checking if machine is already enrolled..." -existing_check=$(curl $CURL_FLAGS -s -X POST \ - -H "X-API-ID: $API_ID" \ - -H "X-API-KEY: $API_KEY" \ - -H "Content-Type: application/json" \ - -d "{\"machine_id\": \"$MACHINE_ID\"}" \ - "$PATCHMON_URL/api/v1/hosts/check-machine-id" \ - -w "\n%{http_code}" 2>&1) - -http_code=$(echo "$existing_check" | tail -n 1) -response_body=$(echo "$existing_check" | sed '$d') - -if [[ "$http_code" == "200" ]]; then - already_enrolled=$(echo "$response_body" | jq -r '.exists' 2>/dev/null || echo "false") - if [[ "$already_enrolled" == "true" ]]; then - warning "โ ๏ธ This machine is already enrolled in PatchMon" - info "Machine ID: $MACHINE_ID" - info "Existing host: $(echo "$response_body" | jq -r '.host.friendly_name' 2>/dev/null)" - info "" - info "The agent will be reinstalled/updated with existing credentials." - echo "" - else - success "โ Machine not yet enrolled - proceeding with installation" - fi -fi - info "๐งช Testing API credentials and connectivity..." if /usr/local/bin/patchmon-agent ping; then success "โ TEST: API credentials are valid and server is reachable" diff --git a/agents/proxmox_auto_enroll.sh b/agents/proxmox_auto_enroll.sh index 01c4158..04516f4 100755 --- a/agents/proxmox_auto_enroll.sh +++ b/agents/proxmox_auto_enroll.sh @@ -230,6 +230,40 @@ while IFS= read -r line; do info " โ Host enrolled successfully: $api_id" + # Check if agent is already installed and working + info " Checking if agent is already configured..." + config_check=$(timeout 10 pct exec "$vmid" -- bash -c " + if [[ -f /etc/patchmon/config.yml ]] && [[ -f /etc/patchmon/credentials.yml ]]; then + if [[ -f /usr/local/bin/patchmon-agent ]]; then + # Try to ping using existing configuration + if /usr/local/bin/patchmon-agent ping >/dev/null 2>&1; then + echo 'ping_success' + else + echo 'ping_failed' + fi + else + echo 'binary_missing' + fi + else + echo 'not_configured' + fi + " 2>/dev/null /dev/null 2>&1 && echo 'installed' || echo 'missing'" 2>/dev/null { try { @@ -71,7 +76,11 @@ router.post( return res.status(400).json({ errors: errors.array() }); } - const { token } = req.body; + // Ensure token is a string (convert if needed) + let { token } = req.body; + if (typeof token !== "string") { + token = String(token); + } const userId = req.user.id; // Get user's TFA secret diff --git a/frontend/src/pages/Repositories.jsx b/frontend/src/pages/Repositories.jsx index 5bcf845..77d0300 100644 --- a/frontend/src/pages/Repositories.jsx +++ b/frontend/src/pages/Repositories.jsx @@ -237,8 +237,14 @@ const Repositories = () => { // Handle special cases if (sortField === "security") { - aValue = a.isSecure ? "Secure" : "Insecure"; - bValue = b.isSecure ? "Secure" : "Insecure"; + // Use the same logic as filtering to determine isSecure + const aIsSecure = + a.isSecure !== undefined ? a.isSecure : a.url.startsWith("https://"); + const bIsSecure = + b.isSecure !== undefined ? b.isSecure : b.url.startsWith("https://"); + // Sort by boolean: true (Secure) comes before false (Insecure) when ascending + aValue = aIsSecure ? 1 : 0; + bValue = bIsSecure ? 1 : 0; } else if (sortField === "status") { aValue = a.is_active ? "Active" : "Inactive"; bValue = b.is_active ? "Active" : "Inactive"; @@ -535,12 +541,12 @@ const Repositories = () => { {visibleColumns.map((column) => (