louisdh / openterm

OpenTerm, a sandboxed command line interface for iOS
Other
1.62k stars 247 forks source link

invoke OpenTerm through x-callback-url #60

Open palmin opened 6 years ago

palmin commented 6 years ago

I think it would be useful to be able to run commands in OpenTerm from other apps through x-callback-url, which is sort of the reverse of issue #26.

Imagine something along the lines of:

openterm://x-callback-url/run?command=grep%20find&input=stuff%20%on%20stdin%20to%find
                             &x-success=...&x-error=...

The command parameter is the command that is executed, while input is passed to stdin. Depending on the status code of the command either x-success or x-error callbacks are done with the text result from either stdout or stderr.

Since commands can do all sorts of things, it would probably be best to have a key parameter with a random password like Drafts and Working Copy have, such that users are not tricked into running malicious commands.

How would you feel about such a feature?

Anything you would like me to consider?

louisdh commented 6 years ago

Great idea! I also like the key parameter idea. This in combination with Workflow would open so many possibilities.

palmin commented 6 years ago

I have a feeling changes are coming to how commands are processed to facilitate script files and such and that it would be better to wait before implementing invoking commands through x-callback-url.

My strategy will pretty much be: 1) parse x-callback-url and write the contents of the input parameter to a temporary file. 2) invoke the command where stdin is redirected from the temporary file and such that stdout and stderr are redirected to two other temporary files. 3) depending on status code of command, the x-success or x-error callback is made with content of the respective temporary file.

Depending on how scripting ends up working, the command might also be put in a temporary script file if this could make redirection cleaner for composite commands.

I am open to using a different strategy. I'm writing this up to get feedback before doing a lot of work.