Running ssh to a Linux server from IIS/PHP Webapp

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
avvarde
Forum Newbie
Posts: 4
Joined: Wed Jul 22, 2009 8:12 pm

Running ssh to a Linux server from IIS/PHP Webapp

Post by avvarde »

Dear All,

I am developing a php webapp- on IIS 5.1/Win2kR2 that requires to run a couple of commands on a Linux server.
How do i do that? Any Ideas?

Normally, I program in Perl-CGi in Linux environment - So this app is a walk in the park.
All i do is setup ssh keys and grant access to the Apache@webserver.
Even if I would have had to use php on linux it would still be sort of easy - just figure out the syntax.

I was thinking of using the same approach; but i dont know what apps to use on the Windows Webserver?
I usually hate to use it - But i am willing to put a clear text password file and use some form or rlogin to the Linux server.
Are there any php modules available for something like this?
Any pointers would help!!

And Oh, i am not really keen on cygwin!

-Thanks and Regards.
AV
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Running ssh to a Linux server from IIS/PHP Webapp

Post by omniuni »

Hi Avvarde,

IIS. :banghead:

Um... OK, so you could try the ssh EXE bundled with putty or XMing, but I would say that would be finicky at best. It really only works with user interaction.

I would recommend if possible, writing a script on the Linux server that uses some kind of API to return the requested information when you connect to it via something simple like HTTP. You can get through .htaccess restrictions by passing http://username:password@example.com if my memory serves me, and then just call a PHP or whatever script there to execute the commands and get a result. PHP has a rather useful exec() function that you can enable on your Linux server. Have the PHP script just capture the output of the commands and send it back to the requesting script on your IIS server.

Do you think that would work? If not, let me know and I'll get more creative. :)
avvarde
Forum Newbie
Posts: 4
Joined: Wed Jul 22, 2009 8:12 pm

Re: Running ssh to a Linux server from IIS/PHP Webapp

Post by avvarde »

omniuni,
omniuni wrote: IIS. :banghead:
I sooo Agree!!! And In my right mind would NEVER do that.
But, This is one spec i cant change - its driven by some one else!

Yes, I know putty/xming needs user interaction - I use it on my desktop; But since i want it embedded in my webserver, i dont think i can use it.

Well, Your solution is my backup - So Yes it works.
I have made it work a few time with other web technologies.
I had a webpage that was a blackbox - I think it was written in ASP.NET or something; I dont know the details.
But I got the developer to support Query stings on it.
Then in my unix application, which was a command line app, i had
http://example.com/application.aspx?fie ... d3="value3"
And it works for most part.
I have to be careful about the values i pass in - the web technologies converted some characters. I think space was converted to %20.
So i had to format values to reflect that - sometimes by trial and error. I dont know if it was ASP

I will surely let you know what works !

Thanks a lot!!
-- AV
avvarde
Forum Newbie
Posts: 4
Joined: Wed Jul 22, 2009 8:12 pm

Re: Running ssh to a Linux server from IIS/PHP Webapp

Post by avvarde »

Dear Omniuni,
Does this simplify the problem:

I got two servers: Webserver (Windows-IIS/php) and Linux Execution server (I can put an Apache server if its needed)
My php app on the WebServer generates a xml file which will be used by a command executed on the linux server.
What is the best way to configure these two server?

Regards
- av
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Running ssh to a Linux server from IIS/PHP Webapp

Post by omniuni »

http://us.php.net/manual/en/function.header.php

I'd have the scripts work like this:

1. IIS+PHP pings the Linux server with Apache and a partner PHP script using a username:password to unlock the script. Use SSL if possible to increase security.

2. Once triggered, the script calls a different script on the IIS+PHP server, which posts the XML. This XML is then processed, and the script returns true on success, and reports this to the first script on the IIS+PHP server.

Possibly you can simplify this, by posting the XML along with calling the script, but I'm not sure off hand if that's possible. I'm having a script deliver the XML instead of just supplying a URL to an outputted file for security reasons, but if you think it's OK to have the XML publicly accessible for a moment, then you can just use file_get_contents to pull it, and delete it once the script returns success.

Does that help a bit?
Post Reply