Skip to content

Commit

Permalink
add --tftp-pr to specify portrange instead of ephemerals
Browse files Browse the repository at this point in the history
  • Loading branch information
9001 committed Feb 10, 2024
1 parent d636316 commit 8796c09
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions copyparty/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 6 additions & 4 deletions copyparty/tftpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ def __init__(self, hub: "SvcHub") -> None:
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)
Expand All @@ -122,7 +124,7 @@ def _v2a(
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

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions scripts/make-sfx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def run(self):
"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"]},
Expand Down

0 comments on commit 8796c09

Please sign in to comment.