small fix

This commit is contained in:
Zenaku 2026-06-19 06:42:50 -05:00
parent 309ac7bd02
commit e1142c8d24
3 changed files with 64 additions and 47 deletions

View file

@ -2,6 +2,7 @@ import subprocess
import threading import threading
import time import time
from core.utils.encrypted_proxy import killswitch from core.utils.encrypted_proxy import killswitch
from core.utils.encrypted_proxy.singbox import SingboxRunner
drop_state: dict = {"count": 0} drop_state: dict = {"count": 0}
tunnel_state: dict = {"alive": True} tunnel_state: dict = {"alive": True}
@ -86,16 +87,7 @@ class KillswitchMonitor:
self._trigger(CAUSE_DISCONNECT) self._trigger(CAUSE_DISCONNECT)
return return
try: singbox_alive = SingboxRunner().is_running()
result = subprocess.run(
['pgrep', '-x', 'sing-box'],
capture_output=True,
timeout=3,
)
singbox_alive = result.returncode == 0
except (OSError, subprocess.TimeoutExpired):
singbox_alive = True
tunnel_state["alive"] = singbox_alive tunnel_state["alive"] = singbox_alive
if not singbox_alive: if not singbox_alive:

View file

@ -5,9 +5,13 @@ from core.observers.ClientObserver import ClientObserver
from core.observers.ConnectionObserver import ConnectionObserver from core.observers.ConnectionObserver import ConnectionObserver
from core.observers.InvoiceObserver import InvoiceObserver from core.observers.InvoiceObserver import InvoiceObserver
from core.observers.ProfileObserver import ProfileObserver from core.observers.ProfileObserver import ProfileObserver
from cli.ui import Spinner, label_ok, label_error, label_warn, label_connected, label_disconnect, progress_bar, label_killswitch, label_dns from cli.ui import (
Spinner, label_ok, label_error, label_warn,
label_connected, label_disconnect, label_killswitch,
label_dns, label_ipv6, label_ipv4, progress_bar,
)
from cli.helpers import sanitize_profile from cli.helpers import sanitize_profile
from cli.killswitch_monitor import drop_state from cli.killswitch_monitor import drop_state, tunnel_state
import pprint import pprint
application_version_observer = ApplicationVersionObserver() application_version_observer = ApplicationVersionObserver()
@ -22,7 +26,7 @@ _timer_state = None
application_version_observer.subscribe('downloading', lambda event: print(f'Downloading {ApplicationController.get(event.subject.application_code).name}, version {event.subject.version_number}...')) application_version_observer.subscribe('downloading', lambda event: print(f'Downloading {ApplicationController.get(event.subject.application_code).name}, version {event.subject.version_number}...'))
application_version_observer.subscribe('download_progressing', lambda event: print(f'Current progress: {event.meta.get("progress"):.2f}%', flush=True, end='\r')) application_version_observer.subscribe('download_progressing',lambda event: print(f'Current progress: {event.meta.get("progress"):.2f}%', flush=True, end='\r'))
application_version_observer.subscribe('downloaded', lambda event: print('\n')) application_version_observer.subscribe('downloaded', lambda event: print('\n'))
client_observer.subscribe('synchronizing', lambda event: print('Synchronizing...\n')) client_observer.subscribe('synchronizing', lambda event: print('Synchronizing...\n'))
@ -41,7 +45,7 @@ def _on_connecting(event):
_timer_state['reconnecting'] = connecting_spinner() _timer_state['reconnecting'] = connecting_spinner()
attempt = event.subject.get("attempt_count", "?") attempt = event.subject.get("attempt_count", "?")
total = event.subject.get("maximum_number_of_attempts", "?") total = event.subject.get("maximum_number_of_attempts", "?")
_spinner = Spinner(f"[net] verify_ip attempt {attempt}/{total}...") _spinner = Spinner(f"Connecting... attempt {attempt}/{total}")
_spinner.start() _spinner.start()
@ -55,20 +59,27 @@ def _on_connected(event):
_timer_state['reconnecting'] = None _timer_state['reconnecting'] = None
if _timer_state: if _timer_state:
_timer_state['_retrying'] = False _timer_state['_retrying'] = False
d = event.subject or {} d = event.subject or {}
label_connected(f"proxy={d.get('proxy_ip','?')} tunnel={d.get('tunnel_if','?')} port={d.get('socks5_port','?')}") tunnel_if = d.get('tunnel_if', '?')
server_ip = d.get('server_ip')
socks5_port = d.get('socks5_port', '?')
label_connected(f"tunnel={tunnel_if} port={socks5_port}")
label_killswitch(killswitch.status()) label_killswitch(killswitch.status())
label_dns( label_dns(
enabled=d.get('dns_enabled', True), enabled=d.get('dns_enabled', True),
active=d.get('dns_active', False), active=d.get('dns_active', False),
) )
label_ipv6(blocked=True)
if server_ip:
label_ipv4(server_ip=server_ip, reachable=True)
if _monitor is not None: if _monitor is not None:
_monitor.set_connection_data( _monitor.set_connection_data(socks5_port=d.get('socks5_port'))
socks5_port=d.get('socks5_port'),
)
if _timer_state is not None: if _timer_state is not None:
from cli.ui import session_timer from cli.ui import session_timer
from cli.killswitch_monitor import tunnel_state
_timer_state['stop'] = session_timer(drop_state=drop_state, tunnel_state=tunnel_state) _timer_state['stop'] = session_timer(drop_state=drop_state, tunnel_state=tunnel_state)

View file

@ -20,6 +20,7 @@ BBLUE = "\033[1;34m"
BCYAN = "\033[1;36m" BCYAN = "\033[1;36m"
BWHITE = "\033[1;37m" BWHITE = "\033[1;37m"
def label_ok(msg: str): def label_ok(msg: str):
print(f" {BGREEN}[ OK ]{RESET} {msg}") print(f" {BGREEN}[ OK ]{RESET} {msg}")
@ -159,8 +160,21 @@ def label_killswitch(armed: bool):
print(f" {BRED}[ KS ]{RESET} Kill switch {BRED}INACTIVE — connection unprotected{RESET}") print(f" {BRED}[ KS ]{RESET} Kill switch {BRED}INACTIVE — connection unprotected{RESET}")
def session_timer(drop_state: dict | None = None, tunnel_state: dict | None = None) -> threading.Event: def label_ipv6(blocked: bool):
if blocked:
print(f" {BGREEN}[ IPv6 ]{RESET} IPv6 blocked")
else:
print(f" {BYELLOW}[ IPv6 ]{RESET} IPv6 {BYELLOW}not blocked{RESET}")
def label_ipv4(server_ip: str, reachable: bool):
if reachable:
print(f" {BGREEN}[ IPv4 ]{RESET} Server {BGREEN}{server_ip}{RESET} reachable")
else:
print(f" {BRED}[ IPv4 ]{RESET} Server {BRED}{server_ip}{RESET} unreachable")
def session_timer(drop_state: dict | None = None, tunnel_state: dict | None = None) -> threading.Event:
stop_event = threading.Event() stop_event = threading.Event()
start = time.time() start = time.time()