's'
This commit is contained in:
parent
4abed7b8f0
commit
38d1a693e5
@ -38,7 +38,9 @@ SHELLCRASH_AUTO_START_ON_WEB_PANEL=0
|
||||
SHELLCRASH_ATTACH_WHEN_DIRECT_OK=0
|
||||
SHELLCRASH_ATTACH_NEKO=auto
|
||||
SHELLCRASH_ATTACH_FFMPEG=auto
|
||||
# Neko 专用 ShellCrash mixed listener(与 FFmpeg 的 7890/tuic3 出口隔离)
|
||||
# Neko 浏览器 HTTP 代理总开关;默认 0=关闭(走宿主机/软路由直连)。开启后才会解析 ShellCrash 或 NEKO_BROWSER_PROXY。
|
||||
ENABLE_NEKO_BROWSER_PROXY=0
|
||||
# Neko 专用 ShellCrash mixed listener(与 FFmpeg 的 7890/tuic3 出口隔离;仅 ENABLE_NEKO_BROWSER_PROXY=1 时生效)
|
||||
NEKO_SHELLCRASH_PROXY_PORT=7894
|
||||
SHELLCRASH_NEKO_PROXY_NODE=proxycheap
|
||||
# 留空则自动使用 http://host.docker.internal:${NEKO_SHELLCRASH_PROXY_PORT}
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
"NEKO_WEBRTC_UDPMUX_2": "52301",
|
||||
"NEKO_WEBRTC_UDPMUX_3": "52302",
|
||||
"NEKO_ACCESS_MODE": "lan",
|
||||
"NEKO_WIREGUARD_HOST": ""
|
||||
"NEKO_WIREGUARD_HOST": "",
|
||||
"ENABLE_NEKO_BROWSER_PROXY": "0"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1750,6 +1750,21 @@ shellcrash_mix_port() {
|
||||
printf '%s' "$port"
|
||||
}
|
||||
|
||||
shellcrash_neko_proxy_port() {
|
||||
local port="${NEKO_SHELLCRASH_PROXY_PORT:-7894}"
|
||||
case "$port" in
|
||||
''|*[!0-9]*) port=7894 ;;
|
||||
esac
|
||||
printf '%s' "$port"
|
||||
}
|
||||
|
||||
neko_browser_proxy_switch_enabled() {
|
||||
case "${ENABLE_NEKO_BROWSER_PROXY:-0}" in
|
||||
1|true|TRUE|yes|YES|on|ON|enable|enabled) return 0 ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
shellcrash_config_available() {
|
||||
[ -s "$SHELLCRASH_DIR/yamls/config.yaml" ] || [ -s "/tmp/ShellCrash/config.yaml" ]
|
||||
}
|
||||
@ -1839,6 +1854,7 @@ shellcrash_proxy_available() {
|
||||
}
|
||||
|
||||
resolve_neko_browser_proxy() {
|
||||
neko_browser_proxy_switch_enabled || return 0
|
||||
case "${NEKO_BROWSER_PROXY:-}" in
|
||||
0|false|FALSE|off|OFF|none|NONE|direct|DIRECT)
|
||||
printf '%s' "$NEKO_BROWSER_PROXY"
|
||||
@ -1849,13 +1865,13 @@ resolve_neko_browser_proxy() {
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
case "$SHELLCRASH_ATTACH_NEKO" in
|
||||
case "${SHELLCRASH_ATTACH_NEKO:-auto}" in
|
||||
0|false|FALSE|off|OFF|none|NONE|direct|DIRECT)
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
local port
|
||||
port="$(shellcrash_mix_port)"
|
||||
port="$(shellcrash_neko_proxy_port)"
|
||||
if shellcrash_proxy_available "$port"; then
|
||||
printf 'http://host.docker.internal:%s' "$port"
|
||||
return 0
|
||||
@ -1864,7 +1880,7 @@ resolve_neko_browser_proxy() {
|
||||
return 0
|
||||
fi
|
||||
shellcrash_autostart_if_needed >/dev/null 2>&1 || true
|
||||
port="$(shellcrash_mix_port)"
|
||||
port="$(shellcrash_neko_proxy_port)"
|
||||
if shellcrash_proxy_available "$port"; then
|
||||
printf 'http://host.docker.internal:%s' "$port"
|
||||
fi
|
||||
|
||||
@ -48,6 +48,7 @@ SHELLCRASH_AUTO_START_ON_WEB_PANEL="${SHELLCRASH_AUTO_START_ON_WEB_PANEL:-0}"
|
||||
SHELLCRASH_ATTACH_WHEN_DIRECT_OK="${SHELLCRASH_ATTACH_WHEN_DIRECT_OK:-0}"
|
||||
SHELLCRASH_ATTACH_NEKO="${SHELLCRASH_ATTACH_NEKO:-auto}"
|
||||
SHELLCRASH_ATTACH_FFMPEG="${SHELLCRASH_ATTACH_FFMPEG:-auto}"
|
||||
ENABLE_NEKO_BROWSER_PROXY="${ENABLE_NEKO_BROWSER_PROXY:-0}"
|
||||
NEKO_SHELLCRASH_PROXY_PORT="${NEKO_SHELLCRASH_PROXY_PORT:-7894}"
|
||||
SHELLCRASH_NEKO_PROXY_NODE="${SHELLCRASH_NEKO_PROXY_NODE:-proxycheap}"
|
||||
NETWORK_PROBE_GOOGLE_URL="${NETWORK_PROBE_GOOGLE_URL:-https://www.google.com/generate_204}"
|
||||
@ -1091,7 +1092,12 @@ shellcrash_neko_proxy_port() {
|
||||
printf '%s' "$port"
|
||||
}
|
||||
|
||||
neko_browser_proxy_switch_enabled() {
|
||||
flag_enabled "${ENABLE_NEKO_BROWSER_PROXY:-0}"
|
||||
}
|
||||
|
||||
neko_shellcrash_proxy_enabled() {
|
||||
neko_browser_proxy_switch_enabled || return 1
|
||||
[ "${ENABLE_NEKO:-1}" = "1" ] || return 1
|
||||
case "$SHELLCRASH_ATTACH_NEKO" in
|
||||
0|false|FALSE|off|OFF|none|NONE|direct|DIRECT) return 1 ;;
|
||||
@ -1206,6 +1212,7 @@ shellcrash_proxy_available() {
|
||||
}
|
||||
|
||||
resolve_neko_browser_proxy() {
|
||||
neko_browser_proxy_switch_enabled || return 0
|
||||
case "${NEKO_BROWSER_PROXY:-}" in
|
||||
0|false|FALSE|off|OFF|none|NONE|direct|DIRECT)
|
||||
printf '%s' "$NEKO_BROWSER_PROXY"
|
||||
@ -1238,6 +1245,7 @@ resolve_neko_browser_proxy() {
|
||||
}
|
||||
|
||||
service_neko_reconfigure_for_shellcrash_change() {
|
||||
neko_browser_proxy_switch_enabled || return 0
|
||||
case "$SHELLCRASH_ATTACH_NEKO" in
|
||||
0|false|FALSE|off|OFF|none|NONE|direct|DIRECT)
|
||||
return 0
|
||||
|
||||
@ -29,6 +29,7 @@ from src.youtube_config_paths import resolve_youtube_style_config_paths
|
||||
from src.wireguard_config import (
|
||||
WireGuardConfigError,
|
||||
apply_wireguard_config,
|
||||
configure_neko_browser_proxy,
|
||||
configure_neko_wireguard_access,
|
||||
read_imported_wireguard_config,
|
||||
save_imported_wireguard_config,
|
||||
@ -226,6 +227,11 @@ class WireGuardNekoAccessBody(BaseModel):
|
||||
restart: bool = True
|
||||
|
||||
|
||||
class NekoBrowserProxyBody(BaseModel):
|
||||
enabled: bool
|
||||
restart: bool = True
|
||||
|
||||
|
||||
class YoutubeLiveCloseBody(BaseModel):
|
||||
reason: str = Field(default="manual", max_length=200)
|
||||
|
||||
@ -432,6 +438,18 @@ async def hub_network_wireguard_neko_access(body: WireGuardNekoAccessBody) -> di
|
||||
return {"message": "ok", "neko_access": access}
|
||||
|
||||
|
||||
@router.post("/network/neko_browser_proxy")
|
||||
async def hub_network_neko_browser_proxy(body: NekoBrowserProxyBody) -> dict[str, Any]:
|
||||
repo_root = _repo_root or Path.cwd()
|
||||
result = await asyncio.to_thread(
|
||||
configure_neko_browser_proxy,
|
||||
repo_root=repo_root,
|
||||
enabled=body.enabled,
|
||||
restart=body.restart,
|
||||
)
|
||||
return {"message": "ok", "neko_browser_proxy": result}
|
||||
|
||||
|
||||
@router.get("/network/wireguard/config/{name}")
|
||||
async def hub_network_wireguard_config(name: str) -> dict[str, Any]:
|
||||
repo_root = _repo_root or Path.cwd()
|
||||
|
||||
@ -267,6 +267,7 @@ def shellcrash_policy() -> dict[str, Any]:
|
||||
"configured_autostart": _env_flag("SHELLCRASH_AUTOSTART", False),
|
||||
"auto_start_on_web_panel": _env_flag("SHELLCRASH_AUTO_START_ON_WEB_PANEL", False),
|
||||
"attach_when_direct_ok": _env_flag("SHELLCRASH_ATTACH_WHEN_DIRECT_OK", False),
|
||||
"enable_neko_browser_proxy": _env_flag("ENABLE_NEKO_BROWSER_PROXY", False),
|
||||
"attach_neko": attach_neko,
|
||||
"attach_neko_mode": _attach_mode(attach_neko),
|
||||
"attach_ffmpeg": attach_ffmpeg,
|
||||
|
||||
@ -1288,6 +1288,7 @@ def wireguard_runtime_status(*, repo_root: Path) -> dict[str, Any]:
|
||||
"repo_configs": repo_configs,
|
||||
"shellcrash": _shellcrash_status(),
|
||||
"neko_access": neko_access,
|
||||
"neko_browser_proxy": _neko_browser_proxy_status(repo_root),
|
||||
"recommendations": recommendations,
|
||||
"last_checked_at": int(time.time()),
|
||||
}
|
||||
@ -1337,6 +1338,55 @@ def configure_neko_wireguard_access(
|
||||
return result
|
||||
|
||||
|
||||
def _env_flag_enabled(env: dict[str, str], key: str, *, default: bool = False) -> bool:
|
||||
raw = str(env.get(key, "1" if default else "0")).strip().lower()
|
||||
return raw in {"1", "true", "yes", "on", "enable", "enabled"}
|
||||
|
||||
|
||||
def _neko_browser_proxy_status(repo_root: Path) -> dict[str, Any]:
|
||||
env = _read_stack_env(repo_root)
|
||||
enabled = _env_flag_enabled(env, "ENABLE_NEKO_BROWSER_PROXY", default=False)
|
||||
explicit = str(env.get("NEKO_BROWSER_PROXY") or "").strip()
|
||||
port = str(env.get("NEKO_SHELLCRASH_PROXY_PORT") or "7894").strip() or "7894"
|
||||
node = str(env.get("SHELLCRASH_NEKO_PROXY_NODE") or "proxycheap").strip() or "proxycheap"
|
||||
attach = str(env.get("SHELLCRASH_ATTACH_NEKO") or "auto").strip() or "auto"
|
||||
resolved = ""
|
||||
if enabled:
|
||||
if explicit and explicit.lower() not in {"0", "false", "off", "none", "direct"}:
|
||||
resolved = explicit
|
||||
elif attach.lower() not in {"0", "false", "off", "none", "direct"}:
|
||||
resolved = f"http://host.docker.internal:{port}"
|
||||
return {
|
||||
"enabled": enabled,
|
||||
"switch": "ENABLE_NEKO_BROWSER_PROXY",
|
||||
"explicit_proxy": explicit,
|
||||
"resolved_proxy": resolved,
|
||||
"shellcrash_port": port,
|
||||
"shellcrash_node": node,
|
||||
"attach_mode": attach,
|
||||
}
|
||||
|
||||
|
||||
def configure_neko_browser_proxy(
|
||||
*,
|
||||
repo_root: Path,
|
||||
enabled: bool,
|
||||
restart: bool = True,
|
||||
) -> dict[str, Any]:
|
||||
changed = _upsert_stack_env_values(repo_root, {"ENABLE_NEKO_BROWSER_PROXY": "1" if enabled else "0"})
|
||||
reconfigure: dict[str, Any] = {"ok": True, "skipped": True, "reason": "unchanged"}
|
||||
if restart and changed:
|
||||
reconfigure = _reconfigure_neko_containers(repo_root)
|
||||
status = _neko_browser_proxy_status(repo_root)
|
||||
return {
|
||||
**status,
|
||||
"changed": changed,
|
||||
"restart_requested": restart,
|
||||
"reconfigured": bool(reconfigure.get("ok") and not reconfigure.get("skipped")),
|
||||
"reconfigure": reconfigure,
|
||||
}
|
||||
|
||||
|
||||
def apply_wireguard_config(
|
||||
content: str,
|
||||
*,
|
||||
|
||||
@ -195,50 +195,60 @@ class NekoConfigTests(unittest.TestCase):
|
||||
def test_neko_runtime_scripts_use_generated_compose(self) -> None:
|
||||
service_ctl = (ROOT / "scripts" / "linux" / "service_ctl.sh").read_text(encoding="utf-8")
|
||||
common = (ROOT / "scripts" / "linux" / "lib" / "common.sh").read_text(encoding="utf-8")
|
||||
shared_markers = (
|
||||
"render_neko_compose_file()",
|
||||
"tools/render_neko_compose.py",
|
||||
"docker-compose.generated.yml",
|
||||
'compose_file="$(render_neko_compose_file)"',
|
||||
"NEKO_MAX_INSTANCE_COUNT:-64",
|
||||
"NEKO_MANAGED_POLICIES",
|
||||
"NEKO_TAMPERMONKEY_REPAIR",
|
||||
"NEKO_BROWSER_PROXY",
|
||||
"NEKO_CONTAINER_USER",
|
||||
"NEKO_CONTAINER_UID",
|
||||
"NEKO_DISPLAY",
|
||||
"ENV_USER",
|
||||
"ENV_DISPLAY",
|
||||
"Default/WebStorage/3/IndexedDB",
|
||||
'chown -R "$owner" "$prof"',
|
||||
"resolve_neko_browser_proxy()",
|
||||
"neko_browser_proxy_switch_enabled()",
|
||||
"shellcrash_neko_proxy_port()",
|
||||
"shellcrash_proxy_available()",
|
||||
"ensure_shellcrash_docker_proxy_access()",
|
||||
'chmod +x "$launch"',
|
||||
"copy_neko_tampermonkey_seed_dir()",
|
||||
"copy_neko_tampermonkey_storage_dir()",
|
||||
"find_neko_tampermonkey_seed_profile()",
|
||||
"services/neko/tampermonkey-seed",
|
||||
"sync_neko_tampermonkey_preferences()",
|
||||
"should_replace_current",
|
||||
'value.get("from_webstore") is not True',
|
||||
'path.startswith("/")',
|
||||
'value.get("location") == 8',
|
||||
"neko_managed_policies_enabled()",
|
||||
)
|
||||
for script in (service_ctl, common):
|
||||
self.assertIn("render_neko_compose_file()", script)
|
||||
self.assertIn("tools/render_neko_compose.py", script)
|
||||
self.assertIn("docker-compose.generated.yml", script)
|
||||
self.assertIn("compose_file=\"$(render_neko_compose_file)\"", script)
|
||||
self.assertIn("NEKO_MAX_INSTANCE_COUNT:-64", script)
|
||||
self.assertIn("NEKO_MANAGED_POLICIES", script)
|
||||
self.assertIn("NEKO_TAMPERMONKEY_REPAIR", script)
|
||||
self.assertIn("NEKO_BROWSER_PROXY", script)
|
||||
self.assertIn("NEKO_CONTAINER_USER", script)
|
||||
self.assertIn("NEKO_CONTAINER_UID", script)
|
||||
self.assertIn("NEKO_DISPLAY", script)
|
||||
self.assertIn("ENV_USER", script)
|
||||
self.assertIn("ENV_DISPLAY", script)
|
||||
self.assertIn("Default/WebStorage/3/IndexedDB", script)
|
||||
self.assertIn("chown -R \"$owner\" \"$prof\"", script)
|
||||
self.assertIn("resolve_neko_browser_proxy()", script)
|
||||
self.assertIn("shellcrash_mix_port()", script)
|
||||
self.assertIn("shellcrash_neko_proxy_port()", script)
|
||||
self.assertIn("shellcrash_proxy_available()", script)
|
||||
self.assertIn("ensure_shellcrash_docker_proxy_access()", script)
|
||||
self.assertIn("ensure_shellcrash_proxy_ports_for_docker()", script)
|
||||
self.assertIn("neko_shellcrash_proxy_enabled()", script)
|
||||
self.assertIn("SHELLCRASH_NEKO_PROXY_NODE", script)
|
||||
self.assertIn("ip saddr 172.16.0.0/12 tcp dport", script)
|
||||
self.assertIn('chmod +x "$launch"', script)
|
||||
self.assertIn("copy_neko_tampermonkey_seed_dir()", script)
|
||||
self.assertIn("copy_neko_tampermonkey_storage_dir()", script)
|
||||
self.assertIn("find_neko_tampermonkey_seed_profile()", script)
|
||||
self.assertIn("services/neko/tampermonkey-seed", script)
|
||||
self.assertIn("sync_neko_tampermonkey_preferences()", script)
|
||||
self.assertIn("should_replace_current", script)
|
||||
self.assertIn('value.get("from_webstore") is not True', script)
|
||||
self.assertIn('path.startswith("/")', script)
|
||||
self.assertIn('value.get("location") == 8', script)
|
||||
self.assertIn("neko_managed_policies_enabled()", script)
|
||||
self.assertIn("docker_container_http_port_published()", script)
|
||||
self.assertIn("docker_container_network_attached()", script)
|
||||
self.assertIn("remove_unreachable_neko_containers", script)
|
||||
self.assertIn("service_neko_restart()", service_ctl)
|
||||
self.assertIn("service_neko_reconfigure", service_ctl)
|
||||
self.assertIn("service_neko_reconfigure_for_shellcrash_change", service_ctl)
|
||||
self.assertIn("neko_http_probe_code()", service_ctl)
|
||||
self.assertIn("published=", service_ctl)
|
||||
for marker in shared_markers:
|
||||
self.assertIn(marker, script)
|
||||
service_ctl_markers = (
|
||||
"shellcrash_mix_port()",
|
||||
"ensure_shellcrash_proxy_ports_for_docker()",
|
||||
"neko_shellcrash_proxy_enabled()",
|
||||
"SHELLCRASH_NEKO_PROXY_NODE",
|
||||
"ip saddr 172.16.0.0/12 tcp dport",
|
||||
"docker_container_http_port_published()",
|
||||
"docker_container_network_attached()",
|
||||
"remove_unreachable_neko_containers",
|
||||
"service_neko_restart()",
|
||||
"service_neko_reconfigure",
|
||||
"service_neko_reconfigure_for_shellcrash_change",
|
||||
"ENABLE_NEKO_BROWSER_PROXY",
|
||||
"neko_http_probe_code()",
|
||||
"published=",
|
||||
)
|
||||
for marker in service_ctl_markers:
|
||||
self.assertIn(marker, service_ctl)
|
||||
|
||||
def test_tampermonkey_external_extension_seed_is_available_without_managed_policy(self) -> None:
|
||||
external = json.loads(
|
||||
@ -433,6 +443,7 @@ class NekoConfigTests(unittest.TestCase):
|
||||
self.assertIn("install_neko_ip_watch_service", upgrade)
|
||||
self.assertIn("live-neko-ip-watch.service", uninstall)
|
||||
self.assertIn("NEKO_ACCESS_MODE=lan", stack_env)
|
||||
self.assertIn("ENABLE_NEKO_BROWSER_PROXY=0", stack_env)
|
||||
self.assertIn("NEKO_IP_WATCH_INTERVAL=15", stack_env)
|
||||
self.assertIn("NEKO_MANAGED_POLICIES=1", stack_env)
|
||||
self.assertIn("NEKO_TAMPERMONKEY_REPAIR=1", stack_env)
|
||||
|
||||
@ -253,6 +253,27 @@ class WireGuardConfigTests(unittest.TestCase):
|
||||
with self.assertRaises(WireGuardConfigError):
|
||||
configure_neko_wireguard_access(repo_root=Path(tmp), mode="remote", restart=False)
|
||||
|
||||
def test_neko_browser_proxy_defaults_off_and_can_be_enabled(self) -> None:
|
||||
from src.wireguard_config import configure_neko_browser_proxy
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
repo = Path(tmp)
|
||||
env = repo / "config" / "system-stack.env"
|
||||
env.parent.mkdir(parents=True)
|
||||
env.write_text(
|
||||
"NEKO_SHELLCRASH_PROXY_PORT=7894\nSHELLCRASH_NEKO_PROXY_NODE=proxycheap\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
status = configure_neko_browser_proxy(repo_root=repo, enabled=False, restart=False)
|
||||
self.assertFalse(status["enabled"])
|
||||
self.assertEqual(status["resolved_proxy"], "")
|
||||
|
||||
with patch("src.wireguard_config._reconfigure_neko_containers", return_value={"ok": True, "skipped": False}):
|
||||
enabled = configure_neko_browser_proxy(repo_root=repo, enabled=True, restart=True)
|
||||
self.assertTrue(enabled["enabled"])
|
||||
self.assertEqual(enabled["resolved_proxy"], "http://host.docker.internal:7894")
|
||||
self.assertIn("ENABLE_NEKO_BROWSER_PROXY=1", env.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
197
d2ypp2/tools/deploy_full_stream.py
Normal file
197
d2ypp2/tools/deploy_full_stream.py
Normal file
@ -0,0 +1,197 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Stream full deploy output and post-configure ShellCrash/Neko for proxycheap."""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import select
|
||||
import shlex
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import paramiko
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(ROOT / "tools"))
|
||||
|
||||
import deploy_full_paramiko as deploy # noqa: E402
|
||||
|
||||
CONFIG_YAML = ROOT.parent / "config.yaml"
|
||||
REMOTE_PATH = os.environ.get("LIVE_DEPLOY_PATH", "/opt/live/d2ypp").rstrip("/")
|
||||
|
||||
|
||||
def stream_remote(ssh: paramiko.SSHClient, command: str, password: str, timeout: int = 3600) -> int:
|
||||
stdin, stdout, stderr = ssh.exec_command(command, timeout=timeout, get_pty=True)
|
||||
stdin.write(password + "\n")
|
||||
stdin.flush()
|
||||
try:
|
||||
stdin.channel.shutdown_write()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
channel = stdout.channel
|
||||
while True:
|
||||
if channel.exit_status_ready() and not channel.recv_ready() and not channel.recv_stderr_ready():
|
||||
break
|
||||
r, _, _ = select.select([channel], [], [], 0.5)
|
||||
if r:
|
||||
data = channel.recv(4096)
|
||||
if data:
|
||||
sys.stdout.buffer.write(data)
|
||||
sys.stdout.buffer.flush()
|
||||
if channel.recv_stderr_ready():
|
||||
err = channel.recv_stderr(4096)
|
||||
if err:
|
||||
sys.stderr.buffer.write(err)
|
||||
sys.stderr.buffer.flush()
|
||||
return channel.recv_exit_status()
|
||||
|
||||
|
||||
def run_post_config(ssh: paramiko.SSHClient, sftp: paramiko.SFTPClient, password: str) -> int:
|
||||
print("\n[post] updating system-stack.env for proxycheap/neko proxy ports")
|
||||
env_updates = {
|
||||
"NEKO_SHELLCRASH_PROXY_PORT": "7894",
|
||||
"SHELLCRASH_NEKO_PROXY_NODE": "proxycheap",
|
||||
"ENABLE_NEKO_BROWSER_PROXY": "0",
|
||||
}
|
||||
env_path = f"{REMOTE_PATH}/config/system-stack.env"
|
||||
try:
|
||||
existing = sftp.file(env_path, "r").read().decode("utf-8", "replace")
|
||||
except OSError:
|
||||
existing = ""
|
||||
|
||||
lines = existing.splitlines()
|
||||
keys = set(env_updates)
|
||||
kept = [line for line in lines if line.split("=", 1)[0].strip() not in keys]
|
||||
for key, value in env_updates.items():
|
||||
kept.append(f"{key}={value}")
|
||||
payload = "\n".join(kept).rstrip() + "\n"
|
||||
with sftp.file(env_path, "w") as fh:
|
||||
fh.write(payload)
|
||||
|
||||
if CONFIG_YAML.is_file():
|
||||
print(f"[post] uploading {CONFIG_YAML} to ShellCrash yamls")
|
||||
tmp_yaml = f"/tmp/d2ypp-config-{int(time.time())}.yaml"
|
||||
sftp.put(str(CONFIG_YAML), tmp_yaml)
|
||||
sftp.chmod(tmp_yaml, 0o644)
|
||||
install_cmd = (
|
||||
f"sudo -S -p '' bash -lc "
|
||||
f"'mkdir -p /etc/ShellCrash/yamls && install -m 0644 {shlex.quote(tmp_yaml)} /etc/ShellCrash/yamls/config.yaml'"
|
||||
)
|
||||
code = stream_remote(ssh, install_cmd, password, timeout=120)
|
||||
if code != 0:
|
||||
print(f"[post] install config.yaml exit={code}", file=sys.stderr)
|
||||
return code
|
||||
|
||||
print("[post] applying ShellCrash profile via control_plane -> proxycheap")
|
||||
apply_cmd = (
|
||||
f"sudo -S -p '' bash -lc "
|
||||
f"'cd {shlex.quote(REMOTE_PATH)} && "
|
||||
f". scripts/linux/lib/common.sh && load_env && "
|
||||
f"PY={shlex.quote(REMOTE_PATH)}/.venv/bin/python3; "
|
||||
f"[ -x \"$PY\" ] || PY=python3; "
|
||||
f"\"$PY\" - <<\"PY\"\n"
|
||||
"import asyncio\n"
|
||||
"from src.control_plane import apply_shellcrash_profile\n"
|
||||
"result = asyncio.run(apply_shellcrash_profile(\"config.yaml\", \"proxycheap\"))\n"
|
||||
"print(result)\n"
|
||||
"PY'"
|
||||
)
|
||||
code = stream_remote(ssh, apply_cmd, password, timeout=600)
|
||||
if code != 0:
|
||||
print(f"[post] apply_shellcrash_profile exit={code}", file=sys.stderr)
|
||||
return code
|
||||
else:
|
||||
print(f"[post] WARN: missing {CONFIG_YAML}, skip ShellCrash apply")
|
||||
|
||||
print("[post] restart Neko with ShellCrash proxy")
|
||||
cmd = (
|
||||
f"sudo -S -p '' bash -lc "
|
||||
f"'cd {shlex.quote(REMOTE_PATH)} && "
|
||||
f". scripts/linux/lib/common.sh && load_env && "
|
||||
f"bash scripts/linux/service_ctl.sh neko reconfigure'"
|
||||
)
|
||||
code = stream_remote(ssh, cmd, password, timeout=300)
|
||||
if code != 0:
|
||||
print(f"[post] neko reconfigure exit={code}", file=sys.stderr)
|
||||
|
||||
print("[post] verify proxy listeners and neko containers")
|
||||
verify = (
|
||||
"set -e; "
|
||||
"echo '--- system-stack env ---'; "
|
||||
f"grep -E 'ENABLE_NEKO_BROWSER_PROXY|NEKO_SHELLCRASH|SHELLCRASH_NEKO' {shlex.quote(env_path)} || true; "
|
||||
"echo '--- shellcrash listeners ---'; "
|
||||
"grep -A6 'name: neko-mixed' /etc/ShellCrash/yamls/config.yaml 2>/dev/null || "
|
||||
"grep -A6 'name: neko-mixed' /tmp/ShellCrash/config.yaml 2>/dev/null || true; "
|
||||
"echo '--- neko proxy env ---'; "
|
||||
f"cd {shlex.quote(REMOTE_PATH)} && . scripts/linux/lib/common.sh && load_env && "
|
||||
"bash scripts/linux/service_ctl.sh neko status 2>/dev/null | head -30 || true; "
|
||||
"echo '--- docker neko ---'; "
|
||||
"docker ps -a --format '{{.Names}} {{.Status}}' | grep -i neko || true; "
|
||||
"echo '--- health ---'; "
|
||||
"curl -sf -m 5 http://127.0.0.1:8001/health && echo health_ok || echo health_fail"
|
||||
)
|
||||
stream_remote(ssh, verify, password, timeout=120)
|
||||
return 0
|
||||
|
||||
|
||||
def main() -> int:
|
||||
if hasattr(sys.stdout, "reconfigure"):
|
||||
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
||||
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
|
||||
|
||||
config = deploy.load_config()
|
||||
if not config.password:
|
||||
raise SystemExit("LIVE_DEPLOY_PASS is required")
|
||||
|
||||
stamp = time.strftime("%Y%m%d_%H%M%S")
|
||||
revision = deploy._revision()
|
||||
deploy.LOG_DIR.mkdir(parents=True, exist_ok=True)
|
||||
local_log = deploy.LOG_DIR / f"full_deploy_stream_{stamp}.log"
|
||||
|
||||
print(f"==> full deploy {revision} -> {config.user}@{config.host}:{config.remote_path}")
|
||||
archive = deploy.create_source_archive(stamp)
|
||||
print(f"==> local archive: {archive} ({archive.stat().st_size} bytes)")
|
||||
|
||||
remote_archive = f"/tmp/d2ypp2-full-{stamp}.tar.gz"
|
||||
remote_script = f"/tmp/d2ypp2-full-deploy-{stamp}.sh"
|
||||
|
||||
ssh = None
|
||||
sftp = None
|
||||
try:
|
||||
ssh, sftp = deploy.connect(config)
|
||||
print(f"==> uploading archive to {remote_archive}")
|
||||
sftp.put(str(archive), remote_archive)
|
||||
deploy._sftp_put_text(sftp, deploy.build_remote_script(), remote_script)
|
||||
|
||||
args = [
|
||||
remote_script,
|
||||
remote_archive,
|
||||
config.remote_path,
|
||||
stamp,
|
||||
revision,
|
||||
config.profile,
|
||||
"1" if config.run_install else "0",
|
||||
]
|
||||
command = "sudo -S -p '' bash " + " ".join(shlex.quote(arg) for arg in args)
|
||||
print("==> running remote full deployment (streaming)")
|
||||
code = stream_remote(ssh, command, config.password, timeout=config.timeout)
|
||||
print(f"\n==> deploy exit code: {code}")
|
||||
if code != 0:
|
||||
return code
|
||||
|
||||
post_code = run_post_config(ssh, sftp, config.password)
|
||||
print(f"\n==> post-config exit code: {post_code}")
|
||||
with local_log.open("a", encoding="utf-8") as fh:
|
||||
fh.write(f"deploy={code} post={post_code} revision={revision}\n")
|
||||
print(f"==> local log: {local_log}")
|
||||
return post_code if post_code else code
|
||||
finally:
|
||||
if sftp is not None:
|
||||
sftp.close()
|
||||
if ssh is not None:
|
||||
ssh.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@ -377,6 +377,13 @@ type WireGuardRuntimeStatus = {
|
||||
needs_reconfigure?: boolean;
|
||||
remote_urls?: Array<{ id?: number; kind?: string; host?: string; port?: number; url?: string }>;
|
||||
};
|
||||
neko_browser_proxy?: {
|
||||
enabled?: boolean;
|
||||
resolved_proxy?: string;
|
||||
shellcrash_port?: string;
|
||||
shellcrash_node?: string;
|
||||
attach_mode?: string;
|
||||
};
|
||||
recommendations?: string[];
|
||||
last_checked_at?: number;
|
||||
};
|
||||
@ -415,6 +422,7 @@ type SystemNetworkProbe = {
|
||||
auto_start_on_web_panel?: boolean;
|
||||
attach_when_direct_ok?: boolean;
|
||||
attach_neko?: string;
|
||||
enable_neko_browser_proxy?: boolean;
|
||||
attach_ffmpeg?: string;
|
||||
recommendation?: string;
|
||||
};
|
||||
@ -913,6 +921,29 @@ export default function LiveControlApp() {
|
||||
}
|
||||
};
|
||||
|
||||
const setNekoBrowserProxy = async (enabled: boolean) => {
|
||||
setBusy(`neko:proxy:${enabled ? "on" : "off"}`);
|
||||
try {
|
||||
await fetchJson<{ neko_browser_proxy?: WireGuardRuntimeStatus["neko_browser_proxy"] }>("/hub/network/neko_browser_proxy", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ enabled, restart: true }),
|
||||
});
|
||||
await refreshWireGuardStatus();
|
||||
await refreshDashboard();
|
||||
notify(
|
||||
enabled
|
||||
? t("已开启 Neko 浏览器代理", "Neko browser proxy enabled")
|
||||
: t("已关闭 Neko 浏览器代理", "Neko browser proxy disabled"),
|
||||
);
|
||||
} catch (e) {
|
||||
notify((e as Error).message);
|
||||
await refreshWireGuardStatus();
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
};
|
||||
|
||||
const importWireGuardConfig = async () => {
|
||||
await saveWireGuardConfig(false);
|
||||
};
|
||||
@ -2372,6 +2403,43 @@ export default function LiveControlApp() {
|
||||
<p>Target: {wgStatus?.neko_access?.target_nat1to1 || "-"}</p>
|
||||
<p>ShellCrash: {wgStatus?.shellcrash?.running ? `running:${wgStatus?.shellcrash?.mixed_port || "7890"}` : "stopped"}</p>
|
||||
</div>
|
||||
<div className={`mt-3 rounded-lg border px-3 py-2 ${portalTheme === "light" ? "border-slate-200 bg-white" : "border-white/10 bg-black/20"}`}>
|
||||
<p className={`text-[11px] font-medium ${portalTheme === "light" ? "text-slate-500" : "text-zinc-500"}`}>
|
||||
{t("Neko 浏览器代理", "Neko browser proxy")}
|
||||
</p>
|
||||
<div className={`mt-2 grid grid-cols-2 rounded-lg p-1 text-xs font-semibold ${portalTheme === "light" ? "bg-slate-200/70" : "bg-black/40"}`}>
|
||||
{([false, true] as const).map((enabled) => {
|
||||
const active = Boolean(wgStatus?.neko_browser_proxy?.enabled) === enabled;
|
||||
const disabled = busy?.startsWith("neko:proxy");
|
||||
return (
|
||||
<button
|
||||
key={enabled ? "on" : "off"}
|
||||
onClick={() => void setNekoBrowserProxy(enabled)}
|
||||
disabled={disabled}
|
||||
className={`rounded-md px-2.5 py-1.5 transition disabled:opacity-40 ${
|
||||
active
|
||||
? portalTheme === "light"
|
||||
? "bg-white text-cyan-800 shadow-sm"
|
||||
: "bg-cyan-500/25 text-cyan-100 ring-1 ring-cyan-400/25"
|
||||
: portalTheme === "light"
|
||||
? "text-slate-600 hover:bg-white/60"
|
||||
: "text-zinc-300 hover:bg-white/10"
|
||||
}`}
|
||||
>
|
||||
{enabled ? t("开启", "On") : t("关闭", "Off")}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<div className={`mt-2 space-y-1 font-mono text-[11px] ${portalTheme === "light" ? "text-slate-700" : "text-zinc-300"}`}>
|
||||
<p>
|
||||
{t("当前", "Current")}: {wgStatus?.neko_browser_proxy?.resolved_proxy || t("直连", "direct")}
|
||||
</p>
|
||||
<p>
|
||||
{t("节点", "Node")}: {wgStatus?.neko_browser_proxy?.shellcrash_node || "-"} · :{wgStatus?.neko_browser_proxy?.shellcrash_port || "7894"}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{(wgStatus?.neko_access?.remote_urls || []).length ? (
|
||||
<div className="mt-3 flex flex-wrap gap-2">
|
||||
{(wgStatus?.neko_access?.remote_urls || []).slice(0, 4).map((item) => (
|
||||
@ -2448,6 +2516,7 @@ export default function LiveControlApp() {
|
||||
<p>ShellCrash: {systemNetworkProbe?.shellcrash?.running ? `running:${systemNetworkProbe?.shellcrash?.mixed_port || "7890"}` : "manual/stopped"}</p>
|
||||
<p>Autostart: {systemNetworkProbe?.shellcrash_policy?.autostart_on_direct_fail ? "on direct fail" : "off"}</p>
|
||||
<p>Neko attach: {systemNetworkProbe?.shellcrash_policy?.attach_neko || "auto"}</p>
|
||||
<p>Neko proxy switch: {systemNetworkProbe?.shellcrash_policy?.enable_neko_browser_proxy ? "on" : "off"}</p>
|
||||
</div>
|
||||
{systemNetworkProbeLoading ? (
|
||||
<p className={`mt-3 inline-flex items-center gap-2 text-xs ${portalTheme === "light" ? "text-cyan-700" : "text-cyan-200"}`}>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user