mirror of
https://github.com/anten-ka/gotelegram_pro.git
synced 2026-05-19 18:26:07 +00:00
v2.5.0: harden telemt user reloads
This commit is contained in:
@@ -279,6 +279,8 @@ _DOMAIN_RE = re.compile(
|
||||
)
|
||||
_USER_NAME_RE = re.compile(r"^[A-Za-z0-9_.-]{1,48}$")
|
||||
MAX_UNIQUE_IP_LIMIT = 1000000
|
||||
TELEMT_RESTART_DEBOUNCE_SECONDS = float(os.getenv("GOTELEGRAM_TELEMT_RESTART_DEBOUNCE", "8"))
|
||||
_LAST_TELEMT_RESTART = 0.0
|
||||
|
||||
|
||||
class FileLock:
|
||||
@@ -1638,7 +1640,15 @@ def save_telemt_users(users: Dict[str, str]) -> bool:
|
||||
|
||||
|
||||
async def refresh_telemt_after_user_change() -> bool:
|
||||
"""Restart telemt after config user changes."""
|
||||
"""Restart telemt after config user changes, coalescing rapid UI clicks."""
|
||||
global _LAST_TELEMT_RESTART
|
||||
now = time.monotonic()
|
||||
if _LAST_TELEMT_RESTART > 0 and now - _LAST_TELEMT_RESTART < TELEMT_RESTART_DEBOUNCE_SECONDS:
|
||||
code, stdout, _ = await sh("systemctl", "is-active", TELEMT_SERVICE, timeout=5)
|
||||
if code == 0 and stdout.strip() == "active":
|
||||
return True
|
||||
await sh("systemctl", "reset-failed", TELEMT_SERVICE, timeout=5)
|
||||
_LAST_TELEMT_RESTART = now
|
||||
code, _, _ = await sh("systemctl", "--no-block", "restart", TELEMT_SERVICE, timeout=5)
|
||||
return code == 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user