#!/usr/bin/perl -w
##################
$title = "BAZCAM!";
$image = "webcam.jpg";
$off = "off.png";
##################
use File::stat;
unless(-e "$image") {
print <<"END";
Content-Type: text/html
<html>
<head>
<meta http-equiv="refresh" content="1">
<title>$title</title>
</head>
<body bgcolor="#FFFFFF">
<font face="Arial, Helvetica">Please wait, image is being uploaded</font>
</body>
</html>
END
} else {
$webcam = stat("$image");
$ts = $webcam->mtime;
if(time - $webcam->mtime > 120) {
$image = $off;
} else {
$image = "$image?$ts";
}
print <<"END";
Content-Type: text/html
<html>
<head>
<meta http-equiv="refresh" content="30">
<title>$title</title></head>
<body bgcolor=#FFFFFF onLoad="getStarted()">
<center>
<table height=100% border=0>
<tr><td align=center valign=center>
END
if($ARGV[0] eq "remote") {
print "<img src=\"$image\" border=0>\n";
} else {
print "<a href=\"blank.html\" onclick=window2=window.open(\"?remote\",\"bazcamRemote\",\"toolbar=0,status=0,resizable=0,width=400,height=350\")><img src=\"$image\" border=0></a>\n";
}
print <<"END";
</td></tr>
<tr><td>
<form name="myForm">
<center><input name="numberShown" type="text" size="2"> <font face="Arial, Helvetica">seconds
</p>
</td></tr>
</table>
<script language="JavaScript">
//-- JavaScript code written by Alan Simpson - www.coolnerds.com
//-- This function subtracts one from the current value in the form field,
//-- and decides whether to keep going, or end the countdown.
function subtractOne() {
//Subtract 1 from current value in form field.
var newValue = parseInt(document.myForm.numberShown.value)-1
//Replace the contents of form field with smaller number.
document.myForm.numberShown.value = newValue
//-- If countdown hasn't reached zero, pause then do it again.
if (newValue > 0) {
//-- From here on out, this function calls itself once every second.
myTimer=setTimeout("subtractOne()",1000)
//-- When countdown does reach zero, stop the timer and call reachedZero().
}else{
clearTimeout("myTimer")
reachedZero()
}
}
//-- This function is called by onload="getStarted()" in this page's
//-- body tag, and gets the ball rolling.
function getStarted() {
//-- Loads the number 10 into the form field.
document.myForm.numberShown.value="30"
//-- Pauses one-second, then calles the subtractOne function.
myTimer=setTimeout("subtractOne()",1000)
}
function reachedZero() {
//-- This is the function that is executed when the countdown ends.
}
</script>
</center>
</body>
</html>
END
}
syntax highlighted by Code2HTML, v. 0.9