Harden WG+Neko install defaults, Neko proxy egress probe, and YouTube multi-Pro UI.
WireGuard overlay persists remote NAT1TO1 at install, opens WebRTC via ShellCrash trusted CIDRs, and reconfigures Neko after wg-quick restarts. Neko proxy probes Google before proxycheap. Console defaults to multi-channel Pro; docs updated. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
eb81d824cc
commit
3bc2cf6a1e
@ -6,9 +6,9 @@
|
||||
|
||||
### 核心能力
|
||||
|
||||
- 抖音直播间 → YouTube Live:支持单频道 / 多频道同时推流,每个任务独立 `youtube.ini`、`URL_config` 与 PM2 进程
|
||||
- 抖音直播间 → YouTube Live:**控制台默认多频道 Pro**(每条线路独立 `youtube.ini`、`URL_config` 与 PM2 进程);单频道模式仍保留在代码中,UI 切换已隐藏
|
||||
- TikTok 直播:支持视频流转发到硬件 HDMI,也可配合 SRS / OBS 接流后再转发
|
||||
- Neko 浏览器:默认个人管理员模式,不挂 Chrome 企业策略、不禁用 Google Sync;保留管理员会话、开发者工具与 Tampermonkey 持久化;按 `NEKO_INSTANCE_COUNT` 动态生成独立容器,默认保底 2 个,YouTube PRO 频道保存会自动提升容量
|
||||
- Neko 浏览器:默认个人管理员模式,不挂 Chrome 企业策略、不禁用 Google Sync;保留管理员会话、开发者工具与 Tampermonkey 持久化;按 `NEKO_INSTANCE_COUNT` 动态生成独立容器,默认保底 2 个,YouTube PRO 频道保存会自动提升容量;**WireGuard 上线后安装脚本自动持久化 `NEKO_ACCESS_MODE=remote` 与 overlay `NAT1TO1`,并放行 WebRTC 端口**;直连失败时 Neko 默认走 ShellCrash `:7890`,仅在 proxycheap 实测可用时才自动开启 `:7894`
|
||||
- 兼容架构:Linux `x86_64` / `arm64`,使用一键脚本部署,控制面板默认域名 `live.local`
|
||||
|
||||
## Linux Unmanned Live Profiles
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
- 统一入口:`live.local` 由 Caddy `live-edge.service` 承接,默认反代到 `live-console.service`,并由 `live-edge-watch.service` 持续自愈,控制台无需记端口。
|
||||
- 总览:展示硬件、软件、网络、直播业务状态,并给出健康检查、失败原因与下一步操作。
|
||||
- 服务:展示 ShellCrash、SRS、Neko、Redroid、ADB、File Browser、Netdata、WebTTY 等服务的安装、运行、端口与控制按钮。
|
||||
- YouTube 无人直播:单频道与多频道 Pro 共存。每条 Pro 线路独立保存 URL、推流密钥、PM2 进程、日志、Neko 工作室入口。
|
||||
- YouTube 无人直播:控制台**默认多频道 Pro**(单频道逻辑保留、UI 切换隐藏)。每条 Pro 线路独立保存 URL、推流密钥、PM2 进程、日志、Neko 工作室入口。
|
||||
- TikTok 无人直播:视频源转发到设备 HDMI,面板可检测输出设备、预览命令、启动/停止链路。
|
||||
- 安卓:Redroid 与真实手机都通过 ADB 识别;Web 面板可看屏、点按、长按、输入、安装 APK、批量执行命令。
|
||||
- 网络:ShellCrash 解决单机代理上网,面板展示实时/累计上行下行、代理状态、DNS 与出口连通性。
|
||||
|
||||
@ -58,11 +58,17 @@ Installer downloads for ShellCrash also try with proxy and without (`--noproxy`
|
||||
## WireGuard + Neko
|
||||
|
||||
- Overlay address for this fleet is typically `10.66.66.0/24` (腾讯云) or legacy `10.88.0.0/24`.
|
||||
- `NEKO_ACCESS_MODE=remote` should use the WG address for `NEKO_WEBRTC_NAT1TO1`, not the physical LAN IP.
|
||||
- **`sync_neko_wireguard_remote_access`** (in `scripts/linux/lib/common.sh` and `service_ctl.sh`): when a `wg*` / `wgeasy` interface is up, the installer and `service_ctl neko` persist `NEKO_ACCESS_MODE=remote`, `NEKO_WIREGUARD_HOST`, and `NEKO_WEBRTC_NAT1TO1` into `config/system-stack.env` so restarts do not drift back to the physical LAN IP.
|
||||
- **`ensure_neko_webrtc_ports_for_trusted_cidrs`**: opens ShellCrash trusted accept rules for overlay CIDRs so Neko HTTP `:920x` and WebRTC UDP/TCP mux ports work over WireGuard, not only on the physical LAN.
|
||||
- **`live-wireguard-watch.service`**: after restarting a stale `wg-quick@*.service`, calls Neko reconfigure so WebRTC candidates stay aligned with the overlay IP.
|
||||
- `resolve_neko_nat1to1` auto-picks `wg*` / overlay `10.x` when remote mode is set.
|
||||
- If a WireGuard overlay IP is already present during Neko install, the installer switches to `remote` automatically.
|
||||
- Applying a WG conf via the hub also switches Neko to remote when the overlay address is ready, and re-runs the ShellCrash trusted-CIDR hook.
|
||||
|
||||
## Neko browser proxy (ShellCrash)
|
||||
|
||||
- Default: `ENABLE_NEKO_BROWSER_PROXY=0` → Neko uses ShellCrash mixed port **7890** when direct Google/YouTube fails.
|
||||
- Optional proxycheap listener **7894** is enabled only when egress probe through that port succeeds (`shellcrash_proxy_egress_ready` / `shellcrash_listener_egress_ok`); a listening but dead upstream no longer auto-flips the switch on fresh installs.
|
||||
|
||||
## Ports to remember
|
||||
|
||||
| Service | Default |
|
||||
|
||||
@ -102,10 +102,12 @@ That means the TCP connection was **rejected or nothing listens** on the address
|
||||
4. From a **laptop/phone**, open **`http://<device-LAN-IP>:8001/`** first (same Wi‑Fi). If that works but `http://live.local` does not, the problem is **mDNS** (Windows often needs Bonjour) or you’re not on the same LAN — use the IP bookmark.
|
||||
5. **Firewall** (nftables/ufw) blocking **80/8001** from Wi‑Fi will also show as “refused” from other hosts while loopback still works.
|
||||
|
||||
### PM2:单频道与多频道 Pro(Linux ARM / x86_64)
|
||||
### PM2:多频道 Pro(Linux ARM / x86_64,控制台默认)
|
||||
|
||||
- **单频道**:在项目根启用一个业务进程即可,例如取消注释 `ecosystem.config.cjs` 里的 `youtube` 或 `tiktok`,执行 `pm2 start ecosystem.config.cjs && pm2 save`。
|
||||
- **多频道 Pro**:每路直播需要**独立的** `config/youtube.ini` 与 `config/URL_config.ini`(或整份独立工作目录)。为第二路及以后各复制一份目录(或符号链接脚本外的配置),在 PM2 里为每个 app 设置不同的 `cwd`,`name` 与 Web 控制台 Pro 线路建议名一致(如 `youtube2__<channelId>`)。
|
||||
Web 控制台 **YouTube 无人直播** 默认进入多频道 Pro;每条线路在 SQLite 落盘并生成独立配置文件。
|
||||
|
||||
- **多频道 Pro(默认)**:每路直播需要**独立的** `config/youtube.<pm2>.ini` 与 `config/URL_config.<pm2>.ini`。控制台保存线路时自动创建;PM2 名与 Web 线路一致(如 `youtube2__<channelId>`)。
|
||||
- **单频道(遗留)**:仍可通过 PM2 手动启一个 `youtube` / `tiktok` 进程;控制台 UI 切换已隐藏,见 `LiveYoutubeUnmannedView.tsx` 中 `HIDE_YOUTUBE_MODE_TOGGLE`。
|
||||
- **硬件编码**:`sudo python3 scripts/hardware_probe.py --write` 会写入 `config/hardware.env` 与 `hardware-profile.json`;推流侧可选 `LIVE_VIDEO_ENCODER`(RKMPP / V4L2M2M / VA-API / QSV 等,见 `config/hardware.env.example`)。NVIDIA 一般由 `douyin_youtube_ffplay.py` 自动走 NVENC。
|
||||
- **音频链**:与 GitLab 分支 `ffmpegAudioRMFoode` 中 `douyin_youtube_ffplay.py` 的 FFmpeg 处理思路一致(`fast_audio`、arnndn、EQ 等);当前主线在 Linux 上还包含板载编码探测与推流稳定性增强,以前端无需对齐 Electron 为准。
|
||||
|
||||
|
||||
@ -39,3 +39,21 @@
|
||||
4. 部署注意
|
||||
- `live.local` 实际运行目录不是当前仓库 `/home/eric/sh/d2ypp2`,而是 `/home/eric/d2ypp`。
|
||||
- 如果只改当前目录而不把修复同步到 `/home/eric/d2ypp`,`live.local` 不会生效。
|
||||
|
||||
---
|
||||
|
||||
项目修复记录(2026-08-26)
|
||||
|
||||
1. 一键安装 / Neko / WireGuard
|
||||
- WireGuard overlay 上线后,`install_neko_browser` 与 `service_ctl neko` 通过 `sync_neko_wireguard_remote_access` 自动写入 `NEKO_ACCESS_MODE=remote`、`NEKO_WIREGUARD_HOST`、`NEKO_WEBRTC_NAT1TO1`,避免 WebRTC 仍广播物理网 IP 导致黑屏/重连。
|
||||
- `ensure_neko_webrtc_ports_for_trusted_cidrs` 在 ShellCrash WAN 防火墙下为 overlay 网段放行 Neko HTTP/WebRTC;`wireguard_watch` 在 WG 重启后自动 reconfigure Neko。
|
||||
- Neko 浏览器代理:`shellcrash_proxy_egress_ready` 实测 Google 204 后再选端口;proxycheap `:7894` 不可用时保持 `ENABLE_NEKO_BROWSER_PROXY=0`,走 mixed `:7890`。
|
||||
|
||||
2. YouTube 无人直播控制台
|
||||
- 默认多频道 Pro,隐藏「单频道 / 多频道」切换条(`HIDE_YOUTUBE_MODE_TOGGLE`)。
|
||||
|
||||
3. 关键文件
|
||||
- `scripts/linux/lib/common.sh`、`scripts/linux/service_ctl.sh`、`scripts/linux/wireguard_watch.sh`
|
||||
- `src/network_preflight.py`、`src/wireguard_config.py`
|
||||
- `web-console/components/live-product/LiveYoutubeUnmannedView.tsx`
|
||||
- `docs/deploy-hardening.md`、`README.md`
|
||||
|
||||
@ -1921,6 +1921,62 @@ clear_live_http_proxy_env() {
|
||||
configure_docker_http_proxy
|
||||
}
|
||||
|
||||
stack_env_upsert() {
|
||||
local key="$1" value="$2"
|
||||
[ -n "$key" ] || return 1
|
||||
mkdir -p "$(dirname "$STACK_ENV")"
|
||||
touch "$STACK_ENV"
|
||||
sed -i 's/\r$//' "$STACK_ENV" 2>/dev/null || true
|
||||
value="${value//$'\r'/}"
|
||||
local prefix="${key}=" next_line="${key}=${value}"
|
||||
local line found=0
|
||||
: >"${STACK_ENV}.tmp"
|
||||
while IFS= read -r line || [ -n "$line" ]; do
|
||||
case "$line" in
|
||||
"${prefix}"*)
|
||||
if [ "$found" -eq 0 ]; then
|
||||
printf '%s\n' "$next_line" >>"${STACK_ENV}.tmp"
|
||||
found=1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
printf '%s\n' "$line" >>"${STACK_ENV}.tmp"
|
||||
;;
|
||||
esac
|
||||
done <"$STACK_ENV"
|
||||
if [ "$found" -eq 0 ]; then
|
||||
printf '%s\n' "$next_line" >>"${STACK_ENV}.tmp"
|
||||
fi
|
||||
mv "${STACK_ENV}.tmp" "$STACK_ENV"
|
||||
sed -i 's/\r$//' "$STACK_ENV" 2>/dev/null || true
|
||||
}
|
||||
|
||||
# One-click install: when WireGuard overlay is up, Neko must advertise the WG IP for
|
||||
# WebRTC (not the physical LAN address). Persist into system-stack.env so restarts
|
||||
# and service_ctl do not drift back to LAN NAT1TO1.
|
||||
sync_neko_wireguard_remote_access() {
|
||||
local wg_ip="" target="" persist="${1:-1}"
|
||||
wg_ip="$(detect_wireguard_overlay_ip || true)"
|
||||
[ -n "$wg_ip" ] || return 1
|
||||
case "${NEKO_ACCESS_MODE:-lan}" in
|
||||
lan|remote)
|
||||
export NEKO_ACCESS_MODE=remote
|
||||
export NEKO_WIREGUARD_HOST="${NEKO_WIREGUARD_HOST:-$wg_ip}"
|
||||
;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
target="$(resolve_neko_nat1to1 || true)"
|
||||
[ -n "$target" ] || return 1
|
||||
export NEKO_WEBRTC_NAT1TO1="$target"
|
||||
if [ "$persist" = "1" ]; then
|
||||
stack_env_upsert NEKO_ACCESS_MODE remote
|
||||
stack_env_upsert NEKO_WIREGUARD_HOST "$wg_ip"
|
||||
stack_env_upsert NEKO_WEBRTC_NAT1TO1 "$target"
|
||||
fi
|
||||
log "WireGuard overlay ready ($wg_ip); Neko remote access NAT1TO1=${target}"
|
||||
return 0
|
||||
}
|
||||
|
||||
detect_wireguard_overlay_ip() {
|
||||
local path name ip preferred="${SHELLCRASH_WG_CIDR:-10.88.0.0/24}"
|
||||
preferred="${preferred%%/*}"
|
||||
@ -2191,6 +2247,21 @@ ensure_shellcrash_proxy_ports_for_docker() {
|
||||
fi
|
||||
}
|
||||
|
||||
# WireGuard/LAN peers reach Neko via HTTP + WebRTC UDP/TCP mux; ShellCrash WAN reject
|
||||
# otherwise drops overlay sources unless trusted CIDR accept rules are present.
|
||||
ensure_neko_webrtc_ports_for_trusted_cidrs() {
|
||||
local cidr
|
||||
[ "${ENABLE_NEKO:-1}" = "1" ] || return 0
|
||||
# Broad trusted accept covers Neko HTTP/WebRTC when ShellCrash WAN reject is active.
|
||||
while IFS= read -r cidr; do
|
||||
[ -n "$cidr" ] || continue
|
||||
ensure_shellcrash_cidr_port_access "9200" tcp "Neko/WebRTC from trusted overlay" "$cidr"
|
||||
done <<EOF
|
||||
$(shellcrash_trusted_cidrs)
|
||||
EOF
|
||||
[ -x /usr/local/sbin/shellcrash-allow-trusted.sh ] && /usr/local/sbin/shellcrash-allow-trusted.sh >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
install_shellcrash_trusted_firewall_hook() {
|
||||
local hook="/usr/local/sbin/shellcrash-allow-trusted.sh"
|
||||
mkdir -p /usr/local/sbin /etc/systemd/system/shellcrash.service.d
|
||||
@ -2244,6 +2315,18 @@ shellcrash_proxy_available() {
|
||||
return 1
|
||||
}
|
||||
|
||||
shellcrash_proxy_egress_ready() {
|
||||
local port="$1" url="${NETWORK_PROBE_GOOGLE_URL:-https://www.google.com/generate_204}"
|
||||
shellcrash_proxy_available "$port" || return 1
|
||||
if have curl; then
|
||||
curl -kfsSL --connect-timeout 3 --max-time 8 -x "http://127.0.0.1:${port}" -o /dev/null "$url" 2>/dev/null && return 0
|
||||
elif have wget; then
|
||||
env http_proxy="http://127.0.0.1:${port}" https_proxy="http://127.0.0.1:${port}" \
|
||||
wget -q --no-check-certificate --timeout=8 -O /dev/null "$url" 2>/dev/null && return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
neko_shellcrash_proxy_port_from_url() {
|
||||
local url="${1:-}" port=""
|
||||
port="$(printf '%s' "$url" | sed -n 's|.*:\([0-9][0-9]*\)$|\1|p')"
|
||||
@ -2289,7 +2372,7 @@ resolve_neko_browser_proxy() {
|
||||
if neko_shellcrash_proxy_port_from_url "$NEKO_BROWSER_PROXY" >/dev/null 2>&1; then
|
||||
local shell_port
|
||||
shell_port="$(neko_shellcrash_proxy_port_from_url "$NEKO_BROWSER_PROXY")"
|
||||
if shellcrash_proxy_available "$shell_port"; then
|
||||
if shellcrash_proxy_egress_ready "$shell_port"; then
|
||||
printf 'http://host.docker.internal:%s' "$shell_port"
|
||||
return 0
|
||||
fi
|
||||
@ -2305,19 +2388,19 @@ resolve_neko_browser_proxy() {
|
||||
system_direct_global_ready && return 0
|
||||
local port fallback
|
||||
port="$(resolve_neko_browser_proxy_primary_port)"
|
||||
if shellcrash_proxy_available "$port"; then
|
||||
if shellcrash_proxy_egress_ready "$port"; then
|
||||
printf 'http://host.docker.internal:%s' "$port"
|
||||
return 0
|
||||
fi
|
||||
fallback="$(resolve_neko_browser_proxy_fallback_port)"
|
||||
if [ -n "$fallback" ] && [ "$fallback" != "$port" ] && shellcrash_proxy_available "$fallback"; then
|
||||
if [ -n "$fallback" ] && [ "$fallback" != "$port" ] && shellcrash_proxy_egress_ready "$fallback"; then
|
||||
printf 'http://host.docker.internal:%s' "$fallback"
|
||||
return 0
|
||||
fi
|
||||
shellcrash_autostart_if_needed >/dev/null 2>&1 || true
|
||||
for port in "$(resolve_neko_browser_proxy_primary_port)" "$(resolve_neko_browser_proxy_fallback_port)"; do
|
||||
[ -n "$port" ] || continue
|
||||
if shellcrash_proxy_available "$port"; then
|
||||
if shellcrash_proxy_egress_ready "$port"; then
|
||||
printf 'http://host.docker.internal:%s' "$port"
|
||||
return 0
|
||||
fi
|
||||
@ -2543,6 +2626,7 @@ EOF
|
||||
fi
|
||||
shellcrash_sync_runtime_config || log "WARN: ShellCrash config.yaml is not staged yet; apply a YAML profile before starting"
|
||||
ensure_shellcrash_proxy_ports_for_docker >/dev/null 2>&1 || true
|
||||
ensure_neko_webrtc_ports_for_trusted_cidrs >/dev/null 2>&1 || true
|
||||
/usr/local/sbin/shellcrash-allow-trusted.sh >/dev/null 2>&1 || true
|
||||
grant_shellcrash_web_write_access
|
||||
}
|
||||
@ -2693,16 +2777,7 @@ install_neko_browser() {
|
||||
export NEKO_WEBRTC_EPR_2="${NEKO_WEBRTC_EPR_2:-$NEKO_WEBRTC_UDP_RANGE_2}"
|
||||
export NEKO_WEBRTC_EPR_3="${NEKO_WEBRTC_EPR_3:-$NEKO_WEBRTC_UDP_RANGE_3}"
|
||||
export NEKO_ACCESS_MODE="${NEKO_ACCESS_MODE:-lan}"
|
||||
# If WireGuard overlay is already up and the operator did not force lan, prefer remote NAT1TO1.
|
||||
if [ "${NEKO_ACCESS_MODE}" = "lan" ]; then
|
||||
local wg_ip=""
|
||||
wg_ip="$(detect_wireguard_overlay_ip || true)"
|
||||
if [ -n "$wg_ip" ]; then
|
||||
log "WireGuard overlay detected ($wg_ip); switching Neko access mode to remote"
|
||||
export NEKO_ACCESS_MODE=remote
|
||||
export NEKO_WIREGUARD_HOST="${NEKO_WIREGUARD_HOST:-$wg_ip}"
|
||||
fi
|
||||
fi
|
||||
sync_neko_wireguard_remote_access 1 || true
|
||||
# Upstream n.eko images include STUN servers by default, and ICE Lite with ICE servers is unstable.
|
||||
# Keep full ICE on by default even if an older system-stack.env still contains NEKO_WEBRTC_ICELITE=1.
|
||||
if [ "${NEKO_FORCE_ICELITE:-0}" = "1" ]; then
|
||||
@ -2718,12 +2793,14 @@ install_neko_browser() {
|
||||
export NEKO_WEBRTC_UDPMUX_1="${NEKO_WEBRTC_UDPMUX_1:-$NEKO_WEBRTC_UDPMUX}"
|
||||
export NEKO_WEBRTC_UDPMUX_2="${NEKO_WEBRTC_UDPMUX_2:-52301}"
|
||||
export NEKO_WEBRTC_UDPMUX_3="${NEKO_WEBRTC_UDPMUX_3:-52302}"
|
||||
target_nat1to1="$(resolve_neko_nat1to1)"
|
||||
if [ -n "$target_nat1to1" ]; then
|
||||
export NEKO_WEBRTC_NAT1TO1="$target_nat1to1"
|
||||
if [ -z "${NEKO_WEBRTC_NAT1TO1:-}" ]; then
|
||||
target_nat1to1="$(resolve_neko_nat1to1 || true)"
|
||||
[ -n "$target_nat1to1" ] && export NEKO_WEBRTC_NAT1TO1="$target_nat1to1"
|
||||
fi
|
||||
export NEKO_PLUGINS_ENABLED="${NEKO_PLUGINS_ENABLED:-true}"
|
||||
ensure_neko_browser_launcher_executable
|
||||
ensure_shellcrash_proxy_ports_for_docker >/dev/null 2>&1 || true
|
||||
ensure_neko_webrtc_ports_for_trusted_cidrs >/dev/null 2>&1 || true
|
||||
for idx in $(seq 1 "$instance_count"); do
|
||||
neko_prof="$(resolve_neko_profile_dir_for_instance "$idx")"
|
||||
seed_neko_tampermonkey_profile "$neko_prof" "$(resolve_neko_profile_dir_for_instance 1)"
|
||||
|
||||
@ -261,10 +261,10 @@ neko_browser_proxy_auto_enable_if_needed() {
|
||||
system_direct_global_ready && return 0
|
||||
local port
|
||||
port="$(shellcrash_neko_proxy_port)"
|
||||
if ! shellcrash_proxy_available "$port"; then
|
||||
if ! shellcrash_proxy_egress_ready "$port"; then
|
||||
shellcrash_autostart_if_needed >/dev/null 2>&1 || true
|
||||
port="$(shellcrash_neko_proxy_port)"
|
||||
shellcrash_proxy_available "$port" || return 0
|
||||
shellcrash_proxy_egress_ready "$port" || return 0
|
||||
fi
|
||||
stack_env_upsert ENABLE_NEKO_BROWSER_PROXY 1
|
||||
export ENABLE_NEKO_BROWSER_PROXY=1
|
||||
@ -1035,6 +1035,74 @@ neko_nat1to1_is_overlay_iface() {
|
||||
esac
|
||||
}
|
||||
|
||||
detect_wireguard_overlay_ip() {
|
||||
local path name ip preferred="${SHELLCRASH_WG_CIDR:-10.88.0.0/24}"
|
||||
preferred="${preferred%%/*}"
|
||||
preferred="${preferred%.*}"
|
||||
for path in /sys/class/net/*; do
|
||||
[ -e "$path" ] || continue
|
||||
name="${path##*/}"
|
||||
case "$name" in
|
||||
wg*|wgeasy|wireguard*) ;;
|
||||
*) continue ;;
|
||||
esac
|
||||
ip="$(ip -4 addr show dev "$name" 2>/dev/null | awk '$1=="inet" {sub(/\/.*/, "", $2); print $2; exit}')"
|
||||
[ -n "$ip" ] || continue
|
||||
if [ -n "$preferred" ] && printf '%s' "$ip" | grep -q "^${preferred}\\."; then
|
||||
printf '%s\n' "$ip"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
for path in /sys/class/net/*; do
|
||||
[ -e "$path" ] || continue
|
||||
name="${path##*/}"
|
||||
case "$name" in
|
||||
wg*|wgeasy|wireguard*) ;;
|
||||
*) continue ;;
|
||||
esac
|
||||
ip="$(ip -4 addr show dev "$name" 2>/dev/null | awk '$1=="inet" {sub(/\/.*/, "", $2); print $2; exit}')"
|
||||
if [ -n "$ip" ]; then
|
||||
printf '%s\n' "$ip"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
sync_neko_wireguard_remote_access() {
|
||||
local wg_ip="" target="" persist="${1:-1}"
|
||||
wg_ip="$(detect_wireguard_overlay_ip || true)"
|
||||
[ -n "$wg_ip" ] || return 1
|
||||
case "${NEKO_ACCESS_MODE:-lan}" in
|
||||
lan|remote)
|
||||
export NEKO_ACCESS_MODE=remote
|
||||
export NEKO_WIREGUARD_HOST="${NEKO_WIREGUARD_HOST:-$wg_ip}"
|
||||
;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
target="$(resolve_neko_nat1to1 || true)"
|
||||
[ -n "$target" ] || return 1
|
||||
export NEKO_WEBRTC_NAT1TO1="$target"
|
||||
if [ "$persist" = "1" ]; then
|
||||
stack_env_upsert NEKO_ACCESS_MODE remote
|
||||
stack_env_upsert NEKO_WIREGUARD_HOST "$wg_ip"
|
||||
stack_env_upsert NEKO_WEBRTC_NAT1TO1 "$target"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
ensure_neko_webrtc_ports_for_trusted_cidrs() {
|
||||
local cidr
|
||||
[ "${ENABLE_NEKO:-1}" = "1" ] || return 0
|
||||
while IFS= read -r cidr; do
|
||||
[ -n "$cidr" ] || continue
|
||||
ensure_shellcrash_docker_port_access "9200" tcp "Neko/WebRTC from trusted overlay"
|
||||
done <<EOF
|
||||
$(shellcrash_trusted_cidrs)
|
||||
EOF
|
||||
[ -x /usr/local/sbin/shellcrash-allow-trusted.sh ] && /usr/local/sbin/shellcrash-allow-trusted.sh >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
resolve_neko_nat1to1() {
|
||||
local mode="${NEKO_ACCESS_MODE:-lan}" candidate="" lan_ip="" iface=""
|
||||
lan_ip="$(detect_preferred_lan_ip || true)"
|
||||
@ -1577,6 +1645,19 @@ shellcrash_proxy_available() {
|
||||
return 1
|
||||
}
|
||||
|
||||
# Port listening is not enough: proxycheap listener can accept CONNECT while upstream is dead.
|
||||
shellcrash_proxy_egress_ready() {
|
||||
local port="$1" url="${NETWORK_PROBE_GOOGLE_URL:-https://www.google.com/generate_204}"
|
||||
shellcrash_proxy_available "$port" || return 1
|
||||
if have curl; then
|
||||
curl -kfsSL --connect-timeout 3 --max-time 8 -x "http://127.0.0.1:${port}" -o /dev/null "$url" 2>/dev/null && return 0
|
||||
elif have wget; then
|
||||
env http_proxy="http://127.0.0.1:${port}" https_proxy="http://127.0.0.1:${port}" \
|
||||
wget -q --no-check-certificate --timeout=8 -O /dev/null "$url" 2>/dev/null && return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
neko_shellcrash_attach_disabled() {
|
||||
case "${SHELLCRASH_ATTACH_NEKO:-auto}" in
|
||||
0|false|FALSE|off|OFF|none|NONE|direct|DIRECT) return 0 ;;
|
||||
@ -1613,7 +1694,7 @@ resolve_neko_browser_proxy() {
|
||||
if neko_shellcrash_proxy_port_from_url "$NEKO_BROWSER_PROXY" >/dev/null 2>&1; then
|
||||
local shell_port
|
||||
shell_port="$(neko_shellcrash_proxy_port_from_url "$NEKO_BROWSER_PROXY")"
|
||||
if shellcrash_proxy_available "$shell_port"; then
|
||||
if shellcrash_proxy_egress_ready "$shell_port"; then
|
||||
neko_proxy_url_for_port "$shell_port"
|
||||
return 0
|
||||
fi
|
||||
@ -1629,19 +1710,19 @@ resolve_neko_browser_proxy() {
|
||||
system_direct_global_ready && return 0
|
||||
local port fallback
|
||||
port="$(resolve_neko_browser_proxy_primary_port)"
|
||||
if shellcrash_proxy_available "$port"; then
|
||||
if shellcrash_proxy_egress_ready "$port"; then
|
||||
neko_proxy_url_for_port "$port"
|
||||
return 0
|
||||
fi
|
||||
fallback="$(resolve_neko_browser_proxy_fallback_port)"
|
||||
if [ -n "$fallback" ] && [ "$fallback" != "$port" ] && shellcrash_proxy_available "$fallback"; then
|
||||
if [ -n "$fallback" ] && [ "$fallback" != "$port" ] && shellcrash_proxy_egress_ready "$fallback"; then
|
||||
neko_proxy_url_for_port "$fallback"
|
||||
return 0
|
||||
fi
|
||||
shellcrash_autostart_if_needed >/dev/null 2>&1 || true
|
||||
for port in "$(resolve_neko_browser_proxy_primary_port)" "$(resolve_neko_browser_proxy_fallback_port)"; do
|
||||
[ -n "$port" ] || continue
|
||||
if shellcrash_proxy_available "$port"; then
|
||||
if shellcrash_proxy_egress_ready "$port"; then
|
||||
neko_proxy_url_for_port "$port"
|
||||
return 0
|
||||
fi
|
||||
@ -2630,6 +2711,7 @@ service_neko_start() {
|
||||
ensure_neko_browser_launcher_executable
|
||||
prepare_neko_profile_dirs_for_compose
|
||||
ensure_shellcrash_proxy_ports_for_docker >/dev/null 2>&1 || true
|
||||
ensure_neko_webrtc_ports_for_trusted_cidrs >/dev/null 2>&1 || true
|
||||
for idx in $(seq 1 "$instance_count"); do
|
||||
prof="$(resolve_neko_profile_dir_for_instance "$idx")"
|
||||
port="$(resolve_neko_http_port_for_instance "$idx")"
|
||||
@ -2669,6 +2751,7 @@ service_neko_reconfigure() {
|
||||
sync_neko_host_assets
|
||||
prepare_neko_profile_dirs_for_compose
|
||||
ensure_shellcrash_proxy_ports_for_docker >/dev/null 2>&1 || true
|
||||
ensure_neko_webrtc_ports_for_trusted_cidrs >/dev/null 2>&1 || true
|
||||
for idx in $(seq 1 "$instance_count"); do
|
||||
service_names="${service_names} neko${idx}"
|
||||
done
|
||||
@ -2731,6 +2814,7 @@ export_neko_env() {
|
||||
export NEKO_WEBRTC_EPR_2="${NEKO_WEBRTC_EPR_2:-$NEKO_WEBRTC_UDP_RANGE_2}"
|
||||
export NEKO_WEBRTC_EPR_3="${NEKO_WEBRTC_EPR_3:-$NEKO_WEBRTC_UDP_RANGE_3}"
|
||||
export NEKO_ACCESS_MODE="${NEKO_ACCESS_MODE:-lan}"
|
||||
sync_neko_wireguard_remote_access 1 || true
|
||||
# Upstream n.eko images include STUN servers by default, and ICE Lite with ICE servers is unstable.
|
||||
# Keep full ICE on by default even if an older system-stack.env still contains NEKO_WEBRTC_ICELITE=1.
|
||||
if [ "${NEKO_FORCE_ICELITE:-0}" = "1" ]; then
|
||||
@ -2746,12 +2830,12 @@ export_neko_env() {
|
||||
export NEKO_WEBRTC_UDPMUX_1="${NEKO_WEBRTC_UDPMUX_1:-$NEKO_WEBRTC_UDPMUX}"
|
||||
export NEKO_WEBRTC_UDPMUX_2="${NEKO_WEBRTC_UDPMUX_2:-52301}"
|
||||
export NEKO_WEBRTC_UDPMUX_3="${NEKO_WEBRTC_UDPMUX_3:-52302}"
|
||||
target_nat1to1="$(resolve_neko_nat1to1)"
|
||||
if [ -n "$target_nat1to1" ]; then
|
||||
if [ "${NEKO_WEBRTC_NAT1TO1:-}" != "$target_nat1to1" ]; then
|
||||
if [ -z "${NEKO_WEBRTC_NAT1TO1:-}" ]; then
|
||||
target_nat1to1="$(resolve_neko_nat1to1 || true)"
|
||||
if [ -n "$target_nat1to1" ]; then
|
||||
stack_env_upsert NEKO_WEBRTC_NAT1TO1 "$target_nat1to1"
|
||||
export NEKO_WEBRTC_NAT1TO1="$target_nat1to1"
|
||||
fi
|
||||
export NEKO_WEBRTC_NAT1TO1="$target_nat1to1"
|
||||
fi
|
||||
export NEKO_PLUGINS_ENABLED="${NEKO_PLUGINS_ENABLED:-true}"
|
||||
}
|
||||
|
||||
@ -62,6 +62,23 @@ interface_is_stale() {
|
||||
'
|
||||
}
|
||||
|
||||
refresh_neko_after_wireguard_restart() {
|
||||
local root="${LIVE_STACK_ROOT:-/opt/live/d2ypp}"
|
||||
local ctl="$root/scripts/linux/service_ctl.sh"
|
||||
local common="$root/scripts/linux/lib/common.sh"
|
||||
[ -f "$common" ] || return 0
|
||||
# shellcheck source=/dev/null
|
||||
. "$common"
|
||||
STACK_ENV="${LIVE_STACK_ENV:-$root/config/system-stack.env}"
|
||||
ROOT_DIR="$root"
|
||||
sync_neko_wireguard_remote_access 1 || return 0
|
||||
ensure_neko_webrtc_ports_for_trusted_cidrs >/dev/null 2>&1 || true
|
||||
[ -f "$ctl" ] || return 0
|
||||
command -v docker >/dev/null 2>&1 || return 0
|
||||
docker ps --format '{{.Names}}' 2>/dev/null | grep -q '^live-neko-' || return 0
|
||||
bash "$ctl" neko reconfigure >/dev/null 2>&1 || log "WARN: Neko reconfigure after WireGuard restart failed"
|
||||
}
|
||||
|
||||
restart_interface() {
|
||||
local iface="$1"
|
||||
if systemctl list-unit-files "wg-quick@${iface}.service" --no-legend 2>/dev/null | grep -q .; then
|
||||
@ -76,6 +93,7 @@ restart_interface() {
|
||||
log "WARN: $iface is stale but wg-quick@${iface}.service is not installed"
|
||||
return 1
|
||||
fi
|
||||
refresh_neko_after_wireguard_restart || true
|
||||
}
|
||||
|
||||
watch_once() {
|
||||
|
||||
@ -284,6 +284,17 @@ def _attach_mode(raw: str | None) -> str:
|
||||
return "auto"
|
||||
|
||||
|
||||
def shellcrash_listener_egress_ok(port: str | int, *, url: str = GOOGLE_204) -> bool:
|
||||
"""Return True when a ShellCrash mixed/listener port can reach global targets."""
|
||||
port_s = str(port or "").strip()
|
||||
if not port_s.isdigit():
|
||||
return False
|
||||
if not shellcrash_runtime().get("running"):
|
||||
return False
|
||||
result = _probe_url(url, proxy=f"http://127.0.0.1:{port_s}")
|
||||
return bool(result.get("ok"))
|
||||
|
||||
|
||||
def neko_browser_proxy_auto_desired(probe: dict[str, Any]) -> bool:
|
||||
"""Enable Neko browser proxy when direct Google/YouTube fails but ShellCrash proxy works."""
|
||||
if bool(probe.get("global_direct_ok")):
|
||||
|
||||
@ -1403,12 +1403,15 @@ def _resolve_neko_browser_proxy_url(env: dict[str, str], *, proxycheap_enabled:
|
||||
docker_host_ip = _resolve_neko_docker_host_ip()
|
||||
neko_port = str(env.get("NEKO_SHELLCRASH_PROXY_PORT") or "7894").strip() or "7894"
|
||||
try:
|
||||
from src.network_preflight import shellcrash_runtime
|
||||
from src.network_preflight import shellcrash_runtime, shellcrash_listener_egress_ok
|
||||
|
||||
mix_port = str(shellcrash_runtime().get("mixed_port") or "7890").strip() or "7890"
|
||||
except Exception:
|
||||
mix_port = "7890"
|
||||
shellcrash_listener_egress_ok = None # type: ignore[assignment]
|
||||
port = neko_port if proxycheap_enabled else mix_port
|
||||
if proxycheap_enabled and shellcrash_listener_egress_ok is not None and not shellcrash_listener_egress_ok(neko_port):
|
||||
port = mix_port
|
||||
return build_neko_browser_proxy_url(docker_host_ip, port)
|
||||
|
||||
|
||||
@ -1454,6 +1457,22 @@ def ensure_neko_browser_proxy_for_network(repo_root: Path, *, restart: bool = Tr
|
||||
probe = system_network_probe()
|
||||
if not neko_browser_proxy_auto_desired(probe):
|
||||
return {"applied": False, "reason": "not_needed", "mode": probe.get("mode")}
|
||||
neko_port = str(env.get("NEKO_SHELLCRASH_PROXY_PORT") or "7894").strip() or "7894"
|
||||
from src.network_preflight import shellcrash_listener_egress_ok
|
||||
|
||||
if not shellcrash_listener_egress_ok(neko_port):
|
||||
reconfigure: dict[str, Any] = {"ok": True, "skipped": True, "reason": "proxycheap_unhealthy"}
|
||||
if restart:
|
||||
reconfigure = _reconfigure_neko_containers(repo_root)
|
||||
status = _neko_browser_proxy_status(repo_root)
|
||||
return {
|
||||
"applied": bool(reconfigure.get("ok") and not reconfigure.get("skipped")),
|
||||
"reason": "direct_blocked_mixed_only",
|
||||
"enabled": False,
|
||||
"mode": probe.get("mode"),
|
||||
**status,
|
||||
"reconfigure": reconfigure,
|
||||
}
|
||||
result = configure_neko_browser_proxy(
|
||||
repo_root=repo_root,
|
||||
enabled=True,
|
||||
|
||||
@ -304,12 +304,40 @@ class WireGuardConfigTests(unittest.TestCase):
|
||||
"mode": "shellcrash",
|
||||
}
|
||||
with patch("src.network_preflight.system_network_probe", return_value=probe):
|
||||
with patch("src.wireguard_config._reconfigure_neko_containers", return_value={"ok": True, "skipped": False}):
|
||||
result = ensure_neko_browser_proxy_for_network(repo_root=repo, restart=True)
|
||||
with patch("src.network_preflight.shellcrash_listener_egress_ok", return_value=True):
|
||||
with patch("src.wireguard_config._reconfigure_neko_containers", return_value={"ok": True, "skipped": False}):
|
||||
result = ensure_neko_browser_proxy_for_network(repo_root=repo, restart=True)
|
||||
self.assertTrue(result["applied"])
|
||||
self.assertTrue(result["enabled"])
|
||||
self.assertNotIn("NEKO_BROWSER_PROXY_MANUAL=1", env.read_text(encoding="utf-8"))
|
||||
|
||||
def test_neko_browser_proxy_auto_uses_mixed_when_proxycheap_dead(self) -> None:
|
||||
from src.wireguard_config import ensure_neko_browser_proxy_for_network
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
repo = Path(tmp)
|
||||
env = repo / "config" / "system-stack.env"
|
||||
env.parent.mkdir(parents=True)
|
||||
env.write_text(
|
||||
"ENABLE_NEKO_BROWSER_PROXY=0\nSHELLCRASH_ATTACH_NEKO=auto\nNEKO_SHELLCRASH_PROXY_PORT=7894\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
probe = {
|
||||
"global_direct_ok": False,
|
||||
"global_proxy_ok": True,
|
||||
"shellcrash": {"running": True, "mixed_port": "7890"},
|
||||
"shellcrash_policy": {"attach_neko_mode": "auto"},
|
||||
"mode": "shellcrash",
|
||||
}
|
||||
with patch("src.network_preflight.system_network_probe", return_value=probe):
|
||||
with patch("src.network_preflight.shellcrash_listener_egress_ok", return_value=False):
|
||||
with patch("src.wireguard_config._reconfigure_neko_containers", return_value={"ok": True, "skipped": False}) as reconf:
|
||||
result = ensure_neko_browser_proxy_for_network(repo_root=repo, restart=True)
|
||||
self.assertTrue(result["applied"])
|
||||
self.assertFalse(result["enabled"])
|
||||
self.assertEqual(result["reason"], "direct_blocked_mixed_only")
|
||||
reconf.assert_called_once()
|
||||
|
||||
def test_neko_browser_proxy_auto_skips_when_direct_ok(self) -> None:
|
||||
from src.wireguard_config import ensure_neko_browser_proxy_for_network
|
||||
|
||||
|
||||
@ -176,8 +176,9 @@ function resolveChannelPm2(channel: YoutubeProChannel): string {
|
||||
const MODE_KEY = "live-hub-youtube-mode-v1";
|
||||
const PRO_PM2_RESERVED = new Set(["douyin_youtube", "tiktok", "obs", "web"]);
|
||||
|
||||
/** UI 暂时隐藏「多频道 Pro」切换(DOM 与逻辑保留,改 false 即可恢复) */
|
||||
const HIDE_YOUTUBE_MULTI_PRO_TOGGLE = false;
|
||||
/** 隐藏单频道/多频道切换条;默认多频道 Pro(改 false 可恢复切换) */
|
||||
const HIDE_YOUTUBE_MODE_TOGGLE = true;
|
||||
const DEFAULT_YOUTUBE_MODE: "single" | "pro" = "pro";
|
||||
|
||||
/** UI 隐藏顶部「转播实况」概览卡(状态、指标网格、打开源站等) */
|
||||
const HIDE_YOUTUBE_RELAY_SNAPSHOT = true;
|
||||
@ -802,7 +803,7 @@ export function LiveYoutubeUnmannedView({
|
||||
[liveProcesses, singleProcessOptions],
|
||||
);
|
||||
|
||||
const [mode, setMode] = useState<"single" | "pro">("single");
|
||||
const [mode, setMode] = useState<"single" | "pro">(DEFAULT_YOUTUBE_MODE);
|
||||
const [channels, setChannels] = useState<YoutubeProChannel[]>([]);
|
||||
const [activeCh, setActiveCh] = useState<string>("");
|
||||
const [singleUrlDraft, setSingleUrlDraft] = useState(urlConfig);
|
||||
@ -1037,12 +1038,14 @@ export function LiveYoutubeUnmannedView({
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
if (HIDE_YOUTUBE_MULTI_PRO_TOGGLE) {
|
||||
setMode("single");
|
||||
if (HIDE_YOUTUBE_MODE_TOGGLE) {
|
||||
setMode(DEFAULT_YOUTUBE_MODE);
|
||||
window.localStorage.setItem(MODE_KEY, DEFAULT_YOUTUBE_MODE);
|
||||
return;
|
||||
}
|
||||
const m = window.localStorage.getItem(MODE_KEY);
|
||||
if (m === "pro" || m === "single") setMode(m);
|
||||
else setMode(DEFAULT_YOUTUBE_MODE);
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
@ -3061,17 +3064,17 @@ export function LiveYoutubeUnmannedView({
|
||||
</h2>
|
||||
<p className="mt-0.5 text-xs text-zinc-500">
|
||||
{t(
|
||||
"单路一条流;多路时每条线路独立保存自己的密钥、URL 列表和 PM2 任务。填好后保存,再点「开始」。Neko 浏览器仅作辅助工作室,不再阻塞推流。",
|
||||
"Single lane or multi-lane: every lane keeps its own key, URL list, and PM2 task. Save, then Start. Neko is optional browser tooling and no longer blocks streaming.",
|
||||
"多频道 Pro:每条线路独立保存密钥、URL 列表和 PM2 任务。填好后保存,再点「开始」。Neko 浏览器仅作辅助工作室,不再阻塞推流。",
|
||||
"Multi Pro: each lane keeps its own key, URL list, and PM2 task. Save, then Start. Neko is optional browser tooling and no longer blocks streaming.",
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className={`ml-auto flex shrink-0 self-start rounded-xl border border-white/10 bg-black/30 p-1 ${
|
||||
HIDE_YOUTUBE_MULTI_PRO_TOGGLE ? "hidden" : ""
|
||||
HIDE_YOUTUBE_MODE_TOGGLE ? "hidden" : ""
|
||||
}`}
|
||||
aria-hidden={HIDE_YOUTUBE_MULTI_PRO_TOGGLE}
|
||||
aria-hidden={HIDE_YOUTUBE_MODE_TOGGLE}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user