Listing 1. Server-Side Script

#!/usr/bin/perl

# Grab the URL variable
$variable = $ARGV[0];

# Set some important environment variables.
$ENV{'XAUTHORITY'} = '/home/saturn/.Xauthority';
$ENV{'DISPLAY'}    = ':0';
$ENV{'HOME'}       = '/home/saturn';

# if the 5 minutes warning button is pushed
if ($variable =~ /^5min$/) {
    # Lets create a child process to deal with the notifications
    defined(my $childpid = fork);

    if ($childpid) { # If a child pid exists... this is the parent
        # Send response so the browser is happy
        print "Content-type: text/html\n\n";

        # Show a popup warning message
        # displaying 5 minutes remaining.
        `zenity --warning --text='5 minutes left to play'`;
    } else { # Otherwise it's the child
        # Print the amount of time left with a subtle gnome
        # notification message.
        sleep(60);
        `notify-send '4 minutes left to play'`;
        sleep(60);
        `notify-send '3 minutes left to play'`;
        sleep(60);
        `notify-send '2 minutes left to play'`;
        sleep(60);
        `notify-send '1 minutes left to play'`;
        sleep(60);

        # We are now out of time.
        # Let's close all the fun applications
        `/usr/bin/tvtime-command quit`; # Close the TV
        `pkill mplayer`;                # Close mplayer
        `pkill totem`;                  # Close Totem movie player
        `pkill rhythmbox`;              # Close the music player
        `pkill firefox`;                # Close the web browser
    }
}

# If the Cancel Countdown button has been pushed.
if ($variable =~ /^cancel$/) {
    defined(my $childpid = fork);

    if ($childpid) { # If parent
        print "Content-type: text/html\n\n";
    } else {
       `pkill big-meanie`;
    }
}

# If the Get Off Now button has been pushed.
if ($variable =~ /^off-now$/) {
    defined(my $childpid = fork);

    if ($childpid) { # If parent
        print "Content-type: text/html\n\n";
    } else {
        `/usr/bin/tvtime-command quit`; # Close the TV
        `pkill mplayer`;                # Close mplayer
        `pkill totem`;                  # Close Totem movie player
        `pkill rhythmbox`;              # Close the music player
        `pkill firefox`;                # Close the web browser

         # Just because we can... Send out a tweet that
         # someone has been kicked off the computer
         `curl -u <twitterUser>:<twitterPassword> -d
            status='Someone has been rudely kicked off the computer.'
            http://twitter.com/statuses/update.xml > /dev/null`;
    }
}

