"""
Iran OSINT Key Findings - Instagram Post Generator
Creates square 1080x1080 PNG images using Iran flag colors
"""

from PIL import Image, ImageDraw, ImageFont
import os
import textwrap

# Iran flag colors
IRAN_GREEN = "#239F40"
IRAN_WHITE = "#FFFFFF"
IRAN_RED = "#DA0000"
IRAN_DARK = "#1A1A2E"  # Dark background for contrast

# Instagram dimensions
SIZE = 1080

OUTPUT_DIR = r"C:\Users\Squir\OneDrive\Iran Pwned"
os.makedirs(OUTPUT_DIR, exist_ok=True)

# Key findings for posts
POSTS = [
    {
        "title": "IRAN'S PROPAGANDA SITES",
        "subtitle": "ARE TRACKING YOU",
        "main_text": "Google Tag Manager detected on Iranian state media sites",
        "details": [
            "IRNA.IR - State news agency",
            "KHAMENEI.IR - Supreme Leader's site",
            "Your IP, browser, location logged",
            "Data flows to government servers"
        ],
        "footer": "OSINT FINDING #1"
    },
    {
        "title": "PRIVATE IP LEAK",
        "subtitle": "IRNA.IR EXPOSED",
        "main_text": "Internal RFC1918 IP exposed in public DNS",
        "details": [
            "kateb.irna.ir -> 10.30.41.85",
            "Internal subnet: 10.30.41.0/24",
            "Editorial system 'Kateb' exposed",
            "Split-horizon DNS misconfigured"
        ],
        "footer": "OSINT FINDING #2"
    },
    {
        "title": "VPN ENDPOINT EXPOSED",
        "subtitle": "FOREIGN MINISTRY",
        "main_text": "Ministerial VPN hostname in public DNS",
        "details": [
            "r1.vpn.minister.local.mfa.gov.ir",
            "Resolves to: 185.143.235.201",
            "Internal naming leaked",
            "Target for credential attacks"
        ],
        "footer": "OSINT FINDING #3"
    },
    {
        "title": "ADMIN PORTAL FOUND",
        "subtitle": "KHAMENEI.IR",
        "main_text": "Admin subdomain exposed via SSL certificates",
        "details": [
            "admin.english.khamenei.ir",
            "Found in Certificate Transparency",
            "Administrative interface exists",
            "Internal system now public"
        ],
        "footer": "OSINT FINDING #4"
    },
    {
        "title": "HIDDEN API DOMAIN",
        "subtitle": "KHAMENEI.LINK",
        "main_text": "Separate TLD used to hide API infrastructure",
        "details": [
            "formx.khamenei.link",
            "Not found via subdomain scan",
            "Discovered via JS analysis",
            "Contains redirect tracking"
        ],
        "footer": "OSINT FINDING #5"
    },
    {
        "title": "MOBILE APK EXPOSED",
        "subtitle": "FARSNEWS.IR",
        "main_text": "Android app available for reverse engineering",
        "details": [
            "dl.farsnews.ir/app.apk",
            "May contain hardcoded secrets",
            "Device fingerprinting system",
            "API authentication exposed"
        ],
        "footer": "OSINT FINDING #6"
    },
    {
        "title": "182 EMBASSY SUBDOMAINS",
        "subtitle": "MFA.GOV.IR MAPPED",
        "main_text": "Complete Iranian diplomatic network mapped",
        "details": [
            "lebanon.mfa.gov.ir (Hezbollah)",
            "venezuela.mfa.gov.ir (Maduro)",
            "russia.mfa.gov.ir, china.mfa.gov.ir",
            "cms, cloud, email systems found"
        ],
        "footer": "OSINT FINDING #7"
    },
    {
        "title": "HEZBOLLAH HOSTING",
        "subtitle": "RUSSIAN PROTECTION",
        "main_text": "Deliberate use of Russian hosting for resilience",
        "details": [
            "moqawama.org.lb -> Moscow",
            "almanar.com.lb -> Selectel Moscow",
            "Backup: Czech Republic, Malaysia",
            ".lb TLD avoids US seizures"
        ],
        "footer": "OSINT FINDING #8"
    },
    {
        "title": "EXIF METADATA",
        "subtitle": "ATTRIBUTION FOUND",
        "main_text": "Photoshop metadata preserved in graphics",
        "details": [
            "Adobe Photoshop 7.0 (2002) - pirated",
            "Same workstation, multiple files",
            "Timestamps = Beirut hours (GMT+3)",
            "Individual creators trackable"
        ],
        "footer": "OSINT FINDING #9"
    },
    {
        "title": "WHATSAPP OPSEC FAIL",
        "subtitle": "FILENAME PRESERVED",
        "main_text": "Original WhatsApp filename on news site",
        "details": [
            "\"WhatsApp Image 2025-12-13...\"",
            "alahednews.com.lb exposed",
            "Internal comms pattern revealed",
            "Editorial workflow exposed"
        ],
        "footer": "OSINT FINDING #10"
    },
    {
        "title": "GOVERNMENT ASNs",
        "subtitle": "ATTRIBUTION CONFIRMED",
        "main_text": "Dedicated government-owned networks identified",
        "details": [
            "AS34592 - Presidential Admin",
            "AS29079 - IRNA network",
            "AS205585 - ArvanCloud CDN",
            "Single point of failure identified"
        ],
        "footer": "OSINT FINDING #11"
    }
]


