a simple NTP server status web-page

A quick how-to create a simple NTP server status web-page.

I will be using apache to serve the status web-page, but any cgi capable web-server will do.

The NTP server status script.

#!/usr/bin/perl
#g0 2013  , http://ipduh.com/contact
#simple ntp server status web-page
#Prerequisites: ntpdate & ntptrace
use strict;
#configure
my $myNTPIP="10.21.241.4";
my $myNTPDNS="ntp.ipduh.awmn";
my $ntptrace="/usr/bin/ntptrace";
my $ntpdate="/usr/sbin/ntpdate";
#configure END

my $epoch=time();
my @ntptrace=`$ntptrace $myNTPIP`;
my @date=`$ntpdate -q $myNTPIP`;
my @fields=();
my $liin;
my @ntptrace_out=();
foreach my $li(@ntptrace){
 @fields=split(/:/,$li);
 $fields[0]="<a href=http://ipduh.com/apropos/?$fields[0]>$fields[0]</a>";
 $liin="$fields[0]".":"."$fields[1]";
 push(@ntptrace_out,$liin); 
}

print <<"TOP";
Content-type: text/html \n\n
<!doctype html><html><head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>$myNTPDNS</title>
<meta name='description' content='$myNTPIP - $myNTPDNS NTP server status web-page' /> 
<style>
p { padding-left: 0px; font-family:  Fixed, monospace; font-weight: 1em; }
.little { padding-left: 0px; font-family:  monospace; font-weight: .4em; }
.board { position:absolute; top:100px; left:100px; }
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;
</style>
</head><body>
<div class=board>
TOP
print "<p> $myNTPIP - $myNTPDNS </p><pre> @date <br /> @ntptrace_out </pre>";
print <<'BOT';
<pre>
|__________   ________________________________________________________________________|
           \ |
            \|
            
        |   /\________/\   |
        |  /____    ____\  |
        |_/     \__/     \_|
        [_       __       _]
          \_____/  \_____/
           \    ____    / 
            |   \__/   |   
          _  \________/  _
          \\  /|    |\  //
           \\IPDUHHUD9I//

</pre>
BOT
print <<"TOEND";
<center><p class=little> &copy; <a href=http://ipduh.com>ipduh</a> <a href="http://ipduh.com/epoch/?$epoch" class=goto>$epoch</a>
</p></center><br /><br /><br /><br /></div></body></html>
TOEND


    


A sample apache2 virtual host configuration.


<VirtualHost 10.21.241.4:80>
        DocumentRoot "/var/www/ntp.ipduh.awmn/www/"
        ServerName  ntp.ipduh.awmn
        ScriptAlias /cgi-bin2/ "/var/www/ntp.ipduh.awmn/www/"
        AddHandler cgi-script .pl

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

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



To install the ntp-status-page put the ntp-status script to a cgi directory. You can get the ntp-status script from http://kod.ipduh.com/lib/ntp-status-web.pl
If you are planning on using an apache2 virtual host similar to the one above just for this you could do the following.
$ cd /path/to/vhost-web-root
$ wget http://kod.ipduh.com/lib/ntp-status-web.pl
$ mv ntp-status-web.pl index.pl
$ chmod 755 index.pl




A simple NTP status web-page script