#!/usr/bin/perl
# Quick presentation controller hack - setup a web server
# and on certain requests skip to the next slide
# mjc@redhat.com May 2006

use strict;
use warnings;

use X11::GUITest qw/SendKeys/;
use HTTP::Daemon;
use HTTP::Status;

my $d = HTTP::Daemon->new(LocalPort => 8111) || die;
print "Listening at ".$d->url."\n";
while (my $c = $d->accept) {
    while (my $r = $c->get_request) {
        if ($r->method eq 'GET' and $r->url->path eq "/slide") {
            SendKeys(' ');
            my $date = `date +%H:%M`;
            $c->send_response("Content-type: text/html\r\n\r\n<h1>$date</h1><form method=\"GET\" action=\"http://192.168.0.2:8111/slide\"><input type=\"submit\"></form>");
        }
        else {
            $c->send_error(RC_NOT_FOUND);
        }
    }
    $c->close;
    undef($c);
}
