#!/usr/bin/env python3
# Serves victim.html / attacker.html / receiver.html / media.webm.
# To approximate distinct origins on a single host, the attacker page can be
# loaded via http://127.0.0.1:8080/attacker.html and the victim page via
# http://localhost:8080/victim.html (different origin per URL host string).
import http.server, socketserver, os, sys

PORT = int(sys.argv[1]) if len(sys.argv) > 1 else 8080
os.chdir(os.path.dirname(os.path.abspath(__file__)))

class H(http.server.SimpleHTTPRequestHandler):
    def end_headers(self):
        self.send_header('Cache-Control', 'no-store')
        super().end_headers()

socketserver.TCPServer.allow_reuse_address = True
with socketserver.TCPServer(('', PORT), H) as httpd:
    print(f'Victim:   http://localhost:{PORT}/victim.html')
    print(f'Attacker: http://127.0.0.1:{PORT}/attacker.html')
    print(f'Receiver: http://127.0.0.1:{PORT}/receiver.html')
    httpd.serve_forever()
