#!/usr/bin/perl
use strict;
use HTML::Template;
use Apache;
use constant TMPL_PATH => '/home/httpd/domain.com/html/app_templates';
use constant TMPL_FILE => 'login.tmpl';
my $r = Apache->request;
$r->status(200);
my $destination;
my $authcookiereason;
if ( $r->prev() ) { # we are called as a subrequest.
$destination = $r->prev()->args()
? $r->prev()->uri() . '?' . $r->prev->args()
: $r->prev()->uri();
$authcookiereason = $r->prev()->subprocess_env( 'AuthCookieReason' );
} else {
$destination = $r->args( 'destination' );
$authcookiereason = $r->args( 'AuthCookieReason' );
}
$r->log_error( "previous was: $destination" );
my $reason = $r->prev->subprocess_env("AuthCookieReason");
my $tmpl = HTML::Template->new( path => TMPL_PATH,
filename => TMPL_FILE
);
my $msg = ( $authcookiereason and $authcookiereason ne 'no_cookie' ? 1 : 0 );
$tmpl->param( REASON => $msg );
$tmpl->param( uri => $destination );
my $form = $tmpl->output();
$r->no_cache(1);
my $x = length($form);
$r->content_type("text/html");
$r->header_out("Content-length","$x");
$r->header_out("Pragma", "no-cache");
$r->send_http_header;
$r->print($form);