Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
Co-authored-by: Cursor <cursoragent@cursor.com>
49 lines
2.5 KiB
Bash
Executable File
49 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Add NPMplus proxy hosts for Gov Portals xom-dev via direct database access
|
|
# Use when API is unreachable. Runs via SSH to Proxmox host → pct exec 10233 → docker exec npmplus
|
|
#
|
|
# Usage: bash scripts/nginx-proxy-manager/add-gov-portals-xom-dev-proxy-hosts-db.sh
|
|
set -euo pipefail
|
|
|
|
NPMPLUS_VMID="${NPMPLUS_VMID:-10233}"
|
|
NPMPLUS_NODE="${NPMPLUS_NODE:-r630-01}"
|
|
PROXMOX_HOST="${PROXMOX_HOST:-192.168.11.11}"
|
|
IP_GOV="${IP_GOV_PORTALS_DEV:-192.168.11.54}"
|
|
|
|
add_host() {
|
|
local domain=$1
|
|
local port=$2
|
|
echo "Adding $domain -> $IP_GOV:$port..."
|
|
ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new root@"$PROXMOX_HOST" \
|
|
"pct exec $NPMPLUS_VMID -- docker exec -e DOMAIN='$domain' -e PORT=$port -e IP='$IP_GOV' npmplus node -e \"
|
|
const Database = require('better-sqlite3');
|
|
const db = new Database('/data/npmplus/database.sqlite');
|
|
const domain = process.env.DOMAIN;
|
|
const port = parseInt(process.env.PORT, 10);
|
|
const ip = process.env.IP;
|
|
const existing = db.prepare('SELECT id FROM proxy_host WHERE domain_names LIKE ?').get('%' + domain + '%');
|
|
if (existing) {
|
|
console.log(' Exists (id=' + existing.id + '), updating...');
|
|
db.prepare('UPDATE proxy_host SET forward_host=?, forward_port=?, forward_scheme=\\\"http\\\", enabled=1 WHERE id=?').run(ip, port, existing.id);
|
|
} else {
|
|
const maxId = db.prepare('SELECT MAX(id) as max FROM proxy_host').get();
|
|
const nextId = (maxId?.max || 0) + 1;
|
|
var now = new Date().toISOString().slice(0, 19).replace('T', ' ');
|
|
var sql = 'INSERT INTO proxy_host (id, created_on, modified_on, owner_user_id, is_deleted, domain_names, forward_host, forward_port, access_list_id, certificate_id, ssl_forced, caching_enabled, block_exploits, advanced_config, meta, allow_websocket_upgrade, http2_support, forward_scheme, enabled, locations, hsts_enabled, hsts_subdomains) VALUES (?, ?, ?, 1, 0, ?, ?, ?, 0, 0, 0, 0, 0, ?, ?, 0, 0, ?, 1, null, 0, 0)';
|
|
db.prepare(sql).run(nextId, now, now, JSON.stringify([domain]), ip, port, '', '{}', 'http');
|
|
console.log(' Created id=' + nextId);
|
|
}
|
|
db.close();
|
|
\"" 2>/dev/null
|
|
}
|
|
|
|
echo "Adding Gov Portals xom-dev proxy hosts via NPMplus DB..."
|
|
add_host "dbis.xom-dev.phoenix.sankofa.nexus" 3001
|
|
add_host "iccc.xom-dev.phoenix.sankofa.nexus" 3002
|
|
add_host "omnl.xom-dev.phoenix.sankofa.nexus" 3003
|
|
add_host "xom.xom-dev.phoenix.sankofa.nexus" 3004
|
|
|
|
echo "Reloading NPMplus nginx..."
|
|
ssh root@"$PROXMOX_HOST" "pct exec $NPMPLUS_VMID -- docker exec npmplus nginx -s reload 2>/dev/null" || true
|
|
echo "Done."
|