Pay-then-profile join desk with live card, S3 upload fallback, hydration-safe drafts; document on test9 README. Co-authored-by: Cursor <cursoragent@cursor.com>
206 lines
7.4 KiB
Python
206 lines
7.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Make US .com stack data/config independent from .cn (do not touch CN)."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace", line_buffering=True)
|
|
|
|
US = ("108.174.50.68", "root", "Xiao4669805")
|
|
|
|
|
|
def connect():
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(*US, timeout=60, allow_agent=False, look_for_keys=False, banner_timeout=120)
|
|
# fix connect - need host,port,user,pass
|
|
return c
|
|
|
|
|
|
def connect2():
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
host, user, password = US
|
|
c.connect(host, 22, user, password, timeout=60, allow_agent=False, look_for_keys=False, banner_timeout=120)
|
|
return c
|
|
|
|
|
|
def run(c, cmd, timeout=300, check=True):
|
|
print(f"\n$ {cmd[:220]}", flush=True)
|
|
_s, o, e = c.exec_command(cmd, timeout=timeout, get_pty=True)
|
|
out = o.read().decode("utf-8", "replace")
|
|
print(out[-5000:] if len(out) > 5000 else out, flush=True)
|
|
code = o.channel.recv_exit_status()
|
|
if check and code != 0:
|
|
raise RuntimeError(f"fail {code}")
|
|
return code, out
|
|
|
|
|
|
def put(c, path, content, mode=0o644):
|
|
sftp = c.open_sftp()
|
|
with sftp.file(path, "w") as f:
|
|
f.write(content)
|
|
sftp.chmod(path, mode)
|
|
sftp.close()
|
|
|
|
|
|
# Independent .com API env — no CN WeChat / ntfy / PB coupling
|
|
API_ENV = """DEBUG=false
|
|
WX_ALLOW_DEVTOOLS_LOGIN=false
|
|
JWT_SECRET=nomadro-com-jwt-us-independent-2026
|
|
ADMIN_USERNAME=hackrobot
|
|
ADMIN_PASSWORD=Xiao4669805@
|
|
USE_POCKETBASE=false
|
|
PB_URL=
|
|
PUBLIC_API_BASE=https://api.nomadro.com
|
|
ADMIN_ORIGIN=https://admin.nomadro.com
|
|
CORS_ORIGINS=https://admin.nomadro.com,https://api.nomadro.com,https://nomadro.com,https://www.nomadro.com,http://localhost:5174,http://127.0.0.1:5174,http://localhost:5173,http://127.0.0.1:5173,http://localhost:3000,http://127.0.0.1:3000
|
|
|
|
DEFAULT_PRODUCT_ID=ebook_unlock_default
|
|
DEFAULT_PRICE_FEN=100
|
|
DEFAULT_UNLOCK_PERCENT=30
|
|
SQLITE_PATH=/opt/nomadmini/data/nomadmini.db
|
|
NTFY_ENABLED=false
|
|
WX_PAY_ENV=1
|
|
# Explicitly blank — do NOT inherit CN WeChat app credentials from code defaults
|
|
WX_APPID=
|
|
WX_SECRET=
|
|
WX_OFFER_ID=
|
|
WX_APP_KEY=
|
|
WX_SANDBOX_APP_KEY=
|
|
WX_PUSH_TOKEN=
|
|
WX_PUSH_ENCODING_AES_KEY=
|
|
"""
|
|
|
|
PORTAL_ENV = """NOMADRO_PUBLIC_ORIGIN=https://nomadro.com
|
|
CENTRIFUGO_ENABLED=false
|
|
API_URL=http://127.0.0.1:8020
|
|
# .com stack — independent from nomadro.cn
|
|
"""
|
|
|
|
|
|
def main():
|
|
c = connect2()
|
|
|
|
print("=== stop services ===", flush=True)
|
|
run(c, "systemctl stop nomadro nomadmini-api nomadro-social || true", check=False)
|
|
|
|
print("=== quarantine CN-copied databases (keep backup, start fresh) ===", flush=True)
|
|
run(
|
|
c,
|
|
r"""
|
|
set -euo pipefail
|
|
ts=$(date +%Y%m%d%H%M%S)
|
|
mkdir -p /opt/nomadmini/data/_from_cn_bak_$ts /var/www/nomadro-data/_from_cn_bak_$ts
|
|
# move, do not delete — prove isolation without destroying evidence
|
|
if [ -f /opt/nomadmini/data/nomadmini.db ]; then
|
|
mv /opt/nomadmini/data/nomadmini.db /opt/nomadmini/data/_from_cn_bak_$ts/nomadmini.db
|
|
fi
|
|
if [ -f /var/www/nomadro-data/social/social.db ]; then
|
|
mv /var/www/nomadro-data/social/social.db /var/www/nomadro-data/_from_cn_bak_$ts/social.db
|
|
fi
|
|
if [ -f /var/www/nomadro-data/community/community_store.json ]; then
|
|
mv /var/www/nomadro-data/community/community_store.json /var/www/nomadro-data/_from_cn_bak_$ts/community_store.json
|
|
fi
|
|
# fresh empty placeholders; apps create schema on boot
|
|
: > /var/www/nomadro-data/community/community_store.json
|
|
echo '{}' > /var/www/nomadro-data/community/community_store.json
|
|
ls -la /opt/nomadmini/data/ /var/www/nomadro-data/social/ /var/www/nomadro-data/community/
|
|
echo QUARANTINE_OK ts=$ts
|
|
""",
|
|
)
|
|
|
|
print("=== rewrite independent .com envs ===", flush=True)
|
|
put(c, "/opt/nomadmini/backend/.env", API_ENV, 0o600)
|
|
put(c, "/etc/nomadro/portal.env", PORTAL_ENV, 0o644)
|
|
|
|
print("=== rewrite hardcoded .cn → .com in admin SPA + portal build (URLs only) ===", flush=True)
|
|
run(
|
|
c,
|
|
r"""
|
|
set -euo pipefail
|
|
# Admin SPA UI strings / domains
|
|
if [ -f /www/wwwroot/admin.nomadro.com/assets/index-Ct9cUJjU.js ]; then
|
|
sed -i \
|
|
-e 's/admin\.nomadro\.cn/admin.nomadro.com/g' \
|
|
-e 's/api\.nomadro\.cn/api.nomadro.com/g' \
|
|
-e 's/nomadro\.cn\/admin/nomadro.com\/admin/g' \
|
|
-e 's/nomadro_admin_token/nomadro_com_admin_token/g' \
|
|
/www/wwwroot/admin.nomadro.com/assets/index-Ct9cUJjU.js
|
|
fi
|
|
# Portal Next build: public domain references
|
|
find /var/www/nomadro.cn/.next -type f \( -name '*.js' -o -name '*.html' -o -name '*.json' -o -name '*.css' \) -print0 \
|
|
| xargs -0 -r sed -i \
|
|
-e 's/https:\/\/www\.nomadro\.cn/https:\/\/nomadro.com/g' \
|
|
-e 's/https:\/\/nomadro\.cn/https:\/\/nomadro.com/g' \
|
|
-e 's/https:\/\/api\.nomadro\.cn/https:\/\/api.nomadro.com/g' \
|
|
-e 's/https:\/\/admin\.nomadro\.cn/https:\/\/admin.nomadro.com/g' \
|
|
-e 's/wss:\/\/nomadro\.cn/wss:\/\/nomadro.com/g' \
|
|
-e 's/https:\/\/ntfy\.nomadro\.cn/https:\/\/nomadro.com/g' \
|
|
-e 's/https:\/\/umami\.nomadro\.cn/https:\/\/nomadro.com/g' \
|
|
-e 's/https:\/\/mirotalk\.nomadro\.cn/https:\/\/nomadro.com/g'
|
|
# Count remaining .cn refs (informational)
|
|
echo REMAINING_CN_REFS:
|
|
grep -RIl --include='*.js' --include='*.html' --include='*.json' 'nomadro\.cn' /var/www/nomadro.cn/.next /www/wwwroot/admin.nomadro.com 2>/dev/null | wc -l
|
|
echo URL_REWRITE_OK
|
|
""",
|
|
timeout=600,
|
|
)
|
|
|
|
print("=== start services (fresh DBs) ===", flush=True)
|
|
run(c, "systemctl start nomadmini-api nomadro-social nomadro && sleep 4 && systemctl is-active nomadro nomadmini-api nomadro-social")
|
|
|
|
print("=== verify isolation ===", flush=True)
|
|
run(
|
|
c,
|
|
r"""
|
|
set +e
|
|
echo '--- login ---'
|
|
curl -sS -X POST https://api.nomadro.com/api/admin/login \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"username":"hackrobot","password":"Xiao4669805@"}' | head -c 200
|
|
echo
|
|
echo '--- health ---'
|
|
curl -sS -o /dev/null -w 'portal:%{http_code} api:%{http_code} admin:%{http_code}\n' \
|
|
https://nomadro.com/ https://api.nomadro.com/health https://admin.nomadro.com/
|
|
# fix multi curl write
|
|
curl -sS -o /dev/null -w 'portal:%{http_code}\n' https://nomadro.com/
|
|
curl -sS -o /dev/null -w 'api:%{http_code}\n' https://api.nomadro.com/health
|
|
curl -sS -o /dev/null -w 'admin:%{http_code}\n' https://admin.nomadro.com/
|
|
echo '--- fresh db counts ---'
|
|
python3 - <<'PY'
|
|
import os, sqlite3
|
|
for p in ['/opt/nomadmini/data/nomadmini.db','/var/www/nomadro-data/social/social.db']:
|
|
print(p, 'exists' if os.path.exists(p) else 'MISSING', 'size', os.path.getsize(p) if os.path.exists(p) else 0)
|
|
if not os.path.exists(p):
|
|
continue
|
|
con=sqlite3.connect(p); cur=con.cursor()
|
|
tabs=cur.execute("SELECT name FROM sqlite_master WHERE type='table'").fetchall()
|
|
for t in tabs:
|
|
try:
|
|
n=cur.execute(f'SELECT COUNT(*) FROM "{t[0]}"').fetchone()[0]
|
|
if n: print(' ', t[0], n)
|
|
except Exception:
|
|
pass
|
|
con.close()
|
|
PY
|
|
echo '--- env domains ---'
|
|
grep -E 'PUBLIC_|ADMIN_ORIGIN|CORS_|NOMADRO_PUBLIC|JWT_SECRET' /opt/nomadmini/backend/.env /etc/nomadro/portal.env | sed 's/JWT_SECRET=.*/JWT_SECRET=***/;s/ADMIN_PASSWORD=.*/ADMIN_PASSWORD=***/'
|
|
echo '--- cn bak ---'
|
|
ls /opt/nomadmini/data/_from_cn_bak_* 2>/dev/null | head
|
|
ls /var/www/nomadro-data/_from_cn_bak_* 2>/dev/null | head
|
|
""",
|
|
check=False,
|
|
)
|
|
|
|
c.close()
|
|
print("=== DONE: .com isolated ===", flush=True)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|