#!/usr/bin/perl
use CGI qw(:standard :cgi-lib);
use DateTime;
my $logfile = "/afs/sipb/project/door/log";
my @states = ("closed", "open");

if (-e $logfile) {
        open(LOGFILE, "<$logfile") or die "Can't open logfile " . $logfile . ": $!";
        my @lines = <LOGFILE>;
        my $line = pop(@lines);
        ($curstate, $lasttime) = split(/,/,$line);
        close(LOGFILE) or system("zwrite ternus -m \"Badness 10000: $!\"");
}

my $changetime = DateTime->from_epoch(epoch => $lasttime);
$changetime->set_time_zone('America/New_York');

print header;
print "<html>";
print "The SIPB door has been $states[$curstate] since " . $changetime->strftime("%R on %A, %F") . ".\n";
print "</html>";
