Re: SSHD Custom ShellFactory

2020-10-29 Thread Oskar Z
Looks like I was able to get it to work JLine following the example outlined 
here:

https://www.google.com/amp/s/blog.javaforge.net/post/68495259926/embedded-ssh-daemon-and-remote-shell-for-java-applicatio/amp
 


Thanks for the help!

> On Oct 28, 2020, at 5:02 PM, Oskar Z  wrote:
> 
> Thank you!
> 
> Are there examples of JLine and using in App code?
> 
> Regards,
> Oskar
> 
>> On Oct 28, 2020, at 3:48 PM, Guillaume Nodet  wrote:
>> 
>> Jline can be used to create a fully functional shell and integrate it into
>> JLine.
>> The issue Lyor pointed is when you want to integrate SSHD with a native
>> shell such as bash instead of using a java shell.  This cause issues which
>> haven't been fully resolved yet.
>> If you want to check using a java shell, you can simply run the jline demo
>>> [build jline locally]
>>> cd demo
>>> ././jline-gogo.sh ssh jansi
>>> sshd start
>> 
>> It will create an sshd server that you can connect to with any ssh client.
>> You'll end up in the jline-gogo shell with smart completion, history, etc...
>> 
>> Cheers,
>> Guillaume
>> 
>> Le mer. 28 oct. 2020 à 17:44, Lyor Goldstein  a
>> écrit :
>> 
> I found this project called JLine, and help can be provided there for
>>> SSHD and console/terminals?
>>> 
>>> See https://issues.apache.org/jira/browse/SSHD-1029 - turns out it's not
>>> that simple even with JLine
>>> 
>> 
>> 
>> -- 
>> 
>> Guillaume Nodet
> 
> 
> -
> To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org
> For additional commands, e-mail: dev-h...@mina.apache.org
> 



Re: SSHD Custom ShellFactory

2020-10-28 Thread Oskar Z
Thank you!

Are there examples of JLine and using in App code?

Regards,
Oskar

> On Oct 28, 2020, at 3:48 PM, Guillaume Nodet  wrote:
> 
> Jline can be used to create a fully functional shell and integrate it into
> JLine.
> The issue Lyor pointed is when you want to integrate SSHD with a native
> shell such as bash instead of using a java shell.  This cause issues which
> haven't been fully resolved yet.
> If you want to check using a java shell, you can simply run the jline demo
>> [build jline locally]
>> cd demo
>> ././jline-gogo.sh ssh jansi
>> sshd start
> 
> It will create an sshd server that you can connect to with any ssh client.
> You'll end up in the jline-gogo shell with smart completion, history, etc...
> 
> Cheers,
> Guillaume
> 
> Le mer. 28 oct. 2020 à 17:44, Lyor Goldstein  a
> écrit :
> 
 I found this project called JLine, and help can be provided there for
>> SSHD and console/terminals?
>> 
>> See https://issues.apache.org/jira/browse/SSHD-1029 - turns out it's not
>> that simple even with JLine
>> 
> 
> 
> -- 
> 
> Guillaume Nodet


-
To unsubscribe, e-mail: users-unsubscr...@mina.apache.org
For additional commands, e-mail: users-h...@mina.apache.org



Re: SSHD Custom ShellFactory

2020-10-28 Thread Oskar Z
I found this project called JLine, and help can be provided there for SSHD and 
console/terminals?

> On Oct 28, 2020, at 12:23 PM, Lyor Goldstein  wrote:
> 
>>> But now the issue is how do I get the ECHO to work! When I type my
> command, I need to see what I type, as soon as I type a character, just
> like in any normal terminal. I understand how the ProcessShell works, as
> the process has Input, Output and Error (which is used as Echo stream)
> streams,
> 
>  Looks like you have made significant progress.
> 
>>> but in this case I have Input and Output only, and don’t have a Process.
>  Actually SSH provides input, output AND error streams - see the Command
> interface (from which Shell is derived).
> 
>>> What happens now, is as I type I don’t see anything, then I press
> ‘Enter’ and it gets read in and gets executed correctly, so what I have to
> do is type it up in Text editor and then copy/paste the command into the
> Terminal.
>>> Please help!
> 
> I wish we had the time we need to really resolve this issue. All I can
> suggest - as frustrating as it may be - keep trying and debugging the code.
> Hint: try looking at InvertedShell and InvertedShellWrapper - perhaps they
> have what you need...


-
To unsubscribe, e-mail: users-unsubscr...@mina.apache.org
For additional commands, e-mail: users-h...@mina.apache.org



Re: SSHD Custom ShellFactory

2020-10-27 Thread Oskar Z
I have made some more progress, not sure if this will work for all cases, but 
it works on MacOS and Linux.

I had to extend TtyFilterOutputStream with my own class / methods to handleLF 
and handleCR.

So the output looks fine:

READY

STARTRECORD
Status
---
Running: 1 Sessions
ENDRECORD

READY

STARTRECORD
Key, Name, OrgNodeID, TypeName, OperatorActions, Links
---
Types,Types,TypeOrgNode#9900#Types#Types,Types,,Link Types: XYZ
ENDRECORD

But now the issue is how do I get the ECHO to work! When I type my command, I 
need to see what I type, as soon as I type a character, just like in any normal 
terminal. I understand how the ProcessShell works, as the process has Input, 
Output and Error (which is used as Echo stream) streams, but in this case I 
have Input and Output only, and don’t have a Process. What happens now, is as I 
type I don’t see anything, then I press ‘Enter’ and it gets read in and gets 
executed correctly, so what I have to do is type it up in Text editor and then 
copy/paste the command into the Terminal.

Please help!

Thank you,
Oskar

> On Oct 27, 2020, at 1:15 PM, Oskar Z  wrote:
> 
> Thanks! So looks like the issue is still unresolved.
> 
> I think this is very critical.
> 
> So I have made some progress, but now everything is written to the same line, 
> no matter what.
> 
> I’m using the following PTY options:
> 
> PtyMode.ONLCR
> PtyMode.OCRNL
> PtyMode.ONOCR
> PtyMode.ECHO
> PtyMode.INLCR
> PtyMode.ICRNL
> 
> And using the following constructors:
> 
> CmdLineServiceHandler(CLIShellFactory.CLIShell shell) throws IOException {
>   super("Command line server handler");
>   //PtyMode.ONLCR, PtyMode.OCRNL, PtyMode.ONLRET, PtyMode.ONOCR
>   //PtyMode.ECHO, PtyMode.INLCR, PtyMode.ICRNL, PtyMode.IGNCR
>   Set mode_options = 
> Collections.unmodifiableSet(EnumSet.of(PtyMode.ONLCR, PtyMode.OCRNL, 
> PtyMode.ONOCR, PtyMode.ECHO, PtyMode.INLCR, PtyMode.ICRNL));
>   TtyFilterInputStream echoStream = new 
> TtyFilterInputStream(shell.getInputStream(), mode_options);
>   input = new BufferedReader(new InputStreamReader(new 
> TtyFilterInputStream(shell.getInputStream(), mode_options)));
>   output = new PrintStream(new 
> TtyFilterOutputStream(shell.getOutputStream(), echoStream, mode_options), 
> true);
>   //input = new BufferedReader(new 
> InputStreamReader(shell.getInputStream()));
>   //output = new PrintStream(shell.getOutputStream());
> 
> Any idea on correct PTY options? I tried InteractiveProcessShellFactory.java 
> 
>  and it seems to work, but not with my Custom Shell and Command.
> 
> Thanks,
> Oskar
> 
>> On Oct 27, 2020, at 12:53 PM, Lyor Goldstein > > wrote:
>> 
 I would really appreciate someone who has experience with this to give
>> me some guidance. I have searched the web and cannot seem to find anything.
>> 
 Hope someone can help…
>> 
>> This is an oldie but goodie - we have made several attempts in the past
>> (see SSHD-897 SSHD-1029) but we always come up short since there seem to be
>> many behavior variations on the sent escape sequence and echo options...
> 



Re: SSHD Custom ShellFactory

2020-10-26 Thread Oskar Z
Let me see if I could put some more details around this.

