Skip to first unread message

Andre Castro

unread,
May 11, 2019, 10:32:27 AM5/11/19
to mitappinv...@googlegroups.com

Android client SSH extension for MIT Application Inventor 2 

The following attached file contains an SSH Client extension Name:  ssh_hkj_icon.png
Views: 35
Size:  271 Bytes which I made for my own use, but it may also be useful for users of the MIT Application Inventor 2 (AI2) community, or even to the AppyBuilder community (code intrinsically compatible, but not tested). This is just the current stage of development, but if you want to get updated revisions, you can get the last released source code (.java) and corresponding binary (.aix) at github repository. 

Click image for larger version. 

Name:	Component.png 
Views:	11 
Size:	75.7 KB 
ID:	152955

It is being shared "as-is", which means that:

  • No implicit or expressed warranty provided - (leastwise worked for me),
  • No functional optimization performed, no refactoring made,
  • Not intended to be an "state-of-the-art" work, but rather a quick solution to a big problem,
  • Not tested in all devices, OS builds, etc... (tested on Android 4.2 and 8.1, both Samsung mobiles)
  • Attempted to follow good coding/style formatting practices, but not strictly committed to this.

This is an extension that sends simple SSH commands, and captures the returned "string" sentence. All commands execution have to be as quick as possible, once the AsynchUtil.runAsynchronously class is being used to instantiate the thread which embed the whole SSH execution (send/receive), and it is well known that this thread locks UI execution, turning the application unresponsive to the user.

It is important to be aware that whenever instaling a new revision of the .apk, DO NOT EVER clean cache nor clean data from mobile for this application, otherwise the security keys (public/private, whatever) will be lost and you'll be not able to connect to the known hosts anymore, and you'll have to recover the keys manually, a boring task.

Click image for larger version. 

Name:	Screen.png 
Views:	1 
Size:	12.1 KB 
ID:	152991

In the attached demo application, the text field displays only the last line, and for this reason, if you want to see the whole sentence got from host, you can make simple changes in the code in order to merge incoming messages subsequently.

Click image for larger version. 

Name:	TestApp.png 
Views:	2 
Size:	98.5 KB 
ID:	152992

It is worthy to mention that due to the oftentimes changes in the security policies of the protocols, it would not be improbable that the attached .aix file would not work in the future, therefore this extension should be re-compiled (with the Apache ANT builder), but now adding a more recent release of JSch at the LIB folder (current revision: jsch-0.1.54.jar).

Another point to remark is that, althought including the source code of the JSch library in the project, the correspondent compield JAR was necessary just to embed it into the application during build stage, without the need to give external dependencies to the user.

USAGE:
=====

1 ) Fill string variables "SetUser", "SetHost" and "SetPasswords" accordingly, without queotes
2 ) Fill string variable "Command" with the Bash/Shell command to be issued, without queotes (e.g: ls )
3 ) Call the function "SendData"
4 ) Get result either:
4.1 ) ...from within "NewIncomingMessage" event, argument "data" contains current text line, indded the last one.
4.1 ) ...by reading "GetReceivedMessage" variable; be aware that it is assyncronously updated (intermediary values are superseded)

Feel free to make changes and give feedback !!!

Client_SSH_AI2_Ext (1).rar

TimAI2

unread,
May 11, 2019, 10:58:13 AM5/11/19
to MIT App Inventor Forum
No aix file attached ?

Andre Castro

unread,
May 11, 2019, 11:41:14 AM5/11/19
to MIT App Inventor Forum
I just appended right now to the above message, thanks for warning, I had previously posted this topic, but the internet connection crashed, and when re-posting I forgot to attach again.

TimAI2

unread,
May 11, 2019, 1:46:54 PM5/11/19
to mitappinv...@googlegroups.com
There is an error in your aia that prevents connection - need to change setpassword to setcommand for the textboxcommand.txt



How to send commands that don't return std out?

For example cd

I am unable to change directory ?

Also, is it possible to just be connected without having to send a command ?

What does "Exit from infinite loop - recieve" mean ? I seem to get that message a lot ...

How to gracefully exit a ssh session ?

Andre Castro

unread,
May 11, 2019, 2:19:50 PM5/11/19
to mitappinv...@googlegroups.com
need to change setpassword to setcommand for the textboxcommand.txt
 
Thanks for remarking, I`ll fix it soon. 
I made a refactoring at the App (.aia) without performing tests again.
Anyay, woth to note that this was an issue at the demo application, not the extension itself. 

 I am unable to change directory ?

As pointed out above, this is an implementation of the JSch library with the "exec" option, not the "shell" option. The first one is a single-shot implementation of the SSH protocol, whereas the second one ehxibit a shell running forever.

What does "Exit from infinite loop - recieve" mean ? I seem to get that message a lot ..

Ok, I'll remove it, added issue to the git repository. (note anyway that is is just a Debug message, not the Received data)

 How to gracefully exit a ssh session ?

Nice idea, I'll add this option aswell, added issue to the git repository.

Andre Castro

unread,
May 11, 2019, 9:42:32 PM5/11/19
to mitappinv...@googlegroups.com
Just to share: 

There is an updated revision at the above mentioned link, github.
All (most) the above issues were considered and fixed.

( Thanks TimAI2 for your feedback )
Reply all
Reply to author
Forward
0 new messages