obsidian-vault/ligbox-ops-platform/api/app/collectors/webmail.py
2026-06-19 17:26:42 +00:00

41 lines
1.2 KiB
Python

"""Webmail HTTPS check (read-only)."""
from __future__ import annotations
from typing import Any
import httpx
def collect(domain: str) -> dict[str, dict[str, Any]]:
domain = domain.lower().strip()
url = f"https://mail.{domain}/"
try:
with httpx.Client(timeout=12.0, follow_redirects=True, verify=True) as client:
response = client.get(url)
code = response.status_code
if 200 <= code < 400:
status, message = "pass", f"HTTP {code}"
elif code == 403:
status, message = "warn", f"HTTP {code}"
else:
status, message = "fail", f"HTTP {code}"
return {
"webmail_http": {
"check_id": "webmail_http",
"label": "Webmail HTTPS",
"status": status,
"message": message,
"evidence": {"url": url, "status_code": code},
}
}
except Exception as exc:
return {
"webmail_http": {
"check_id": "webmail_http",
"label": "Webmail HTTPS",
"status": "fail",
"message": str(exc)[:200],
"evidence": {"url": url},
}
}