ftp: banner (#1504)

Signed-off-by: ed <s@ocv.me>
Co-authored-by: ed <s@ocv.me>
This commit is contained in:
doskel 2026-07-04 03:25:29 -06:00 committed by GitHub
parent 34c856e838
commit 8242e69359
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

View file

@ -1521,6 +1521,7 @@ def add_ftp(ap):
ap2.add_argument("--ftp-wt", metavar="SEC", type=int, default=7, help="grace period for resuming interrupted uploads (any client can write to any file last-modified more recently than \033[33mSEC\033[0m seconds ago)") ap2.add_argument("--ftp-wt", metavar="SEC", type=int, default=7, help="grace period for resuming interrupted uploads (any client can write to any file last-modified more recently than \033[33mSEC\033[0m seconds ago)")
ap2.add_argument("--ftp-nat", metavar="ADDR", type=u, default="", help="the NAT address to use for passive connections") ap2.add_argument("--ftp-nat", metavar="ADDR", type=u, default="", help="the NAT address to use for passive connections")
ap2.add_argument("--ftp-pr", metavar="P-P", type=u, default="", help="the range of TCP ports to use for passive connections, for example \033[32m12000-13000") ap2.add_argument("--ftp-pr", metavar="P-P", type=u, default="", help="the range of TCP ports to use for passive connections, for example \033[32m12000-13000")
ap2.add_argument("--ftp-banner", metavar="T", type=u, default="welcome to the party", help="bannertext to send when someone connects; \\n is newline, can be @filepath (loaded into memory on startup); if it has a newline then banner must be longer than 75 chars")
def add_webdav(ap): def add_webdav(ap):

View file

@ -28,6 +28,7 @@ from .util import (
fsenc, fsenc,
ipnorm, ipnorm,
pybin, pybin,
read_utf8,
relchk, relchk,
runhook, runhook,
sanitize_fn, sanitize_fn,
@ -624,11 +625,17 @@ class Ftpd(object):
hs.append([h1, self.args.ftps]) hs.append([h1, self.args.ftps])
zs = self.args.ftp_banner.replace("\\n", "\n")
if zs.startswith("@"):
zs = read_utf8(None, zs[1:], False)
banner = zs.replace("\r", "").replace("\n", "\r\n").strip()
for h_lp in hs: for h_lp in hs:
h2, lp = h_lp h2, lp = h_lp
FtpHandler.hub = h2.hub = hub FtpHandler.hub = h2.hub = hub
FtpHandler.args = h2.args = hub.args FtpHandler.args = h2.args = hub.args
FtpHandler.authorizer = h2.authorizer = FtpAuth(hub) FtpHandler.authorizer = h2.authorizer = FtpAuth(hub)
FtpHandler.banner = banner
if self.args.ftp_pr: if self.args.ftp_pr:
p1, p2 = [int(x) for x in self.args.ftp_pr.split("-")] p1, p2 = [int(x) for x in self.args.ftp_pr.split("-")]