v1.2.0 + v1.3.0: Localization, About dialog, TOTP/2FA, stability improvements
v1.2.0: - GUI localization (EN/RU/ZH) with language switcher and persistent selection - About dialog (ⓘ) with app info, features, quick start guide - core/i18n.py — internationalization module with t() function - All GUI components translated via t() keys v1.3.0: - TOTP/2FA tab — Google Authenticator compatible codes with live 30s countdown, one-click copy, per-server secret management - core/totp.py — TOTP module (pyotp, RFC 6238) - core/logger.py — rotating file logger (5MB, 3 backups) - Stronger Fernet encryption key with automatic migration from old key - Thread-safe server store with locks, atomic writes, auto-restore on corruption - Parallel status checks via ThreadPoolExecutor (up to 10 concurrent) - SSH client: explicit channel cleanup, Unix key permissions - Server dialog: port validation (1-65535), TOTP secret field - Language change preserves active tab and server selection - pyotp dependency added Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
"""
|
||||
Background status checker — daemon thread that pings servers periodically.
|
||||
Background status checker — parallel server pings.
|
||||
"""
|
||||
|
||||
import threading
|
||||
import time
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.server_store import ServerStore
|
||||
|
||||
from core.ssh_client import SSHClientWrapper
|
||||
from core.logger import log
|
||||
|
||||
|
||||
class StatusChecker:
|
||||
@@ -18,7 +20,7 @@ class StatusChecker:
|
||||
self.interval = interval
|
||||
self._running = False
|
||||
self._thread: threading.Thread | None = None
|
||||
self._gui_callback = None # set by GUI for thread-safe updates
|
||||
self._gui_callback = None
|
||||
|
||||
def start(self):
|
||||
if self._running:
|
||||
@@ -29,19 +31,18 @@ class StatusChecker:
|
||||
|
||||
def stop(self):
|
||||
self._running = False
|
||||
if self._thread:
|
||||
self._thread.join(timeout=3.0)
|
||||
|
||||
def set_gui_callback(self, callback):
|
||||
"""Set callback for thread-safe GUI updates."""
|
||||
self._gui_callback = callback
|
||||
|
||||
def check_one(self, server: dict) -> bool:
|
||||
"""Check single server. Returns True if online."""
|
||||
key_path = self.store.get_ssh_key_path()
|
||||
wrapper = SSHClientWrapper(server, key_path)
|
||||
return wrapper.check_connection()
|
||||
|
||||
def check_all_now(self):
|
||||
"""Run a full check cycle immediately (in background thread)."""
|
||||
threading.Thread(target=self._check_cycle, daemon=True).start()
|
||||
|
||||
def _loop(self):
|
||||
@@ -54,18 +55,35 @@ class StatusChecker:
|
||||
|
||||
def _check_cycle(self):
|
||||
servers = self.store.get_all()
|
||||
for server in servers:
|
||||
if not self._running:
|
||||
return
|
||||
alias = server["alias"]
|
||||
server_type = server.get("type", "ssh")
|
||||
ssh_servers = [s for s in servers if s.get("type", "ssh") == "ssh"]
|
||||
|
||||
if server_type != "ssh":
|
||||
self.store.set_status(alias, "unknown")
|
||||
continue
|
||||
# Mark non-SSH as unknown
|
||||
for s in servers:
|
||||
if s.get("type", "ssh") != "ssh":
|
||||
self.store.set_status(s["alias"], "unknown")
|
||||
|
||||
online = self.check_one(server)
|
||||
self.store.set_status(alias, "online" if online else "offline")
|
||||
if not ssh_servers:
|
||||
return
|
||||
|
||||
# Parallel checks — up to 10 concurrent
|
||||
max_workers = min(10, len(ssh_servers))
|
||||
try:
|
||||
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
||||
futures = {
|
||||
executor.submit(self.check_one, s): s["alias"]
|
||||
for s in ssh_servers
|
||||
}
|
||||
for future in as_completed(futures, timeout=30):
|
||||
if not self._running:
|
||||
return
|
||||
alias = futures[future]
|
||||
try:
|
||||
online = future.result(timeout=10)
|
||||
self.store.set_status(alias, "online" if online else "offline")
|
||||
except Exception:
|
||||
self.store.set_status(alias, "offline")
|
||||
except Exception as e:
|
||||
log.warning(f"Status check cycle error: {e}")
|
||||
|
||||
if self._gui_callback:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user