Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP. Co-authored-by: Cursor <cursoragent@cursor.com>
68 lines
2.0 KiB
Python
68 lines
2.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Bring up wg-dy on PVE guest now that wireguard-tools is installed."""
|
|
import sys
|
|
import time
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
v = paramiko.SSHClient()
|
|
v.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
v.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=25, allow_agent=False, look_for_keys=False)
|
|
|
|
p = paramiko.SSHClient()
|
|
p.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
p.connect("107.173.30.245", 4014, "eric", "4669805", timeout=30, allow_agent=False, look_for_keys=False)
|
|
|
|
|
|
def run(c, cmd, timeout=60):
|
|
_, o, e = c.exec_command(cmd, timeout=timeout)
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
|
|
keys = run(v, "echo SERVER_PUB $(cat /etc/wireguard/wg-dy.server.pub); echo PVE_PRIV $(cat /etc/wireguard/wg-dy.pve.key)")
|
|
kv = {}
|
|
for line in keys.splitlines():
|
|
parts = line.split()
|
|
if len(parts) == 2:
|
|
kv[parts[0]] = parts[1]
|
|
|
|
pve_conf = f"""[Interface]
|
|
Address = 10.8.0.2/24
|
|
PrivateKey = {kv['PVE_PRIV']}
|
|
|
|
[Peer]
|
|
PublicKey = {kv['SERVER_PUB']}
|
|
Endpoint = 107.173.30.245:51820
|
|
AllowedIPs = 10.8.0.0/24
|
|
PersistentKeepalive = 25
|
|
"""
|
|
|
|
sftp = p.open_sftp()
|
|
with sftp.file("/tmp/wg-dy.conf", "w") as f:
|
|
f.write(pve_conf)
|
|
sftp.close()
|
|
|
|
print(run(
|
|
p,
|
|
"echo '4669805' | sudo -S -p '' bash -c '"
|
|
"mkdir -p /etc/wireguard; "
|
|
"install -m 600 /tmp/wg-dy.conf /etc/wireguard/wg-dy.conf; rm -f /tmp/wg-dy.conf; "
|
|
"wg-quick down wg-dy 2>/dev/null || true; "
|
|
"wg-quick up wg-dy; "
|
|
"systemctl enable wg-quick@wg-dy; "
|
|
"wg show wg-dy; ip -4 addr show wg-dy"
|
|
"'",
|
|
40,
|
|
))
|
|
|
|
time.sleep(4)
|
|
print("=== ping ===")
|
|
print("VPS->PVE", run(v, "ping -c 5 -W 3 10.8.0.2; echo; wg show wg-dy", 25))
|
|
print("PVE->VPS", run(p, "ping -c 5 -W 3 10.8.0.1; echo; wg show wg-dy", 25))
|
|
print("=== dylive ===")
|
|
print(run(v, "curl -sS -m 8 -o /dev/null -w 'dylive:%{http_code}\\n' https://dylive.nomadro.com/api/health; systemctl is-active caddy sing-box docker", 20))
|
|
|
|
v.close()
|
|
p.close()
|