From 8796c09f569872077a7a4c1831b65c4d0c668176 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 10 Feb 2024 21:45:57 +0000 Subject: [PATCH] add `--tftp-pr` to specify portrange instead of ephemerals --- copyparty/__main__.py | 1 + copyparty/tftpd.py | 10 ++++++---- pyproject.toml | 2 +- scripts/make-sfx.sh | 4 ++-- setup.py | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index ef1540f9..3e190caf 100755 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -1020,6 +1020,7 @@ def add_tftp(ap): ap2.add_argument("--tftpv", action="store_true", help="verbose") ap2.add_argument("--tftpvv", action="store_true", help="verboser") ap2.add_argument("--tftp-ipa", metavar="PFX", type=u, default="", help="only accept connections from IP-addresses starting with \033[33mPFX\033[0m; specify [\033[32many\033[0m] to disable inheriting \033[33m--ipa\033[0m. Example: [\033[32m127., 10.89., 192.168.\033[0m]") + ap2.add_argument("--tftp-pr", metavar="P-P", type=u, help="the range of UDP ports to use for data transfer, for example \033[32m12000-13000") def add_smb(ap): diff --git a/copyparty/tftpd.py b/copyparty/tftpd.py index 9155186f..ce23b626 100644 --- a/copyparty/tftpd.py +++ b/copyparty/tftpd.py @@ -103,10 +103,12 @@ class Tftpd(object): self.srv = TftpServer.TftpServer("/", self._ls) self.stop = self.srv.stop - Daemon(self.srv.listen, "tftp", [self.ip, self.port]) + ports = [] + if self.args.tftp_pr: + p1, p2 = [int(x) for x in self.args.tftp_pr.split("-")] + ports = list(range(p1, p2 + 1)) - # XXX TODO hook TftpContextServer.start; - # append tftp-ipa check at bottom and throw TftpException if not match + Daemon(self.srv.listen, "tftp", [self.ip, self.port], ka={"ports": ports}) def nlog(self, msg: str, c: Union[int, str] = 0) -> None: self.log("tftp", msg, c) @@ -122,7 +124,7 @@ class Tftpd(object): vfs, rem = self.asrv.vfs.get(vpath, "*", *perms) return vfs, vfs.canonical(rem) - def _ls(self, vpath: str) -> Any: + def _ls(self, vpath: str, raddress: str, rport: int) -> Any: # generate file listing if vpath is dir.txt and return as file object return None diff --git a/pyproject.toml b/pyproject.toml index f940c2dc..9e58d831 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,7 @@ thumbnails2 = ["pyvips"] audiotags = ["mutagen"] ftpd = ["pyftpdlib"] ftps = ["pyftpdlib", "pyopenssl"] -tftpd = ["partftpy"] +tftpd = ["partftpy>=0.2.0"] pwhash = ["argon2-cffi"] [project.scripts] diff --git a/scripts/make-sfx.sh b/scripts/make-sfx.sh index 8a56ecab..44f26938 100755 --- a/scripts/make-sfx.sh +++ b/scripts/make-sfx.sh @@ -225,9 +225,9 @@ necho() { mv pyftpdlib ftp/ necho collecting partftpy - f="../build/partftpy-0.1.0.tar.gz" + f="../build/partftpy-0.2.0.tar.gz" [ -e "$f" ] || - (url=https://files.pythonhosted.org/packages/55/25/e043193fb3d941b91fc84a55e0560b1c248f3f04d73747eb4f35f5e2776e/partftpy-0.1.0.tar.gz; + (url=https://files.pythonhosted.org/packages/64/4a/360dde1e7277758a4ccb0d6434ec661042d9d745aa6c3baa9ec0699df3e9/partftpy-0.2.0.tar.gz; wget -O$f "$url" || curl -L "$url" >$f) tar -zxf $f diff --git a/setup.py b/setup.py index 9601970f..4cc3cd2a 100755 --- a/setup.py +++ b/setup.py @@ -140,7 +140,7 @@ args = { "audiotags": ["mutagen"], "ftpd": ["pyftpdlib"], "ftps": ["pyftpdlib", "pyopenssl"], - "tftpd": ["partftpy"], + "tftpd": ["partftpy>=0.2.0"], "pwhash": ["argon2-cffi"], }, "entry_points": {"console_scripts": ["copyparty = copyparty.__main__:main"]},