fix hysteria and vless bug

This commit is contained in:
Zenaku 2026-06-06 09:30:31 -05:00
parent 9372fe4c26
commit 76d3650979
2 changed files with 17 additions and 36 deletions

View file

@ -1,5 +1,4 @@
import socket import socket
import subprocess
import time import time
from pathlib import Path from pathlib import Path
from core.Constants import Constants from core.Constants import Constants
@ -7,24 +6,21 @@ from core.utils.encrypted_proxy.net import get_real_ip, verify_ip
from core.utils.encrypted_proxy.singbox import SingboxRunner from core.utils.encrypted_proxy.singbox import SingboxRunner
from core.utils.encrypted_proxy.dns import wait_for_tun, set_dns_on_tun, revert_dns_on_tun from core.utils.encrypted_proxy.dns import wait_for_tun, set_dns_on_tun, revert_dns_on_tun
from core.utils.encrypted_proxy import killswitch from core.utils.encrypted_proxy import killswitch
from core.services.encrypted_proxy.disable_service import get_public_ip
def _resolve(host: str) -> str: def _resolve(host: str) -> str:
return socket.gethostbyname(host) return socket.gethostbyname(host)
def build_hysteria_config(username: str, password: str, def build_hysteria_config(username: str, password: str,
server_host: str, socks5_port: int) -> dict: server_host: str, socks5_port: int,
server_ip: str = None) -> dict:
if server_ip is None:
server_ip = _resolve(server_host) server_ip = _resolve(server_host)
return { return {
"dns": { "dns": {
"servers": [ "servers": [{"tag": "tunnel-dns", "type": "udp", "server": "9.9.9.9"}],
{
"tag": "tunnel-dns",
"type": "udp",
"server": "9.9.9.9",
},
],
"final": "tunnel-dns", "final": "tunnel-dns",
"strategy": "ipv4_only", "strategy": "ipv4_only",
"independent_cache": True, "independent_cache": True,
@ -83,17 +79,14 @@ def _cleanup_all() -> None:
SingboxRunner().stop() SingboxRunner().stop()
except Exception: except Exception:
pass pass
try: try:
revert_dns_on_tun() revert_dns_on_tun()
except Exception: except Exception:
pass pass
try: try:
killswitch.disarm() killswitch.disarm()
except Exception: except Exception:
pass pass
time.sleep(1) time.sleep(1)
@ -113,7 +106,8 @@ def enable_hysteria(username: str, password: str, server_host: str,
runner = SingboxRunner() runner = SingboxRunner()
runner.stop() runner.stop()
config_path = Path(Constants.SINGBOX_CONFIG_DIR) / f"{username}-sing-box.json" config_path = Path(Constants.SINGBOX_CONFIG_DIR) / f"{username}-sing-box.json"
config = build_hysteria_config(username, password, server_host, socks5_port) config = build_hysteria_config(username, password, server_host, socks5_port,
server_ip=server_ip)
try: try:
runner.write_config(config_path, config) runner.write_config(config_path, config)
@ -156,12 +150,11 @@ def enable_hysteria(username: str, password: str, server_host: str,
}) })
return True return True
def disable_hysteria(observer=None) -> bool: def disable_hysteria(observer=None) -> bool:
revert_dns_on_tun() revert_dns_on_tun()
SingboxRunner().stop() SingboxRunner().stop()
killswitch.disarm() killswitch.disarm()
time.sleep(1)
ip = get_public_ip()
if observer: if observer:
observer.notify("disconnected", {"ip": ip}) observer.notify("disconnected", {})
return True return True

View file

@ -1,9 +1,7 @@
from urllib.parse import unquote from urllib.parse import unquote
from pathlib import Path from pathlib import Path
import socket import socket
import subprocess
import time import time
from core.services.encrypted_proxy.disable_service import get_public_ip
from core.Constants import Constants from core.Constants import Constants
from core.utils.encrypted_proxy.net import get_real_ip, verify_ip from core.utils.encrypted_proxy.net import get_real_ip, verify_ip
from core.utils.encrypted_proxy.singbox import SingboxRunner from core.utils.encrypted_proxy.singbox import SingboxRunner
@ -36,18 +34,13 @@ def parse_vless_link(link: str) -> dict:
} }
def build_vless_config(vless: dict, socks5_port: int) -> dict: def build_vless_config(vless: dict, socks5_port: int, server_ip: str = None) -> dict:
if server_ip is None:
server_ip = socket.gethostbyname(vless["host"]) server_ip = socket.gethostbyname(vless["host"])
return { return {
"dns": { "dns": {
"servers": [ "servers": [{"tag": "tunnel-dns", "type": "udp", "server": "9.9.9.9"}],
{
"tag": "tunnel-dns",
"type": "udp",
"server": "9.9.9.9",
},
],
"final": "tunnel-dns", "final": "tunnel-dns",
"strategy": "ipv4_only", "strategy": "ipv4_only",
"independent_cache": True, "independent_cache": True,
@ -111,17 +104,14 @@ def _cleanup_all() -> None:
SingboxRunner().stop() SingboxRunner().stop()
except Exception: except Exception:
pass pass
try: try:
revert_dns_on_tun() revert_dns_on_tun()
except Exception: except Exception:
pass pass
try: try:
killswitch.disarm() killswitch.disarm()
except Exception: except Exception:
pass pass
time.sleep(1) time.sleep(1)
@ -142,7 +132,7 @@ def enable_vless(vless_link: str, username: str,
runner = SingboxRunner() runner = SingboxRunner()
runner.stop() runner.stop()
config_path = Path(Constants.SINGBOX_CONFIG_DIR) / f"{username}-sing-box.json" config_path = Path(Constants.SINGBOX_CONFIG_DIR) / f"{username}-sing-box.json"
config = build_vless_config(vless, socks5_port) config = build_vless_config(vless, socks5_port, server_ip=server_ip)
try: try:
runner.write_config(config_path, config) runner.write_config(config_path, config)
@ -190,8 +180,6 @@ def disable_vless(observer=None) -> bool:
revert_dns_on_tun() revert_dns_on_tun()
SingboxRunner().stop() SingboxRunner().stop()
killswitch.disarm() killswitch.disarm()
time.sleep(1)
ip = get_public_ip()
if observer: if observer:
observer.notify("disconnected", {"ip": ip}) observer.notify("disconnected", {})
return True return True