 |
 |
Web-based Spotlight search of remote computer.
|
 |
|
 |
|
Posting Junkie
Join Date: Jun 2001
Location: Washington DC
Status:
Offline
|
|
Fun, eh?
So here's what I want to do. I want to have a web page running on a server within my network that has a search form on it. When you put a search term into the form it calls a script which sends a spotlight query out to some other computer(s) on the network and gets the results back to be displayed on the web page.
Really, this should be entirely possible.
I can easily run a spotlight search on a remote computer by combing SSH and mdfind in the terminal. If I have an account called 'foo' on server 'bar' I can search for puppies in foo's area of bar by entering the command 'ssh foo@bar mdfind puppies'. If I have SSH set up right, which is easy enough to do, it won't even prompt me for a password.
So in theory, if my web search form ran a PHP script that did something like '$result = exec('ssh foo@bar mdfind puppies');' $result would end up looking something like this:
Code:
/Users/foo/IT Stuff/Software/333/xml-schema/xml-schemas/examples/tests/AttributeExamples.xml
/Users/fooo/Movies/Past Projects/Airgo/Airgo video folder/CBSNews.com_ Print This Story.pdf
However, when I write the web page and script it doesn't work. $result always comes up empty. So to test, I changed it so that the PHP script just ran a Bash script that did this 'ssh foo@bar mdfind puppies > result.txt'. If I run the script from the terminal it works just fine. If I run the script from the web page, nothing happens. result.txt is not created and I get no results.
I assume this has something to do with the permissions of the www user, but I don't really know that much about apache or how to go about working with this sort of thing. Does anyone have any ideas of what I could do to make this work?
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status:
Offline
|
|
Originally Posted by nonhuman
Fun, eh?
So here's what I want to do. I want to have a web page running on a server within my network that has a search form on it. When you put a search term into the form it calls a script which sends a spotlight query out to some other computer(s) on the network and gets the results back to be displayed on the web page.
Really, this should be entirely possible.
I can easily run a spotlight search on a remote computer by combing SSH and mdfind in the terminal. If I have an account called 'foo' on server 'bar' I can search for puppies in foo's area of bar by entering the command 'ssh foo@bar mdfind puppies'. If I have SSH set up right, which is easy enough to do, it won't even prompt me for a password.
So in theory, if my web search form ran a PHP script that did something like '$result = exec('ssh foo@bar mdfind puppies');' $result would end up looking something like this:
Code:
/Users/foo/IT Stuff/Software/333/xml-schema/xml-schemas/examples/tests/AttributeExamples.xml
/Users/fooo/Movies/Past Projects/Airgo/Airgo video folder/CBSNews.com_ Print This Story.pdf
However, when I write the web page and script it doesn't work. $result always comes up empty. So to test, I changed it so that the PHP script just ran a Bash script that did this 'ssh foo@bar mdfind puppies > result.txt'. If I run the script from the terminal it works just fine. If I run the script from the web page, nothing happens. result.txt is not created and I get no results.
I assume this has something to do with the permissions of the www user, but I don't really know that much about apache or how to go about working with this sort of thing. Does anyone have any ideas of what I could do to make this work?
Hmmm. It's a tricky one, as the environment from which you are calling the Bash script is different to the PHP Apache module. I'm no expert in SSH, but from my limited logic, I'd guess that the fact that the 'www' is not a 'real' user (i.e. has no home folder and therefore no .ssh folder to store known_hosts and identity certificates) that this may be the reason that it's falling over. Try setting up PHP on the Mac Box you're currently working off and see if the same exec command works without SSH.
If that turns out to be the culprit, then you may wish to google for some PHP-native solutions for SSHing to the box, rather than relying on exec. You may get more reliable results. I'm sure I saw a PHP script to achieve just that at www.phpclasses.org
Good luck
|
|
Computer thez nohhh...
|
| |
|
|
|
 |
|
 |
|
Posting Junkie
Join Date: Jun 2001
Location: Washington DC
Status:
Offline
|
|
Yeah, that's about what I was thinking as well. I'll check out phpclasses.org and see if I can find that script. Thanks.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|