feat: add WiFi provisioning for headless devices (AP + Captive Portal)

- Add lib/network.js: WiFi scan, connect, AP hotspot via nmcli
- Add lib/dns-hijack.js: dnsmasq management for DNS hijack + DHCP
- Add lib/captive-server.js: embedded HTTP captive portal with WiFi setup page
- Add lib/provisioning.js: orchestrator (detect network -> AP mode -> wait -> exit)
- Update client.js: call ensureNetwork() before WS connection
- Update install.sh: auto-install dnsmasq dependency

Made-with: Cursor
This commit is contained in:
stswangzhiping
2026-03-16 08:58:51 +08:00
parent b3770d21d4
commit eb9f4ab1c3
7 changed files with 712 additions and 2 deletions

View File

@@ -28,6 +28,26 @@ if [ "$MAJOR" -lt 18 ]; then
fi
info "Node.js $NODE_VER"
# ── 检查/安装 dnsmasqWiFi 配网需要)──────────────────────────────────────
if ! command -v dnsmasq &>/dev/null; then
info "安装 dnsmasqWiFi 配网所需)..."
if command -v apt-get &>/dev/null; then
apt-get install -y -qq dnsmasq >/dev/null 2>&1
elif command -v yum &>/dev/null; then
yum install -y -q dnsmasq >/dev/null 2>&1
elif command -v apk &>/dev/null; then
apk add --quiet dnsmasq >/dev/null 2>&1
else
warn "无法自动安装 dnsmasqWiFi 配网功能可能不可用"
fi
# 禁止 dnsmasq 系统服务自启clawd 自己管理)
systemctl disable dnsmasq 2>/dev/null || true
systemctl stop dnsmasq 2>/dev/null || true
fi
if command -v dnsmasq &>/dev/null; then
info "dnsmasq ✓"
fi
# ── 安装 clawd ───────────────────────────────────────────────────────────────
INSTALL_DIR="/opt/clawd"
CONFIG_DIR="/etc/clawd"