Home » Technology

HOWTO: Track your mac

Written By: Tom on January 23, 2010 6 Comments

A couple years ago, after I purchased a mac laptop with a built-in camera, I set it up to take a picture every time it booted/woke up and upload it to one of my web servers if internet access was available.  I called it my poor man’s laptop lojack. Of course with all good things, Apple came out with an operating system update that disabled access to the camera from any user (even root) except for the locally logged in user. I suppose that is a good thing except when you actually *want* to be able to do what I was doing. Once it broke, I hadn’t bothered to figure out a way around it until the other night when I was pissed off enough to find a way!

Luckily, a couple weeks ago, I learned about launchctl. It is now the primary way in OSX to launch system daemons instead of init scripts or xinetd. It turns out, using launchctl, as root, you can execute a program in another context using its bsexec subcommand! If you use the loginwindow process id’s context you’d like to run your program in, it will now run just as if you were physically sitting at the keyboard.  The command:

isightcapture image.jpg

which would before fail if you ssh’d into a remote machine now becomes:

export PID=`ps auxww |grep loginwindow |grep -v grep |awk ‘{print $2}’`
launchctl bsexec $PID isightcapture image.jpg

Bamo! Now you’re breakin’ the law in style!

So, since I’ve got my crappy little image uploader working once again, I thought I’d share it with the rest of the world. I’m using sleepwatcher, isightcapture, and some other craziness that I hacked together to overlay some good information on a picture from your webcam and upload it to a website of your choice!

If you know what you’re doing, you should be able to follow my instructions just fine, if you don’t know what you’re doing, you might possibly blow up your mac and kill a kitten.  You have been warned!

First, download the following file (I’m going to assume it will download into your Downloads folder):

http://tompohl.com/files/locateme.tgz

Create a directory on your web server to host the supporting scripts and uploaded images for example:

mkdir /var/www/html/locateme
Create a password file and user (myuser in this example) that will be used
mkdir /var/www/etc
htpasswd -c /var/www/etc/locateme.passwd myuser
If you’d like to add more users, simply run htpasswd without the -c option:
htpasswd /var/www/etc/locateme.passwd anotheruser
In your apache configuration, add a directory declaration that enables password authentication with the password file you created. This would go inside your virtual host declaration.
<Directory “/var/www/html/locateme”>
AuthType Basic
AuthName Private
AuthUserFile /var/www/etc/locateme.passwd
AllowOverride None
Order allow,deny
Allow from all
require valid-user
</Directory>
run:
apachectl configtest
If you get “Syntax OK” feel free to gracefully restart apache:
apachectl graceful
Back on your local computer in Terminal:
cd ~/Downloads
tar -xzvf locateme.tgz
cd locateme
mv .locateme /
Then, copy the contents of locateme/web directory into your /var/www/html/locateme directory on your web server
make the uploads directory writable by your web server (the following would work):
chmod 777 /var/www/html/locateme/uploads
Open the sleepwatcher_2.0.5.dmg and install both “SleepWatcher.pkg” and “SleepWatcher StartupItem.pkg” You then need to modify the /etc/rc.wakeup script
sudo vi /etc/rc.wakeup
Edit line 36 to read from:
su – $user -c “$home/.wakeup”
To:
$home/.wakeup
Then symlink my custom .wakeup script to your home directory
ln -s /.locateme/.wakeup ~/.wakeup
Now, you need to customize the locateme configuration script to match your username, password, and url for your website
vi /.locateme/locateme.conf
Put your mac to sleep, then wake it up and you should see your camera light up and when you visit your website (http://yourwaycoolwebsite.com/locateme) and enter in your username and password, you should see your picture with some good information overlaid in a box in the corner!
Things to note:
  • If your computer doesn’t connect to the network, it will still save your pictures in /.locateme/images/taken and all images successfully sent to the webserver will be moved into /.locateme/images/sent
  • On the webserver, all images will be saved in the directory locateme/username/ with locateme/username/latest.jpg always pointing to the last picture taken.
To give credit where credit is due, here are the sites I originally found the programs that I used:
isightcapture:
http://www.intergalactic.de/pages/iSight.html
sleepwatcher:
http://www.bernhard-baehr.de/
Digg this!Add to del.icio.us!Stumble this!Add to Techorati!Share on Facebook!Seed Newsvine!Reddit!

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

6 Responses to “HOWTO: Track your mac”

  1. Matthew Nuzum says on: 25 January 2010 at 2:44 pm

    Clever trick. There's no gps built into the computer but somehow my phone is able to grab remarkably accurate coordinates using wifi. Maybe tagging the image w/ current location would be a nice enhancement.

    Of course when my wife's phone got stolen I was able to track it's location just fine and yet I still had to buy a new phone. :-)

    • tompohl says on: 25 January 2010 at 2:54 pm

      If you look through my server-side code, you'll see that I make a call out to api.hostip.info to get a rough idea of where the machine is based upon source ip. It is fairly accurate. I was debating about using a service that returned the gps coordinates, but didn't think it would be very accurate because it wasn't taking into consideration BSSIDs of networks physically near by like the iphone or ipod does!

  2. me with SL says on: 1 March 2010 at 5:49 pm

    i cannot get this to work on my SL?

    • tompohl says on: 1 March 2010 at 7:39 pm

      Which part do you think isn't working? Does it take pictures and place them in /.locateme/images (either its send or taken subfolder)? You won't be able to browse to the /.locateme folder directly from Finder since it is a hidden folder, but you can get there by choosing "Go"->"Go to Folder …" from the menu in Finder.

Leave a Reply:

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2010 Tom Pohl, All rights reserved.