A simple Web Clock

I was asked around the same time from family members and a good friend in the Athens Wireless Metropolitan Network AWMN to make an accurate web-clock with large numbers.

Hence, this simple web clock , good to put on an NTP synchronized web-server.

To get it
wget http://kod.ipduh.com/lib/clock.pl

An example apache configuration file

        DocumentRoot "/var/www/clock.ipduh.awmn/www/"
        ServerName  clock.ipduh.awmn
        ScriptAlias /cgi-bin2/ "/var/www/clock.ipduh.awmn/www/"
        AddHandler cgi-script .pl

<Directory "/var/www/clock.ipduh.awmn/www">
        AllowOverride None
        Options       ExecCGI
        Order         allow,deny
        Allow         from all 
        DirectoryIndex index.pl index.html index.htm

ErrorLog  "|/usr/sbin/rotatelogs /var/www/clock.ipduh.awmn/logs/error/clock.ipduh.awmn-error_log.%Y%m%d 86400"
CustomLog "|/usr/sbin/rotatelogs /var/www/clock.ipduh.awmn/logs/access/clock.ipduh.awmn-access_log.%Y%m%d 86400" combined


The Clock

#g0 2013 a simple web clock

use strict;
use POSIX qw(strftime);
my $date = strftime "%a %b %e %Y" , localtime;
my $hour = strftime "%H" , localtime;
my $min = strftime "%M" , localtime;
my $sec = strftime "%S" , localtime;
my $epoch=time();

print <<"PAGE";
Content-type: text/html \n\n <!doctype html> <html>
<title> clock </title>
<meta  http-equiv='refresh' content='15'>

.clock { font-family: monospace , Arial ; font-size: 6em; }
.little { padding-left: 0px; font-family:  monospace; font-size: .9em; }
a.goto:link { color:#000000; text-decoration:underline; }
a.goto:visited { color:#000000; text-decoration:underline; }
a.goto:hover {color:#000000;text-decoration:none;background:yellow;}
a.goto:active {color:#00FF00;text-decoration:none;background:yellow;}
<script type='text/javascript'>

function tick() {
 if(document.getElementById("min").innerHTML == 59 && document.getElementById("sec").innerHTML == 59 ){
  document.getElementById("hour").innerHTML = document.getElementById("hour").innerHTML - 1 + 2;
  document.getElementById("min").innerHTML = 0;
  document.getElementById("sec").innerHTML = 0;
 else if(document.getElementById("sec").innerHTML == 59 ){
  document.getElementById("min").innerHTML = document.getElementById("min").innerHTML - 1 + 2;
  document.getElementById("sec").innerHTML = 0;
         document.getElementById("sec").innerHTML = document.getElementById("sec").innerHTML - 1 + 2;
 //it will be funny for a dousin of seconds after 1 am --g0

<p class=clock>
<span id='hour'>$hour</span>:<span id='min'>$min</span>:<span id='sec'>$sec</span>
<p class=little> &copy; $date  
<a href="http://ipduh.com/epoch/?$epoch" class=goto>$epoch</a> 
<a class=goto href=http://alog.ipduh.com/2013/05/a-simple-web-clock.html>source</a>
</body> </html>

A simple web clock script