Use your MacBook camera to see who's using your laptop

  MacBook ProSoftware DevelopmentSoftware Development

Dylan O'Donnel published a simple method to capture a user's picture using the MacBook's built-in camera when a user logs in. An excellent idea! I followed the instructions on his web page Here, then decided to customize it a bit.

I had a couple of issues with Dylan's initial implementation.

  • It uses ~/.netrc to create an FTP session to upload files; I wanted to use curl instead, as it is much more capable.
  • I wanted to append the user's IP address to the end of the file to aid in locating potential thiefs.
  • The script contains username and password, in plaintext, for the FTP server upload. if a thief got my laptop, they would have my hosting information!
  • My home directory uses FileVault, so it is inaccessible when the machine first wakes up. The script needs to work in a public folder.


So I made some changes to the capture script. You can download it Here.



The Script

The script contains the following modifications:

  • Simple configuration at top of script. no need to hunt for variables to change.
  • Supports FTP or Form Post methods for uploading picture.
  • Uses curl for FTP transfer - no more .netrc tinkering.
  • Places all files in /tmp rather than user directory.
  • Easily specify file format for pictures in one configuration entry.
  • Appends user's IP address to end of image filename.



Installation Instructions

Installation instructions are similar to Dylan's.

  1. Download capture.sh and copy to /usr/bin.
  2. Download iSightCapture and copy to /bin.
  3. Downlad and install SleepWatcher.
  4. Install bolGallery on your website.
  5. Download Easy PHP Upload on your website (optional, see instructions below)



Configuring SleepWatcher

I wanted the picture to be taken regardless of whether or not the user had a FileVault home directory. I have disabled auto-login and require a password when the machine wakes up; ideally, the picture would be taken when the login window appears. In order for this to happen, you need to modify the wakeup script. Open /etc/rc.wakeup in your favorite editor (eg, sudo emacs /etc/rc.wakeup). Just below the line that reads unset name shell home, add the line /usr/bin/capture.sh > /dev/null 2>&1. That's it!



Configuring the script

You will need to edit the capture script for your environment. Open /usr/bin/capture.sh in your favorite editor. At the top of this file you will see a section with variables to define; these are pretty well documented in the file. You need to decide whether you want to upload these images with FTP or with an HTTP form post to your website. I prefer the HTTP post method, as it does not require that the script file has your user name and password in it.

If you use FORM as the upload method, you need to set the following variables:

  • FORMURL This should be the URL of your upload script.
  • FORMSUBMITFIELD This should be the name of the HTTP submit button on your upload form.
  • FORMSUBMITVALUE Value to be submitted for the HTTP submit parameter

If you use FTP as the upload method, you need to set the following variables:

  • HOST Name of host to upload to
  • HOSTDIR Directory on host to upload file to
  • FTPUSER User name for FTP login
  • FTPPASSWORD Password for FTP login



Configuring Easy PHP Upload

Easy PHP Upload is a free PHP class for uploading files to your web site. It is very easy to set up. After downloading the distribution from the snippet site, open the resulting folder.

  1. First, you need to create the folder /classes/upload in your web host directory.
  2. Next, upload the file upload_class.php to this folder.
  3. You will then need to edit the file upload_example.php:
    • Change the value of upload_dir to the directory where the image files should be uploaded.
    • Add .jpg to the list of extensions in the extensionsvariable
    • Change the value of rename_file to false - we want to specify the filename in the script.