mirror of
				https://github.com/9001/copyparty.git
				synced 2025-11-03 21:43:12 +00:00 
			
		
		
		
	hook-flag to send input on stdin
This commit is contained in:
		@@ -813,6 +813,7 @@ def get_sects():
 | 
			
		||||
             \033[36mf\033[35m forks the process, doesn't wait for completion
 | 
			
		||||
             \033[36mc\033[35m checks return code, blocks the action if non-zero
 | 
			
		||||
             \033[36mj\033[35m provides json with info as 1st arg instead of filepath
 | 
			
		||||
             \033[36ms\033[35m provides input data on stdin (instead of 1st arg)
 | 
			
		||||
             \033[36mwN\033[35m waits N sec after command has been started before continuing
 | 
			
		||||
             \033[36mtN\033[35m sets an N sec timeout before the command is abandoned
 | 
			
		||||
             \033[36miN\033[35m xiu only: volume must be idle for N sec (default = 5)
 | 
			
		||||
@@ -846,6 +847,9 @@ def get_sects():
 | 
			
		||||
              the \033[33m--\033[35m stops notify-send from reading the message as args
 | 
			
		||||
              and the alert will be "hey" followed by the messagetext
 | 
			
		||||
 | 
			
		||||
             \033[36m--xm s,,tee,-a,log.txt\033[35m appends each msg to log.txt;
 | 
			
		||||
             \033[36m--xm s,j,,tee,-a,log.txt\033[35m writes it as json instead
 | 
			
		||||
 | 
			
		||||
             \033[36m--xau zmq:pub:tcp://*:5556\033[35m announces uploads on zeromq;
 | 
			
		||||
             \033[36m--xau t3,zmq:push:tcp://*:5557\033[35m also works, and you can
 | 
			
		||||
             \033[36m--xau t3,j,zmq:req:tcp://localhost:5555\033[35m too for example
 | 
			
		||||
@@ -855,7 +859,8 @@ def get_sects():
 | 
			
		||||
            as soon as the volume has been idle for iN seconds (5 by default)
 | 
			
		||||
 | 
			
		||||
            \033[36mxiu\033[0m is also unique in that it will pass the metadata to the
 | 
			
		||||
            executed program on STDIN instead of as argv arguments, and
 | 
			
		||||
            executed program on STDIN instead of as argv arguments (so
 | 
			
		||||
            just like the \033[36ms\033[0m option does for the other hook types), and
 | 
			
		||||
            it also includes the wark (file-id/hash) as a json property
 | 
			
		||||
 | 
			
		||||
            \033[36mxban\033[0m can be used to overrule / cancel a user ban event;
 | 
			
		||||
 
 | 
			
		||||
@@ -3629,12 +3629,13 @@ def retchk(
 | 
			
		||||
 | 
			
		||||
def _parsehook(
 | 
			
		||||
    log: Optional["NamedLogger"], cmd: str
 | 
			
		||||
) -> tuple[str, bool, bool, bool, bool, float, dict[str, Any], list[str]]:
 | 
			
		||||
) -> tuple[str, bool, bool, bool, bool, bool, float, dict[str, Any], list[str]]:
 | 
			
		||||
    areq = ""
 | 
			
		||||
    chk = False
 | 
			
		||||
    fork = False
 | 
			
		||||
    jtxt = False
 | 
			
		||||
    imp = False
 | 
			
		||||
    sin = False
 | 
			
		||||
    wait = 0.0
 | 
			
		||||
    tout = 0.0
 | 
			
		||||
    kill = "t"
 | 
			
		||||
@@ -3650,6 +3651,8 @@ def _parsehook(
 | 
			
		||||
            jtxt = True
 | 
			
		||||
        elif arg == "I":
 | 
			
		||||
            imp = True
 | 
			
		||||
        elif arg == "s":
 | 
			
		||||
            sin = True
 | 
			
		||||
        elif arg.startswith("w"):
 | 
			
		||||
            wait = float(arg[1:])
 | 
			
		||||
        elif arg.startswith("t"):
 | 
			
		||||
@@ -3694,7 +3697,7 @@ def _parsehook(
 | 
			
		||||
 | 
			
		||||
    argv[0] = os.path.expandvars(os.path.expanduser(argv[0]))
 | 
			
		||||
 | 
			
		||||
    return areq, chk, imp, fork, jtxt, wait, sp_ka, argv
 | 
			
		||||
    return areq, chk, imp, fork, sin, jtxt, wait, sp_ka, argv
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def runihook(
 | 
			
		||||
@@ -3704,7 +3707,7 @@ def runihook(
 | 
			
		||||
    vol: "VFS",
 | 
			
		||||
    ups: list[tuple[str, int, int, str, str, str, int, str]],
 | 
			
		||||
) -> bool:
 | 
			
		||||
    _, chk, imp, fork, jtxt, wait, sp_ka, acmd = _parsehook(log, cmd)
 | 
			
		||||
    _, chk, _, fork, _, jtxt, wait, sp_ka, acmd = _parsehook(log, cmd)
 | 
			
		||||
    bcmd = [sfsenc(x) for x in acmd]
 | 
			
		||||
    if acmd[0].endswith(".py"):
 | 
			
		||||
        bcmd = [sfsenc(pybin)] + bcmd
 | 
			
		||||
@@ -3883,7 +3886,7 @@ def _runhook(
 | 
			
		||||
    txt: str,
 | 
			
		||||
) -> dict[str, Any]:
 | 
			
		||||
    ret = {"rc": 0}
 | 
			
		||||
    areq, chk, imp, fork, jtxt, wait, sp_ka, acmd = _parsehook(log, cmd)
 | 
			
		||||
    areq, chk, imp, fork, sin, jtxt, wait, sp_ka, acmd = _parsehook(log, cmd)
 | 
			
		||||
    if areq:
 | 
			
		||||
        for ch in areq:
 | 
			
		||||
            if ch not in perms:
 | 
			
		||||
@@ -3919,7 +3922,11 @@ def _runhook(
 | 
			
		||||
            raise Exception("zmq says %d" % (zi,))
 | 
			
		||||
        return {"rc": 0, "stdout": zs}
 | 
			
		||||
 | 
			
		||||
    acmd += [arg]
 | 
			
		||||
    if sin:
 | 
			
		||||
        sp_ka["sin"] = (arg + "\n").encode("utf-8", "replace")
 | 
			
		||||
    else:
 | 
			
		||||
        acmd += [arg]
 | 
			
		||||
 | 
			
		||||
    if acmd[0].endswith(".py"):
 | 
			
		||||
        acmd = [pybin] + acmd
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user