From a3d950678302e61e62e0d5383528342d2109968b Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 27 Sep 2025 19:11:15 +0000 Subject: [PATCH] mdns: customize http/https ports (#855) --- copyparty/__main__.py | 2 ++ copyparty/mdns.py | 17 +++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 6dc76f04..6223a0ba 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -1364,6 +1364,8 @@ def add_zc_mdns(ap): ap2.add_argument("--zm6", action="store_true", help="IPv6 only") ap2.add_argument("--zmv", action="store_true", help="verbose mdns") ap2.add_argument("--zmvv", action="store_true", help="verboser mdns") + ap2.add_argument("--zm-http", metavar="PORT", type=int, default=-1, help="port to announce for http/webdav; [\033[32m-1\033[0m] = auto, [\033[32m0\033[0m] = disabled, [\033[32m4649\033[0m] = port 4649") + ap2.add_argument("--zm-https", metavar="PORT", type=int, default=-1, help="port to announce for https/webdavs; [\033[32m-1\033[0m] = auto, [\033[32m0\033[0m] = disabled, [\033[32m4649\033[0m] = port 4649") ap2.add_argument("--zm-no-pe", action="store_true", help="mute parser errors (invalid incoming MDNS packets)") ap2.add_argument("--zm-nwa-1", action="store_true", help="disable workaround for avahi-bug #379 (corruption in Avahi's mDNS reflection feature)") ap2.add_argument("--zms", metavar="dhf", type=u, default="", help="list of services to announce -- d=webdav h=http f=ftp s=smb -- lowercase=plaintext uppercase=TLS -- default: all enabled services except http/https (\033[32mDdfs\033[0m if \033[33m--ftp\033[0m and \033[33m--smb\033[0m is set, \033[32mDd\033[0m otherwise)") diff --git a/copyparty/mdns.py b/copyparty/mdns.py index 6cb02ad0..fc429aad 100644 --- a/copyparty/mdns.py +++ b/copyparty/mdns.py @@ -102,9 +102,14 @@ class MDNS(MCast): self.log_func(self.logsrc, msg, c) def build_svcs(self) -> tuple[dict[str, dict[str, Any]], set[str]]: + ar = self.args zms = self.args.zms - http = {"port": 80 if 80 in self.args.p else self.args.p[0]} - https = {"port": 443 if 443 in self.args.p else self.args.p[0]} + + zi = ar.zm_http + http = {"port": zi if zi != -1 else 80 if 80 in ar.p else ar.p[0]} + zi = ar.zm_https + https = {"port": zi if zi != -1 else 443 if 443 in ar.p else ar.p[0]} + webdav = http.copy() webdavs = https.copy() webdav["u"] = webdavs["u"] = "u" # KDE requires username @@ -129,16 +134,16 @@ class MDNS(MCast): svcs: dict[str, dict[str, Any]] = {} - if "d" in zms: + if "d" in zms and http["port"]: svcs["_webdav._tcp.local."] = webdav - if "D" in zms: + if "D" in zms and https["port"]: svcs["_webdavs._tcp.local."] = webdavs - if "h" in zms: + if "h" in zms and http["port"]: svcs["_http._tcp.local."] = http - if "H" in zms: + if "H" in zms and https["port"]: svcs["_https._tcp.local."] = https if "f" in zms.lower():