#!/bin/sh

# This code is in the public domain.  It's not worth copyrighting.

# sample webcam CGI

PATH_TO_WEBCAM=/usr/local/bin/webcam
WEBCAM_OPTIONS="-r"

# don't mess with anything below here unless you know what you're doing.

if [ "$REQUEST_METHOD" = "HEAD" ]; then
  echo HTTP/1.1 200 OK
  echo Date: `date`
  echo Server: $SERVER_SOFTWARE
  echo Connection: close
  echo Content-type: multipart/x-mixed-replace
  echo
elif [ "$REQUEST_METHOD" = "GET" ]; then
  echo HTTP/1.1 200 OK
  echo Date: `date`
  echo Server: $SERVER_SOFTWARE
  echo Connection: close
  exec $PATH_TO_WEBCAM $WEBCAM_OPTIONS
else
cat <<EOF
HTTP/1.1 405 Method Not Allowed
Date: `date`
Server: $SERVER_SOFTWARE
Allow: GET, HEAD
Connection: close
Content-type: text/html

<HTML><HEAD>
<TITLE>405 Method Not Allowed</TITLE>
</HEAD><BODY>
<H1>Method Not Allowed</H1>
The requested method $REQUEST_METHOD is not allowed for the URL $REQUEST_URI.<P>
</BODY></HTML>
EOF
fi