def create_post(post_data, index):
    """Create a single Instagram post image"""
    img = Image.new('RGB', (SIZE, SIZE), IRAN_DARK)
    draw = ImageDraw.Draw(img)

    # Try to load fonts, fall back to default if not available
    try:
        font_title = ImageFont.truetype("arial.ttf", 72)
        font_subtitle = ImageFont.truetype("arialbd.ttf", 56)
        font_main = ImageFont.truetype("arial.ttf", 36)
        font_detail = ImageFont.truetype("arial.ttf", 32)
        font_footer = ImageFont.truetype("arialbd.ttf", 28)
    except:
        font_title = ImageFont.load_default()
        font_subtitle = font_title
        font_main = font_title
        font_detail = font_title
        font_footer = font_title

    y_offset = 60

    # Top accent bar - Green
    draw.rectangle([0, 0, SIZE, 8], fill=IRAN_GREEN)

    # Bottom accent bar - Red
    draw.rectangle([0, SIZE-8, SIZE, SIZE], fill=IRAN_RED)

    # Side accents
    draw.rectangle([0, 0, 8, SIZE], fill=IRAN_GREEN)
    draw.rectangle([SIZE-8, 0, SIZE, SIZE], fill=IRAN_RED)

    # Title
    title = post_data["title"]
    bbox = draw.textbbox((0, 0), title, font=font_title)
    title_width = bbox[2] - bbox[0]
    draw.text(((SIZE - title_width) // 2, y_offset), title, fill=IRAN_RED, font=font_title)
    y_offset += 90

    # Subtitle
    subtitle = post_data["subtitle"]
    bbox = draw.textbbox((0, 0), subtitle, font=font_subtitle)
    subtitle_width = bbox[2] - bbox[0]
    draw.text(((SIZE - subtitle_width) // 2, y_offset), subtitle, fill=IRAN_GREEN, font=font_subtitle)
    y_offset += 100

    # Divider line
    draw.rectangle([100, y_offset, SIZE-100, y_offset+4], fill=IRAN_WHITE)
    y_offset += 50

    # Main text
    main_text = post_data["main_text"]
    wrapped = textwrap.wrap(main_text, width=35)
    for line in wrapped:
        bbox = draw.textbbox((0, 0), line, font=font_main)
        line_width = bbox[2] - bbox[0]
        draw.text(((SIZE - line_width) // 2, y_offset), line, fill=IRAN_WHITE, font=font_main)
        y_offset += 50

    y_offset += 40

    # Details with bullets
    for detail in post_data["details"]:
        bullet_text = f"• {detail}"
        # Wrap long lines
        wrapped = textwrap.wrap(bullet_text, width=40)
        for i, line in enumerate(wrapped):
            if i > 0:
                line = "  " + line  # Indent continuation
            draw.text((80, y_offset), line, fill=IRAN_WHITE, font=font_detail)
            y_offset += 45

    y_offset += 30

    # Divider line
    draw.rectangle([100, y_offset, SIZE-100, y_offset+4], fill=IRAN_WHITE)
    y_offset += 40

    # Footer
    footer = post_data["footer"]
    bbox = draw.textbbox((0, 0), footer, font=font_footer)
    footer_width = bbox[2] - bbox[0]
    draw.text(((SIZE - footer_width) // 2, SIZE - 80), footer, fill=IRAN_GREEN, font=font_footer)

    # Watermark
    watermark = "@RINGMAST4R"
    bbox = draw.textbbox((0, 0), watermark, font=font_footer)
    wm_width = bbox[2] - bbox[0]
    draw.text((SIZE - wm_width - 30, SIZE - 50), watermark, fill="#666666", font=font_footer)

    # Save
    filename = f"{OUTPUT_DIR}/iran_osint_{index:02d}.png"
    img.save(filename, "PNG")
    print(f"Created: {filename}")
    return filename


def main():
    print("=" * 60)
    print("IRAN OSINT Instagram Post Generator")
    print("=" * 60)
    print(f"Creating {len(POSTS)} posts...")
    print(f"Output: {OUTPUT_DIR}")
    print()

    created = []
    for i, post in enumerate(POSTS, 1):
        filename = create_post(post, i)
        created.append(filename)

    print()
    print("=" * 60)
    print(f"SUCCESS: Created {len(created)} Instagram posts")
    print("=" * 60)


if __name__ == "__main__":
    main()
