From 06d2d445edd891ab06e95fe8cf7533fd30328b8a Mon Sep 17 00:00:00 2001 From: Toni Spets Date: Wed, 1 Nov 2023 07:48:24 +0200 Subject: [PATCH] Don't listen on all interfaces if empty reg URL --- heisenbridge/__main__.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/heisenbridge/__main__.py b/heisenbridge/__main__.py index 9f4ff3b..acb6df2 100644 --- a/heisenbridge/__main__.py +++ b/heisenbridge/__main__.py @@ -489,7 +489,9 @@ async def run(self, listen_address, listen_port, homeserver_url, owner, safe_mod url = urllib.parse.urlparse(homeserver_url) ws = None if url.scheme in ["ws", "wss"]: - print("Using websockets to receive transactions. Listening is still enabled.") + print( + f"Using websockets to receive transactions. Listening is still enabled on http://{listen_address}:{listen_port}" + ) ws = AppserviceWebsocket(homeserver_url, self.registration["as_token"], self._on_mx_event) homeserver_url = url._replace(scheme=("https" if url.scheme == "wss" else "http")).geturl() print(f"Connecting to HS at {homeserver_url}") @@ -941,18 +943,24 @@ async def async_main(): listen_port = args.listen_port if not listen_address: + listen_address = "127.0.0.1" + try: url = urllib.parse.urlparse(service.registration["url"]) - listen_address = url.hostname + if url.hostname: + listen_address = url.hostname except Exception: - listen_address = "127.0.0.1" + pass if not listen_port: + listen_port = 9898 + try: url = urllib.parse.urlparse(service.registration["url"]) - listen_port = url.port + if url.port: + listen_port = url.port except Exception: - listen_port = 9898 + pass await service.run(listen_address, listen_port, args.homeserver, args.owner, args.safe_mode)