#!/usr/local/bin/perl # *********************************************************************** # # * * # # * Copyright (c) 1996-1999 Scott Crevier * # # * All Rights Reserved Worldwide * # # * * # # * This program product material is the property of Scott Crevier. * # # * This program may be used and modified by anyone free of charge, * # # * as long as this copyright notice remains in tact. By using this * # # * code, you agree to indemnify Scott Crevier from any liability * # # * that might arise from its use. * # # * * # # * scott@crevier.org - Scott M. Crevier - www.crevier.org * # # *********************************************************************** # # * smcLive v1.1 05-Apr-1999 * # # * * # # * If you have a live webcam, this script allows you to display a * # # * specific message based on when you last snapped a picture. This * # # * would allow you to tell your visitors if your webcam is currently * # # * live, or if it's been turned off. * # # * * # # * For example, if it's been over 30 minutes since the webcam image * # # * has been updated, then you can display a 'webcam off' message. If * # # * not, then you can display a 'webcam on' message. Both messages as * # # * well as the time interval are configurable below. * # # * * # # * This script can be called as a server-side include like this: * # # * * # # * * # # * * # # * NOTES: * # # * - Most web servers require that the name of your HTML file ends * # # * with ".shtml" in order to use server-side includes. * # # * - Be sure to set the $filename variable to the path of your * # # * image file. * # # * * # # *********************************************************************** # $filename = $ENV{'DOCUMENT_ROOT'} . '/webcam/webcam32.jpg'; $max_age = 30; # minutes # *********************************************************************** # # * Get datestamp on image, and calculate its age (minutes). * # # *********************************************************************** # $now = time; $timestamp = (stat($filename))[9]; $actual_age = int(($now - $timestamp) / 60); # *********************************************************************** # # * Print the message. * # # *********************************************************************** # print "Content-type: text/html", "\n\n"; &checkImage; if ($actual_age < $max_age) { &imageIsLive; } else { &imageNotLive; } exit (0); # *********************************************************************** # # * This subroutine checks to see if the path to the image is valid. * # # *********************************************************************** # sub checkImage { my $bytes; if (-r $filename) { $bytes = (-s $filename); if ($bytes) { print "\n"; } else { print "ERROR: Image file found ($filename), but the file is empty.\n"; exit(1); } } else { print "ERROR: Can't read image: ($filename).\n"; exit(1); } } # *********************************************************************** # # * This subroutine runs if the webcam is live. * # # *********************************************************************** # sub imageIsLive { print "Hello, my webcam is now live and the image will ", "update every 5 minutes.", "
\n"; } # *********************************************************************** # # * This subroutine runs if the webcam is not live. * # # *********************************************************************** # sub imageNotLive { print "Sorry, my webcam is not live right now. Please stop ", "back later.", "
\n"; }