websocketd icon indicating copy to clipboard operation
websocketd copied to clipboard

Can you make websocketd execute the program before any client connecting

Open argmhz opened this issue 4 years ago • 3 comments

First of all, thank you for building this ;)

I have a program i would like to be running before any clients connect to the websocket. Is that possible?

../websocketd --port=8080 --address=$(hostname -I) sudo someprogram

argmhz avatar Jul 30 '21 22:07 argmhz

I'd say you should be careful with hostname -I; at least I assume you've read:

  --address=ADDRESS              Address to bind to (multiple options allowed)
                                 Use square brackets to specify IPv6 address.
                                 Default: "" (all)

If your SUDO is passwordless it'll work. Otherwise, since the env is always new it'll be asking for password into websocketd's input/output stream which will not quite work as expected. You can use program's STDIN/OUT and enter password from the browser using "sudo -S" but it just feels not right from security standpoint :))) You also will not see password prompt unless you catch stderr.

asergeyev avatar Aug 02 '21 01:08 asergeyev

Thanks for the answer, but I don´t think i was clear enough, sorry.

The script actually works, but the problem is that, it first executes when I connect to the websocket. So what I want to achieve, is the script is executed when i start the websocketd, and then after you connect to it with clients. Or if the websocketd could send and receive stdout/stdin to a running process.

thanks :)

argmhz avatar Aug 03 '21 19:08 argmhz

wouldn't ./script && websocketd [OPTS] ./script work for your usecase?

asergeyev avatar Nov 13 '21 20:11 asergeyev