view release on metacpan or search on metacpan
Centipaid.pm view on Meta::CPAN
package Apache::Centipaid;
use Apache ();
use Apache::Constants qw(OK REDIRECT AUTH_REQUIRED DECLINED FORBIDDEN DECLINED SERVER_ERROR);
use Apache::File;
use IO::Socket;
use Net::hostent;
use DBI;
use CGI::Cookie;
use strict;
$Apache::Centipaid::VERSION = '1.3.1';
sub need_to_pay($) {
my $r = shift(@_);
my $payto = $r->dir_config("acct") || 0;
Centipaid.pm view on Meta::CPAN
# connect to the database
my $dsn = "DBI:$dbtype:database=$dbname;host=$dbhost;port=$dbport";
my $dbh = DBI->connect($dsn,$dbuser,$dbpass);
my $connect_to ="$server:$port";
my $line;
my $and;
#cookie information
my %cookies = CGI::Cookie->parse($r->header_in('Cookie'));
my $cookie;
if ( $cookies{$cookie_name} =~ /$cookie_name=([^;]+)/ ) { $cookie = $1; }
#print some stats if debug is on
$r->log_error("$prefix: payto $payto") if $debug >= 2;
$r->log_error("$prefix: server $server") if $debug >= 2;
$r->log_error("$prefix: port $port") if $debug >= 2;
$r->log_error("$prefix: ip $ip") if $debug >= 2;
Centipaid.pm view on Meta::CPAN
"$rcpt",NOW(),
DATE_ADD(NOW(),INTERVAL $duration SECOND),
$paid,
"$ip",
"$cookie_name"
)
};
my $sth = $dbh->do("$sql");
# set the cookie so we do not call the server again..
my $str = CGI::Cookie->new(-name => "$cookie_name",
-path=> "$access",
-domain => "$domain",
-value => "$rcpt",
-expires => "+".$duration."s");
$r->err_headers_out->add('Set-Cookie' => $str);
$r->content_type('text/html');
$r->header_out(Location =>"$uri");
return REDIRECT;
}# if paid == amount
}#end if 250
if ($received =~ /^500/) {
# if we get a 500 code then it was an invalid receipt
Centipaid.pm view on Meta::CPAN
my $sth = $dbh->prepare($sql);
$sth->execute or db_err("Unable to execute query \n$sql\n", $dbh->errstr);
while ( @row = $sth->fetchrow_array ) {
my ($rcpt,$date,$expire,$paid,$ip) = @row;
$r->log_error("$prefix: receipt record found $rcpt,$date,$expire,$paid,$ip") if $debug >= 2;
return OK;
}
#if we are at this stage, then the cookie is not valid or not found and we should remove it..
my $str = CGI::Cookie->new(-name => "$cookie_name",
-path=> "$access",
-domain => "$domain",
-value => "",
-expires => "-".$duration."s");
$r->err_headers_out->add('Set-Cookie' => $str);
need_to_pay($r);
} else {
# if there is no receipt, and no cookie, then they need to pay
need_to_pay($r);
}#end check for cookie
Centipaid.pm view on Meta::CPAN
PerlSetVar dbhost localhost
PerlSetVar dbport 3306
PerlSetVar dbname centipaid_rcpt
perlSetVar dbuser user
perlSetVar dbpass pass
</directory>
=head1 REQUIRES
Perl5.004_04, mod_perl 1.15, IO::Socket, Net::hostent, DBI, DBD, DBD::mysql, CGI::Cookie;
=head1 DESCRIPTION
B<Apache::Centipaid> is a mod_perl Authentication handler used in
granting access to users wishing to access paid web services, after
making payment on centipaid.com which process micropayments using
internet stamps.
Centipaid.com offers websites the flexibility to charge small amounts
check that by running make test in the Apache::Centipaid directory.
---> if this condition is met, thenm proceed to next test
2)Check that the local database "centipaid_rcpt" is installed and can be accessed
using the username/password specified in the configuration
---> if this condition is met, thenm proceed to next test
3)Check the error logs of your virtual host with Apache::Centipaid
If you see an error log that references to CGI/Cookie.pm (see example)
then you need to reinstall CGI.pm - We have included a tested version
of CGI.pm in the contrib directory, however it is recommended to get the
latest version from http://www.perl.com/CPAN/modules/by-module/CGI/
>Attempt to free unreferenced scalar.
>[Wed Jan 15 14:36:45 2003] [error] Undefined subroutine &CGI::unescape called at
>/usr/lib/perl5/5.6.1/CGI/Cookie.pm line 75.
---> if this condition is met, thenm proceed to next test
4) Check which type of authetication has been chosen. i.e. is it an httpd.conf
configuration? or an .htaccess
--> If it is an httpd.conf and the steps above did not resolve it, please check
support forum for more information.
--> If it is an .htaccess configuration, then you need to make sure that the
Makefile.PL view on Meta::CPAN
'ABSTRACT' => 'Micropayment module with interface to centipaid.com payment gateway',
'AUTHOR' => 'Adonis El Fakih (me@centipaid.com)',
'NAME' => 'Apache::Centipaid',
'PREREQ_PM' => {
'Apache' => 1.02,
'Apache::File' => 1.01,
'IO::Socket' => 1.26,
'Net::hostent' => 0,
'DBI' => 1.21,
'DBD::mysql' => 2.0419,
'CGI::Cookie' => 1.21
},
'VERSION_FROM' => 'Centipaid.pm', # finds $VERSION
dist => {
SUFFIX => 'gz',
COMPRESS => 'gzip -9',
}
);
RCS/Centipaid.pm,v view on Meta::CPAN
package Apache::Centipaid;
use Apache ();
use Apache::Constants qw(OK REDIRECT AUTH_REQUIRED DECLINED FORBIDDEN DECLINED SERVER_ERROR);
use Apache::File;
use IO::Socket;
use Net::hostent;
use DBI;
use CGI::Cookie;
use strict;
$Apache::Centipaid::VERSION = '1.2';
sub need_to_pay($) {
my $r = shift(@@_);
my $payto = $r->dir_config("acct") || 0;
RCS/Centipaid.pm,v view on Meta::CPAN
# connect to the database
my $dsn = "DBI:$dbtype:database=$dbname;host=$dbhost;port=$dbport";
my $dbh = DBI->connect($dsn,$dbuser,$dbpass);
my $connect_to ="$server:$port";
my $line;
my $and;
#cookie information
my %cookies = CGI::Cookie->parse($r->header_in('Cookie'));
my $cookie;
if ( $cookies{$cookie_name} =~ /$cookie_name=([^;]+)/ ) { $cookie = $1; }
#print some stats if debug is on
$r->log_error("$prefix: payto $payto") if $debug >= 2;
$r->log_error("$prefix: server $server") if $debug >= 2;
$r->log_error("$prefix: port $port") if $debug >= 2;
$r->log_error("$prefix: ip $ip") if $debug >= 2;
RCS/Centipaid.pm,v view on Meta::CPAN
"$rcpt",NOW(),
DATE_ADD(NOW(),INTERVAL $duration SECOND),
$paid,
"$ip",
"$cookie_name"
)
};
my $sth = $dbh->do("$sql");
# set the cookie so we do not call the server again..
my $str = CGI::Cookie->new(-name => "$cookie_name",
-path=> "$access",
-domain => "$domain",
-value => "$rcpt",
-expires => "+".$duration."s");
$r->err_headers_out->add('Set-Cookie' => $str);
$r->content_type('text/html');
$r->header_out(Location =>"$uri");
return REDIRECT;
}# if paid == amount
}#end if 250
if ($received =~ /^500/) {
# if we get a 500 code then it was an invalid receipt
RCS/Centipaid.pm,v view on Meta::CPAN
my $sth = $dbh->prepare($sql);
$sth->execute or db_err("Unable to execute query \n$sql\n", $dbh->errstr);
while ( @@row = $sth->fetchrow_array ) {
my ($rcpt,$date,$expire,$paid,$ip) = @@row;
$r->log_error("$prefix: receipt record found $rcpt,$date,$expire,$paid,$ip") if $debug >= 2;
return OK;
}
#if we are at this stage, then the cookie is not valid or not found and we should remove it..
my $str = CGI::Cookie->new(-name => "$cookie_name",
-path=> "$access",
-domain => "$domain",
-value => "",
-expires => "-".$duration."s");
$r->err_headers_out->add('Set-Cookie' => $str);
need_to_pay($r);
} else {
# if there is no receipt, and no cookie, then they need to pay
need_to_pay($r);
}#end check for cookie
RCS/Centipaid.pm,v view on Meta::CPAN
PerlSetVar dbhost localhost
PerlSetVar dbport 3306
PerlSetVar dbname centipaid_rcpt
perlSetVar dbuser user
perlSetVar dbpass pass
</directory>
=head1 REQUIRES
Perl5.004_04, mod_perl 1.15, IO::Socket, Net::hostent, DBI, DBD, DBD::mysql, CGI::Cookie;
=head1 DESCRIPTION
B<Apache::Centipaid> is a mod_perl Authentication handler used in
granting access to users wishing to access paid web services, after
making payment on centipaid.com which process micropayments using
internet stamps.
Centipaid.com offers websites the flexibility to charge small amounts
config/htaccess view on Meta::CPAN
AuthName Centipaid
AuthType Cookie
PerlAuthenHandler Apache::Centipaid
require valid-user
PerlSetVar debug 0
# payee information
# To signup for an account go to www.centipaid.com
PerlSetVar acct AEF001
PerlSetVar pass adonis
PerlSetVar amount 0.005
config/htaccess-dist view on Meta::CPAN
AuthName Centipaid
AuthType Cookie
PerlAuthenHandler Apache::Centipaid
require valid-user
PerlSetVar debug 0
# payee information
# To signup for an account go to www.centipaid.com
PerlSetVar acct AEF001
PerlSetVar pass adonis
PerlSetVar amount 0.005
config/httpd.conf view on Meta::CPAN
ServerAdmin adonis@aynacorp.com
DocumentRoot /home/adonis/centipaid/www
ErrorLog logs/error_log
CustomLog logs/access_log common
# assuming that we want to protect a directory,
# then we ass the following
<directory /home/adonis/centipaid/www/custom>
AuthName Centipaid
AuthType Cookie
PerlAuthenHandler Apache::Centipaid
require valid-user
# debug level 5 shows everything, 0 show nothing
PerlSetVar debug 0
# payee information
# To signup for an account go to www.centipaid.com
PerlSetVar acct AEF001
PerlSetVar pass adonis
config/httpd.conf-dist view on Meta::CPAN
ServerAdmin adonis@aynacorp.com
DocumentRoot /home/adonis/centipaid/www
ErrorLog logs/error_log
CustomLog logs/access_log common
# assuming that we want to protect a directory,
# then we ass the following
<directory /home/adonis/centipaid/www/custom>
AuthName Centipaid
AuthType Cookie
PerlAuthenHandler Apache::Centipaid
require valid-user
# debug level 5 shows everything, 0 show nothing
PerlSetVar debug 0
# payee information
# To signup for an account go to www.centipaid.com
PerlSetVar acct AEF001
PerlSetVar pass adonis
use Apache::File;
print "ok Apache::File\n";
use IO::Socket;
print "ok IO::Socket\n";
use Net::hostent;
print "ok Net::hostent\n";
use DBI;
print "ok DBI\n";
use DBD::mysql;
print "ok DBD::mysql\n";
use CGI::Cookie;
print "ok CGI::Cookie\n";
use Apache::Centipaid;
print "ok Apache::Centipaid\n";
$loaded = 1;
######################### End of black magic.
# Insert your test code below (better if it prints "ok 13"
# (correspondingly "not ok 13") depending on the success of chunk 13
# of the test code):