3 ms·
This sounds like a great addition for servers written in Swift. Pair it with the very easy to use and clean command line arguments package and it should be "tri
by jws 6y ago
This sounds like a great addition for servers written in Swift. Pair it with the very easy to use and clean command line arguments package and it should be "trivial" to add management/diagnostic console full of commands to your server.
Traditionally for HTTP servers I carve off a URL prefix, e.g. /diagnostics/ or listen on a different port, and make handlers there to let me know how things are going. The downside is that I then have to protect those which collides with whatever other authentication is going on.
Moving that to a command console eliminates all those ways to screw up and let evil people into my diagnostic functions.
The command line parser package is trivial to use once you get the hang of it and generates acceptable "help" automatically, so you'll end up with a custom CLI of your diagnostic commands with a "help" function to remember them for essentially zero coding and maintenance effort.
Now I have to spend all day resisting the urge to weld this into my latest HTTP server to see how it goes.
Update: There is an example server in the Sources/NIOSSHServer directory of the repository. 5 files, about 500 lines total to implement a "bash" command executer and a remote port forwarder.
Update 2: 50 minutes in and I have an ssh server embedded in my server. Maybe. When I send a command it explodes my process with a Posix.close() to a bad file descriptor tripping a precondition check. So, maybe don't rush this to a live server.
- jws 6y agoFor anyone following in these footsteps: It works well. I spent more time fighting Swift Argument Parser than the NIOSSH. Fundamentally, there is not a way to pass context down to a command that is run. Fine when you are a whole program reading its commands and everything is implicitly global, but if you have a bunch of SSH connections coming in then just getting the output to the right one needs context. I'm not real happy with my solution, but its clean and it works. Figure two days to get a usable subsystem working. I have a few more things to try to clean up my mess. If it works I'll tidy up the package and publish it.
- jws 6y agoTwo days in. The package is useful and mostly complete. See https://github.com/jimstudt/SSHConsole https://github.com/jimstudt/SSHConsole if you have needs, or just want to see another example of using NIOSS on the server. This one includes the public key authentication which in retrospect is trivial-ish.