diff --git a/install.sh b/install.sh index a0e5217..479b09e 100644 --- a/install.sh +++ b/install.sh @@ -12,6 +12,10 @@ info() { printf '%s\n' "$*" } +warn() { + printf 'WARN: %s\n' "$*" >&2 +} + die() { printf 'ERROR: %s\n' "$*" >&2 exit 1 @@ -134,6 +138,73 @@ package_manager() { printf 'unknown' } +package_installed() { + local pkg manager + pkg="$1" + manager="$(package_manager)" + case "$manager" in + opkg) + opkg list-installed "$pkg" 2>/dev/null | grep -Fq "$pkg" + ;; + apk) + apk info -e "$pkg" >/dev/null 2>&1 + ;; + *) + return 1 + ;; + esac +} + +install_packages() { + local manager + manager="$(package_manager)" + case "$manager" in + opkg) + opkg update >/dev/null 2>&1 || warn "не удалось обновить список opkg, пробую ставить пакеты как есть" + opkg install "$@" + ;; + apk) + apk update >/dev/null 2>&1 || warn "не удалось обновить список apk, пробую ставить пакеты как есть" + apk add "$@" + ;; + *) + return 1 + ;; + esac +} + +ensure_wol_support() { + local need manager tool_pkg candidate + [ "${ROOT%/}" = "" ] || return 0 + manager="$(package_manager)" + [ "$manager" != "unknown" ] || { + warn "не найден пакетный менеджер для установки WOL-пакетов" + return 0 + } + need="" + if ! package_installed "luci-app-wol"; then + need="$need luci-app-wol" + fi + if ! command -v etherwake >/dev/null 2>&1 && ! command -v wakeonlan >/dev/null 2>&1 && ! command -v wol >/dev/null 2>&1; then + tool_pkg="etherwake" + for candidate in etherwake wakeonlan wol; do + if package_installed "$candidate"; then + tool_pkg="" + break + fi + done + if [ -n "${tool_pkg:-}" ]; then + need="$need $tool_pkg" + fi + fi + need="${need# }" + [ -n "$need" ] || return 0 + info "Устанавливаю поддержку Wake-on-LAN: $need" + if ! install_packages $need; then + warn "не удалось установить WOL-пакеты автоматически: $need" + fi +} + install_xray_runtime() { local remote_bin [ "${ROOT%/}" = "" ] || return 0 @@ -152,6 +223,8 @@ install_file "usr/share/luci/menu.d/luci-app-owrt-remote.json" 0644 install_file "usr/share/rpcd/acl.d/luci-app-owrt-remote.json" 0644 install_file "www/luci-static/resources/view/owrt_remote.js" 0644 +ensure_wol_support + rm -f "$(target_path usr/lib/lua/luci/controller/owrt_remote.lua)" 2>/dev/null || true rm -rf "$(target_path tmp/luci-indexcache)" "$(target_path tmp/luci-modulecache)" "$(target_path tmp/luci-indexcache.)"* "$(target_path tmp/luci-modulecache.)"* 2>/dev/null || true diff --git a/vps/owrt-remote-hub.py b/vps/owrt-remote-hub.py index b22801e..0410520 100644 --- a/vps/owrt-remote-hub.py +++ b/vps/owrt-remote-hub.py @@ -2477,10 +2477,10 @@ function renderWolPanel(router) {{ - +
`; @@ -2526,10 +2526,10 @@ function renderWolPanelRich(router) {{ - + `; @@ -3956,11 +3956,18 @@ cards.addEventListener('input', (ev) => {{ const routerId = ev.target?.dataset?.wolPassword; if (!routerId) return; const value = ev.target.value || ''; + ev.stopPropagation(); saveWolPassword(routerId, value); - setWolState(routerId, {{sshPassword: value, error: '', message: ''}}); + const state = getWolState(routerId); + wolStateByRouter.set(String(routerId), Object.assign({{}}, state, {{sshPassword: value, error: '', message: ''}})); }}); cards.addEventListener('click', async (ev) => {{ + const wolPasswordField = ev.target.closest('[data-wol-password]'); + if (wolPasswordField) {{ + ev.stopPropagation(); + return; + }} const toggleId = ev.target?.dataset?.cardToggle; if (toggleId) {{ const body = document.getElementById(toggleId); @@ -5736,6 +5743,70 @@ cat "$tmp" item["source"] = ", ".join(item.pop("sources", [])) return ordered + def ensure_router_wol_support(self, row, ssh_password=""): + script = r""" +set -eu + +has_wol_tool() { + command -v etherwake >/dev/null 2>&1 || command -v wakeonlan >/dev/null 2>&1 || command -v wol >/dev/null 2>&1 +} + +install_pkg() { + pkg="$1" + case "$PKG_MANAGER" in + opkg) + opkg install "$pkg" >/dev/null 2>&1 + ;; + apk) + apk add "$pkg" >/dev/null 2>&1 + ;; + *) + return 1 + ;; + esac +} + +if has_wol_tool; then + echo "WOL tool already present on router" + exit 0 +fi + +PKG_MANAGER="" +if command -v apk >/dev/null 2>&1; then + PKG_MANAGER="apk" +elif command -v opkg >/dev/null 2>&1; then + PKG_MANAGER="opkg" +fi + +[ -n "$PKG_MANAGER" ] || { + echo "No package manager found to install WOL support." >&2 + exit 1 +} + +case "$PKG_MANAGER" in + opkg) + opkg update >/dev/null 2>&1 || true + ;; + apk) + apk update >/dev/null 2>&1 || true + ;; +esac + +install_pkg luci-app-wol || true +install_pkg etherwake || true +install_pkg wakeonlan || true +install_pkg wol || true + +if has_wol_tool; then + echo "WOL support installed via $PKG_MANAGER" + exit 0 +fi + +echo "WOL package installation finished, but no etherwake/wakeonlan/wol command is available." >&2 +exit 1 +""" + return self.run_router_ssh_script(row, script, timeout=75, ssh_password=ssh_password).strip() + def send_router_wol_packet(self, row, mac, iface="", ssh_password=""): clean_mac = self.normalize_wol_mac(mac) if not clean_mac: @@ -5766,13 +5837,27 @@ fi echo "No WOL tool found on router. Install etherwake, wakeonlan or wol." >&2 exit 127 """ - output = self.run_router_ssh_script( - row, - script, - [clean_mac, str(iface or "")], - timeout=12, - ssh_password=ssh_password, - ) + try: + output = self.run_router_ssh_script( + row, + script, + [clean_mac, str(iface or "")], + timeout=12, + ssh_password=ssh_password, + ) + except RuntimeError as exc: + if "No WOL tool found on router" not in str(exc): + raise + install_output = self.ensure_router_wol_support(row, ssh_password=ssh_password) + output = self.run_router_ssh_script( + row, + script, + [clean_mac, str(iface or "")], + timeout=18, + ssh_password=ssh_password, + ) + if install_output: + output = (install_output + "\n" + output).strip() return {"mac": clean_mac, "iface": str(iface or ""), "output": output.strip() or "Wake packet sent"} def vps_shell_args(self):