#!/usr/bin/perl
#
# $Id: avhdi.cgi,v 1.2 2005-07-01 06:41:27 atlev Exp $
#
#
# Simple CGI interface to AuthViaHTTP Daemon.
#
# USAGE:
#   # allow
#   avhdi.cgi
#
#   # expire
#   avhdi.cgi?expire
#
############################################################
  use strict;

############################################################
##  CONFIGURABLE SECTION
############################################################

  # Location to the FIFO queue which avhd listens to.
  my $FIFO       = '/tmp/dmz.avh';

  # IP and PORT of what you want to allow access to. Format:
  # 'IP PORT'
  my $SECURE_CFG = 'any 443';

  # Location to redirect the remote client to after the
  # command has been sent for processing
  my $REDIRECT   = 'http://secure.flyingcroc.net/goodbye.html';


############################################################
##  MAIN SECTION
############################################################

  # IP of remote client
  my $remote_addr = $ENV{ 'REMOTE_ADDR' };

  # USERNAME of remote client
  my $remote_user = $ENV{ 'REMOTE_USER' };

  # ACTION; either 'allow' or 'expire'. Default is allow.
  my $action      = ( $ENV{ 'QUERY_STRING' } ne '' ) ?
    'expire' : 'allow';


  # Send the command to the FIFO queue, sleep 5 minutes
  # (allowing the command to be processed), then redirect
  # 
  system( "/bin/echo '$action $remote_user $remote_addr $SECURE_CFG' > $FIFO" );
  sleep 5;
  print "Location: $REDIRECT\n\n";


# Done!
1;
