From 2f48f65bc8f22c8963c8c6c18e85de5c7f6eaa48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3n=20Arnar?= <7620842+jonarnar77@users.noreply.github.com> Date: Tue, 3 Jun 2025 23:49:17 +0000 Subject: [PATCH] Fix HTML output generation and syntax errors --- mx-report.py | 101 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 15 deletions(-) diff --git a/mx-report.py b/mx-report.py index 48bc504..c98d471 100644 --- a/mx-report.py +++ b/mx-report.py @@ -548,6 +548,76 @@ def print_report_html(domain, mx_info, spf_info, dmarc_info, dkim_info, health_s def H(text): return html.escape(str(text) if text is not None else "") + mx_warnings = "".join(f"

[MX WARNING] {H(w)}

" for w in mx_info['warnings']) + if mx_info['records']: + mx_rows = "".join( + f"{H(r['preference'])}{H(r['exchange'])}" for r in mx_info['records'] + ) + mx_table = f"{mx_rows}
PreferenceExchange
" + else: + mx_table = "

No MX records found or error fetching them.

" + + spf_warnings = "".join(f"

[SPF WARNING] {H(w)}

" for w in spf_info['warnings']) + spf_recs = "".join(f"

[SPF RECOMMENDATION] {H(r)}

" for r in spf_info['recommendations']) + spf_raw = ( + f'

Raw SPF Record:

{H(spf_info["record"])}
' + if spf_info["record"] + else "

No SPF record found.

" + ) + spf_components = ( + "

Parsed SPF Components:

" + if spf_info.get("parsed_components") + else "" + ) + + dmarc_warnings = "".join(f"

[DMARC WARNING] {H(w)}

" for w in dmarc_info['warnings']) + dmarc_recs = "".join(f"

[DMARC RECOMMENDATION] {H(r)}

" for r in dmarc_info['recommendations']) + dmarc_raw = ( + f'

Raw DMARC Record:

{H(dmarc_info["record"])}
' + if dmarc_info["record"] + else "

No DMARC record found.

" + ) + dmarc_tags = ( + "

Parsed DMARC Tags:

" + if dmarc_info.get("parsed") + else "" + ) + + dkim_warnings = "".join(f"

[DKIM WARNING] {H(w)}

" for w in dkim_info['warnings']) + dkim_recs = "".join(f"

[DKIM RECOMMENDATION] {H(r)}

" for r in dkim_info['recommendations']) + if dkim_info.get("selectors_checked"): + dkim_list = "".join( + ( + f"
  • Selector: {H(s['selector'])}._domainkey.{H(domain)}" + f"
    Status: {'FOUND' if s['found'] else 'Not Found/Error'}
    " + + ( + f"Record:
    {H(s['record'][:100] + '...' if s['record'] and len(s['record']) > 100 else s.get('record'))}
    " + if s["found"] + else "" + ) + + ( + f"Error: {H(s['error'])}" if s["error"] else "" + ) + + "
  • " + ) + for s in dkim_info.get("selectors_checked", []) + ) + dkim_html = f"" + else: + dkim_html = "

    No DKIM selectors were checked or results to display.

    " + + details_list = "".join(f"
  • {H(detail)}
  • " for detail in health_summary_data["details"]) + html_output = f""" @@ -579,49 +649,50 @@ def H(text):

    MX Records

    Provider Detected: {H(mx_info['provider'])}

    - {"".join([f"

    [MX WARNING] {H(w)}

    " for w in mx_info['warnings']])} - {f"{''.join([f'' for r in mx_info['records']])}
    PreferenceExchange
    {H(r['preference'])}{H(r['exchange'])}
    " if mx_info['records'] else "

    No MX records found or error fetching them.

    "} + {mx_warnings} + {mx_table}

    SPF Record

    - {"".join([f"

    [SPF WARNING] {H(w)}

    " for w in spf_info['warnings']])} - {"".join([f"

    [SPF RECOMMENDATION] {H(rec)}

    " for rec in spf_info['recommendations']])} - {f'

    Raw SPF Record:

    {H(spf_info["record"])}
    ' if spf_info["record"] else "

    No SPF record found.

    "} - {f"

    Parsed SPF Components:

    " if spf_info.get("parsed_components") else ""} + {spf_warnings} + {spf_recs} + {spf_raw} + {spf_components}

    DMARC Record

    - {"".join([f"

    [DMARC WARNING] {H(w)}

    " for w in dmarc_info['warnings']])} - {"".join([f"

    [DMARC RECOMMENDATION] {H(rec)}

    " for rec in dmarc_info['recommendations']])} - {f'

    Raw DMARC Record:

    {H(dmarc_info["record"])}
    ' if dmarc_info["record"] else "

    No DMARC record found.

    "} - {f"

    Parsed DMARC Tags:

    " if dmarc_info.get("parsed") else ""} + {dmarc_warnings} + {dmarc_recs} + {dmarc_raw} + {dmarc_tags}

    DKIM Records (Common Selectors Checked)

    - {"".join([f"

    [DKIM WARNING] {H(w)}

    " for w in dkim_info['warnings']])} - {"".join([f"

    [DKIM RECOMMENDATION] {H(rec)}

    " for rec in dkim_info['recommendations']])} - {f"" if dkim_info.get('selectors_checked') else "

    No DKIM selectors were checked or results to display.

    "} + {dkim_warnings} + {dkim_recs} + {dkim_html}

    Overall Health Summary

    Status: {H(health_summary_data['status'])}

    -

    Overall Score: {H(f'{health_summary_data["score"]:.1f}')} (out of 4.0 possible)

    +

    Overall Score: {H(f"{health_summary_data['score']:.1f}")} (out of 4.0 possible)

    Identified Issues Count: {H(health_summary_data['issues_count'])}

    Details:

    - +
    """ print(html_output) + def main(): parser = argparse.ArgumentParser(description="Analyze domain email health (MX, SPF, DMARC, DKIM).") parser.add_argument("domain", help="The domain to analyze (e.g., example.com).")