From df57d71b4c4bb9a7ec6542ecf8ad6ea335f54d99 Mon Sep 17 00:00:00 2001 From: Capybara-z Date: Thu, 26 Jun 2025 00:21:31 +0300 Subject: [PATCH] Fix SSL certificate validation / Fix tariff sorting for subscription renewals --- database/tariffs.py | 2 +- servers.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/database/tariffs.py b/database/tariffs.py index 2e867b70..a4bf9e26 100644 --- a/database/tariffs.py +++ b/database/tariffs.py @@ -41,7 +41,7 @@ async def get_tariffs( result = await session.execute(select(Tariff).where(Tariff.id == tariff_id)) elif group_code: result = await session.execute( - select(Tariff).where(Tariff.group_code == group_code) + select(Tariff).where(Tariff.group_code == group_code).order_by(Tariff.id) ) else: result = await session.execute(select(Tariff)) diff --git a/servers.py b/servers.py index e49df5f1..89c21099 100644 --- a/servers.py +++ b/servers.py @@ -41,8 +41,11 @@ async def check_tcp_connection(host: str, port: int) -> bool: await writer.wait_closed() return True except ssl.SSLError as e: + err_text = str(e) + if "hostname mismatch" in err_text or "certificate is not valid for" in err_text: + return False logger.warning(f"[SSL Error] Сертификат сервера {host} вызвал ошибку: {e}") - await notify_ssl_error(host, str(e)) + await notify_ssl_error(host, err_text) return False except Exception: return False @@ -171,4 +174,4 @@ async def check_servers(session: AsyncSession): def extract_host(api_url: str) -> str: """Извлекает хост из `api_url`.""" match = re.match(r"(https?://)?([^:/]+)", api_url) - return match.group(2) if match else api_url + return match.group(2) if match else api_url \ No newline at end of file