adidasrta
08-04-2004, 11:47 PM
i am looking to get a a php page to connect to a remote linux box's ssh on a back end. Ex. if a person hits execute. it will login to the remote machine through ssh, and execute it. And they'll never even know it is linux.
is php the right thing to do?
and can you lead me to any direction into fulfilling this?
SEATi
08-04-2004, 11:50 PM
You can do it using PHP, but for as long as I know there isn't a PHP class that will connect to a SSH server due to key exchange issues. However you can use expect, a wonderful scripting language, and have the php script execute the expect script passing the right arguments so that it logs into the desired box using the desired login and password.
fraudgate
08-04-2004, 11:59 PM
If you want to use PHP to do SSH it may be possible. You can look at PHP's system function to call system commands and do it that way. However, your control will be fairly limited this way.
adidasrta
08-05-2004, 12:01 AM
well the control is basically to execute scripts such as ./start and ./stop
SEATi
08-05-2004, 12:02 AM
the system() function will only call the ssh client, but won't be able to send any commands to it.
Expect on the other side "sits" and "waits" for the server response in order to send a new string.
Let's say that you instruct your expect script to wait for "ssword:" (commonly used for the password prompt) and then you tell it to send "yourpassword" and a return char (\r\n), after that to wait for "$" (the prompt) and send "ls" and another return (\r\n), that way you could get a remote directory listing using php and expect.
adidasrta
08-05-2004, 12:03 AM
do you have a site that has more information about expect scripting?
adidasrta
08-05-2004, 07:44 PM
and what about windows solutions to this?
SEATi
08-06-2004, 12:28 AM
http://expect.nist.gov/
That will explain everything you need to know about the expect scripting language.
In windows it can be done by using some VB, however I guess you would need to buy a commercial ssh client.