diff --git a/README.md b/README.md index 73b2389..bfa807c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # cteave -Recklessly open all new websites in the browser. \ No newline at end of file +Recklessly open all new websites on the internet. That's the idea, anyway. For now, we just open any website that +obtains an HTTPS certificate, lol. + +![screenshot](screenshot.png) diff --git a/main.py b/main.py new file mode 100644 index 0000000..03f88f0 --- /dev/null +++ b/main.py @@ -0,0 +1,52 @@ +import asyncio +import webbrowser + +import certstream +import httpx +from termcolor import colored + +client = httpx.AsyncClient() +semaphore = asyncio.Semaphore(10) + + +async def handler(message: dict, context: dict) -> None: + if message["message_type"] != "certificate_update": + return + + domains = message["data"]["leaf_cert"]["all_domains"] + try: + domain = next(d for d in domains if "*" not in d) + except StopIteration: + return + + url = f"https://{domain}" + + try: + async with semaphore: + r = await client.head(url, timeout=1) + except httpx.HTTPError: + print(colored("???", on_color="on_dark_grey"), domain) + return + + if r.status_code != 200: + print(colored(str(r.status_code), on_color="on_yellow"), domain) + return + + print(colored(str(r.status_code), on_color="on_cyan"), domain) + webbrowser.open_new_tab(url) + + +async def main() -> None: + loop = asyncio.get_running_loop() + + def callback(message: dict, context: dict) -> None: + asyncio.run_coroutine_threadsafe(handler(message, context), loop=loop) + + await asyncio.to_thread( + certstream.listen_for_events, + message_callback=callback, + url="wss://certstream.calidog.io/", + ) + + +asyncio.run(main()) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e3decf9 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +certstream~=1.12 +httpx~=0.23 +colorama~=0.4 diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..7122d8b Binary files /dev/null and b/screenshot.png differ