Business-PhoneBill-Allopass
view release on metacpan or search on metacpan
Allopass.pm view on Meta::CPAN
Please consider using Business::PhoneBill::Allopass::Simple if you don't need session management.
See I<http://www.allopass.com/index.php4?ADV=1508058> for more informations on their system and how it basically works.
=cut
use strict;
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
use CGI::Cookie;
my $baseurl = 'http://www.allopass.com/check/vf.php4';
=head1 METHODS
=over 4
=item B<new> Class constructor. Provides session-based access check.
$allopass=Billing::Allopass->new($session_file, [$ttl]);
Allopass.pm view on Meta::CPAN
$ua->agent('Business::PhoneBill::Allopass/'.$VERSION);
$req = POST $baseurl,
[
'SITE_ID' => $site_id ,
'DOC_ID' => $doc_id ,
'CODE0' => $code ,
'DATAS' => $datas ,
'AP_CA' => $ap_ca
];
$res = $ua->simple_request($req)->as_string;
if ($res=~/Set-Cookie: AP_CHECK/) {
$self->_set_error('Allopass Check Code OK');
my $r = $self->_add_session($docid, $code);
if ($r) {
$self->_set_error($r);
return 0;
}
return 1;
}
}
0;
Allopass.pm view on Meta::CPAN
$self->{os}=1 if $val;
$self->{os};
}
### PRIVATE FUNCTIONS ==========================================================
sub _is_session {
my $self = shift;
my $doc_id = shift;
my $ok=0;
my %cookies = fetch CGI::Cookie;
my $docid=$doc_id; $docid=~s/\//\./g;
if (!$doc_id) {
$self->_set_error("No Document ID");
return 0
}
if (!$cookies{$docid}){
$self->_set_error("No Session Cookie");
return 0
}
return 0 if !ref $cookies{$docid};
return 0 if !defined $cookies{$docid}->value;
my $code = $cookies{$docid}->value || $self->{code};
my $a=time;
$self->_set_error("Error opening ".$self->{ses_file}." for read");
open (TEMP, $self->{ses_file}) or return 0;
Allopass.pm view on Meta::CPAN
next unless ($index[$i]);
my ($docid, $pass, $IP, $heure, @autres) = split (/\|/, $index[$i]);
next if ($a > ($heure + $self->{ttl} * 60));
next if $docid eq $doc_id && $pass eq $code;
print OUTPUT "$docid|$pass|$IP|$heure||\n";
}
print OUTPUT "$doc_id|$code|$ENV{REMOTE_ADDR}|" . $a . "||\n";
if ($self->{os} == 0) {flock (OUTPUT, 8);}
close (OUTPUT);
$doc_id=~s/\//\./g;
my $cookie = new CGI::Cookie(-name=>$doc_id, -value=> $code );
if (ref $self->{hhttp}) {
$self->{hhttp}->add_cookie("Set-Cookie: ".$cookie->as_string);
} else {
print "Set-Cookie: ",$cookie->as_string,"\n";
}
0;
}
sub _end_session {
my $self=shift;
my $doc_id = shift;
my %cookies = fetch CGI::Cookie;
my $docid=$doc_id; $docid=~s/\//\./g;
my $code = $self->{code};
unless ($code) {
return("Unable to remove session : Undefined sid") if !ref $cookies{$docid};
return("Unable to remove session : Undefined sid") if !defined $cookies{$docid};
return("Unable to remove session : Undefined sid") if !defined $cookies{$docid}->value;
$code = $cookies{$docid}->value if defined $cookies{$docid}->value;
}
Allopass.pm view on Meta::CPAN
chomp $index[$i];
next unless ($index[$i]);
my ($ldocid, $pass, $IP, $heure, @autres) = split (/\|/, $index[$i]);
next if ($a > ($heure + $self->{ttl} * 60));
next if $pass eq $code;
print OUTPUT "$docid|$pass|$IP|$heure|$code|\n";
}
if ($self->{os} == 0) {flock (TEMP, 8);}
close (OUTPUT);
$doc_id=~s/\//\./g;
my $cookie = new CGI::Cookie(-name=>$docid, -value=> '-' );
if (ref $self->{hhttp}) {
$self->{hhttp}->add_cookie("Set-Cookie: ".$cookie->as_string);
} else {
print "Set-Cookie: ",$cookie->as_string,"\n";
}
0;
}
sub _is_res_ok {
my $self=shift;
my $res=shift;
my($h, $c, $a)=split(/\n\n/, $res); chomp $c;
if($res && $res!~/NOK/ && $res!~/ERR/ && $res!~/error/i && $c=~/OK/) {
$self->_set_error('Allopass Recall OK');
return 1;
$ make
$ make test
# make install
DEPENDENCIES
This module requires these other modules and libraries available at CPAN:
HTTP::Request::Common
LWP::UserAgent
CGI::Cookie
COPYRIGHT AND LICENCE
Copyright (C) 2003 Bernard Nauwelaerts <bpn@it-development.be>
This library is free software; you can redistribute it and/or modify
it under the GPL/artistic licence. See COPYING for details.
examples/Simple.txt view on Meta::CPAN
package Business::PhoneBill::Allopass::Simple;
use vars qw($VERSION @ISA @EXPORT $session_file);
$VERSION = "1.01";
use HTTP::Request::Common qw(GET POST);
use LWP::UserAgent;
use CGI::Cookie;
my $baseurl = 'http://www.allopass.com/check/vf.php4';
=head1 NAME
Billing::Allopass::Simple - A class for micro-payment system from allopass I<http://www.allopass.com/>
=head1 SYNOPSIS
use Business::PhoneBill::Allopass::Simple;
( run in 0.284 second using v1.01-cache-2.11-cpan-e9199f4ba4c )