Home » Technology

HOWTO: Track your mac

Written By: Tom on January 23, 2010 20 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!

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 © 2011 Tom Pohl, All rights reserved.