Apache-Recorder

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

Revision history for Perl extension Apache::Recorder.

0.07 Sun Oct 13, 1:00:00 2002
        - Changed the PREREQ_PM value for the CGI::Cookie key to 1.21.
	  CGI::Cookie 1.18 has a bug in the parse method -- unescape
	  is erroneously attributed to CGI, rather than CGI::Util,
	  and this was causing one of the tests in t/get_id.t to fail.
	- Updated the description in Recorder.pm to include a more
	  generic statement of what Apache::Recorder does.

0.06 Thu Jul 18 16:30:00 2002
        - updated README
	- update POD for Mock::Apache::Request
        - Added PREREQ_PM to Makefile.PL to ensure that all necessary
	  modules get installed.

Makefile.PL  view on Meta::CPAN

use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
    'NAME'	=> 'Apache::Recorder',
    'VERSION_FROM' => 'Recorder.pm', # finds $VERSION
    'PREREQ_PM' => {
	'CGI::Cookie'       => 1.21, #1.18 has a bug during parse()
	'Apache::URI'       => 0,
	'Storable'          => 0,
	'Apache::Constants' => 0,
    },

);

Recorder.pm  view on Meta::CPAN


=cut

use strict;
use vars qw( $VERSION );
$VERSION = '0.07';


use Apache::Constants qw(:common);
#use Apache::File;
use CGI::Cookie;
use Apache::URI;

sub handler {
    my $r = shift;
    my $id = get_id( $r );
    return DECLINED unless $id;

    #This should stop all but the most aggressive proxy server and browser cache settings.
    $r->no_cache(1);

Recorder.pm  view on Meta::CPAN

    my $config_file = WORLD_WRITEABLE_DIR . "recorder_conf_".$id;
    unless ( write_config_file( $config_file, $uri, $request_type, \%params ) ) {
        warn "ERROR: Apache::Recorder could not write successfully to $config_file";
    }
    return DECLINED;
}

sub get_id {
    my $r = shift;

    my %cookies = CGI::Cookie->parse( $r->header_in( 'Cookie' ) );
    if (exists( $cookies{ 'HTTPRecorderID' } ) ) {
	return $cookies{ 'HTTPRecorderID' }->value;
    }
}

=pod

=head1 DETAILS

Apache::Recorder is intended to work as a stand-alone mod_perl handler.  As such,

recorder.pl  view on Meta::CPAN

#!/usr/bin/perl -wT
#<[tmpl:99]>
use strict;
use CGI;
use CGI::Cookie;

my ( $q ) = new CGI;

my ( $action ) = $q->param( 'action' ) || 'welcome';

if ( $action eq 'welcome' ) {
    print $q->header;
    &print_welcome();
}
elsif ( $action eq 'set_cookie' ) {
    my ( $semi_random ) = &get_semi_random;
    &set_cookie( $q, $semi_random );
    print $q->header;
    &print_confirmation( $semi_random );
}

sub set_cookie {
    my ( $q ) = shift; 
    my ( $semi_random ) = shift;
    my ( %cookies ) = fetch CGI::Cookie;
    my ( $id, $return );
    foreach my $key (keys %cookies ) {
        if ( $key eq 'HTTPRecorderID' ) {
	    $id = $cookies{ 'HTTPRecorderID' }->value;    
	}
    }

    unless ( $id ) {
	my ( $cookie ) = $q->cookie(
	    -name => 'HTTPRecorderID',

recorder.pl  view on Meta::CPAN

	<body bgcolor='FFFFFF'>
	    <p>
	    Welcome to Apache::Recorder. By clicking the button below, you will 
	    set a cookie that will allow a handler to track all of your movements on the 
	    present domain.  That handler, in turn, will create a map of your "click-through" 
	    of the site, including GET and POST parameters.  Upon returning to this script, 
	    you will be able to disable that cookie, and then create a simple script that 
	    will allow automated testing of the path that you followed.  
	    </p>
	    <p>
	    When you are ready to begin, please click on the "Set Cookie" button below.
	    </p>
	    <form action='/cgi-bin/recorder.pl' method='POST'>
	        <input type='submit' value='Set Cookie'>
		<input type='hidden' name='action' id='action' value='set_cookie'>
	    </form>
	</body>
    </html>
~;
}

sub print_confirmation {
    my ( $semi_random ) = shift;
    print qq~

t/Mock/Apache/Request.pm  view on Meta::CPAN

package Mock::Apache::Request;
use strict;
use CGI::Cookie;

sub new {
    my ( $class ) = shift;
    my ( $self ) = {};
    bless( $self, $class );
    $self->_init( @_ );
    return $self;
}

sub _init {
    my ( $self ) = shift;

    my ( %args ) = (@_);
    $self->{uc($_)} = $args{$_} foreach (keys %args);
}

sub header_in {
    my $self = shift;
    my $requested_param = shift;
    if ( $requested_param eq 'Cookie' ) {
	my $cookie = new CGI::Cookie(
	    -name=>'HTTPRecorderID',
	    -value=>$self->{ 'COOKIE_ID' } 
	    );
        return $cookie;
    }
    else {
        die "Mock::Apache::Request does not support $requested_param: $!";
    }
}

t/Mock/Apache/Request.pm  view on Meta::CPAN


Mock::Apache::Request imitates a real Apache::Request object just long enough to 
allow for a simple test during the installation of Apache::Recorder.

=head1 USAGE

my $cookie_id = '12345';

my $mock_r = new Mock::Apache:Request( 'cookie_id' => $cookie_id );

my $cookie = $mock_r->header_in( 'Cookie' );

use Data::Dumper;

print Dumper( $cookie );

=head1 AUTHOR

Chris Brooks <cbrooks@organiccodefarm.com>

=cut

t/get_id.t  view on Meta::CPAN

END {print "not ok 2\n" unless $cookie;}
END {print "not ok 1\n" unless $loaded;}

use strict;
use vars qw( $loaded $storable $cookie );

use Apache::Recorder;
$loaded = 1;
print "ok 1\n";

use CGI::Cookie;
$cookie = 1;
print "ok 2\n";

########################################################
# Test Apache::Recorder::get_id()
########################################################

use lib "t/";
use Mock::Apache::Request;
my $cookie_id = '123456';



( run in 0.447 second using v1.01-cache-2.11-cpan-4e96b696675 )