Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
Made-with: Cursor
160 lines
8.2 KiB
Bash
Executable File
160 lines
8.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Get all NPMplus proxy host mappings with VMID, Service, IP, Port, and FQDN
|
|
|
|
set -euo pipefail
|
|
|
|
# Load IP configuration
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
|
|
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
|
|
cd "$PROJECT_ROOT"
|
|
|
|
# Source .env
|
|
if [ -f .env ]; then
|
|
set +euo pipefail
|
|
source .env 2>/dev/null || true
|
|
set -euo pipefail
|
|
fi
|
|
|
|
NPM_URL="${NPM_URL:-https://${IP_NPMPLUS_ETH0:-192.168.11.166}:81}"
|
|
NPM_EMAIL="${NPM_EMAIL:-nsatoshi2007@hotmail.com}"
|
|
NPM_PASSWORD="${NPM_PASSWORD:-}"
|
|
|
|
if [ -z "$NPM_PASSWORD" ]; then
|
|
echo "Error: NPM_PASSWORD not set in .env"
|
|
exit 1
|
|
fi
|
|
|
|
# Authenticate
|
|
TOKEN_RESPONSE=$(curl -s -k -X POST "$NPM_URL/api/tokens" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"identity\":\"$NPM_EMAIL\",\"secret\":\"$NPM_PASSWORD\"}")
|
|
|
|
TOKEN=$(echo "$TOKEN_RESPONSE" | jq -r '.token // empty' 2>/dev/null || echo "")
|
|
|
|
if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ]; then
|
|
echo "Error: Authentication failed"
|
|
exit 1
|
|
fi
|
|
|
|
# Get proxy hosts
|
|
PROXY_HOSTS=$(curl -s -k -X GET "$NPM_URL/api/nginx/proxy-hosts" \
|
|
-H "Authorization: Bearer $TOKEN")
|
|
|
|
# Create IP to VMID mapping from ALL_VMIDS_ENDPOINTS.md
|
|
# This is a simplified mapping - you may need to enhance this
|
|
declare -A IP_TO_VMID
|
|
IP_TO_VMID["${IP_VALIDATOR_0:-${IP_VALIDATOR_0:-${IP_VALIDATOR_0:-${IP_VALIDATOR_0:-192.168.11.100}}}}"]="1000"
|
|
IP_TO_VMID["${IP_VALIDATOR_1:-${IP_VALIDATOR_1:-${IP_VALIDATOR_1:-${IP_VALIDATOR_1:-192.168.11.101}}}}"]="1001"
|
|
IP_TO_VMID["${IP_VALIDATOR_2:-${IP_VALIDATOR_2:-${IP_VALIDATOR_2:-${IP_VALIDATOR_2:-192.168.11.102}}}}"]="1002"
|
|
IP_TO_VMID["${IP_VALIDATOR_3:-${IP_VALIDATOR_3:-${IP_VALIDATOR_3:-${IP_VALIDATOR_3:-192.168.11.103}}}}"]="1003"
|
|
IP_TO_VMID["${IP_VALIDATOR_4:-${IP_VALIDATOR_4:-${IP_VALIDATOR_4:-${IP_VALIDATOR_4:-192.168.11.104}}}}"]="1004"
|
|
IP_TO_VMID["${IP_BESU_RPC_0:-${IP_BESU_RPC_0:-${IP_BESU_RPC_0:-${IP_BESU_RPC_0:-192.168.11.150}}}}"]="1500"
|
|
IP_TO_VMID["${IP_BESU_RPC_1:-${IP_BESU_RPC_1:-${IP_BESU_RPC_1:-${IP_BESU_RPC_1:-192.168.11.151}}}}"]="1501"
|
|
IP_TO_VMID["${IP_BESU_RPC_2:-${IP_BESU_RPC_2:-${IP_BESU_RPC_2:-${IP_BESU_RPC_2:-192.168.11.152}}}}"]="1502"
|
|
IP_TO_VMID["${IP_BESU_RPC_3:-${IP_BESU_RPC_3:-${IP_BESU_RPC_3:-${IP_BESU_RPC_3:-192.168.11.153}}}}"]="1503"
|
|
IP_TO_VMID["${IP_BESU_SENTRY:-192.168.11.154}"]="1504"
|
|
IP_TO_VMID["${RPC_CORE_1:-${IP_SERVICE_21:-${IP_SERVICE_21:-${IP_SERVICE_21:-192.168.11.21}}}1}"]="2101"
|
|
IP_TO_VMID["${RPC_PUBLIC_1:-192.168.11.221}"]="2201"
|
|
IP_TO_VMID["${RPC_PRIVATE_1:-192.168.11.232}"]="2301"
|
|
IP_TO_VMID["${RPC_NODE_233:-${RPC_NODE_233:-${RPC_NODE_233:-${RPC_NODE_233:-192.168.11.233}}}}"]="2303"
|
|
IP_TO_VMID["${RPC_NODE_234:-${RPC_NODE_234:-${RPC_NODE_234:-${RPC_NODE_234:-192.168.11.234}}}}"]="2304"
|
|
IP_TO_VMID["${RPC_NODE_235:-${RPC_NODE_235:-${RPC_NODE_235:-${RPC_NODE_235:-192.168.11.235}}}}"]="2305"
|
|
IP_TO_VMID["${RPC_NODE_236:-${RPC_NODE_236:-${RPC_NODE_236:-${RPC_NODE_236:-192.168.11.236}}}}"]="2306"
|
|
IP_TO_VMID["${IP_SERVICE_35:-${IP_SERVICE_35:-${IP_SERVICE_35:-${IP_SERVICE_35:-192.168.11.35}}}}"]="6200"
|
|
IP_TO_VMID["${IP_SERVICE_36:-${IP_SERVICE_36:-${IP_SERVICE_36:-${IP_SERVICE_36:-192.168.11.36}}}}"]="7811"
|
|
IP_TO_VMID["${IP_MIM_WEB:-192.168.11.37}"]="7810"
|
|
IP_TO_VMID["${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-192.168.11.50}}}}"]="7800"
|
|
IP_TO_VMID["${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-192.168.11.51}}}}"]="7801"
|
|
IP_TO_VMID["192.168.11.52"]="7802"
|
|
IP_TO_VMID["${DB_HOST:-192.168.11.53}"]="7803"
|
|
IP_TO_VMID["192.168.11.57"]="6201"
|
|
IP_TO_VMID["192.168.11.64"]="6400"
|
|
IP_TO_VMID["192.168.11.65"]="6000"
|
|
IP_TO_VMID["${IP_VALIDATOR_0:-${IP_VALIDATOR_0:-${IP_VALIDATOR_0:-${IP_VALIDATOR_0:-192.168.11.100}}}}"]="1000"
|
|
IP_TO_VMID["${IP_VALIDATOR_1:-${IP_VALIDATOR_1:-${IP_VALIDATOR_1:-${IP_VALIDATOR_1:-192.168.11.101}}}}"]="1001"
|
|
IP_TO_VMID["${IP_VALIDATOR_2:-${IP_VALIDATOR_2:-${IP_VALIDATOR_2:-${IP_VALIDATOR_2:-192.168.11.102}}}}"]="1002"
|
|
IP_TO_VMID["${IP_VALIDATOR_3:-${IP_VALIDATOR_3:-${IP_VALIDATOR_3:-${IP_VALIDATOR_3:-192.168.11.103}}}}"]="1003"
|
|
IP_TO_VMID["${IP_VALIDATOR_4:-${IP_VALIDATOR_4:-${IP_VALIDATOR_4:-${IP_VALIDATOR_4:-192.168.11.104}}}}"]="1004"
|
|
IP_TO_VMID["${DBIS_POSTGRES_PRIMARY:-192.168.11.105}"]="10100"
|
|
IP_TO_VMID["${DBIS_POSTGRES_REPLICA:-192.168.11.106}"]="10101"
|
|
IP_TO_VMID["192.168.11.125"]="10120"
|
|
IP_TO_VMID["${IP_DBIS_FRONTEND:-${IP_SERVICE_13:-${IP_SERVICE_13:-${IP_SERVICE_13:-192.168.11.13}}}0}"]="10130"
|
|
IP_TO_VMID["${IP_BLOCKSCOUT:-${IP_DEVICE_14:-${IP_DEVICE_14:-${IP_DEVICE_14:-192.168.11.14}}}0}"]="5000"
|
|
IP_TO_VMID["${IP_BESU_RPC_0:-${IP_BESU_RPC_0:-${IP_BESU_RPC_0:-${IP_BESU_RPC_0:-192.168.11.150}}}}"]="1500"
|
|
IP_TO_VMID["${IP_BESU_RPC_1:-${IP_BESU_RPC_1:-${IP_BESU_RPC_1:-${IP_BESU_RPC_1:-192.168.11.151}}}}"]="1501"
|
|
IP_TO_VMID["${IP_BESU_RPC_2:-${IP_BESU_RPC_2:-${IP_BESU_RPC_2:-${IP_BESU_RPC_2:-192.168.11.152}}}}"]="1502"
|
|
IP_TO_VMID["${IP_BESU_RPC_3:-${IP_BESU_RPC_3:-${IP_BESU_RPC_3:-${IP_BESU_RPC_3:-192.168.11.153}}}}"]="1503"
|
|
IP_TO_VMID["${IP_BESU_SENTRY:-192.168.11.154}"]="1504"
|
|
IP_TO_VMID["${IP_DBIS_API:-192.168.11.155}"]="10150"
|
|
IP_TO_VMID["${IP_DBIS_API_2:-192.168.11.156}"]="10151"
|
|
IP_TO_VMID["${RPC_CORE_1:-${IP_SERVICE_21:-${IP_SERVICE_21:-${IP_SERVICE_21:-192.168.11.21}}}1}"]="2101"
|
|
IP_TO_VMID["${RPC_PUBLIC_1:-192.168.11.221}"]="2201"
|
|
IP_TO_VMID["${RPC_PRIVATE_1:-192.168.11.232}"]="2301"
|
|
IP_TO_VMID["${RPC_NODE_233:-${RPC_NODE_233:-${RPC_NODE_233:-${RPC_NODE_233:-192.168.11.233}}}}"]="2303"
|
|
IP_TO_VMID["${RPC_NODE_234:-${RPC_NODE_234:-${RPC_NODE_234:-${RPC_NODE_234:-192.168.11.234}}}}"]="2304"
|
|
IP_TO_VMID["${RPC_NODE_235:-${RPC_NODE_235:-${RPC_NODE_235:-${RPC_NODE_235:-192.168.11.235}}}}"]="2305"
|
|
IP_TO_VMID["${RPC_NODE_236:-${RPC_NODE_236:-${RPC_NODE_236:-${RPC_NODE_236:-192.168.11.236}}}}"]="2306"
|
|
IP_TO_VMID["192.168.11.237"]="2307"
|
|
IP_TO_VMID["192.168.11.238"]="2308"
|
|
IP_TO_VMID["${RPC_THIRDWEB_PRIMARY:-192.168.11.240}"]="2400"
|
|
IP_TO_VMID["${RPC_THIRDWEB_1:-${RPC_THIRDWEB_1:-${RPC_THIRDWEB_1:-${RPC_THIRDWEB_1:-192.168.11.241}}}}"]="2401"
|
|
IP_TO_VMID["${RPC_THIRDWEB_2:-${RPC_THIRDWEB_2:-${RPC_THIRDWEB_2:-${RPC_THIRDWEB_2:-192.168.11.242}}}}"]="2402"
|
|
IP_TO_VMID["192.168.11.243"]="2403"
|
|
IP_TO_VMID["${IP_NGINX_LEGACY:-192.168.11.26}"]="105"
|
|
IP_TO_VMID["192.168.11.27"]="130"
|
|
IP_TO_VMID["192.168.11.30"]="103"
|
|
IP_TO_VMID["192.168.11.31"]="104"
|
|
IP_TO_VMID["192.168.11.32"]="100"
|
|
IP_TO_VMID["192.168.11.33"]="101"
|
|
IP_TO_VMID["192.168.11.110"]="106"
|
|
IP_TO_VMID["192.168.11.111"]="107"
|
|
IP_TO_VMID["192.168.11.112"]="108"
|
|
IP_TO_VMID["${IP_NPMPLUS_ETH0:-192.168.11.166}"]="10233"
|
|
IP_TO_VMID["${IP_NPMPLUS:-192.168.11.167}"]="10234"
|
|
|
|
# Get hostname from IP (if we can SSH)
|
|
get_hostname() {
|
|
local ip=$1
|
|
local vmid=${IP_TO_VMID[$ip]:-}
|
|
if [ -n "$vmid" ]; then
|
|
# Try to get hostname from Proxmox
|
|
local hostname=$(ssh -o StrictHostKeyChecking=no -o ConnectTimeout=2 root@${PROXMOX_HOST_R630_01:-192.168.11.11} "pct config $vmid 2>/dev/null | grep '^hostname:' | awk '{print \$2}'" 2>/dev/null || echo "")
|
|
if [ -n "$hostname" ]; then
|
|
echo "$hostname"
|
|
else
|
|
echo "VMID-$vmid"
|
|
fi
|
|
else
|
|
echo "Unknown"
|
|
fi
|
|
}
|
|
|
|
# Print header
|
|
printf "%-8s %-40s %-18s %-6s %-60s\n" "VMID" "Service/Hostname" "IP Address" "Port" "FQDN"
|
|
printf "%-8s %-40s %-18s %-6s %-60s\n" "--------" "----------------------------------------" "------------------" "------" "------------------------------------------------------------"
|
|
|
|
# Process each proxy host
|
|
echo "$PROXY_HOSTS" | jq -r '.[] | "\(.id)|\(.domain_names | join(","))|\(.forward_scheme)|\(.forward_host)|\(.forward_port)|\(.ssl_forced // false)"' 2>/dev/null | while IFS='|' read -r host_id domains scheme forward_host forward_port ssl_forced; do
|
|
# Get VMID from IP
|
|
vmid=${IP_TO_VMID[$forward_host]:-}
|
|
|
|
# Get service name/hostname
|
|
if [ -n "$vmid" ]; then
|
|
service=$(get_hostname "$forward_host")
|
|
else
|
|
service="External/$forward_host"
|
|
fi
|
|
|
|
# Format domains
|
|
fqdn=$(echo "$domains" | cut -d',' -f1)
|
|
|
|
# Print row
|
|
printf "%-8s %-40s %-18s %-6s %-60s\n" "${vmid:-N/A}" "$service" "$forward_host" "$forward_port" "$fqdn"
|
|
done | sort -k1 -n
|