zendtech / IbmiToolkit

PHP frontend to XMLSERVICE for IBM i development.
BSD 3-Clause "New" or "Revised" License
46 stars 34 forks source link

feat: Add SSH Transport #134

Closed abmusse closed 3 years ago

abmusse commented 3 years ago

Currently the nodejs-itoolkit and python-itoolkit support SSH as a transport. These toolkits establish an ssh connection and call the xmlservice-cli program via ssh. xmlservice-cli is provided by the itoolkit-utils package.

$ yum install itoolkit-utils

At first glance we could probaly make use of https://www.php.net/manual/en/function.ssh2-exec.php to call xmlservice-cli.

Thoughts on adding an ssh transport?

alanseiden commented 3 years ago

@abmusse Thank you for the information on itoolkit-utils. We will take a look at the possibility of SSH transport support.

alanseiden commented 3 years ago

We have reviewed the Node.js implementation for ideas. We will work on the PHP implementation of the SSH transport.

NattyNarwhal commented 3 years ago

I have a private branch for this, but the ssh2 extension API is either deficient or defective; it handles stdio from the remote process very poorly. Plea of desperation to follow.

NattyNarwhal commented 3 years ago

My quest of debugging ssh2 has determined:

  1. It is buggy and probably a superfund site
  2. It doesn't expose libssh2_channel_send_eof at all. The code in stream close when the refcount approaches zero is supposed to do this, but it calls get EOF instead, and if we could just send EOF, we can keep the stdout stream open. (Keeping the stderr stream open keeps the refcount on stdio, meaning closing it doesn't decrement the refcount to zero...)
NattyNarwhal commented 3 years ago

Hit enter too soon. What that basically means is we'd probably have to fix PECL ssh2 and make that new version the minimum for an SSH transport. The alternative is to use Net_SSH which is all managed PHP, but I'm not sure of the quality of that, and it's a PEAR-level dependency we'd have to worry about when the toolkit currently has none.

NattyNarwhal commented 3 years ago

For this to use PECL SSH2, it blocks on php/pecl-networking-ssh2#45.

NattyNarwhal commented 3 years ago

Upstream extension actually merged it! We just need to wait for them to cut a release, but it is possible to start working on it knowing that it'll be able to be used soon. Just have to check for ssh2_send_eof.

ThePrez commented 3 years ago

Nice!