next release

This commit is contained in:
2025-05-05 00:47:57 +03:00
parent 488996222b
commit 1e19399862
7 changed files with 113 additions and 47 deletions

18
modules/checker.py Normal file
View File

@@ -0,0 +1,18 @@
import ssl
import socket
from datetime import datetime, timezone
from typing import Tuple
def get_cert_expiry_utc(host: str, port: int = 443) -> datetime:
"""
Устанавливает TLS-соединение и возвращает дату окончания сертификата
в UTC (timezone-aware).
"""
ctx = ssl.create_default_context()
with ctx.wrap_socket(socket.socket(), server_hostname=host) as sock:
sock.settimeout(5)
sock.connect((host, port))
cert = sock.getpeercert()
exp_str = cert['notAfter'] # 'Jun 15 12:00:00 2025 GMT'
dt = datetime.strptime(exp_str, '%b %d %H:%M:%S %Y %Z')
return dt.replace(tzinfo=timezone.utc)

20
modules/config.py Normal file
View File

@@ -0,0 +1,20 @@
import configparser
from pathlib import Path
from typing import Dict
def load_mail_config(path: Path) -> Dict[str, str]:
"""
Читает mail.conf и возвращает словарь с настройками SMTP:
host, port, username, password, from, to
"""
cfg = configparser.ConfigParser()
cfg.read(path, encoding='utf-8')
smtp = cfg['smtp']
return {
'host': smtp.get('host'),
'port': smtp.getint('port', fallback=587),
'username': smtp.get('username'),
'password': smtp.get('password'),
'from': smtp.get('from'),
'to': smtp.get('to'),
}

19
modules/domains.py Normal file
View File

@@ -0,0 +1,19 @@
from pathlib import Path
from typing import List, Tuple
def load_domains(path: Path) -> List[Tuple[str, int]]:
"""
Возвращает список кортежей (host, port).
Если порт не указан — 443.
"""
result: List[Tuple[str, int]] = []
for line in path.read_text(encoding='utf-8').splitlines():
line = line.strip()
if not line or line.startswith('#'):
continue
if ':' in line:
host, port = line.split(':', 1)
result.append((host.strip(), int(port)))
else:
result.append((line, 443))
return result

19
modules/notifier.py Normal file
View File

@@ -0,0 +1,19 @@
import smtplib
from email.message import EmailMessage
from typing import Dict
def send_email(cfg: Dict[str, str], subject: str, body: str) -> None:
"""
Отправляет письмо через SMTP по настройкам из cfg.
Ожидает ключи: host, port, username, password, from, to.
"""
msg = EmailMessage()
msg['Subject'] = subject
msg['From'] = cfg['from']
msg['To'] = cfg['to']
msg.set_content(body)
with smtplib.SMTP(cfg['host'], cfg['port']) as smtp:
smtp.starttls()
smtp.login(cfg['username'], cfg['password'])
smtp.send_message(msg)