Hi Everyone,
After digging into this a bit deeper it looks like there are two basic options,
use a pipe stream or use key events. A pipe stream is way more efficient when
sending very large amounts of data, but (as far as I can tell) Guacamole’s SSH
support does not handle inbound pipe streams or using them as a source for
keystrokes. So, something like below won’t work.
var stream = client.createPipeStream("text/plain", "MyStream");
var writer = new Guacamole.StringWriter(stream);
writer.sendText("Hello world!");
writer.sendEnd();
A function to “type” a command at the command prompt like below could be used.
function sendCommand(client, cmd) {
for (var i=0; i < cmd.length; i++) {
// Get current codepoint
var codepoint = cmd.charCodeAt(i);
// Convert to keysym
var keysym;
if (codepoint >= 0x0100)
keysym = 0x01000000 | codepoint;
else
keysym = codepoint;
// Press and release key
client.sendKeyEvent(1, keysym);
client.sendKeyEvent(0, keysym);
}
}
A small delay must be injected between making the client connection and the
start of sending keystrokes. The delay is only needed once to give the
connection and Telnet or SSH session time to start. For a single one time
command execution the function call could be included in a setTimeout statement
like below.
setTimeout(function() { sendCommand (guac, "ls -al\r"); }, 1000);
Regards,
Jeff
From: "McRoy, Jeffrey (GE Healthcare)" <[email protected]>
Reply-To: <[email protected]>
Date: Tuesday, October 3, 2017 at 5:00 PM
To: "[email protected]" <[email protected]>
Subject: EXT: Re: Automatic execution of commands in Telnet/SSH
Hi Nick,
Imagine having a dropdown in the client UI that allows a user to select and
execute pre-defined commands. That’s more what I’m thinking of instead of
running a command specific to a user’s login. Would Guacamole have a way to
programmatically inject commands into the input stream?
Thanks & Regards,
Jeff
From: Nick Couchman <[email protected]>
Reply-To: "[email protected]"
<[email protected]>
Date: Monday, October 2, 2017 at 7:24 PM
To: "[email protected]" <[email protected]>
Subject: EXT: Re: Automatic execution of commands in Telnet/SSH
Jeff,
Guacamole does not work any different in this regard than logging into the SSH
or Telnet system with a terminal emulator. So, you can certainly set a command
to run at login, which will be executed in the context of the user's login
shell and environment, but there's no special way that Guacamole has to inject
commands into the login process that either bypass the user's login shell or
execute something just because it's coming from Guacamole.
There are ways to accomplish this - like setting the SSH session startup
command to a particular shell script that runs and then drops the user into a
shell. But, again, this is exactly the same process you'd use if you wanted to
do this for someone using ssh or telnet on a command line.
-Nick
On Mon, Oct 2, 2017 at 4:46 PM, McRoy, Jeffrey (GE Healthcare)
<[email protected]> wrote:
Hi Everyone,
Has anyone experimented with automatically executing a command on the remote
system directly after logging in using the Telnet or SSH protocol plugins?
Thanks & Regards,
Jeff
smime.p7s
Description: S/MIME cryptographic signature
