allow zeromq to veto uploads

This commit is contained in:
ed 2025-01-25 17:49:03 +00:00
parent f38c754301
commit 3a5c1d9faf
3 changed files with 17 additions and 10 deletions

View file

@ -23,6 +23,9 @@ run this script with "pull" and run copyparty with this:
run this script with "rep" and run copyparty with this:
--xm t3,zmq:req:tcp://localhost:5555
note: to conditionally block uploads based on message contents,
use rep_server to answer with "return 1" and run copyparty with
--xau t3,c,zmq:req:tcp://localhost:5555
"""
@ -56,7 +59,9 @@ def rep_server():
sck.bind("tcp://*:5555")
while True:
print("copyparty says %r" % (sck.recv_string(),))
sck.send(b"thx")
reply = b"thx"
# reply = b"return 1" # non-zero to block an upload
sck.send(reply)
mode = sys.argv[1].lower() if len(sys.argv) > 1 else ""

View file

@ -3482,7 +3482,7 @@ def _zmq_hook(
msg: str,
wait: float,
sp_ka: dict[str, Any],
) -> str:
) -> tuple[int, str]:
import zmq
try:
@ -3493,6 +3493,7 @@ def _zmq_hook(
mtx = ZMQ["mtx"]
ret = ""
nret = 0
t0 = time.time()
if verbose and log:
log("hook(%s) %r entering zmq-main-lock" % (src, cmd), 6)
@ -3554,6 +3555,10 @@ def _zmq_hook(
log("hook(%s) %r awaiting ack from req" % (src, cmd), 6)
try:
ret = sck.recv().decode("utf-8", "replace")
if ret.startswith("return "):
m = re.search("^return ([0-9]+)", ret[:12])
if m:
nret = int(m.group(1))
except:
sck.close()
del ZMQ[cmd] # bad state; must reset
@ -3567,7 +3572,7 @@ def _zmq_hook(
if wait > 0:
time.sleep(wait)
return ret
return nret, ret
def _runhook(
@ -3614,12 +3619,9 @@ def _runhook(
arg = txt or ap
if acmd[0].startswith("zmq:"):
zs = "zmq-error"
try:
zs = _zmq_hook(log, verbose, src, acmd[0][4:].lower(), arg, wait, sp_ka)
except Exception as ex:
if log:
log("zeromq failed: %r" % (ex,))
zi, zs = _zmq_hook(log, verbose, src, acmd[0][4:].lower(), arg, wait, sp_ka)
if zi:
raise Exception("zmq says %d" % (zi,))
return {"rc": 0, "stdout": zs}
acmd += [arg]

View file

@ -141,7 +141,7 @@ class Cfg(Namespace):
ex = "hash_mt hsortn safe_dedup srch_time u2abort u2j u2sz"
ka.update(**{k: 1 for k in ex.split()})
ex = "au_vol dl_list mtab_age reg_cap s_thead s_tbody th_convt"
ex = "au_vol dl_list mtab_age reg_cap s_thead s_tbody th_convt ups_who"
ka.update(**{k: 9 for k in ex.split()})
ex = "db_act k304 loris no304 re_maxage rproxy rsp_jtr rsp_slp s_wr_slp snap_wri theme themes turbo"