xpipe icon indicating copy to clipboard operation
xpipe copied to clipboard

FR: Support for Xshell terminal

Open alexdelprete opened this issue 1 year ago • 20 comments

Hi,

could you add support for NetSarang Xshell? https://netsarang.com/en/xshell/

I added it as a custom terminal, and used the test feature, it correctly opened a local session, so I guess it supports invoking it via CLI. It also supports opening new tabs vs new windows.

Thanks a lot. :)

alexdelprete avatar Jan 22 '24 02:01 alexdelprete

So I looked at the documentation and it seems like the command-line support is limited: https://netsarang.atlassian.net/wiki/spaces/ENSUP/pages/31457646/Command+line+parameters+for+Xshell

It can't be used as an arbitrary terminal, only for certain SSH connections. What I can add is maybe a button for SSH connections to open the connection in Xshell.

crschnick avatar Jan 22 '24 03:01 crschnick

That would be great. Could you give me an example of a proper/full CLI implementation? Because I was merely thinking about opening the SSH connection, but being an Xpipe beginner, I'm surely missing something here. .)

alexdelprete avatar Jan 22 '24 11:01 alexdelprete

It's just that to properly open any arbitrary connection in a terminal or other program like xshell, xpipe needs to be able to call the program via its CLI and pass all relevant options. It usually does it by creating and passing a temporary script to be executed that will open the connection.

But since xshell does not support that, we kinda have to choose the second best option and call it differently, in this case by manually passing the connection information like username, host, etc. This is however not a very good solution as you have to enter any passwords, keys, etc. in xshell again when launched because we can't pass that information. It's better than nothing though.

If it would support the same level of CLI interaction as for example you can do with Windows Terminal, then I could add full support.

crschnick avatar Jan 22 '24 12:01 crschnick

It's just that to properly open any arbitrary connection in a terminal or other program like xshell, xpipe needs to be able to call the program via its CLI and pass all relevant options. It usually does it by creating and passing a temporary script to be executed that will open the connection.

Well, Xshell supports session profiles (.xsh files, an ini format) in which it stores all the info needed to connect to a server. It can also open all sessions files contained in a path.

image

So the script you mentioned could actually be that session file, but it should be in .xsh format, I have to check if it is documented, or I can pass you an example so you can check if it contains all needed parameters used by Xpipe.

This is one of my .xsh files, I redacted pw and auth stuff, I guess you don't need everything but only a minimal subset of this to create a session and pass it to xshell cli to open:

[CONNECTION:PROXY]
Proxy=
StartUp=0
[CONNECTION:SERIAL]
BaudRate=6
StopBits=0
FlowCtrl=0
Parity=0
DataBits=3
ComPort=0
[SessionInfo]
Version=7.1
Description=Xshell session file
[Information]
MinorVersion=0
MajorVersion=3
Description=
[TRACE]
SockConn=1
SshLogin=0
SshTunneling=0
SshPacket=0
TelnetOptNego=0
[CONNECTION:SSH]
LaunchAuthAgent=1
KeyExchange=
SSHCiphers=aes128-ctr:1,aes192-ctr:1,aes256-ctr:1,[email protected]:1,[email protected]:1,aes128-cbc:1,aes192-cbc:1,aes256-cbc:1,3des-cbc:1,blowfish-cbc:1,cast128-cbc:1,arcfour:1,rijndael128-cbc:1,rijndael192-cbc:1,rijndael256-cbc:1,[email protected]:1,arcfour128:1,arcfour256:1,[email protected]:1
ForwardToXmanager=1
AgentForwarding=1
Compression=0
KeyExchangeList=ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
NoTerminal=0
CipherList=aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc,rijndael128-cbc,rijndael192-cbc,rijndael256-cbc,aes256-ctr,aes192-ctr,aes128-ctr,[email protected]
UseAuthAgent=1
MAC=
[email protected]:1,[email protected]:1,[email protected]:1,hmac-sha2-256:1,hmac-sha2-512:1,hmac-sha1:1,hmac-sha1-96:1,hmac-md5:1,hmac-md5-96:1,hmac-ripemd160:1,[email protected]:1,[email protected]:1,[email protected]:1,[email protected]:1,[email protected]:1,[email protected]:1,[email protected]:1,[email protected]:1
ForwardX11=0
InitRemoteDirectory=
VexMode=2
Cipher=
Display=localhost:0.0
FwdReqCount=0
InitLocalDirectory=
MACList=hmac-sha1,hmac-sha1-96,hmac-md5,hmac-md5-96,hmac-ripemd160,[email protected],hmac-sha2-256
[email protected]:1,ecdh-sha2-nistp256:1,ecdh-sha2-nistp384:1,ecdh-sha2-nistp521:1,diffie-hellman-group-exchange-sha256:1,diffie-hellman-group-exchange-sha1:1,diffie-hellman-group14-sha1:1,diffie-hellman-group1-sha1:1,diffie-hellman-group18-sha512:1,diffie-hellman-group16-sha512:1,diffie-hellman-group14-sha256:1
NoConnFileManager=0
SaveHostKey=0
RemoteCommand=
[BELL]
FilePath=
RepeatTime=3
FlashWindow=0
BellMode=1
IgnoreTime=3
[USERINTERFACE]
NoQuickButton=0
ShowOnLinkBar=0
QuickCommand=Weewx
[CONNECTION:FTP]
Passive=1
InitRemoteDirectory=
InitLocalDirectory=
[TRANSFER]
FolderMethod=0
DropXferHandler=2
XmodemUploadCmd=rx
ZmodemUploadCmd=rz -E
FolderPath=
YmodemUploadCmd=rb -E
AutoZmodem=1
SendFolderPath=
DuplMethod=0
XYMODEM_1K=0
[CONNECTION]
PasteDelay=0
Port=22
Host=emqx.axel.dom
Protocol=SSH
AutoReconnect=0
AutoReconnectLimit=0
Description=
AutoReconnectInterval=30
FtpPort=21
UseNaglesAlgorithm=0
IPV=0
[CONNECTION:HWCERTIFICATES]
Count=0
[TERMINAL]
Rows=45
CtrlAltIsAltGr=1
InitOriginMode=0
CodePage=65001
InitReverseMode=0
DisableBlinkingText=0
InitAutoWrapMode=1
Cols=200
InitEchoMode=0
Type=xterm-256color
DisableAlternateScreen=0
CJKAmbiAsWide=0
ScrollBottomOnKeyPress=0
PauseScrollBottom=0
DisableTitleChange=0
ForceEraseOnDEL=0
InitInsertMode=0
ShiftForcesLocalUseOfMouse=1
FontLineCharacter=0
ScrollbackSize=10000
InitCursorMode=0
BackspaceSends=2
FixedCols=0
UseAltAsMeta=1
UseInitSize=1
UseLAltAsMeta=1
UseRAltAsMeta=1
AltKeyMapPath=
DeleteSends=0
DisableTermPrinting=0
IgnoreResizeRequest=0
ScrollBottomOnTermOutput=1
FontPowerLine=0
UseAppMouse=1
ScrollErasedText=1
KeyMap=0
RecvLLAsCRLF=0
MoveToWorkFolder=1
EraseWithBackgroundColor=1
InitNewlineMode=0
InitKeypadMode=0
TerminalNameForEcho=
[TERMINAL:WINDOW]
ColorScheme=New Black
FontQuality=6
CursorColor=65280
CursorBlinkInterval=500
LineSpace=0
TabColorType=0
FontStyle=0
CursorAppearance=0
TabColorOther=0
FontSize=10
CursorBlink=1
AsianFontSize=10
BoldMethod=2
BGImageFile=
CursorTextColor=0
BGImagePos=0
AsianFont=FiraCode Nerd Font Mono
FontFace=CaskaydiaCove NFM
CharSpace=0
AsianFontStyle=0
MarginBottom=2
MarginLeft=2
MarginTop=2
MarginRight=2
[CONNECTION:TELNET]
XdispLoc=1
NegoMode=0
CharMode=0
Display=$PCADDR:0.0
[HIGHLIGHT]
HighlightSet=None
[CONNECTION:AUTHENTICATION]
Pkcs11Pin=
ExpectSend_Expect_0=
ExpectSend_Send_0=
Library=0
Passphrase=**redacted**
UseInitScript=0
Delegation=0
Pkcs11Middleware=
TelnetLoginPrompt=ogin:
CapiPin=
Password=**redacted**
RloginPasswordPrompt=assword:
UseExpectSend=1
TelnetPasswordPrompt=assword:
ExpectSend_Count=1
CapiKey=
Method=0
AuthMethodList=11,00,20,30,40,50
ExpectSend_Hide_0=1
ScriptPath=
UserKey=alexdelprete_ed25519_256
UserName=root
[LOGGING]
FilePath=%n_%Y-%m-%d_%t.log
Overwrite=1
WriteFileTimestamp=0
Type=0
FileMethod=0
TimestampFormat=[%a] 
Encoding=2
TermCode=0
AutoStart=1
Timestamp=0
Prompt=0
WriteTermTimestamp=0
[ADVANCED]
WaitPrompt=
PromptMax=0
SendLineDelayType=0
ApplyAllChanges=1
SendLineDelayInterval=0
SendCharDelayInterval=0
[CONNECTION:RLOGIN]
TermSpeed=38400
[CONNECTION:KEEPALIVE]
SendKeepAliveInterval=60
KeepAliveInterval=60
TCPKeepAlive=0
KeepAliveString=
SendKeepAlive=0
KeepAlive=1
[CONNECTION:HWCAKEYS]
Count=0

