mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
allow zeromq to veto uploads
This commit is contained in:
parent
f38c754301
commit
3a5c1d9faf
|
@ -23,6 +23,9 @@ run this script with "pull" and run copyparty with this:
|
||||||
run this script with "rep" and run copyparty with this:
|
run this script with "rep" and run copyparty with this:
|
||||||
--xm t3,zmq:req:tcp://localhost:5555
|
--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")
|
sck.bind("tcp://*:5555")
|
||||||
while True:
|
while True:
|
||||||
print("copyparty says %r" % (sck.recv_string(),))
|
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 ""
|
mode = sys.argv[1].lower() if len(sys.argv) > 1 else ""
|
||||||
|
|
|
@ -3482,7 +3482,7 @@ def _zmq_hook(
|
||||||
msg: str,
|
msg: str,
|
||||||
wait: float,
|
wait: float,
|
||||||
sp_ka: dict[str, Any],
|
sp_ka: dict[str, Any],
|
||||||
) -> str:
|
) -> tuple[int, str]:
|
||||||
import zmq
|
import zmq
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -3493,6 +3493,7 @@ def _zmq_hook(
|
||||||
mtx = ZMQ["mtx"]
|
mtx = ZMQ["mtx"]
|
||||||
|
|
||||||
ret = ""
|
ret = ""
|
||||||
|
nret = 0
|
||||||
t0 = time.time()
|
t0 = time.time()
|
||||||
if verbose and log:
|
if verbose and log:
|
||||||
log("hook(%s) %r entering zmq-main-lock" % (src, cmd), 6)
|
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)
|
log("hook(%s) %r awaiting ack from req" % (src, cmd), 6)
|
||||||
try:
|
try:
|
||||||
ret = sck.recv().decode("utf-8", "replace")
|
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:
|
except:
|
||||||
sck.close()
|
sck.close()
|
||||||
del ZMQ[cmd] # bad state; must reset
|
del ZMQ[cmd] # bad state; must reset
|
||||||
|
@ -3567,7 +3572,7 @@ def _zmq_hook(
|
||||||
if wait > 0:
|
if wait > 0:
|
||||||
time.sleep(wait)
|
time.sleep(wait)
|
||||||
|
|
||||||
return ret
|
return nret, ret
|
||||||
|
|
||||||
|
|
||||||
def _runhook(
|
def _runhook(
|
||||||
|
@ -3614,12 +3619,9 @@ def _runhook(
|
||||||
arg = txt or ap
|
arg = txt or ap
|
||||||
|
|
||||||
if acmd[0].startswith("zmq:"):
|
if acmd[0].startswith("zmq:"):
|
||||||
zs = "zmq-error"
|
zi, zs = _zmq_hook(log, verbose, src, acmd[0][4:].lower(), arg, wait, sp_ka)
|
||||||
try:
|
if zi:
|
||||||
zs = _zmq_hook(log, verbose, src, acmd[0][4:].lower(), arg, wait, sp_ka)
|
raise Exception("zmq says %d" % (zi,))
|
||||||
except Exception as ex:
|
|
||||||
if log:
|
|
||||||
log("zeromq failed: %r" % (ex,))
|
|
||||||
return {"rc": 0, "stdout": zs}
|
return {"rc": 0, "stdout": zs}
|
||||||
|
|
||||||
acmd += [arg]
|
acmd += [arg]
|
||||||
|
|
|
@ -141,7 +141,7 @@ class Cfg(Namespace):
|
||||||
ex = "hash_mt hsortn safe_dedup srch_time u2abort u2j u2sz"
|
ex = "hash_mt hsortn safe_dedup srch_time u2abort u2j u2sz"
|
||||||
ka.update(**{k: 1 for k in ex.split()})
|
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()})
|
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"
|
ex = "db_act k304 loris no304 re_maxage rproxy rsp_jtr rsp_slp s_wr_slp snap_wri theme themes turbo"
|
||||||
|
|
Loading…
Reference in a new issue