So I have two problems. I think they are around PtyModes.

1. The carriage return is not honored no matter what I options I use. I’m just 
simply trying to get it to work in Mac/Linux environment. Unless I specifically 
add \r\n it does not want to work.
2. When I type in a regular SSH session, I see characters as I type them. In 
Apache SSHD, I don’t see my input, but once I enter, it does send it over for 
execution.

So I have created a custom ShellFactory and Command, that will execute Java 
code on the input provided in the shell.

  private class CLIShellFactory implements ShellFactory  {

public Command createShell(ChannelSession channelSession) {
  return new CLIShell();
}

private class CLIShell implements Command, Runnable {

At first I was using regular InputStream and OutpuStream, but then I saw some 
code using TtyFilterInputStream and TtyFilterOutputStream, so I tried to 
convert my code to use these, and provide PtyModes. But I’m still having issues 
with it. Also, the TtyFilterOutputStream requires the following for echo to 
work:

public TtyFilterOutputStream(OutputStream out, TtyFilterInputStream echo, 
Collection ttyOptions) {

If I use TtyFilterInputStream echo and set my InputStream, I will get into an 
infinite loop! So I have set it to null, and removed PtyMode.ECHO, but I do 
need it.

Any light on what I’m doing wrong here?

Is there a ShellFactory where I can just override one method and execute my 
custom Java code which will enable me to have proper new lines and carriage 
returns and echo enabled?

I would really appreciate someone who has experience with this to give me some 
guidance. I have searched the web and cannot seem to find anything.

I did find this that I think has similar problem, which was old thread:

http://apache-mina.10907.n7.nabble.com/sshd-clients-and-echo-td28501.html 


Hope someone can help…

Regards,
Oskar

> On Oct 21, 2020, at 7:13 PM, Oskar Z  wrote:
> 
> 
> 
>> On Oct 21, 2020, at 3:40 PM, Oskar Z > > wrote:
>> 
>> Hello,
>> 
>> Hope someone can help or point in the right direction.
>> 
>> I have created my custom ShellFactory and Command, and commands get executed 
>> fine in-app, but the problem is formatting of output, and I cannot see what 
>> I type until I hit “enter” and output is not seen until I use out.flush().
>> 
>> It seems to have some tabs…..
>> 
>> NodeID, TypeName, OperatorActions, Links
>> ---
>>
>> Types,Types,com.micromuse.response.common.TypeOrgNodeIdentifier#com.micromuse.response.dblayer.TypeOrgNode#9900#Types#Types,Types,
>>  
>>  
>>,Link Types: 
>>  
>>  
>> ENDRECORD
>> 
>> READY
>>  Execution Failed. Check impactserver.log for details.
>>   READY
>>  
>>  
>> READY
>>  
>> READY
>> 
>> Thanks,
>> Oskar
>> 
> 



Re: SSHD Custom ShellFactory

2020-10-22 Thread Oskar Z
Does anyone respond to these mailing lists?

Can anyone help me with this?


> On Oct 21, 2020, at 7:13 PM, Oskar Z  wrote:
> 
> 
> 
>> On Oct 21, 2020, at 3:40 PM, Oskar Z > > wrote:
>> 
>> Hello,
>> 
>> Hope someone can help or point in the right direction.
>> 
>> I have created my custom ShellFactory and Command, and commands get executed 
>> fine in-app, but the problem is formatting of output, and I cannot see what 
>> I type until I hit “enter” and output is not seen until I use out.flush().
>> 
>> It seems to have some tabs…..
>> 
>> NodeID, TypeName, OperatorActions, Links
>> ---
>>
>> Types,Types,com.micromuse.response.common.TypeOrgNodeIdentifier#com.micromuse.response.dblayer.TypeOrgNode#9900#Types#Types,Types,
>>  
>>  
>>,Link Types: 
>>  
>>  
>> ENDRECORD
>> 
>> READY
>>  Execution Failed. Check impactserver.log for details.
>>   READY
>>  
>>  
>> READY
>>  
>> READY
>> 
>> Thanks,
>> Oskar
>> 
>