#!/usr/bin/perl -w # # copyright 2006, gr@eclipsed.net # no warranty expressed or implied, use/modify/redistribute as you like use strict; use CGI qw/:standard/;; use Socket; my $debug = 0; my $server = 'change.this.to.your.webcam'; my $port = 80; my $proto = getprotobyname('tcp'); my $iaddr = inet_aton($server); my $paddr = sockaddr_in($port, $iaddr); print STDERR "query: $ENV{QUERY_STRING}\n" if $debug; my $format; # It's a bad idea to do browser-detect here, since it changes # frequently and, for instance, Opera, which supports MJPEG, often # pretends to be MSIE to get through stupid browser detects... but # we'd still want to give them the MJPEG. So do that in your [D]HTML. # if ((param('format') eq 'mjpg') && !($ENV{HTTP_USER_AGENT} =~ m/MSIE/)) { # $format = "mjpg/video"; # } else { # $format = "jpg/image"; # } if (defined(param('format')) && param('format') eq 'mjpg') { $format = "mjpg/video"; } else { $format = "jpg/image"; } my $resolution = param('resolution') if defined(param('resolution')); $resolution = '320x240' unless (defined($resolution) && ($resolution =~ m/[0-9x]+/)); print STDERR "format: $format\n" if $debug; print STDERR "resolution: $resolution\n" if $debug; my $path = "/axis-cgi/${format}.cgi?resolution=${resolution}"; socket(AXISCAM, PF_INET, SOCK_STREAM, $proto) or die "socket: $!"; connect(AXISCAM, $paddr) or die "connect: $!"; print STDERR "connected\n" if $debug; print AXISCAM "GET $path\n"; print STDERR "GET sent\n" if $debug; binmode AXISCAM; my $rc = 0; while () { if (m,^HTTP/1,) { $rc = (split(' ', $_))[1]; last unless ($rc == 200); } else { print $_; } print STDERR "loop\n" if ($debug > 1); } print STDERR "image received, closing out\n" if $debug; close AXISCAM;