July 15th, 2013, 11:07 AM
Connect to SSH
There is a remote ssh server that I need to connect to.
When I connect through putty, it displays a menu. I enter a selection. Then it asks for one piece of data which I enter then I hit okay. At that point I am done.
I am looking for some solution that will allow me to do this from webpage. User enters data, clicks okay and then webpage opens the SSH connection, selects menu option, enters data and then hits OK.
I was working with phpseclib and it does connect, but it doesn't seem to recognized the menu that comes up (just gives me the command line).
It doesn't have to be PHP based, I am just looking for something that will allow me to do the process described.
July 15th, 2013, 01:05 PM
Show the code you have which works with phpseclib.
In general this sort of thing isn't really PHP's domain, but it's possible. Are you running on a *nux server? You can use fopen to actually open a link directly to the command line of the current server and issue commands and read the output.
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question
or you're a Help Vampire.
Trying to argue intelligently? Please read this.
July 15th, 2013, 01:19 PM
I'm a little confused about this "menu" you're talking about. There's no menu returned by the SSH connection itself. Maybe Putty puts one up for some reason, but that would be something it's doing on its own.
Originally Posted by jerim79
So what's the end goal you're actually trying to achieve? What operation(s) is the web user supposed to kick off over the SSH connection?
From what it sounds like so far you could provide them a menu on the webpage to choose an item from, let them enter any other information, then submit a form. Then on the backend you open up the SSH connection and perform whatever action their input is for.
July 15th, 2013, 01:29 PM
The menu is really just an application that is set to startup automatically on login. Nothing really to do with Putty.
The end goal is to open an ssh connection to a server, login in, select an item from the application's menu (the application that automatically starts up on login), it will ask for piece of data which the script will enter and then the connection is over.
July 15th, 2013, 02:13 PM
Well, if your script can't predict what the menu options and the data they'll request will be, then you're probably looking at a 2-3 stage user input process
Originally Posted by jerim79
1. Ask user for username/password (submit)
2. SSH to the server and read the menu options
3. Ask user for menu option (submit)
4. SSH to the server, input menu option, read data inquiry
5. Ask user for additional data (submit)
6. SSH to the server, input menu option, input additional data
7. Give user success response
If you always use the same username/password you won't need #1.
If the menu never changes then you should be able to skip #2-#5 and ask them for the option and data in one form.
Or if your PHP is running on the same server that's being SSH'd to, just connive a way for PHP to do whatever that SSH menu does behind-the-scenes, and take SSH out of the picture altogether.
July 15th, 2013, 04:35 PM
Thanks for the reply. I have the page built. I was just looking for some specifics on connecting to SSH.
Originally Posted by dmittner
July 15th, 2013, 04:42 PM
I may have confused the situation. Let's start over.
I am looking for something in PHP or any other language that will server as a terminal emulator. Something that connects to a remote SSH server and allows me to interact with it.
July 15th, 2013, 05:32 PM
Been working on this for a while, not sure if it works 100% yet, but feel free to play around with the code:
Last edited by hosttheweb; July 15th, 2013 at 05:39 PM.
July 16th, 2013, 01:18 AM
Going back to what ManiacDan said, the next step is to post the code that you tried but couldn't get to work.
phpseclib has an example of an interactive shell, which is essentially what you would need to do in this case: http://phpseclib.sourceforge.net/ssh...ml#interactive