alexdelprete avatar Jan 22 '24 14:01 alexdelprete

See here: https://netsarang.atlassian.net/wiki/spaces/ENSUP/pages/419957436/Xshell+Command+Line+Option

image

alexdelprete avatar Jan 22 '24 14:01 alexdelprete

So I think there are two options here:

  • Generate a xsh by ourselves to dynamically launch any connection
  • Find an already existing xsh file in the sessions dir that matches the hostname/port/user and then launch that

I think option two would make more sense

crschnick avatar Jan 22 '24 22:01 crschnick

I think option two would make more sense

I initially discarded the second because it would mean maintaining a link in case they are renamed or deleted, etc.

How would xpipe link the right .xsh? by name of the server? the requirement could be that the server name in xpipe is part of the filename of one (and only one) .xsh file in the Sessions folder, so xpipe could make an automatic association, without parsing the content of the xsh.

alexdelprete avatar Jan 23 '24 03:01 alexdelprete

I can just scan all the .xsh for a certain hostname that is used in the xpipe connection and then call xshell with the found .xsh.

I.e. we would scan all .xsh files to find one that contains Host=<hostname>

crschnick avatar Jan 23 '24 03:01 crschnick

Wouldn't that be slow? It's cool though, dynamic and tight integration. :)

alexdelprete avatar Jan 23 '24 03:01 alexdelprete

Not really in terms of other standards. Searching the files for a fixed string should be quick

crschnick avatar Jan 23 '24 03:01 crschnick

That's the best solution then.

Be aware that in the Sessions folder there could be subfolders.

This is my sessions folder in the filesystem:

image

And this is how I navigate it in Xshell (simple and efficient way):

image

alexdelprete avatar Jan 23 '24 03:01 alexdelprete

I found this thread while I was trying to setup XPipe and Xshell as well, from a normal windows terminal I can just type:

xshell $hostname
or
xshell $sessionname

Can the shell function in xpipe just pass the "name" from the xpipe config to xshell, so when you hit the shell icon it just sends "xshell $objectname"?

pixitha avatar Aug 03 '24 14:08 pixitha

Yeah I forgot about this issue somewhat and now my xshell trial is over. I would need to first purchase it to test it locally.

Just calling xshell <name> would be possible although a bit basic.

crschnick avatar Aug 03 '24 19:08 crschnick

my xshell trial is over. I would need to first purchase it to test it locally.

