Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you use WebTerminal features with the %Net.TelnetStream class to connect to other older Cache Instances? #100

Open
swils024 opened this issue May 4, 2017 · 5 comments

Comments

@swils024
Copy link

swils024 commented May 4, 2017

If you have a Windows version of Cache 2017.1 installed with WebTerminal, can you use the Windows Telnet emulator class %Net.TelnetStream to connect to older remote Cache servers and inherit the autocomplete and syntax highlighting features of WebTerminal?

Here is example Cache ObjectScript code, which you can execute from the USER namespace within a WebTerminal session. I called the file TelnetInit.mac

sample_telnet

In the code sample provided, you can ignore prompts after the username and password are processed. 'S' is simply a login menu option for selecting a shell session. Now you have a UNIX Server shell you can run csession to connect to any Cache instance on that server and list globals or run programs. I want to inherit the autocomplete and syntax highlighting but I don't know if this is possible.

@nikitaeverywhere
Copy link
Member

nikitaeverywhere commented May 4, 2017

Hello! First, my congratulations on creating a #100 issue!

Thanks for the cool thing. It should definitely become the part of WebTerminal. Maybe it is worth something like /telnet [email protected] WebTerminal command, what do you think?

The syntax highlighting works only for "native" prompts in WebTerminal (not for read), but it is easy to add an escape sequences to WebTerminal engine which will enable/disable syntax highlighting (can be a feature request). As for the autocomplete on server, it is primarily done by this code, which is wrapped by WebSocket send/receive interface. Its not easy to transfer this behavior to an older server. There are some options I can think of here, regarding to enhancing WebTerminal project with the new functionality:

  1. Place some code on a telnet server and alter some WebTerminal code to make it capable to work with telnet servers. Hard.
  2. Refactor the WebTerminal autocomplete code in that way so it will work with SendChunk/ReceiveChunk methods only (this methods transfer the data between WebSocket controller process and the WebTerminal.Core process, which handles the commands execution). That is definitely a good way to go, because these two methods are well-interchangeable with objTelnet.WriteLine/objTelnet.Read. We can "fake" this methods (create their analogues) to work with while WebTerminal is switched to the new "telnet mode".
  3. Just add a syntax highlight escape sequences and do not implement autocomplete.

Could you please paste the code as a plain text (use ``` ... code ... ```)? It is definitely useful. Any ideas on the options I suggested?

Thanks!

@swils024
Copy link
Author

swils024 commented May 5, 2017

Pasting code as plain text as requested. I'm new to Github so let me know if it's not displaying properly

START
Kill
 Read !,"Enter your server: ",server,!
 Set objTelnet = ##class(%Net.TelnetStream).%New()
 Set pTimeout=60
 Do objTelnet.Open(server,23,.pTimeout,.pSC)
 Set objTelnet.TermTypes="VT-100"
 Write !,"Open Status: " _pSC
 Set read=objTelnet.Read(5000,1,.pSC)
 Write !,"Username Prompt: " _pSC
 Do objTelnet.WriteLine("yourusername",1,.pSC)
 Write !,"Username provided "_pSC 
 Set read=objTelnet.Read(5000,1,.pSC)
 Write !,"Password Prompt: "_pSC
 Do objTelnet.WriteLine("yourpassword",1,.pSC)
 Write !,"Password provided: "_pSC
 Set read=objTelnet.Read(5000,1,.pSC)
 Write !,"Cache Prompt: "_pSC
 Write read
 Do objTelnet.WriteLine("S",1,.pSC)
 Set read=objTelnet.Read(5000,2,.pSC)
 Write read
PROMPT4INPUT
 Read yourcommand
 GOTO:yourcommand="Q" FINISH
 Do objTelnet.WriteLine(yourcommand,1,.pSC)
 Set read=objTelnet.Read(5000,2,.pSC)
 Write !,read
 GOTO PROMPT4INPUT
FINISH 
 Write "Exiting..."
 Quit

The /telnet [email protected] would be very nice. My first preference would be Option 2 to refactor the AutoComplete code. I hope it's not too much work as we will be moving to Cache 2017.1 in the next few months. Right now we are using Cache 2013.1.

I think the %Net.TelnetStream class might be reliant on a Windows platform; if we could make the /telnet option cross-platform that be awesome. I have used C# .NET telnet clients such PIEBALDconsults TelnetSocket wrapper and integrating it with a C# .NET web application hosted inside our corporate network. It's useful as the more good examples you have of telnet interactions the better you understand the protocol. I know Telnet is an insecure protocol that uses plaintext but we use Telnet sessions all the time inside our network, so security isn't a concern here as it is no different from other telnet traffic.

@nikitaeverywhere
Copy link
Member

nikitaeverywhere commented May 5, 2017

Thank you for your code.

we will be moving to Cache 2017.1 in the next few months

Do you mean that old telnet server? Hmm, than I see doing this is not so perspective. Maybe let's just add this little utility to work with remote sessions in WebTerminal? I will try to think, probably there's not so much to do in code to enable autocomplete for telnet sessions.

Anyone's other comments on /telnet feature in WebTerminal are appreciated. Thanks.

@eduard93
Copy link
Contributor

eduard93 commented May 9, 2017

Have you seen RCE project?
It's a Remote Code Execution for InterSystems Caché.
Can execute code on:

  • Windows -> Windows, Linux
  • Linux -> Linux

@eduard93
Copy link
Contributor

eduard93 commented May 9, 2017

@swils024 I can also send you an article on the topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants