Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Web-based Spotlight search of remote computer.

Web-based Spotlight search of remote computer.
Thread Tools
Posting Junkie
Join Date: Jun 2001
Location: Washington DC
Status: Offline
Reply With Quote
Sep 9, 2005, 05:06 PM
 
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
Reply With Quote
Sep 11, 2005, 06:46 AM
 
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
Reply With Quote
Sep 12, 2005, 11:26 AM
 
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.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:35 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2