#!/bin/sh # http://neil.franklin.ch/Projects/webcam - webcam for SGI Indy # author Neil Franklin, last modification 2000.09.14 # this script only works on an SGI Indy with vidtomen and imgcopy # OK, one can do this by Apache+CGI, but where is the fun in doing that? ## inetd provides us with: waiting on port, forking, IO socket, change user ## parse HTTP request read command # strip the \r that HTTP allows/demands in input stream # no ";" evaluation after "$" evaluation, so no security hole command=`echo $command | tr -d "\r"` # split HTTP request method=`echo $command | cut -f 1 -d " "` url=`echo $command | cut -f 2 -d " "` http_version=`echo $command | cut -f 3 -d " "` # if HTTP/1.* is being used, digest the request header fields, do nothing if [ "$http_version" != "" ] ; then option="dummy" while [ "$option" != "" ] ; do read option option=`echo $option | tr -d "\r"` done fi ## decide what to do # what method does the user want, we only implement HEAD and GET if [ "$method" != "HEAD" -a "$method" != "GET" ] ; then echo "HTTP/1.0 501 Not Implemented" echo echo "" echo " " echo " 501 Method Not Implemented" echo " " echo " " echo "

Method Not Implemented

" echo " Method" $method "does not fit list: HEAD GET" echo " " echo "" exit 1 fi ## generate HTTP response - header # we are simple HTTP 1.0, no 1.1 fancies are supported or expected echo "HTTP/1.0 200 OK" # date -u for GMT, to fit RFC 2086 (HTTP/1.1) format echo "Date:" `date -u "+%a, %d %b %Y %X GMT"` echo "Server: http://neil.franklin.ch/Projects/squid_log, yes, sh script!" # last mod = date (we generate output now), file date is unreliable anyway echo "Last-Modified:" `date -u "+%a, %d %b %Y %X GMT` echo "Connection: close" echo "Content-type: image/gif" echo "Content-Language: en" echo # method HEAD does not deliver any data, so exit now if [ "$method" = "HEAD" ] ; then exit 0 fi ## generate HTTP response - HTML output /usr/sbin/vidtomem -f /tmp/webcam-$$ -c 1 2 > /dev/null 2>&1 /usr/sbin/imgcopy -n 10 /tmp/webcam-$$-00000.rgb /tmp/webcam-$$.gif > /dev/null 2>&1 /bin/cat /tmp/webcam-$$.gif /bin/rm /tmp/webcam-$$-00000.rgb /bin/rm /tmp/webcam-$$.gif exit