there's the new open beta for v8. you could use that. I just installed it.

I agree that calling xshell with the hostname is a bit basic. your initial proposal is much better.

alexdelprete avatar Aug 03 '24 19:08 alexdelprete

Oh it's free for home personal use now, fyi.

https://www.xshell.com/en/free-for-home-school/

pixitha avatar Aug 03 '24 19:08 pixitha

Oh it's free for home personal use now, fyi.

it was always free for personal use, it had a session limitation of 8 initially (or 10, can't quite remember) but they increased that last year.

alexdelprete avatar Aug 03 '24 19:08 alexdelprete

Well I guess it's up to interpretation if this constitutes personal use.

But the beta looks to be a good idea as that is not limited for personal use.

crschnick avatar Aug 03 '24 19:08 crschnick

My initial proposal was of course much more work. Just adding a button to launch xshell with the specified connection name is very easy. And if you keep track on keeping your connection names consistent, that would work

crschnick avatar Aug 03 '24 20:08 crschnick

So we can have the easy thing quickly? :)

alexdelprete avatar Aug 03 '24 23:08 alexdelprete

So this simple launch functionality is implemented in https://github.com/xpipe-io/xpipe-ptb now

crschnick avatar Aug 06 '24 15:08 crschnick

So I worked on this more to introduce a general solution for external clients like xshell, mobaxterm, termius, and others.

Right now it can start up a local SSH server that will connect to any connection in xpipe. It is working fine so far, but with xshell I can't get it to launch properly. I'm running "C:\Program Files (x86)\NetSarang\Xshell 8\Xshell.exe" -url ssh://"Christopher Schnick"@localhost:21722 -i "C:\Users\Christopher Schnick\.xpipe\ssh_bridge\identity" to connect to that local server but xshell always asks me for a nonexistent passphrase: image

If I add the connection manually in xshell it works fine.

crschnick avatar Aug 12 '24 15:08 crschnick

Alright I think I managed to implement support for xshell the best I can in the latest PTB: https://github.com/xpipe-io/xpipe-ptb

It is now available to use as terminal in the settings selection.

crschnick avatar Aug 14 '24 16:08 crschnick

Alright I think I managed to implement support for xshell the best I can in the latest PTB

Is there still the passphrase issue of previous post?

alexdelprete avatar Aug 16 '24 22:08 alexdelprete

No, I figured it out. Xshell uses their own key storage and format so I had to work around that. It seems like it does not accept file paths for openssh keys in that cli.

The idea now is that you have to add the key with the right name to Xshell manually once to link it to xpipe, but after that everything should work automatically.

crschnick avatar Aug 16 '24 22:08 crschnick

The idea now is that you have to add the key with the right name to Xshell manually once to link it to xpipe

I just tested it, and it works.

Here's the steps:

  1. launch/open Xshell's Xagent (xshell's ssh agent)
  2. click on Manage Keys
  3. Import the private key from %USERPROFILE%\.xpipe-ptb\ssh_bridge\xpipe_ptb_bridge
  4. Xagent creates the corresponding private key (in NSSSH format) in its data folder

image

alexdelprete avatar Aug 16 '24 23:08 alexdelprete

It seems like it does not accept file paths for openssh keys in that cli

I noticed that importing private keys the resulting key is in NSSSH format, I wonder if maybe it was just a matter of using that kind of key.

alexdelprete avatar Aug 16 '24 23:08 alexdelprete

I guess the xagent works too, I just added the key to xshell itself.

crschnick avatar Aug 17 '24 09:08 crschnick

Yes I think they do the same thing.

alexdelprete avatar Aug 17 '24 11:08 alexdelprete

Alright so can I mark this as completed? Or is there anything else?

crschnick avatar Aug 17 '24 11:08 crschnick

Not yet. Didn't test with xshell connections yet.

If I understood correctly, this version doesn't "integrate" with existing Xshell connection files right?

So, how do I create a connection through Xshell, from scratch? I just configure a new terminal?

alexdelprete avatar Aug 17 '24 11:08 alexdelprete