Security + E-Mail-HTML + Quartalsbericht + Registrierungspflicht
Registrierung & Login: - E-Mail-Verifikation jetzt Pflicht vor erstem Login - Register gibt keinen Token mehr zurück → "Postfach prüfen"-Screen - Login blockt mit EMAIL_NOT_VERIFIED (403) wenn unverifiziert - Resend-Verification ohne Auth (email-basiert) - Frontend: _renderVerifyPending() nach Register und Login-Fehler - Account-Lockout: 5 Fehlversuche → 15 Min gesperrt (ratelimit.py) - Login Rate-Limit zusätzlich per E-Mail-Adresse (5/5 Min) - Fehler-Tracking wird bei erfolgreichem Login zurückgesetzt E-Mail-Templates (alle Mails jetzt HTML): - email_html() Shared-Template in mailer.py (Gradient-Header, Warm-Beige) - Verifikations-Mail, Passwort-Reset → HTML mit CTA-Button - Admin-Outreach: plain text auto-wrapped in HTML - Züchter-Mails (Antrag/Genehmigung/Ablehnung) → Template - Tierschutz-Alert (litters.py) → Template - send_support_mail → HTML - outreach._build_message() + _send_smtp() unterstützen jetzt html= Parameter Forum-Schutz: - Post-Cooldown: 30 Sek zwischen beliebigen Posts (DB-Check) - Stunden-Limit: 5 Threads / 20 Antworten pro User/Stunde - Duplikat-Erkennung: gleicher Text in 5 Min blockiert (in-memory) - content_filter.py: Spam-Keywords, URL-Sperre für Accounts < 7 Tage, Sonderzeichen-Ratio-Check Security-Headers: - HSTS: max-age=31536000; includeSubDomains - Content-Security-Policy: frame-ancestors none, base-uri self, … - X-Frame-Options entfernt (CSP frame-ancestors ist moderner) Honeypot-Fallen (13 Scanner-Pfade → 24h IP-Sperre): - /api/admin/users, /api/v1/users, /api/.env, /api/config, /api/setup, /api/install, /api/phpinfo, /api/debug, /api/actuator, /api/swagger, /api/graphql u.a. Quartalsbericht-System: - backend/scripts/generate_reports.py: 6 Sections (Sicherheit, Funktionsumfang, Dateien, Nutzer, Partner, Server) - make reports: generiert alle Berichte aus dem Container, committed - Scheduler: quarterly_report Job (1. Feb/Mai/Aug/Nov 07:00) → vollständige HTML-Mail an ADMIN_EMAIL - quarterly_report erscheint im täglichen Status-Report Admin-Panel: - "Forum & Meldungen" → "Forum"
This commit is contained in:
parent
c1bb728153
commit
de1677154f
15 changed files with 1363 additions and 141 deletions
|
|
@ -100,6 +100,14 @@ def start():
|
|||
replace_existing=True,
|
||||
misfire_grace_time=1800,
|
||||
)
|
||||
# 1. Feb / Mai / Aug / Nov 07:00 — Quartalsbericht
|
||||
_scheduler.add_job(
|
||||
_job_quarterly_report,
|
||||
CronTrigger(month="2,5,8,11", day=1, hour=7, minute=0),
|
||||
id="quarterly_report",
|
||||
replace_existing=True,
|
||||
misfire_grace_time=7200,
|
||||
)
|
||||
# Jeden Montag 07:00 — KI-Gesundheitsberichte (alle 2 Wochen)
|
||||
_scheduler.add_job(
|
||||
_job_ki_health_report,
|
||||
|
|
@ -109,7 +117,7 @@ def start():
|
|||
misfire_grace_time=3600,
|
||||
)
|
||||
_scheduler.start()
|
||||
logger.info("Scheduler gestartet — Health-Reminder 08:00, Giftköder-Archiv 03:00, Wetter-Alert 07:30, Meilenstein-Check 00:05, Event-Import So 02:00, Rassen-Seed monatlich 1. des Monats, Status-Report täglich 06:00. OSM-Cache: on-demand (kein Prewarm).")
|
||||
logger.info("Scheduler gestartet — Health-Reminder 08:00, Giftköder-Archiv 03:00, Wetter-Alert 07:30, Meilenstein-Check 00:05, Event-Import So 02:00, Rassen-Seed monatlich 1. des Monats, Status-Report täglich 06:00, Quartalsbericht 1. Feb/Mai/Aug/Nov 07:00. OSM-Cache: on-demand (kein Prewarm).")
|
||||
|
||||
|
||||
def stop():
|
||||
|
|
@ -698,6 +706,7 @@ async def _job_status_report():
|
|||
"seed_wikidata": "Rassen-Seed (Wikidata, monatlich)",
|
||||
"weekly_praise": "Wöchentlicher Lober (Mo 09:00)",
|
||||
"ki_health_report": "KI-Gesundheitsberichte",
|
||||
"quarterly_report": "Quartalsbericht (1. Feb/Mai/Aug/Nov)",
|
||||
}
|
||||
job_rows_html = ""
|
||||
job_rows_txt = ""
|
||||
|
|
@ -783,6 +792,133 @@ Züchter (pending): {metrics['zuchter_pending']}
|
|||
logger.error(f"Status-Report: Mail-Fehler: {e}")
|
||||
|
||||
|
||||
async def _job_quarterly_report():
|
||||
"""Quartalsbericht: alle Report-Sections per Mail an ADMIN_EMAIL."""
|
||||
import os, sys
|
||||
from mailer import send_email, email_html
|
||||
|
||||
admin = os.getenv("ADMIN_EMAIL", "")
|
||||
if not admin:
|
||||
logger.info("Quartalsbericht: ADMIN_EMAIL nicht gesetzt, übersprungen.")
|
||||
_log_job("quarterly_report", "ok", "ADMIN_EMAIL nicht gesetzt")
|
||||
return
|
||||
|
||||
now_str = datetime.now(tz=_TZ).strftime("%d.%m.%Y")
|
||||
quarter = (datetime.now(tz=_TZ).month - 1) // 3 + 1
|
||||
|
||||
try:
|
||||
# Report-Script importieren und alle Sections aufrufen
|
||||
sys.path.insert(0, "/app/scripts")
|
||||
import importlib, generate_reports as gr
|
||||
importlib.reload(gr) # sicherstellen dass aktuelle Version
|
||||
|
||||
sections = [
|
||||
("Sicherheit", gr.report_sicherheit),
|
||||
("Funktionsumfang", gr.report_funktionsumfang),
|
||||
("Dateien", gr.report_dateien),
|
||||
("Nutzerübersicht", gr.report_nutzer),
|
||||
("Partnerliste", gr.report_partner),
|
||||
("Server & Speicher", gr.report_server),
|
||||
]
|
||||
|
||||
def md_to_html_simple(text: str) -> str:
|
||||
"""Minimale Markdown→HTML-Konvertierung für E-Mail."""
|
||||
import html as _h
|
||||
lines_out = []
|
||||
in_code = False
|
||||
in_table = False
|
||||
for line in text.split("\n"):
|
||||
if line.startswith("```"):
|
||||
if in_code:
|
||||
lines_out.append("</code></pre>")
|
||||
in_code = False
|
||||
else:
|
||||
lines_out.append('<pre style="background:#f5f0ea;padding:10px;border-radius:6px;font-size:12px;overflow-x:auto"><code>')
|
||||
in_code = True
|
||||
continue
|
||||
if in_code:
|
||||
lines_out.append(_h.escape(line))
|
||||
continue
|
||||
if line.startswith("#### "):
|
||||
lines_out.append(f'<h4 style="margin:12px 0 4px;color:#333">{line[5:]}</h4>')
|
||||
elif line.startswith("### "):
|
||||
lines_out.append(f'<h3 style="margin:16px 0 6px;color:#555;font-size:14px;text-transform:uppercase;letter-spacing:.04em">{line[4:]}</h3>')
|
||||
elif line.startswith("## "):
|
||||
lines_out.append(f'<h2 style="margin:20px 0 8px;color:#C4843A;font-size:16px;border-bottom:1px solid #f0e8dc;padding-bottom:4px">{line[3:]}</h2>')
|
||||
elif line.startswith("# "):
|
||||
pass # Haupttitel kommt vom äußeren Template
|
||||
elif line.startswith("---"):
|
||||
pass # Trennlinie überspringen
|
||||
elif line.startswith("| "):
|
||||
if not in_table:
|
||||
lines_out.append('<table style="width:100%;border-collapse:collapse;font-size:13px;margin:8px 0">')
|
||||
in_table = True
|
||||
if set(line.replace("|","").replace("-","").replace(" ","")) == set():
|
||||
continue # Trenn-Zeile
|
||||
cells = [c.strip() for c in line.split("|")[1:-1]]
|
||||
row_html = "".join(f'<td style="padding:4px 8px;border-bottom:1px solid #f0e8dc">{_h.escape(c)}</td>' for c in cells)
|
||||
lines_out.append(f"<tr>{row_html}</tr>")
|
||||
continue
|
||||
elif line.startswith("- ") or line.startswith("* "):
|
||||
if in_table:
|
||||
lines_out.append("</table>")
|
||||
in_table = False
|
||||
lines_out.append(f'<li style="margin:2px 0;color:#444">{line[2:]}</li>')
|
||||
elif line.startswith("> "):
|
||||
if in_table:
|
||||
lines_out.append("</table>")
|
||||
in_table = False
|
||||
lines_out.append(f'<blockquote style="border-left:3px solid #C4843A;margin:8px 0;padding:6px 12px;background:#fdf6ef;color:#555;font-size:13px">{line[2:]}</blockquote>')
|
||||
elif line.strip() == "":
|
||||
if in_table:
|
||||
lines_out.append("</table>")
|
||||
in_table = False
|
||||
lines_out.append("")
|
||||
else:
|
||||
if in_table:
|
||||
lines_out.append("</table>")
|
||||
in_table = False
|
||||
styled = line.replace("**", "<b>", 1).replace("**", "</b>", 1)
|
||||
lines_out.append(f'<p style="margin:4px 0;color:#444;font-size:14px">{styled}</p>')
|
||||
if in_table:
|
||||
lines_out.append("</table>")
|
||||
if in_code:
|
||||
lines_out.append("</code></pre>")
|
||||
return "\n".join(lines_out)
|
||||
|
||||
# Body aus allen Sections zusammensetzen
|
||||
body_parts = []
|
||||
plain_parts = [f"Ban Yaro Quartalsbericht Q{quarter} {now_str}\n", "=" * 50]
|
||||
|
||||
for title, fn in sections:
|
||||
try:
|
||||
md = fn()
|
||||
body_parts.append(
|
||||
f'<div style="margin-bottom:32px">'
|
||||
f'<h1 style="font-size:18px;font-weight:800;color:#C4843A;margin:0 0 12px;'
|
||||
f'border-bottom:2px solid #f0e8dc;padding-bottom:6px">{title}</h1>'
|
||||
f'{md_to_html_simple(md)}'
|
||||
f'</div>'
|
||||
)
|
||||
plain_parts.append(f"\n=== {title.upper()} ===\n{md}\n")
|
||||
except Exception as e:
|
||||
body_parts.append(f'<p style="color:#dc2626">Fehler in Section {title}: {e}</p>')
|
||||
plain_parts.append(f"\n=== {title.upper()} ===\nFehler: {e}\n")
|
||||
|
||||
full_body = "\n".join(body_parts)
|
||||
full_plain = "\n".join(plain_parts)
|
||||
subject = f"Ban Yaro Quartalsbericht Q{quarter}/{datetime.now(tz=_TZ).year} — {now_str}"
|
||||
html = email_html(full_body, footer_text=f"Ban Yaro · banyaro.app · Quartalsbericht Q{quarter}")
|
||||
|
||||
await send_email(admin, subject, html, full_plain)
|
||||
logger.info(f"Quartalsbericht Q{quarter} gesendet an {admin}.")
|
||||
_log_job("quarterly_report", "ok", f"Q{quarter} → {admin}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Quartalsbericht: Fehler: {e}")
|
||||
_log_job("quarterly_report", "error", str(e))
|
||||
|
||||
|
||||
def _compute_milestone(today: date, bday: date, dog_name: str):
|
||||
"""
|
||||
Gibt (titel, text) zurück wenn heute ein Meilenstein-Tag ist,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue