Thread: Connect to SSH

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    15
    Rep Power
    0

    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.
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,846
    Rep Power
    6351
    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.
  4. #3
  5. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    Originally Posted by jerim79
    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.
    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.

    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.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    15
    Rep Power
    0
    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.
  8. #5
  9. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    Originally Posted by jerim79
    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.
    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

    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.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    15
    Rep Power
    0
    Originally Posted by dmittner
    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

    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.
    Thanks for the reply. I have the page built. I was just looking for some specifics on connecting to SSH.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    15
    Rep Power
    0
    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.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    83
    Rep Power
    3
    jerim79,

    Been working on this for a while, not sure if it works 100% yet, but feel free to play around with the code:

    http://pastie.org/private/lpdgiucsceyieusgtn8fw
    Last edited by hosttheweb; July 15th, 2013 at 04:39 PM.
  16. #9
  17. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    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
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo