Files
proxmox/scripts/archive/consolidated/fix/fix-npmplus-incorrect-mappings.sh
defiQUG fbda1b4beb
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
docs: Ledger Live integration, contract deploy learnings, NEXT_STEPS updates
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands
- CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround
- CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check
- NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere
- MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates
- LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 15:46:57 -08:00

196 lines
6.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Fix incorrect NPMplus proxy host mappings
# Corrects Sankofa and test domain entries that are pointing to wrong services
set -euo pipefail
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
# Load IP configuration
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
NPM_URL="${NPM_URL:-https://${IP_NPMPLUS:-192.168.11.167}: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
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
log_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
log_success() { echo -e "${GREEN}[✓]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[⚠]${NC} $1"; }
log_error() { echo -e "${RED}[✗]${NC} $1"; }
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🔧 Fixing Incorrect NPMplus Proxy Host Mappings"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Authenticate
log_info "Authenticating to NPMplus..."
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
ERROR_MSG=$(echo "$TOKEN_RESPONSE" | jq -r '.error.message // "Unknown error"' 2>/dev/null || echo "$TOKEN_RESPONSE")
log_error "Authentication failed: $ERROR_MSG"
exit 1
fi
log_success "Authentication successful"
echo ""
# Get all proxy hosts
log_info "Fetching current proxy hosts..."
PROXY_HOSTS_JSON=$(curl -s -k -X GET "$NPM_URL/api/nginx/proxy-hosts" \
-H "Authorization: Bearer $TOKEN")
# Define correct mappings
declare -A CORRECT_MAPPINGS
CORRECT_MAPPINGS["sankofa.nexus"]="${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-192.168.11.51}}}}:3000"
CORRECT_MAPPINGS["www.sankofa.nexus"]="${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-${IP_SERVICE_51:-192.168.11.51}}}}:3000"
CORRECT_MAPPINGS["phoenix.sankofa.nexus"]="${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-192.168.11.50}}}}:4000"
CORRECT_MAPPINGS["www.phoenix.sankofa.nexus"]="${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-${IP_SERVICE_50:-192.168.11.50}}}}:4000"
# the-order.sankofa.nexus - TBD, leave as-is for now
# test domains - will be deleted
# Function to update proxy host
update_proxy_host() {
local host_id=$1
local domain=$2
local target_ip=$3
local target_port=$4
log_info "Updating $domain (ID: $host_id) → $target_ip:$target_port"
# Get current proxy host configuration
CURRENT_HOST=$(curl -s -k -X GET "$NPM_URL/api/nginx/proxy-hosts/$host_id" \
-H "Authorization: Bearer $TOKEN" 2>/dev/null || echo "{}")
if [ "$(echo "$CURRENT_HOST" | jq -r '.id // empty')" = "" ]; then
log_error "Proxy host $host_id not found"
return 1
fi
# Update proxy host - preserve all other settings
UPDATE_PAYLOAD=$(echo "$CURRENT_HOST" | jq \
--arg ip "$target_ip" \
--argjson port "$target_port" \
'.forward_host = $ip | .forward_port = $port')
RESPONSE=$(curl -s -k -X PUT "$NPM_URL/api/nginx/proxy-hosts/$host_id" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "$UPDATE_PAYLOAD")
UPDATED_ID=$(echo "$RESPONSE" | jq -r '.id // empty' 2>/dev/null || echo "")
if [ -n "$UPDATED_ID" ] && [ "$UPDATED_ID" != "null" ]; then
log_success "Successfully updated $domain"
return 0
else
ERROR=$(echo "$RESPONSE" | jq -r '.error.message // .error // "Unknown error"' 2>/dev/null || echo "$RESPONSE")
log_error "Failed to update $domain: $ERROR"
return 1
fi
}
# Function to delete proxy host
delete_proxy_host() {
local host_id=$1
local domain=$2
log_info "Deleting test domain: $domain (ID: $host_id)"
RESPONSE=$(curl -s -k -X DELETE "$NPM_URL/api/nginx/proxy-hosts/$host_id" \
-H "Authorization: Bearer $TOKEN" 2>/dev/null || echo "{}")
# Check if deletion was successful (API may return empty response or 200)
if [ $? -eq 0 ]; then
log_success "Successfully deleted $domain"
return 0
else
log_error "Failed to delete $domain"
return 1
fi
}
# Process each proxy host
SUCCESS=0
FAILED=0
DELETED=0
echo "$PROXY_HOSTS_JSON" | jq -r '.[] | "\(.id)|\(.domain_names | join(","))|\(.forward_host)|\(.forward_port)"' 2>/dev/null | while IFS='|' read -r host_id domains_json forward_host forward_port; do
# Parse domain names (JSON array)
domain=$(echo "$domains_json" | jq -r '.[0] // empty' 2>/dev/null || echo "$domains_json")
if [ -z "$domain" ] || [ "$domain" = "null" ]; then
continue
fi
# Check if this domain needs to be fixed
if [[ -n "${CORRECT_MAPPINGS[$domain]:-}" ]]; then
IFS=':' read -r correct_ip correct_port <<< "${CORRECT_MAPPINGS[$domain]}"
if [ "$forward_host" != "$correct_ip" ] || [ "$forward_port" != "$correct_port" ]; then
if update_proxy_host "$host_id" "$domain" "$correct_ip" "$correct_port"; then
((SUCCESS++))
else
((FAILED++))
fi
echo ""
else
log_info "$domain already correctly configured"
fi
# Check if this is a test domain to delete
elif [[ "$domain" == test-*.example.com ]]; then
if delete_proxy_host "$host_id" "$domain"; then
((DELETED++))
else
((FAILED++))
fi
echo ""
fi
done
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📊 Update Summary"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✅ Successfully updated: $SUCCESS"
echo "🗑️ Test domains deleted: $DELETED"
echo "❌ Failed: $FAILED"
echo ""
if [ $FAILED -eq 0 ]; then
log_success "All proxy host mappings fixed successfully!"
echo ""
log_info "Note: the-order.sankofa.nexus is marked as TBD in documentation and was not changed"
else
log_warn "Some updates failed. Please review the errors above."
fi