r100249 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100248‎ | r100249 | r100250 >
Date:18:36, 19 October 2011
Author:khorn
Status:ok
Tags:fundraising 
Comment:
Merging the fundraising branch of DonationInterface back into trunk.
Updates all the "extras" to behave in a gateway-agnostic way. Also, added in a couple Resource Loader lines in RapidHTML and the typical default form, so the css gets loaded properly.
As this is a mid-merge commit, the extension will be broken until the merge is completed.
Modified paths:
  • /trunk/extensions/DonationInterface/extras (modified) (history)
  • /trunk/extensions/DonationInterface/extras/conversion_log/conversion_log.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/conversion_log/conversion_log.php (deleted) (history)
  • /trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.php (deleted) (history)
  • /trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/extras.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/extras.php (deleted) (history)
  • /trunk/extensions/DonationInterface/extras/minfraud/ccfd/CreditCardFraudDetection.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/minfraud/ccfd/HTTPBase.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/minfraud/ccfd/LocationVerification.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/minfraud/ccfd/TelephoneVerification.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/minfraud/minfraud.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/minfraud/minfraud.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/minfraud/tests/minfraudTest.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/recaptcha/recaptcha-php/recaptchalib.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/recaptcha/recaptcha.body.php (modified) (history)
  • /trunk/extensions/DonationInterface/extras/recaptcha/recaptcha.php (deleted) (history)
  • /trunk/extensions/DonationInterface/gateway_forms/RapidHtml.php (modified) (history)
  • /trunk/extensions/DonationInterface/gateway_forms/TwoStepTwoColumn.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/extras/extras.php
@@ -1,29 +0,0 @@
2 -<?php
3 -/**
4 - * An abstract class and set up for payflowpro gateway 'extras'
5 - *
6 - * To install:
7 - * require_once( "$IP/extensions/DonationInterface/payflowpro_gateway/extras/extras.php"
8 - * Note: This should be specified in LocalSettings.php BEFORE requiring any of the other 'extras'
9 - */
10 -
11 -if ( !defined( 'MEDIAWIKI' ) ) {
12 - die( "This file is part of PayflowPro Gateway extension. It is not a valid entry point.\n" );
13 -}
14 -
15 -$wgExtensionCredits['payflowprogateway_extras'][] = array(
16 - 'name' => 'extras',
17 - 'author' => 'Arthur Richards',
18 - 'url' => '',
19 - 'description' => "This extension handles some of the set up required for PayflowPro Gateway extras"
20 -);
21 -
22 -/**
23 - * Full path to file to use for logging for Payflowpro Gateway scripts
24 - *
25 - * Declare in LocalSettings.php
26 - */
27 -$wgPayflowGatewayLog = '';
28 -
29 -$dir = dirname( __FILE__ ) . "/";
30 -$wgAutoloadClasses['PayflowProGateway_Extras'] = $dir . "extras.body.php";
\ No newline at end of file
Index: trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.php
@@ -1,48 +0,0 @@
2 -<?php
3 -/**
4 - * Provides a unified way to define and run custom filters for incoming transactions
5 - *
6 - * Running filters through 'custom filters' rather than directly through the validate hook in the gateway
7 - * offers the advantage of simplifying the passage of relvent data between filters/validators that's
8 - * needed to perform more complex validation/filtering of transactions.
9 - *
10 - * The actual filters themselves are regular MW extensions and can optional be organized in filters/
11 - * They should be invoked by using the 'PayflowGatewayCustomFilter' hook, which will pass the entire
12 - * CustomFilter object to the filter. The gateway object and its data are included in the CustomFilter
13 - * object.
14 - */
15 -
16 -if ( !defined( 'MEDIAWIKI' ) ) {
17 - die( "This file is part of the MinFraud for PayflowPro Gateway extension. It is not a valid entry point.\n" );
18 -}
19 -
20 -$wgExtensionCredits['payflowprogateway_custom_filters'][] = array(
21 - 'name' => 'custom filters',
22 - 'author' => 'Arthur Richards',
23 - 'url' => '',
24 - 'description' => 'This extension provides a way to define custom filters for incoming transactions for the Payflow Pro gateway.'
25 -);
26 -
27 -/**
28 - * Define the action to take for a given $risk_score
29 - */
30 -$wgPayflowGatewayCustomFiltersActionRanges = array(
31 - 'process' => array( 0, 100 ),
32 - 'review' => array( -1, -1 ),
33 - 'challenge' => array( -1, -1 ),
34 - 'reject' => array( -1, -1 ),
35 -);
36 -
37 -/**
38 - * A value for tracking the 'riskiness' of a transaction
39 - *
40 - * The action to take based on a transaction's riskScore is determined by
41 - * $action_ranges. This is built assuming a range of possible risk scores
42 - * as 0-100, although you can probably bend this as needed.
43 - */
44 -$wgPayflowGatewayCustomFiltersRiskScore = 0;
45 -
46 -$dir = dirname( __FILE__ ) . "/";
47 -$wgAutoloadClasses['PayflowProGateway_Extras_CustomFilters'] = $dir . "custom_filters.body.php";
48 -
49 -$wgHooks["PayflowGatewayValidate"][] = array( 'PayflowProGateway_Extras_CustomFilters::onValidate' );
Index: trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php
@@ -1,6 +1,7 @@
22 <?php
33
4 -class PayflowProGateway_Extras_CustomFilters extends PayflowProGateway_Extras {
 4+class Gateway_Extras_CustomFilters extends Gateway_Extras {
 5+
56 /**
67 * A value for tracking the 'riskiness' of a transaction
78 *
@@ -18,35 +19,15 @@
1920 public $action_ranges;
2021
2122 /**
22 - * A container for the gateway object
23 - *
24 - * This gets populated on construction.
25 - * @var object
26 - */
27 - public $gateway_object;
28 -
29 - /**
30 - * A container for data from the gateway
31 - *
32 - * This gets populated on construction.
33 - */
34 - public $gateway_data;
35 -
36 - /**
3723 * A container for an instance of self
3824 */
3925 static $instance;
4026
41 - public function __construct( &$pfp_gateway_object, &$data ) {
42 - parent::__construct();
43 -
44 - $this->gateway_object =& $pfp_gateway_object;
45 - $this->gateway_data =& $data;
46 -
47 - // load user action ranges and risk score
48 - global $wgPayflowGatewayCustomFiltersActionRanges, $wgPayflowGatewayCustomFiltersRiskScore;
49 - if ( isset( $wgPayflowGatewayCustomFiltersActionRanges ) ) $this->action_ranges = $wgPayflowGatewayCustomFiltersActionRanges;
50 - if ( isset( $wgPayflowGatewayCustomFiltersRiskScore ) ) $this->risk_score = $wgPayflowGatewayCustomFiltersRiskScore;
 27+ public function __construct( &$gateway_adapter ) {
 28+ parent::__construct( $gateway_adapter ); //gateway_adapter is set in there.
 29+ // load user action ranges and risk score
 30+ $this->action_ranges = $this->gateway_adapter->getGlobal( 'CustomFiltersActionRanges' );
 31+ $this->risk_score = $this->gateway_adapter->getGlobal( 'CustomFiltersRiskScore' );
5132 }
5233
5334 /**
@@ -56,11 +37,13 @@
5738 */
5839 public function determineAction() {
5940 // possible risk scores are between 0 and 100
60 - if ( $this->risk_score < 0 ) $this->risk_score = 0;
61 - if ( $this->risk_score > 100 ) $this->risk_score = 100;
 41+ if ( $this->risk_score < 0 )
 42+ $this->risk_score = 0;
 43+ if ( $this->risk_score > 100 )
 44+ $this->risk_score = 100;
6245
6346 foreach ( $this->action_ranges as $action => $range ) {
64 - if ( $this->risk_score >= $range[0] && $this->risk_score <= $range[1] ) {
 47+ if ( $this->risk_score >= $range[0] && $this->risk_score <= $range[1] ) {
6548 return $action;
6649 }
6750 }
@@ -71,22 +54,24 @@
7255 */
7356 public function validate() {
7457 // expose a hook for custom filters
75 - wfRunHooks( 'PayflowGatewayCustomFilter', array( &$this ) );
76 - $this->gateway_object->action = $this->determineAction();
 58+ wfRunHooks( 'GatewayCustomFilter', array( &$this->gateway_adapter, &$this ) );
 59+ $this->gateway_adapter->action = $this->determineAction();
7760
78 - $log_msg = '"' . $this->gateway_object->action . "\"\t\"" . $this->risk_score . "\"";
79 - $this->log( $this->gateway_data['contribution_tracking_id'], 'Filtered', $log_msg );
 61+ $log_msg = '"' . $this->gateway_adapter->action . "\"\t\"" . $this->risk_score . "\"";
 62+ $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Filtered', $log_msg );
8063 return TRUE;
8164 }
8265
83 - static function onValidate( &$pfp_gateway_object, &$data ) {
84 - return self::singleton( $pfp_gateway_object, $data )->validate();
 66+ static function onValidate( &$gateway_adapter ) {
 67+ $gateway_adapter->debugarray[] = 'custom filters onValidate hook!';
 68+ return self::singleton( $gateway_adapter )->validate();
8569 }
8670
87 - static function singleton( &$pfp_gateway_object, &$data ) {
 71+ static function singleton( &$gateway_adapter ) {
8872 if ( !self::$instance ) {
89 - self::$instance = new self( $pfp_gateway_object, $data );
 73+ self::$instance = new self( $gateway_adapter );
9074 }
9175 return self::$instance;
9276 }
 77+
9378 }
Property changes on: trunk/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php
___________________________________________________________________
Added: svn:mergeinfo
9479 Merged /branches/fundraising/extensions/DonationInterface/extras/custom_filters/custom_filters.body.php:r98262-100243
9580 Merged /branches/fundraising/extensions/DonationInterface/payflowpro_gateway/extras/custom_filters/custom_filters.body.php:r95444-98261
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.body.php
@@ -1,6 +1,7 @@
22 <?php
33
4 -class PayflowProGateway_Extras_CustomFilters_Source extends PayflowProGateway_Extras {
 4+class Gateway_Extras_CustomFilters_Source extends Gateway_Extras {
 5+
56 /**
67 * Container for an instance of self
78 * @var object
@@ -13,14 +14,14 @@
1415 */
1516 public $cfo;
1617
17 - public function __construct( &$custom_filter_object ) {
18 - parent::__construct();
19 - $this->cfo =& $custom_filter_object;
 18+ public function __construct( &$gateway_adapter, &$custom_filter_object ) {
 19+ parent::__construct( &$gateway_adapter );
 20+ $this->cfo = & $custom_filter_object;
2021 }
2122
2223 public function filter() {
2324 // pull out the source from the filter object
24 - $source = $this->cfo->gateway_data['utm_source'];
 25+ $source = $this->gateway_adapter->getData( 'utm_source' );
2526
2627 // a very complex filtering algorithm for sources
2728 global $wgCustomFiltersSrcRules;
@@ -37,9 +38,7 @@
3839 $log_msg .= "\t\"" . addslashes( $regex ) . "\"";
3940 $log_msg .= "\t\"" . $this->cfo->risk_score . "\"";
4041 $this->log(
41 - $this->cfo->gateway_data['contribution_tracking_id'],
42 - 'Filter: Source',
43 - $log_msg
 42+ $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Filter: Source', $log_msg
4443 );
4544 }
4645 }
@@ -48,6 +47,7 @@
4948 }
5049
5150 static function onFilter( &$custom_filter_object ) {
 51+ $gateway_adapter->debugarray[] = 'source onFilter hook!';
5252 return self::singleton( $custom_filter_object )->filter();
5353 }
5454
@@ -57,4 +57,5 @@
5858 }
5959 return self::$instance;
6060 }
 61+
6162 }
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/source/source.php
@@ -1,16 +1,16 @@
22 <?php
 3+
34 /**
45 * Provides a method for filtering transactions based on source
56 *
67 * To install:
7 - * require_once( "$IP/extensions/DonationInterface/payflowpro_gateway/extras/custom_filters/filters/source/source.php" );
 8+ * require_once( "$IP/extensions/DonationInterface/extras/custom_filters/filters/source/source.php" );
89 */
9 -
1010 if ( !defined( 'MEDIAWIKI' ) ) {
11 - die( "This file is part of the source custom filter part of the PayflowPro Gateway extension. It is not a valid entry point\n" );
 11+ die( "This file is part of the source custom filter part of the Gateway extension. It is not a valid entry point\n" );
1212 }
1313
14 -$wgExtensionCredits['payflowprogateway_customfilters_source'][] = array(
 14+$wgExtensionCredits['gateway_customfilters_source'][] = array(
1515 'name' => 'custom filter: source',
1616 'author' => 'Arthur Richards',
1717 'url' => '',
@@ -28,7 +28,7 @@
2929 * $wgCustomFiltersSrcRules['support.cc'] = "100";
3030 * // increases risk score for trxns with source of 'support.cc' referrals by 100
3131 */
32 -$wgCustomFiltersSrcRules = array();
 32+$wgCustomFiltersSrcRules = array( );
3333
34 -$wgAutoloadClasses['PayflowProGateway_Extras_CustomFilters_Source'] = dirname( __FILE__ ) . "/source.body.php";
35 -$wgHooks["PayflowGatewayCustomFilter"][] = array( 'PayflowProGateway_Extras_CustomFilters_Source::onFilter' );
 34+$wgAutoloadClasses['Gateway_Extras_CustomFilters_Source'] = dirname( __FILE__ ) . "/source.body.php";
 35+$wgHooks["GatewayCustomFilter"][] = array( 'Gateway_Extras_CustomFilters_Source::onFilter' );
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.body.php
@@ -1,4 +1,5 @@
22 <?php
 3+
34 /**
45 * Wrapper for using minFraud extra as a custom filter
56 *
@@ -6,37 +7,35 @@
78 * with slight modifications. So all we do here is overload validate()
89 * and add in some extra customFilters specific stuff.
910 */
 11+class Gateway_Extras_CustomFilters_MinFraud extends Gateway_Extras_MinFraud {
1012
11 -class PayflowProGateway_Extras_CustomFilters_MinFraud extends PayflowProGateway_Extras_MinFraud {
1213 static $instance;
1314
1415 public function filter( &$custom_filter_object ) {
15 - $pfp_gateway_object =& $custom_filter_object->gateway_object;
16 - $data =& $custom_filter_object->gateway_data;
17 -
1816 // see if we can bypass minfraud
19 - if ( $this->can_bypass_minfraud( $pfp_gateway_object, $data ) ) return TRUE;
 17+ if ( $this->can_bypass_minfraud() )
 18+ return TRUE;
2019
21 - $minfraud_query = $this->build_query( $data );
22 - $this->query_minfraud( $minfraud_query );
23 - $pfp_gateway_object->action = 'Filter';
 20+ $minfraud_query = $this->build_query( $this->gateway_adapter->getData() );
 21+ $this->query_minfraud( $minfraud_query );
 22+ $this->gateway_adapter->action = 'Filter';
2423
2524 $custom_filter_object->risk_score += $this->minfraud_response['riskScore'];
2625
2726 // Write the query/response to the log
2827 // @fixme this will cause the 'action' to be logged even though it's premature here
29 - $this->log_query( $minfraud_query, $pfp_gateway_object, $data );
 28+ $this->log_query( $minfraud_query );
3029 return TRUE;
31 -
3230 }
3331
34 - static function onFilter( &$custom_filter_object ) {
35 - return self::singleton()->filter( $custom_filter_object );
 32+ static function onFilter( &$gateway_adapter, &$custom_filter_object ) {
 33+ $gateway_adapter->debugarray[] = 'minfraud onFilter hook!';
 34+ return self::singleton( &$gateway_adapter )->filter( $custom_filter_object );
3635 }
3736
38 - static function singleton() {
 37+ static function singleton( &$gateway_adapter ) {
3938 if ( !self::$instance ) {
40 - self::$instance = new self;
 39+ self::$instance = new self( &$gateway_adapter );
4140 }
4241 return self::$instance;
4342 }
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/minfraud/minfraud.php
@@ -1,4 +1,5 @@
22 <?php
 3+
34 /**
45 * Custom filter using minFraud
56 *
@@ -12,14 +13,13 @@
1314 * $wgMinFraudStandalone = TRUE
1415 *
1516 * To install:
16 - * require_once( "$IP/extensions/DonationInterface/payflowpro_gateway/extras/custom_filters/filters/minfraud.php" );
 17+ * require_once( "$IP/extensions/DonationInterface/extras/custom_filters/filters/minfraud.php" );
1718 */
18 -
19 - $wgExtensionCredits['payflowprogateway_extras_customfilters_minfraud'][] = array(
20 - 'name' => 'minfraud custom filter',
 19+$wgExtensionCredits['gateway_extras_customfilters_minfraud'][] = array(
 20+ 'name' => 'minfraud custom filter',
2121 'author' => 'Arthur Richards',
2222 'url' => '',
23 - 'description' => 'This extension uses the MaxMind minFraud service as a validator for the Payflow Pro gateway via custom filters.'
 23+ 'description' => 'This extension uses the MaxMind minFraud service as a validator for the gateway via custom filters.'
2424 );
2525
2626 /**
@@ -32,15 +32,16 @@
3333 * you will want to make sure you know whether minFraud queries are
3434 * happening before or after custom filters, defined by the order of
3535 * your require statements in LocalSettings.
 36+ *
 37+ * To install the DontaionInterface extension, put the following line in LocalSettings.php:
 38+ * require_once( "\$IP/extensions/DonationInterface/donationinterface.php" );
 39+ *
 40+ * TODO: Outline required globals to include this bad boy!
 41+ *
3642 */
37 -$wgMinFraudStandalone = FALSE;
3843
39 -$dir = dirname( __FILE__ ) . "/";
40 -$wgAutoloadClasses['PayflowProGateway_Extras_MinFraud'] = $dir . "../../../minfraud/minfraud.body.php";
41 -$wgAutoloadClasses['PayflowProGateway_Extras_CustomFilters_MinFraud'] = $dir . "minfraud.body.php";
42 -$wgExtensionFunctions[] = 'efCustomFiltersMinFraudSetup';
43 -
4444 function efCustomFiltersMinFraudSetup() {
4545 global $wgMinFraudStandalone, $wgHooks;
46 - if ( !$wgMinFraudStandalone ) $wgHooks[ 'PayflowGatewayCustomFilter' ][] = array( "PayflowProGateway_Extras_CustomFilters_MinFraud::onFilter" );
 46+ if ( !$wgMinFraudStandalone )
 47+ $wgHooks['GatewayCustomFilter'][] = array( "Gateway_Extras_CustomFilters_MinFraud::onFilter" );
4748 }
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.php
@@ -1,16 +1,16 @@
22 <?php
 3+
34 /**
45 * Provides a method for filtering transactions based on referrer
56 *
67 * To install:
7 - * require_once( "$IP/extensions/DonationInterface/payflowpro_gateway/extras/custom_filters/filters/referrer/referrer.php" );
 8+ * require_once( "$IP/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.php" );
89 */
9 -
1010 if ( !defined( 'MEDIAWIKI' ) ) {
11 - die( "This file is part of the referrer custom filter part of the PayflowPro Gateway extension. It is not a valid entry point\n" );
 11+ die( "This file is part of the referrer custom filter part of the Gateway extension. It is not a valid entry point\n" );
1212 }
1313
14 -$wgExtensionCredits['payflowprogateway_customfilters_referrer'][] = array(
 14+$wgExtensionCredits['gateway_customfilters_referrer'][] = array(
1515 'name' => 'custom filter: referrer',
1616 'author' => 'Arthur Richards',
1717 'url' => '',
@@ -28,7 +28,7 @@
2929 * $wgCustomFiltersRefRules['fraud\.com'] = "100";
3030 * // increases risk score for trxns with http://fraud.com referrals by 100
3131 */
32 -$wgCustomFiltersRefRules = array();
 32+$wgCustomFiltersRefRules = array( );
3333
34 -$wgAutoloadClasses['PayflowProGateway_Extras_CustomFilters_Referrer'] = dirname( __FILE__ ) . "/referrer.body.php";
35 -$wgHooks["PayflowGatewayCustomFilter"][] = array( 'PayflowProGateway_Extras_CustomFilters_Referrer::onFilter' );
 34+$wgAutoloadClasses['Gateway_Extras_CustomFilters_Referrer'] = dirname( __FILE__ ) . "/referrer.body.php";
 35+$wgHooks["GatewayCustomFilter"][] = array( 'Gateway_Extras_CustomFilters_Referrer::onFilter' );
Index: trunk/extensions/DonationInterface/extras/custom_filters/filters/referrer/referrer.body.php
@@ -1,6 +1,7 @@
22 <?php
33
4 -class PayflowProGateway_Extras_CustomFilters_Referrer extends PayflowProGateway_Extras {
 4+class Gateway_Extras_CustomFilters_Referrer extends Gateway_Extras {
 5+
56 /**
67 * Container for an instance of self
78 * @var object
@@ -13,14 +14,14 @@
1415 */
1516 public $cfo;
1617
17 - public function __construct( &$custom_filter_object ) {
18 - parent::__construct();
19 - $this->cfo =& $custom_filter_object;
 18+ public function __construct( &$gateway_adapter, &$custom_filter_object ) {
 19+ parent::__construct( &$gateway_adapter );
 20+ $this->cfo = & $custom_filter_object;
2021 }
2122
2223 public function filter() {
23 - // pull out the referrer from the filter object
24 - $referrer = $this->cfo->gateway_data['referrer'];
 24+ // pull out the referrer from the gateway_adapter
 25+ $referrer = $this->gateway_adapter->getData( 'referrer' );
2526
2627 // a very complex filtering algorithm for referrers
2728 global $wgCustomFiltersRefRules;
@@ -37,9 +38,7 @@
3839 $log_msg .= "\t\"" . addslashes( $regex ) . "\"";
3940 $log_msg .= "\t\"" . $this->cfo->risk_score . "\"";
4041 $this->log(
41 - $this->cfo->gateway_data['contribution_tracking_id'],
42 - 'Filter: Referrer',
43 - $log_msg
 42+ $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Filter: Referrer', $log_msg
4443 );
4544 }
4645 }
@@ -48,6 +47,7 @@
4948 }
5049
5150 static function onFilter( &$custom_filter_object ) {
 51+ $gateway_adapter->debugarray[] = 'referrer onFilter hook!';
5252 return self::singleton( $custom_filter_object )->filter();
5353 }
5454
@@ -57,4 +57,5 @@
5858 }
5959 return self::$instance;
6060 }
 61+
6162 }
Index: trunk/extensions/DonationInterface/extras/minfraud/ccfd/HTTPBase.php
@@ -20,6 +20,7 @@
2121 */
2222
2323 class HTTPBase {
 24+
2425 var $server;
2526 var $numservers;
2627 var $url;
@@ -35,406 +36,411 @@
3637 var $wsIpaddrCacheFile;
3738 var $useDNS;
3839 var $ipstr;
39 - function __construct() {
40 - $this->isSecure = 0;
41 - $this->debug = 0;
42 - $this->timeout = 0;
43 - $this->check_field = "score";
44 - $this->wsIpaddrRefreshTimeout = 18000;
45 - $this->wsIpaddrCacheFile = $this->_getTempDir() . "/maxmind.ws.cache";
46 - if ( $this->debug == 1 ) {
47 - print "wsIpaddrRefreshTimeout: " . $this->wsIpaddrRefreshTimeout . "\n";
48 - print "wsIpaddrCacheFile: " . $this->wsIpaddrCacheFile . "\n";
49 - print "useDNS: " . $this->useDNS . "\n";
50 - }
51 - }
5240
53 - // this function sets the checked field
54 - function set_check_field( $f ) {
55 - $this->check_field = $f;
56 - }
 41+ //TODO: Instead of passing the gateway_adapter all over the place, we might consider integrating everything for real.
 42+ function __construct( &$gateway_adapter ) {
 43+ $this->gateway_adapter = &$gateway_adapter;
 44+ $this->isSecure = 0;
 45+ $this->debug = 0;
 46+ $this->timeout = 0;
 47+ $this->check_field = "score";
 48+ $this->wsIpaddrRefreshTimeout = 18000;
 49+ $this->wsIpaddrCacheFile = $this->_getTempDir() . "/maxmind.ws.cache";
 50+ if ( $this->debug == 1 ) {
 51+ print "wsIpaddrRefreshTimeout: " . $this->wsIpaddrRefreshTimeout . "\n";
 52+ print "wsIpaddrCacheFile: " . $this->wsIpaddrCacheFile . "\n";
 53+ print "useDNS: " . $this->useDNS . "\n";
 54+ }
 55+ }
5756
58 - // this function sets the allowed fields
59 - function set_allowed_fields( $i ) {
60 - $this->allowed_fields = $i;
61 - $this->num_allowed_fields = count( $i );
62 - }
 57+ // this function sets the checked field
 58+ function set_check_field( $f ) {
 59+ $this->check_field = $f;
 60+ }
6361
64 - // this function queries the servers
65 - function query() {
66 - // query every server in the list
67 - if ( !$this->useDNS ) {
68 - $ipstr = $this->readIpAddressFromCache();
69 - if ( $this->debug == 1 ) {
70 - print "using ip addresses, IPs are " . $ipstr . "\n";
71 - }
72 - }
73 - // query every server using its ip address
74 - // if there was success reading the ip addresses
75 - // from the web or the cache file
76 - if ( $ipstr ) {
77 - $ipaddr = explode( ";", $ipstr );
78 - $numipaddr = count( $ipaddr );
79 - for ( $i = 0; $i < $numipaddr; $i++ ) {
80 - $result = $this->querySingleServer( $ipaddr[$i] );
81 - if ( $this->debug == 1 ) {
82 - print "ip address: " . $ipaddr[$i] . "\n";
83 - print "result: " . $result . "\n";
 62+ // this function sets the allowed fields
 63+ function set_allowed_fields( $i ) {
 64+ $this->allowed_fields = $i;
 65+ $this->num_allowed_fields = count( $i );
8466 }
85 - if ( $result ) {
86 - return $result;
87 - }
88 - }
89 - }
9067
91 - // query every server using its domain name
92 - for ( $i = 0; $i < $this->numservers; $i++ ) {
93 - $result = $this->querySingleServer( $this->server[$i] );
94 - if ( $this->debug == 1 ) {
95 - print "server: " . $this->server[$i] . "\nresult: " . $result . "\n";
96 - }
97 - if ( $result ) {
98 - return $result;
99 - }
100 - }
101 - return 0;
102 - }
 68+ // this function queries the servers
 69+ function query() {
 70+ // query every server in the list
 71+ if ( !$this->useDNS ) {
 72+ $ipstr = $this->readIpAddressFromCache();
 73+ if ( $this->debug == 1 ) {
 74+ print "using ip addresses, IPs are " . $ipstr . "\n";
 75+ }
 76+ }
 77+ // query every server using its ip address
 78+ // if there was success reading the ip addresses
 79+ // from the web or the cache file
 80+ if ( $ipstr ) {
 81+ $ipaddr = explode( ";", $ipstr );
 82+ $numipaddr = count( $ipaddr );
 83+ for ( $i = 0; $i < $numipaddr; $i++ ) {
 84+ $result = $this->querySingleServer( $ipaddr[$i] );
 85+ if ( $this->debug == 1 ) {
 86+ print "ip address: " . $ipaddr[$i] . "\n";
 87+ print "result: " . $result . "\n";
 88+ }
 89+ if ( $result ) {
 90+ return $result;
 91+ }
 92+ }
 93+ }
10394
104 - // this function takes a input hash and stores it in the hash named queries
105 - function input( $vars ) {
106 - $numinputkeys = count( $vars ); // get the number of keys in the input hash
107 - $inputkeys = array_keys( $vars ); // get a array of keys in the input hash
108 - for ( $i = 0; $i < $numinputkeys; $i++ ) {
109 - $key = $inputkeys[$i];
110 - if ( $this->allowed_fields[$key] == 1 ) {
111 - // if key is a allowed field then store it in
112 - // the hash named queries
113 - $this->queries[$key] = urlencode( $this->filter_field( $key, $vars[$key] ) );
114 - } else {
115 - print "invalid input $key - perhaps misspelled field?";
116 - return 0;
117 - }
118 - }
119 - $this->queries["clientAPI"] = $this->API_VERSION;
120 - }
 95+ // query every server using its domain name
 96+ for ( $i = 0; $i < $this->numservers; $i++ ) {
 97+ $result = $this->querySingleServer( $this->server[$i] );
 98+ if ( $this->debug == 1 ) {
 99+ print "server: " . $this->server[$i] . "\nresult: " . $result . "\n";
 100+ }
 101+ if ( $result ) {
 102+ return $result;
 103+ }
 104+ }
 105+ return 0;
 106+ }
121107
122 - // sub-class should override this if it needs to filter inputs
123 - function filter_field( $key, $value ) {
124 - return $value;
125 - }
 108+ // this function takes a input hash and stores it in the hash named queries
 109+ function input( $vars ) {
 110+ $numinputkeys = count( $vars ); // get the number of keys in the input hash
 111+ $inputkeys = array_keys( $vars ); // get a array of keys in the input hash
 112+ for ( $i = 0; $i < $numinputkeys; $i++ ) {
 113+ $key = $inputkeys[$i];
 114+ if ( $this->allowed_fields[$key] == 1 ) {
 115+ // if key is a allowed field then store it in
 116+ // the hash named queries
 117+ $this->queries[$key] = urlencode( $this->filter_field( $key, $vars[$key] ) );
 118+ } else {
 119+ print "invalid input $key - perhaps misspelled field?";
 120+ return 0;
 121+ }
 122+ }
 123+ $this->queries["clientAPI"] = $this->API_VERSION;
 124+ }
126125
127 - // this function returns the output from the server
128 - function output() {
129 - return $this->outputstr;
130 - }
 126+ // sub-class should override this if it needs to filter inputs
 127+ function filter_field( $key, $value ) {
 128+ return $value;
 129+ }
131130
132 - // write the ip Addresses and the time right now to
133 - // the cache file
134 - function writeIpAddressToCache( $filename, $ipstr ) {
135 - $datetime = time();
136 - $fh = fopen( $this->wsIpaddrCacheFile, 'w' );
137 - fwrite( $fh, $ipstr . "\n" );
138 - fwrite( $fh, $datetime . "\n" );
139 - fclose( $fh );
140 - if ( $this->debug == 1 ) {
141 - print "writing ip address to cache\n";
142 - print "ip str: " . $ipstr . "\n";
143 - print "date time: " . $datetime . "\n";
144 - }
145 - }
 131+ // this function returns the output from the server
 132+ function output() {
 133+ return $this->outputstr;
 134+ }
146135
147 - function readIpAddressFromCache() {
148 - // if the cache file exists then
149 - // read the ip addresses and the time
150 - // IPs were cached
151 - if ( file_exists( $this->wsIpaddrCacheFile ) ) {
152 - $fh = fopen( $this->wsIpaddrCacheFile, 'r' );
153 - $ipstr = fgets( $fh, 1024 );
154 - $ipstr = rtrim( $ipstr );
155 - $datetime = fgets( $fh, 1024 );
156 - $datetime = rtrim( $datetime );
157 - fclose( $fh );
158 - }
 136+ // write the ip Addresses and the time right now to
 137+ // the cache file
 138+ function writeIpAddressToCache( $filename, $ipstr ) {
 139+ $datetime = time();
 140+ $fh = fopen( $this->wsIpaddrCacheFile, 'w' );
 141+ fwrite( $fh, $ipstr . "\n" );
 142+ fwrite( $fh, $datetime . "\n" );
 143+ fclose( $fh );
 144+ if ( $this->debug == 1 ) {
 145+ print "writing ip address to cache\n";
 146+ print "ip str: " . $ipstr . "\n";
 147+ print "date time: " . $datetime . "\n";
 148+ }
 149+ }
159150
160 - // if the ip addresses expired or don't exist then
161 - // get them from the web and write
162 - // them to the cache file
163 - if ( ( ( time() - $datetime ) > $this->wsIpaddrRefreshTimeout ) | ( !$ipstr ) ) {
164 - $tryIpstr = $this->readIpAddressFromWeb();
165 - if ( $tryIpstr ) {
166 - $ipstr = $tryIpstr;
167 - } else {
168 - if ( $this->debug == 1 ) {
169 - print "Warning, unable to get ws_ipaddr from www.maxmind.com\n";
170 - }
171 - }
172 - // we write to cache whether or not we were able to get $tryIpStr, since
173 - // in case DNS goes down, we don't want to check app/ws_ipaddr over and over
174 - $this->writeIpAddressToCache( $this->wsIpaddrCacheFile, $ipstr );
175 - }
176 - if ( $this->debug == 1 ) {
177 - print "reading ip address from cache\n";
178 - print "ip str: " . $ipstr . "\n";
179 - print "date time: " . $datetime . "\n";
180 - }
181 - // return the ip addresses
182 - return $ipstr;
183 - }
 151+ function readIpAddressFromCache() {
 152+ // if the cache file exists then
 153+ // read the ip addresses and the time
 154+ // IPs were cached
 155+ if ( file_exists( $this->wsIpaddrCacheFile ) ) {
 156+ $fh = fopen( $this->wsIpaddrCacheFile, 'r' );
 157+ $ipstr = fgets( $fh, 1024 );
 158+ $ipstr = rtrim( $ipstr );
 159+ $datetime = fgets( $fh, 1024 );
 160+ $datetime = rtrim( $datetime );
 161+ fclose( $fh );
 162+ } else {
 163+ //otherwise, this thing complains loudly when the file doesn't exist.
 164+ $datetime = time();
 165+ }
184166
185 - function readIpAddressFromWeb() {
186 - // check if the curl module exists
187 - $url = "http://www.maxmind.com/app/ws_ipaddr";
188 - if ( extension_loaded( 'curl' ) ) {
189 - // open curl
190 - $ch = curl_init();
 167+ // if the ip addresses expired or don't exist then
 168+ // get them from the web and write
 169+ // them to the cache file
 170+ if ( ( ( time() - $datetime ) > $this->wsIpaddrRefreshTimeout ) | (!$ipstr ) ) {
 171+ $tryIpstr = $this->readIpAddressFromWeb();
 172+ if ( $tryIpstr ) {
 173+ $ipstr = $tryIpstr;
 174+ } else {
 175+ if ( $this->debug == 1 ) {
 176+ print "Warning, unable to get ws_ipaddr from www.maxmind.com\n";
 177+ }
 178+ }
 179+ // we write to cache whether or not we were able to get $tryIpStr, since
 180+ // in case DNS goes down, we don't want to check app/ws_ipaddr over and over
 181+ $this->writeIpAddressToCache( $this->wsIpaddrCacheFile, $ipstr );
 182+ }
 183+ if ( $this->debug == 1 ) {
 184+ print "reading ip address from cache\n";
 185+ print "ip str: " . $ipstr . "\n";
 186+ print "date time: " . $datetime . "\n";
 187+ }
 188+ // return the ip addresses
 189+ return $ipstr;
 190+ }
191191
192 - // set curl options
193 - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
194 - curl_setopt( $ch, CURLOPT_URL, $url );
195 - curl_setopt( $ch, CURLOPT_TIMEOUT, $this->timeout );
 192+ function readIpAddressFromWeb() {
 193+ // check if the curl module exists
 194+ $url = "http://www.maxmind.com/app/ws_ipaddr";
 195+ if ( extension_loaded( 'curl' ) ) {
 196+ // open curl
 197+ $ch = curl_init();
196198
197 - // get the content
198 - $content = curl_exec( $ch );
199 - $content = rtrim( $content );
200 - if ( $this->debug == 1 ) {
201 - print "using curl\n";
202 - }
203 - } else {
204 - // we using HTTP without curl
 199+ // set curl options
 200+ curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
 201+ curl_setopt( $ch, CURLOPT_URL, $url );
 202+ curl_setopt( $ch, CURLOPT_TIMEOUT, $this->timeout );
205203
206 - // parse the url to get
207 - // host, path and query
208 - $url3 = parse_url( $url );
209 - $host = $url3["host"];
210 - $path = $url3["path"];
 204+ // get the content
 205+ $content = curl_exec( $ch );
 206+ $content = rtrim( $content );
 207+ if ( $this->debug == 1 ) {
 208+ print "using curl\n";
 209+ }
 210+ } else {
 211+ // we using HTTP without curl
 212+ // parse the url to get
 213+ // host, path and query
 214+ $url3 = parse_url( $url );
 215+ $host = $url3["host"];
 216+ $path = $url3["path"];
211217
212 - // open the connection
213 - $fp = fsockopen ( $host, 80, $errno, $errstr, $this->timeout );
214 - if ( $fp ) {
215 - // send the request
216 - fputs ( $fp, "GET $path HTTP/1.0\nHost: " . $host . "\n\n" );
217 - while ( !feof( $fp ) ) {
218 - $buf .= fgets( $fp, 128 );
219 - }
220 - $lines = preg_split( "/\n/", $buf );
221 - // get the content
222 - $content = $lines[count( $lines ) -1];
223 - // close the connection
224 - fclose( $fp );
225 - }
226 - if ( $this->debug == 1 ) {
227 - print "using fsockopen\n";
228 - }
229 - }
230 - if ( $this->debug == 1 ) {
231 - print "readIpAddressFromWeb found ip addresses: " . $content . "\n";
232 - }
233 - // TODO fix regexp so that it checks if it only has IP addresses
234 - if ( preg_match( "/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/", $content ) ) {
235 - return $content;
236 - }
237 - return "";
238 - }
 218+ // open the connection
 219+ $fp = fsockopen( $host, 80, $errno, $errstr, $this->timeout );
 220+ if ( $fp ) {
 221+ // send the request
 222+ fputs( $fp, "GET $path HTTP/1.0\nHost: " . $host . "\n\n" );
 223+ while ( !feof( $fp ) ) {
 224+ $buf .= fgets( $fp, 128 );
 225+ }
 226+ $lines = preg_split( "/\n/", $buf );
 227+ // get the content
 228+ $content = $lines[count( $lines ) - 1];
 229+ // close the connection
 230+ fclose( $fp );
 231+ }
 232+ if ( $this->debug == 1 ) {
 233+ print "using fsockopen\n";
 234+ }
 235+ }
 236+ if ( $this->debug == 1 ) {
 237+ print "readIpAddressFromWeb found ip addresses: " . $content . "\n";
 238+ }
 239+ // TODO fix regexp so that it checks if it only has IP addresses
 240+ if ( preg_match( "/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/", $content ) ) {
 241+ return $content;
 242+ }
 243+ return "";
 244+ }
239245
240 - // this function queries a single server
241 - function querySingleServer( $server ) {
242 - global $wgPayflowGatewayUseHTTPProxy, $wgPayflowGatewayHTTPProxy;
 246+ // this function queries a single server
 247+ function querySingleServer( $server ) {
 248+ $useHTTPProxy = $this->gateway_adapter->getGlobal( 'UseHTTPProxy' );
 249+ $HTTPProxy = $this->gateway_adapter->getGlobal( 'HTTPProxy' );
243250
244 - // check if we using the Secure HTTPS proctol
245 - if ( $this->isSecure == 1 ) {
246 - $scheme = "https://"; // Secure HTTPS proctol
247 - } else {
248 - $scheme = "http://"; // Regular HTTP proctol
249 - }
 251+ // check if we using the Secure HTTPS proctol
 252+ if ( $this->isSecure == 1 ) {
 253+ $scheme = "https://"; // Secure HTTPS proctol
 254+ } else {
 255+ $scheme = "http://"; // Regular HTTP proctol
 256+ }
250257
251 - // build a query string from the hash called queries
252 - $numquerieskeys = count( $this->queries ); // get the number of keys in the hash called queries
253 - $querieskeys = array_keys( $this->queries ); // get a array of keys in the hash called queries
254 - if ( $this->debug == 1 ) {
255 - print "number of query keys " . $numquerieskeys . "\n";
256 - }
 258+ // build a query string from the hash called queries
 259+ $numquerieskeys = count( $this->queries ); // get the number of keys in the hash called queries
 260+ $querieskeys = array_keys( $this->queries ); // get a array of keys in the hash called queries
 261+ if ( $this->debug == 1 ) {
 262+ print "number of query keys " . $numquerieskeys . "\n";
 263+ }
257264
258 - $query_string = "";
 265+ $query_string = "";
259266
260 - for ( $i = 0; $i < $numquerieskeys; $i++ ) {
261 - // for each element in the hash called queries
262 - // append the key and value of the element to the query string
263 - $key = $querieskeys[$i];
264 - $value = $this->queries[$key];
265 - // encode the key and value before adding it to the string
266 - // $key = urlencode($key);
267 - // $value = urlencode($value);
268 - if ( $this->debug == 1 ) {
269 - print " query key " . $key . " query value " . $value . "\n";
270 - }
271 - $query_string = $query_string . $key . "=" . $value;
272 - if ( $i < $numquerieskeys - 1 ) {
273 - $query_string = $query_string . "&";
274 - }
275 - }
 267+ for ( $i = 0; $i < $numquerieskeys; $i++ ) {
 268+ // for each element in the hash called queries
 269+ // append the key and value of the element to the query string
 270+ $key = $querieskeys[$i];
 271+ $value = $this->queries[$key];
 272+ // encode the key and value before adding it to the string
 273+ // $key = urlencode($key);
 274+ // $value = urlencode($value);
 275+ if ( $this->debug == 1 ) {
 276+ print " query key " . $key . " query value " . $value . "\n";
 277+ }
 278+ $query_string = $query_string . $key . "=" . $value;
 279+ if ( $i < $numquerieskeys - 1 ) {
 280+ $query_string = $query_string . "&";
 281+ }
 282+ }
276283
277 - // check if the curl module exists
278 - if ( extension_loaded( 'curl' ) ) {
279 - // use curl
280 - if ( $this->debug == 1 ) {
281 - print "using curl\n";
282 - }
 284+ // check if the curl module exists
 285+ if ( extension_loaded( 'curl' ) ) {
 286+ // use curl
 287+ if ( $this->debug == 1 ) {
 288+ print "using curl\n";
 289+ }
283290
284 - // open curl
285 - $ch = curl_init();
 291+ // open curl
 292+ $ch = curl_init();
286293
287 - $url = $scheme . $server . "/" . $this->url;
 294+ $url = $scheme . $server . "/" . $this->url;
288295
289 - // set curl options
290 - if ( $this->debug == 1 ) {
291 - print "url " . $url . "\n";
292 - }
293 - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
294 - curl_setopt( $ch, CURLOPT_URL, $url );
295 - curl_setopt( $ch, CURLOPT_TIMEOUT, $this->timeout );
296 - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
 296+ // set curl options
 297+ if ( $this->debug == 1 ) {
 298+ print "url " . $url . "\n";
 299+ }
 300+ curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
 301+ curl_setopt( $ch, CURLOPT_URL, $url );
 302+ curl_setopt( $ch, CURLOPT_TIMEOUT, $this->timeout );
 303+ curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
297304
298 - // this option lets you store the result in a string
299 - curl_setopt( $ch, CURLOPT_POST, 1 );
300 - curl_setopt( $ch, CURLOPT_POSTFIELDS, $query_string );
 305+ // this option lets you store the result in a string
 306+ curl_setopt( $ch, CURLOPT_POST, 1 );
 307+ curl_setopt( $ch, CURLOPT_POSTFIELDS, $query_string );
301308
302 - // set proxy settings if necessary
303 - if ( $wgPayflowGatewayUseHTTPProxy ) {
304 - curl_setopt( $ch, CURLOPT_HTTPPROXYTUNNEL, 1 );
305 - curl_setopt( $ch, CURLOPT_PROXY, $wgPayflowGatewayHTTPProxy );
306 - }
 309+ // set proxy settings if necessary
 310+ if ( $useHTTPProxy ) {
 311+ curl_setopt( $ch, CURLOPT_HTTPPROXYTUNNEL, 1 );
 312+ curl_setopt( $ch, CURLOPT_PROXY, $HTTPProxy );
 313+ }
307314
308 - // get the content
309 - $content = curl_exec( $ch );
 315+ // get the content
 316+ $content = curl_exec( $ch );
310317
311 - // For some reason curl_errno returns an error even when function works
312 - // Until we figure this out, will ignore curl errors - (not good i know)
 318+ // For some reason curl_errno returns an error even when function works
 319+ // Until we figure this out, will ignore curl errors - (not good i know)
313320 // $e = curl_errno($ch);//get error or sucess
314 -
315321 // if (($e == 1) & ($this->isSecure == 1)) {
316 - // HTTPS does not work print error message
 322+ // HTTPS does not work print error message
317323 // print "error: this version of curl does not support HTTPS try build curl with SSL or specify \$ccfs->isSecure = 0\n";
318324 // }
319325 // if ($e > 0) {
320 - // we get a error msg print it
 326+ // we get a error msg print it
321327 // print "Received error message $e from curl: " . curl_error($ch) . "\n";
322328 // return 0;
323329 // }
324 - // close curl
325 - curl_close( $ch );
326 - } else {
327 - // curl does not exist
328 - // use the fsockopen function,
329 - // the fgets function and the fclose function
330 - if ( $this->debug == 1 ) {
331 - print "using fsockopen for querySingleServer\n";
332 - }
 330+ // close curl
 331+ curl_close( $ch );
 332+ } else {
 333+ // curl does not exist
 334+ // use the fsockopen function,
 335+ // the fgets function and the fclose function
 336+ if ( $this->debug == 1 ) {
 337+ print "using fsockopen for querySingleServer\n";
 338+ }
333339
334 - $url = $scheme . $server . "/" . $this->url . "?" . $query_string;
335 - if ( $this->debug == 1 ) {
336 - print "url " . $url . " " . "\n";
337 - }
 340+ $url = $scheme . $server . "/" . $this->url . "?" . $query_string;
 341+ if ( $this->debug == 1 ) {
 342+ print "url " . $url . " " . "\n";
 343+ }
338344
339 - // now check if we are using regular HTTP
340 - if ( $this->isSecure == 0 ) {
341 - // we using regular HTTP
 345+ // now check if we are using regular HTTP
 346+ if ( $this->isSecure == 0 ) {
 347+ // we using regular HTTP
 348+ // parse the url to get
 349+ // host, path and query
 350+ $url3 = parse_url( $url );
 351+ $host = $url3["host"];
 352+ $path = $url3["path"];
 353+ $query = $url3["query"];
342354
343 - // parse the url to get
344 - // host, path and query
345 - $url3 = parse_url( $url );
346 - $host = $url3["host"];
347 - $path = $url3["path"];
348 - $query = $url3["query"];
 355+ // open the connection
 356+ $fp = fsockopen( $host, 80, $errno, $errstr, $this->timeout );
 357+ if ( $fp ) {
 358+ // send the request
 359+ $post = "POST $path HTTP/1.0\nHost: " . $host . "\nContent-type: application/x-www-form-urlencoded\nUser-Agent: Mozilla 4.0\nContent-length: " . strlen( $query ) . "\nConnection: close\n\n$query";
 360+ fputs( $fp, $post );
 361+ while ( !feof( $fp ) ) {
 362+ $buf .= fgets( $fp, 128 );
 363+ }
 364+ $lines = preg_split( "/\n/", $buf );
 365+ // get the content
 366+ $content = $lines[count( $lines ) - 1];
 367+ // close the connection
 368+ fclose( $fp );
 369+ } else {
 370+ return 0;
 371+ }
 372+ } else {
 373+ // secure HTTPS requires CURL
 374+ print "error: you need to install curl if you want secure HTTPS or specify the variable to be $ccfs->isSecure = 0";
 375+ return 0;
 376+ }
 377+ }
349378
350 - // open the connection
351 - $fp = fsockopen ( $host, 80, $errno, $errstr, $this->timeout );
352 - if ( $fp ) {
353 - // send the request
354 - $post = "POST $path HTTP/1.0\nHost: " . $host . "\nContent-type: application/x-www-form-urlencoded\nUser-Agent: Mozilla 4.0\nContent-length: " . strlen( $query ) . "\nConnection: close\n\n$query";
355 - fputs ( $fp, $post );
356 - while ( !feof( $fp ) ) {
357 - $buf .= fgets( $fp, 128 );
358 - }
359 - $lines = preg_split( "/\n/", $buf );
360 - // get the content
361 - $content = $lines[count( $lines ) -1];
362 - // close the connection
363 - fclose( $fp );
364 - } else {
365 - return 0;
366 - }
367 - } else {
368 - // secure HTTPS requires CURL
369 - print "error: you need to install curl if you want secure HTTPS or specify the variable to be $ccfs->isSecure = 0";
370 - return 0;
371 - }
372 - }
 379+ if ( $this->debug == 1 ) {
 380+ print "content = " . $content . "\n";
 381+ }
 382+ // get the keys and values from
 383+ // the string content and store them
 384+ // the hash named outputstr
 385+ // split content into pairs containing both
 386+ // the key and the value
 387+ $keyvaluepairs = explode( ";", $content );
373388
374 - if ( $this->debug == 1 ) {
375 - print "content = " . $content . "\n";
376 - }
377 - // get the keys and values from
378 - // the string content and store them
379 - // the hash named outputstr
 389+ // get the number of key and value pairs
 390+ $numkeyvaluepairs = count( $keyvaluepairs );
380391
381 - // split content into pairs containing both
382 - // the key and the value
383 - $keyvaluepairs = explode( ";", $content );
 392+ // for each pair store key and value into the
 393+ // hash named outputstr
 394+ $this->outputstr = array( );
 395+ for ( $i = 0; $i < $numkeyvaluepairs; $i++ ) {
 396+ // split the pair into a key and a value
 397+ list( $key, $value ) = explode( "=", $keyvaluepairs[$i] );
 398+ if ( $this->debug == 1 ) {
 399+ print " output " . $key . " = " . $value . "\n";
 400+ }
 401+ // store the key and the value into the
 402+ // hash named outputstr
 403+ $this->outputstr[$key] = $value;
 404+ }
 405+ // check if outputstr has the score if outputstr does not have
 406+ // the score return 0
 407+ if ( $this->outputstr[$this->check_field] == "" ) {
 408+ return 0;
 409+ }
 410+ // one other way to do it
 411+ // if (!array_key_exists("score",$this->outputstr)) {
 412+ // return 0;
 413+ // }
 414+ return 1;
 415+ }
384416
385 - // get the number of key and value pairs
386 - $numkeyvaluepairs = count( $keyvaluepairs );
 417+ function _getTempDir() {
 418+ if ( ini_get( 'upload_tmp_dir' ) ) {
 419+ return ini_get( 'upload_tmp_dir' );
 420+ }
387421
388 - // for each pair store key and value into the
389 - // hash named outputstr
390 - $this->outputstr = array();
391 - for ( $i = 0; $i < $numkeyvaluepairs; $i++ ) {
392 - // split the pair into a key and a value
393 - list( $key, $value ) = explode( "=", $keyvaluepairs[$i] );
394 - if ( $this->debug == 1 ) {
395 - print " output " . $key . " = " . $value . "\n";
396 - }
397 - // store the key and the value into the
398 - // hash named outputstr
399 - $this->outputstr[$key] = $value;
400 - }
401 - // check if outputstr has the score if outputstr does not have
402 - // the score return 0
403 - if ( $this->outputstr[$this->check_field] == "" ) {
404 - return 0;
405 - }
406 - // one other way to do it
407 - // if (!array_key_exists("score",$this->outputstr)) {
408 - // return 0;
409 - // }
410 - return 1;
411 - }
 422+ if ( substr( PHP_OS, 0, 3 ) != 'WIN' ) {
 423+ return '/tmp';
 424+ }
412425
413 - function _getTempDir() {
414 - if ( ini_get( 'upload_tmp_dir' ) ) {
415 - return ini_get( 'upload_tmp_dir' );
416 - }
 426+ if ( isset( $_ENV['TMP'] ) ) {
 427+ return $_ENV['TMP'];
 428+ }
417429
418 - if ( substr( PHP_OS, 0, 3 ) != 'WIN' ) {
419 - return '/tmp';
420 - }
 430+ if ( isset( $_ENV['TEMP'] ) ) {
 431+ return $_ENV['TEMP'];
 432+ }
421433
422 - if ( isset( $_ENV['TMP'] ) ) {
423 - return $_ENV['TMP'];
424 - }
 434+ if ( is_dir( 'c:\\windows\\temp' ) ) {
 435+ return 'c:\\windows\\temp';
 436+ }
425437
426 - if ( isset( $_ENV['TEMP'] ) ) {
427 - return $_ENV['TEMP'];
428 - }
 438+ if ( is_dir( 'c:\\winnt\\temp' ) ) {
 439+ return 'c:\\winnt\\temp';
 440+ }
429441
430 - if ( is_dir( 'c:\\windows\\temp' ) ) {
431 - return 'c:\\windows\\temp';
432 - }
 442+ return '.';
 443+ }
433444
434 - if ( is_dir( 'c:\\winnt\\temp' ) ) {
435 - return 'c:\\winnt\\temp';
436 - }
 445+}
437446
438 - return '.';
439 - }
440 -}
441447 ?>
Index: trunk/extensions/DonationInterface/extras/minfraud/ccfd/LocationVerification.php
@@ -20,31 +20,34 @@
2121 */
2222
2323 require_once ( "HTTPBase.php" );
 24+
2425 class LocationVerification extends HTTPBase {
25 - var $server;
26 - var $numservers;
27 - var $API_VERSION;
2826
29 - function __construct() {
30 - parent::__construct();
31 - $this->isSecure = 1; // use HTTPS by default
 27+ var $server;
 28+ var $numservers;
 29+ var $API_VERSION;
3230
33 - // set the allowed_fields hash
34 - $this->allowed_fields["i"] = 1;
35 - $this->allowed_fields["city"] = 1;
36 - $this->allowed_fields["region"] = 1;
37 - $this->allowed_fields["postal"] = 1;
38 - $this->allowed_fields["country"] = 1;
39 - $this->allowed_fields["license_key"] = 1;
40 - $this->num_allowed_fields = count( $this->allowed_fields );
 31+ function __construct( &$gateway_adapter ) {
 32+ parent::__construct( &$gateway_adapter );
 33+ $this->isSecure = 1; // use HTTPS by default
 34+ // set the allowed_fields hash
 35+ $this->allowed_fields["i"] = 1;
 36+ $this->allowed_fields["city"] = 1;
 37+ $this->allowed_fields["region"] = 1;
 38+ $this->allowed_fields["postal"] = 1;
 39+ $this->allowed_fields["country"] = 1;
 40+ $this->allowed_fields["license_key"] = 1;
 41+ $this->num_allowed_fields = count( $this->allowed_fields );
4142
42 - // set the url of the web service
43 - $this->url = "app/locvr";
44 - $this->check_field = "distance";
 43+ // set the url of the web service
 44+ $this->url = "app/locvr";
 45+ $this->check_field = "distance";
4546
46 - $this->server = array( "www.maxmind.com", "www2.maxmind.com" );
47 - $this->numservers = count( $this->server );
48 - $this->API_VERSION = 'PHP/1.4';
49 - }
 47+ $this->server = array( "www.maxmind.com", "www2.maxmind.com" );
 48+ $this->numservers = count( $this->server );
 49+ $this->API_VERSION = 'PHP/1.4';
 50+ }
 51+
5052 }
 53+
5154 ?>
Index: trunk/extensions/DonationInterface/extras/minfraud/ccfd/CreditCardFraudDetection.php
@@ -20,64 +20,67 @@
2121 */
2222
2323 require_once ( "HTTPBase.php" );
 24+
2425 class CreditCardFraudDetection extends HTTPBase {
25 - var $server;
26 - var $numservers;
27 - var $API_VERSION;
2826
29 - function __construct() {
30 - parent::__construct();
31 - $this->isSecure = 1; // use HTTPS by default
 27+ var $server;
 28+ var $numservers;
 29+ var $API_VERSION;
3230
33 - // set the allowed_fields hash
34 - $this->allowed_fields["i"] = 1;
35 - $this->allowed_fields["domain"] = 1;
36 - $this->allowed_fields["city"] = 1;
37 - $this->allowed_fields["region"] = 1;
38 - $this->allowed_fields["postal"] = 1;
39 - $this->allowed_fields["country"] = 1;
40 - $this->allowed_fields["bin"] = 1;
41 - $this->allowed_fields["binName"] = 1;
42 - $this->allowed_fields["binPhone"] = 1;
43 - $this->allowed_fields["custPhone"] = 1;
44 - $this->allowed_fields["license_key"] = 1;
45 - $this->allowed_fields["requested_type"] = 1;
46 - $this->allowed_fields["forwardedIP"] = 1;
47 - $this->allowed_fields["emailMD5"] = 1;
48 - $this->allowed_fields["shipAddr"] = 1;
49 - $this->allowed_fields["shipCity"] = 1;
50 - $this->allowed_fields["shipRegion"] = 1;
51 - $this->allowed_fields["shipPostal"] = 1;
52 - $this->allowed_fields["shipCountry"] = 1;
53 - $this->allowed_fields["txnID"] = 1;
54 - $this->allowed_fields["sessionID"] = 1;
55 - $this->allowed_fields["usernameMD5"] = 1;
56 - $this->allowed_fields["passwordMD5"] = 1;
57 - $this->allowed_fields["user_agent"] = 1;
58 - $this->allowed_fields["accept_language"] = 1;
 31+ function __construct( &$gateway_adapter ) {
 32+ parent::__construct( $gateway_adapter );
 33+ $this->isSecure = 1; // use HTTPS by default
 34+ // set the allowed_fields hash
 35+ $this->allowed_fields["i"] = 1;
 36+ $this->allowed_fields["domain"] = 1;
 37+ $this->allowed_fields["city"] = 1;
 38+ $this->allowed_fields["region"] = 1;
 39+ $this->allowed_fields["postal"] = 1;
 40+ $this->allowed_fields["country"] = 1;
 41+ $this->allowed_fields["bin"] = 1;
 42+ $this->allowed_fields["binName"] = 1;
 43+ $this->allowed_fields["binPhone"] = 1;
 44+ $this->allowed_fields["custPhone"] = 1;
 45+ $this->allowed_fields["license_key"] = 1;
 46+ $this->allowed_fields["requested_type"] = 1;
 47+ $this->allowed_fields["forwardedIP"] = 1;
 48+ $this->allowed_fields["emailMD5"] = 1;
 49+ $this->allowed_fields["shipAddr"] = 1;
 50+ $this->allowed_fields["shipCity"] = 1;
 51+ $this->allowed_fields["shipRegion"] = 1;
 52+ $this->allowed_fields["shipPostal"] = 1;
 53+ $this->allowed_fields["shipCountry"] = 1;
 54+ $this->allowed_fields["txnID"] = 1;
 55+ $this->allowed_fields["sessionID"] = 1;
 56+ $this->allowed_fields["usernameMD5"] = 1;
 57+ $this->allowed_fields["passwordMD5"] = 1;
 58+ $this->allowed_fields["user_agent"] = 1;
 59+ $this->allowed_fields["accept_language"] = 1;
5960
6061
61 - $this->num_allowed_fields = count( $this->allowed_fields );
 62+ $this->num_allowed_fields = count( $this->allowed_fields );
6263
63 - // set the url of the web service
64 - $this->url = "app/ccv2r";
65 - $this->check_field = "score";
66 - $this->server = array( "minfraud3.maxmind.com", "minfraud1.maxmind.com", "minfraud2.maxmind.com" );
67 - $this->numservers = count( $this->server );
68 - $this->API_VERSION = 'PHP/1.49';
69 - }
 64+ // set the url of the web service
 65+ $this->url = "app/ccv2r";
 66+ $this->check_field = "score";
 67+ $this->server = array( "minfraud3.maxmind.com", "minfraud1.maxmind.com", "minfraud2.maxmind.com" );
 68+ $this->numservers = count( $this->server );
 69+ $this->API_VERSION = 'PHP/1.49';
 70+ }
7071
71 - function filter_field( $key, $value ) {
72 - if ( $key == 'emailMD5' ) {
73 - if ( preg_match( '/@/', $value ) ) {
74 - return md5( strtolower( $value ) );
75 - }
76 - } elseif ( $key == 'usernameMD5' || $key == 'passwordMD5' ) {
77 - if ( strlen( $value ) != 32 ) {
78 - return md5( strtolower( $value ) );
79 - }
80 - }
81 - return $value;
82 - }
 72+ function filter_field( $key, $value ) {
 73+ if ( $key == 'emailMD5' ) {
 74+ if ( preg_match( '/@/', $value ) ) {
 75+ return md5( strtolower( $value ) );
 76+ }
 77+ } elseif ( $key == 'usernameMD5' || $key == 'passwordMD5' ) {
 78+ if ( strlen( $value ) != 32 ) {
 79+ return md5( strtolower( $value ) );
 80+ }
 81+ }
 82+ return $value;
 83+ }
 84+
8385 }
 86+
8487 ?>
Index: trunk/extensions/DonationInterface/extras/minfraud/ccfd/TelephoneVerification.php
@@ -1,26 +1,31 @@
22 <?php
 3+
34 require_once ( "HTTPBase.php" );
 5+
46 class TelephoneVerification extends HTTPBase {
5 - var $server;
6 - var $numservers;
7 - var $API_VERSION;
8 - function __construct() {
9 - parent::__construct();
10 - $this->isSecure = 1; // use HTTPS by default
117
12 - // set the allowed_fields hash
13 - $this->allowed_fields["l"] = 1;
14 - $this->allowed_fields["phone"] = 1;
15 - $this->allowed_fields["verify_code"] = 1;
16 - $this->num_allowed_fields = count( $this->allowed_fields );
 8+ var $server;
 9+ var $numservers;
 10+ var $API_VERSION;
1711
18 - // set the url of the web service
19 - $this->url = "app/telephone_http";
20 - $this->check_field = "refid";
21 - $this->server = array( "www.maxmind.com", "www2.maxmind.com" );
22 - $this->numservers = count( $this->server );
23 - $this->API_VERSION = 'PHP/1.4';
24 - $this->timeout = 30;
25 - }
 12+ function __construct( &$gateway_adapter ) {
 13+ parent::__construct( &$gateway_adapter );
 14+ $this->isSecure = 1; // use HTTPS by default
 15+ // set the allowed_fields hash
 16+ $this->allowed_fields["l"] = 1;
 17+ $this->allowed_fields["phone"] = 1;
 18+ $this->allowed_fields["verify_code"] = 1;
 19+ $this->num_allowed_fields = count( $this->allowed_fields );
 20+
 21+ // set the url of the web service
 22+ $this->url = "app/telephone_http";
 23+ $this->check_field = "refid";
 24+ $this->server = array( "www.maxmind.com", "www2.maxmind.com" );
 25+ $this->numservers = count( $this->server );
 26+ $this->API_VERSION = 'PHP/1.4';
 27+ $this->timeout = 30;
 28+ }
 29+
2630 }
 31+
2732 ?>
Index: trunk/extensions/DonationInterface/extras/minfraud/tests/minfraudTest.php
@@ -1,25 +1,28 @@
22 <?php
 3+
34 /**
45 * @fixme wfGetIP() in minfraud.body.php wonks this up
56 */
67 require_once "PHPUnit/Framework.php";
78
8 -class minfraudTest extends PHPUnit_Framework_TestCase
9 -{
 9+class minfraudTest extends PHPUnit_Framework_TestCase {
 10+
1011 protected function setUp() {
1112 $dir = dirname( __FILE__ ) . '/';
1213 require_once( $dir . '../../extras.php' );
1314 require_once( $dir . '../minfraud.body.php' );
14 - require_once( $dir . "../../../includes/countryCodes.inc" );
15 - global $wgPayflowGatewayLog;
16 - $wgPayflowGatewayLog = dirname( __FILE__ ) . "/test_log";
 15+ global $wgDonationInterfaceExtrasLog;
 16+ $wgDonationInterfaceExtrasLog = dirname( __FILE__ ) . "/test_log";
1717 $license_key = 'XBCKSF4gnHA7';
18 - $this->fixture = new PayflowProGateway_Extras_MinFraud( $license_key );
 18+ global $wgPayflowProGatewayTest;
 19+ $wgPayflowProGatewayTest = true;
 20+ $adapter = new PayflowProAdapter();
 21+ $this->fixture = new Gateway_Extras_MinFraud( &$adapter, $license_key );
1922 }
2023
2124 protected function tearDown() {
22 - global $wgPayflowGatewayLog;
23 - unlink( $wgPayflowGatewayLog );
 25+ global $wgDonationInterfaceExtrasLog;
 26+ unlink( $wgDonationInterfaceExtrasLog );
2427 }
2528
2629 public function testCcfdInstance() {
@@ -43,8 +46,8 @@
4447 $this->assertArrayHasKey( "bin", $query );
4548 $this->assertArrayHasKey( "txnID", $query );
4649 $this->assertArrayNotHasKey( "foo", $query ); // make sure we're not adding extraneous info
47 - $this->assertNotContains( "@", $query[ 'domain' ] ); // make sure we're only getting domains from email addresses
48 - $this->assertEquals( 6, strlen( $query[ 'bin' ] ) ); // make sure our bin is 6 digits long
 50+ $this->assertNotContains( "@", $query['domain'] ); // make sure we're only getting domains from email addresses
 51+ $this->assertEquals( 6, strlen( $query['bin'] ) ); // make sure our bin is 6 digits long
4952 }
5053
5154 public function queryDataProvider() {
@@ -68,11 +71,11 @@
6972 /**
7073 * @dataProvider queryDataProvider
7174 */
72 -/* public function testQueryMinfraud( $data ) {
73 - $query = $this->fixture->build_query( $data );
74 - $this->fixture->query_minfraud( $query );
75 - $this->assertType( 'array', $this->fixture->minfraud_response );
76 - }*/
 75+ /* public function testQueryMinfraud( $data ) {
 76+ $query = $this->fixture->build_query( $data );
 77+ $this->fixture->query_minfraud( $query );
 78+ $this->assertType( 'array', $this->fixture->minfraud_response );
 79+ } */
7780
7881 /**
7982 * @dataProvider hashValidateFalseData
@@ -81,10 +84,18 @@
8285 $this->assertFalse( $this->fixture->validate_minfraud_query( $data ) );
8386 }
8487
 88+ public function setExtrasGlobal( $varname, $value ) {
 89+ //Just set the one for the adapter.
 90+ $adapter_prefix = $this->fixture->gateway_adapter->getGlobalPrefix();
 91+ $globalname = $adapter_prefix . $varname;
 92+ global $$globalname;
 93+ $$globalname = $value;
 94+ }
 95+
8596 public function hashValidateFalseData() {
8697 return array(
8798 array(
88 - array(),
 99+ array( ),
89100 array( 'license_key' => 'a' ),
90101 array(
91102 'license_key' => 'a',
@@ -154,29 +165,26 @@
155166 }
156167
157168 public function testLogging() {
158 - global $wgPayflowGatewayLog;
 169+ global $wgDonationInterfaceExtrasLog;
159170 $this->fixture->log( '', '', "\"foo\"" );
160 - $new_fh = fopen( $wgPayflowGatewayLog, 'r' );
161 - $this->assertEquals( '"' . date( 'c' ) . '"' . "\t\"\"\t\"\"\t\"foo\"\n", fread( $new_fh, filesize( $wgPayflowGatewayLog ) ) );
 171+ $new_fh = fopen( $wgDonationInterfaceExtrasLog, 'r' );
 172+ $this->assertEquals( '"' . date( 'c' ) . '"' . "\t\"\"\t\"\"\t\"foo\"\n", fread( $new_fh, filesize( $wgDonationInterfaceExtrasLog ) ) );
162173 fclose( $new_fh );
163174 }
164175
165176 public function testGenerateHash() {
166 - global $wgPayflowGatewaySalt;
167 - $wgPayflowGatewaySalt = 'salt';
 177+ $this->setExtrasGlobal( 'Salt', 'salt' );
168178 $this->assertEquals( '5a9ee1e4a15adbf03b3ef9f7baa6caffa9f6bcd72c736498f045c073e57753e7b244bc97fe82b075eabd80778a4d56eb14406e9a1ac4b13737b2c3fd8c3717e8', $this->fixture->generate_hash( 'foo' ) );
169179 }
170180
171181 public function testCompareHash() {
172 - global $wgPayflowGatewaySalt;
173 - $wgPayflowGatewaySalt = 'salt';
 182+ $this->setExtrasGlobal( 'Salt', 'salt' );
174183 $this->assertTrue( $this->fixture->compare_hash( '5a9ee1e4a15adbf03b3ef9f7baa6caffa9f6bcd72c736498f045c073e57753e7b244bc97fe82b075eabd80778a4d56eb14406e9a1ac4b13737b2c3fd8c3717e8', 'foo' ) );
175184 $this->assertFalse( $this->fixture->compare_hash( '5a9ee1e4a15adbf03b3ef9f7baa6caffa9f6bcd72c736498f045c073e57753e7b244bc97fe82b075eabd80778a4d56eb14406e9a1ac4b13737b2c3fd8c3717e8', 'bar' ) );
176185 }
177186
178187 public function testBypassMinfraud() {
179 - global $wgPayflowGatewaySalt;
180 - $wgPayflowGatewaySalt = 'salt';
 188+ $this->setExtrasGlobal( 'Salt', 'salt' );
181189 $data = array(
182190 'action' => '4bd7857c851039d1e07a434800fe752c6bd99aec61c325aef460441be1b95c3ab5236e43c8d06f41d77715dbd3cf94e679b86422ec3204f00ad433501e5005e9',
183191 'data_hash' => '029ef6f5c2a165215b5a92ff1a194e4a6de8c668d6193582da42713f119c1b07d8358b5cd94a3bd51c9aa50709c8533295215ce3cce8c2b61e69078d789bc3f3',
@@ -191,4 +199,5 @@
192200 $data[] = 'bar';
193201 $this->assertFalse( $this->fixture->can_bypass_minfraud( $this->fixture, $data ) );
194202 }
 203+
195204 }
Index: trunk/extensions/DonationInterface/extras/minfraud/minfraud.body.php
@@ -1,6 +1,7 @@
22 <?php
3 -class PayflowProGateway_Extras_MinFraud extends PayflowProGateway_Extras {
43
 4+class Gateway_Extras_MinFraud extends Gateway_Extras {
 5+
56 /**
67 * Full response from minFraud
78 * @var public array
@@ -16,14 +17,14 @@
1718 /**
1819 * User-definable riskScore ranges for actions to take
1920 *
20 - * Overload with $wgMinFraudActionRanges
 21+ * Overload with $wgMinFraudActionRanges
2122 * @var public array
2223 */
2324 public $action_ranges = array(
24 - 'process' => array( 0, 100 ),
25 - 'review' => array( -1, -1 ),
26 - 'challenge' => array( -1, -1 ),
27 - 'reject' => array( -1, -1 ),
 25+ 'process' => array( 0, 100 ),
 26+ 'review' => array( -1, -1 ),
 27+ 'challenge' => array( -1, -1 ),
 28+ 'reject' => array( -1, -1 ),
2829 );
2930
3031 /**
@@ -37,11 +38,10 @@
3839 */
3940 static $instance;
4041
41 - function __construct( $license_key = NULL ) {
42 - parent::__construct();
 42+ function __construct( &$gateway_adapter, $license_key = NULL ) {
 43+ parent::__construct( $gateway_adapter );
4344 $dir = dirname( __FILE__ ) . '/';
4445 require_once( $dir . "ccfd/CreditCardFraudDetection.php" );
45 - require_once( $dir . "../../includes/countryCodes.inc" );
4646 global $wgMinFraudLicenseKey, $wgMinFraudActionRanges;
4747
4848 // set the minfraud license key, go no further if we don't have it
@@ -50,46 +50,48 @@
5151 }
5252 $this->minfraud_license_key = ( $license_key ) ? $license_key : $wgMinFraudLicenseKey;
5353
54 - if ( isset( $wgMinFraudActionRanges ) ) $this->action_ranges = $wgMinFraudActionRanges;
 54+ if ( isset( $wgMinFraudActionRanges ) )
 55+ $this->action_ranges = $wgMinFraudActionRanges;
5556 }
5657
5758 /**
5859 * Query minFraud with the transaction, set actions to take and make a log entry
5960 *
60 - * Accessible via $wgHooks[ 'PayflowGatewayValidate' ]
61 - * @param object PayflowPro Gateway object
 61+ * Accessible via $wgHooks[ 'GatewayValidate' ]
 62+ * @param object Gateway object
6263 * @param array The array of data generated from an attempted transaction
6364 */
64 - public function validate( &$pfp_gateway_object, &$data ) {
 65+ public function validate() {
6566 // see if we can bypass minfraud
66 - if ( $this->can_bypass_minfraud( $pfp_gateway_object, $data ) ) return TRUE;
 67+ if ( $this->can_bypass_minfraud() )
 68+ return TRUE;
6769
68 - $minfraud_query = $this->build_query( $data );
 70+ $minfraud_query = $this->build_query( $this->gateway_adapter->getData() );
6971 $this->query_minfraud( $minfraud_query );
70 - $pfp_gateway_object->action = $this->determine_action( $this->minfraud_response[ 'riskScore' ] );
 72+ $this->gateway_adapter->action = $this->determine_action( $this->minfraud_response['riskScore'] );
7173
7274 // reset the data hash
73 - if ( isset( $data[ 'data_hash' ] ) ) unset( $data[ 'data_hash' ] );
74 - $data[ 'action' ] = $this->generate_hash( $pfp_gateway_object->action );
75 - $data[ 'data_hash' ] = $this->generate_hash( serialize( $data ) );
 75+ $this->gateway_adapter->unsetHash();
 76+ $this->gateway_adapter->setActionHash( $this->generate_hash( $this->gateway_adapter->action ) );
 77+ $this->gateway_adapter->setHash( $this->generate_hash( $this->gateway_adapter->getData() ) );
7678
7779 // Write the query/response to the log
78 - $this->log_query( $minfraud_query, $pfp_gateway_object, $data );
 80+ $this->log_query( $minfraud_query );
7981 return TRUE;
8082 }
8183
8284 /**
8385 * Logs a minFraud query and its response
8486 */
85 - public function log_query( $minfraud_query, $pfp_gateway_object, $data ) {
 87+ public function log_query( $minfraud_query ) {
8688 if ( $this->log_fh ) {
87 - $log_message = '"' . addslashes( $data[ 'comment' ] ) . '"';
88 - $log_message .= "\t" . '"' . addslashes( $data[ 'amount' ] . ' ' . $data[ 'currency' ] ) . '"';
 89+ $log_message = '"' . addslashes( $this->gateway_adapter->getData( 'comment' ) ) . '"';
 90+ $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->getData( 'amount' ) . ' ' . $this->gateway_adapter->getData( 'currency' ) ) . '"';
8991 $log_message .= "\t" . '"' . addslashes( json_encode( $minfraud_query ) ) . '"';
9092 $log_message .= "\t" . '"' . addslashes( json_encode( $this->minfraud_response ) ) . '"';
91 - $log_message .= "\t" . '"' . addslashes( $pfp_gateway_object->action ) . '"';
92 - $log_message .= "\t" . '"' . addslashes( $data[ 'referrer' ] ) . '"';
93 - $this->log( $data[ 'contribution_tracking_id' ], 'minFraud query', $log_message );
 93+ $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->action ) . '"';
 94+ $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->getData( 'referrer' ) ) . '"';
 95+ $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'minFraud query', $log_message );
9496 }
9597 }
9698
@@ -102,40 +104,37 @@
103105 * assume the transaction has already gone through the minFraud check and can be passed
104106 * on to the appropriate action.
105107 *
106 - * @param object $pfp_gateway_object The PayflowPro gateway object
107 - * @param array $data The array of data from the form submission
108108 * @return bool
109109 */
110 - public function can_bypass_minfraud( &$pfp_gateway_object, &$data ) {
 110+ public function can_bypass_minfraud() {
111111 // if the data bits data_hash and action are not set, we need to hit minFraud
112 - if ( !strlen( $data[ 'data_hash' ] ) || !strlen( $data[ 'action' ] ) ) {
 112+ $localdata = $this->gateway_adapter->getData();
 113+ if ( !strlen( $localdata['data_hash'] ) || !strlen( $localdata['action'] ) ) {
113114 return FALSE;
114115 }
115116
116 - $data_hash = $data[ 'data_hash' ]; // the data hash passed in by the form submission
117 - $num_attempt = $data[ 'numAttempt' ]; // the num_attempt has been increased by one, so we have to adjust slightly
118 - $data[ 'numAttempt' ] = $num_attempt - 1;
119 -
120 - // unset these values from the data aray since they are not part of the overall data hash
121 - unset( $data[ 'data_hash' ] );
 117+ $data_hash = $localdata['data_hash']; // the data hash passed in by the form submission
 118+ // unset these values since they are not part of the overall data hash
 119+ $this->gateway_adapter->unsetHash();
 120+ unset( $localdata['data_hash'] );
122121 // compare the data hash to make sure it's legit
123 - if ( $this->compare_hash( $data_hash, serialize( $data ) ) ) {
124 - $data[ 'numAttempt' ] = $num_attempt; // reset the current num attempt
125 - $data[ 'data_hash' ] = $this->generate_hash( serialize( $data ) ); // hash the data array
 122+ if ( $this->compare_hash( $data_hash, serialize( $localdata ) ) ) {
126123
 124+ $this->gateway_adapter->setHash( $this->generate_hash( $this->gateway_adapter->getData() ) ); // hash the data array
127125 // check to see if we have a valid action set for us to bypass minfraud
128126 $actions = array( 'process', 'challenge', 'review', 'reject' );
129 - $action_hash = $data[ 'action' ]; // a hash of the action to take passed in by the form submission
 127+ $action_hash = $localdata['action']; // a hash of the action to take passed in by the form submission
130128 foreach ( $actions as $action ) {
131129 if ( $this->compare_hash( $action_hash, $action ) ) {
132130 // set the action that should be taken
133 - $pfp_gateway_object->action = $action;
 131+ $this->gateway_adapter->action = $action;
134132 return TRUE;
135133 }
136134 }
137135 } else {
138136 // log potential tampering
139 - if ( $this->log_fh ) $this->log( $data[ 'contribution_tracking_id'], 'Data hash/action mismatch' );
 137+ if ( $this->log_fh )
 138+ $this->log( $localdata['contribution_tracking_id'], 'Data hash/action mismatch' );
140139 }
141140
142141 return FALSE;
@@ -147,7 +146,7 @@
148147 */
149148 public function get_ccfd() {
150149 if ( !$this->ccfd ) {
151 - $this->ccfd = new CreditCardFraudDetection;
 150+ $this->ccfd = new CreditCardFraudDetection( $this->gateway_adapter );
152151 }
153152 return $this->ccfd;
154153 }
@@ -157,8 +156,6 @@
158157 * @return array containing hash for minfraud query
159158 */
160159 public function build_query( array $data ) {
161 - global $wgPayflowGatewayTest;
162 -
163160 // mapping of data keys -> minfraud array keys
164161 $map = array(
165162 "city" => "city",
@@ -172,20 +169,20 @@
173170 );
174171
175172 // minfraud license key
176 - $minfraud_array[ "license_key" ] = $this->minfraud_license_key;
 173+ $minfraud_array["license_key"] = $this->minfraud_license_key;
177174
178175 // user's IP address
179 - $minfraud_array[ "i" ] = ( $wgPayflowGatewayTest ) ? '12.12.12.12' : wfGetIP();
 176+ $minfraud_array["i"] = ( $this->gateway_adapter->getGlobal( "Test" ) ) ? '12.12.12.12' : wfGetIP();
180177
181178 // user's user agent
182179 global $wgRequest;
183 - $minfraud_array[ "user_agent" ] = $wgRequest->getHeader( 'user-agent' );
 180+ $minfraud_array["user_agent"] = $wgRequest->getHeader( 'user-agent' );
184181
185182 // user's language
186 - $minfraud_array[ 'accept_language' ] = $wgRequest->getHeader( 'accept-language' );
 183+ $minfraud_array['accept_language'] = $wgRequest->getHeader( 'accept-language' );
187184
188185 // fetch the array of country codes
189 - $country_codes = PayflowProGateway::getCountries();
 186+ $country_codes = GatewayForm::getCountries();
190187
191188 // loop through the map and add pertinent values from $data to the hash
192189 foreach ( $map as $key => $value ) {
@@ -193,19 +190,19 @@
194191 // do some data processing to clean up values for minfraud
195192 switch ( $key ) {
196193 case "domain": // get just the domain from the email address
197 - $newdata[ $value ] = substr( strstr( $data[ $value ], '@' ), 1 );
 194+ $newdata[$value] = substr( strstr( $data[$value], '@' ), 1 );
198195 break;
199196 case "bin": // get just the first 6 digits from CC#
200 - $newdata[ $value ] = substr( $data[ $value ], 0, 6 );
 197+ $newdata[$value] = substr( $data[$value], 0, 6 );
201198 break;
202199 case "country":
203 - $newdata[ $value ] = $country_codes[ $data[ $value ]];
 200+ $newdata[$value] = $country_codes[$data[$value]];
204201 break;
205202 default:
206 - $newdata[ $value ] = $data[ $value ];
 203+ $newdata[$value] = $data[$value];
207204 }
208205
209 - $minfraud_array[ $key ] = $newdata[ $value ];
 206+ $minfraud_array[$key] = $newdata[$value];
210207 }
211208
212209 return $minfraud_array;
@@ -229,7 +226,7 @@
230227 * there is a value for a required field and if its length is > 0
231228 *
232229 * @param array $minfraud_query which is the array you would pass to
233 - * minfraud in a query
 230+ * minfraud in a query
234231 * @result bool
235232 */
236233 public function validate_minfraud_query( array $minfraud_query ) {
@@ -244,8 +241,8 @@
245242 );
246243
247244 foreach ( $reqd_fields as $reqd_field ) {
248 - if ( !isset( $minfraud_query[ $reqd_field ] ) ||
249 - strlen( $minfraud_query[ $reqd_field ] ) < 1 ) {
 245+ if ( !isset( $minfraud_query[$reqd_field] ) ||
 246+ strlen( $minfraud_query[$reqd_field] ) < 1 ) {
250247 return FALSE;
251248 }
252249 }
@@ -261,7 +258,7 @@
262259 * @param float risk score (returned from minFraud)
263260 * @return array of actions to be taken
264261 */
265 - public function determine_action( $risk_score ) {
 262+ public function determine_action( $risk_score ) {
266263 foreach ( $this->action_ranges as $action => $range ) {
267264 if ( $risk_score >= $range[0] && $risk_score <= $range[1] ) {
268265 return $action;
@@ -269,14 +266,16 @@
270267 }
271268 }
272269
273 - static function onValidate( &$pfp_gateway_object, &$data ) {
274 - return self::singleton()->validate( $pfp_gateway_object, $data );
 270+ static function onValidate( &$gateway_adapter ) {
 271+ $gateway_adapter->debugarray[] = "minfraud onValidate hook!";
 272+ return self::singleton( $gateway_adapter )->validate();
275273 }
276274
277 - static function singleton() {
 275+ static function singleton( &$gateway_adapter ) {
278276 if ( !self::$instance ) {
279 - self::$instance = new self;
 277+ self::$instance = new self( $gateway_adapter );
280278 }
281279 return self::$instance;
282280 }
 281+
283282 }
Index: trunk/extensions/DonationInterface/extras/minfraud/minfraud.php
@@ -1,74 +1,30 @@
22 <?php
 3+
34 /**
45 * Validates a transaction against MaxMind's minFraud service
56 *
67 * For more details on minFraud, go: http://www.maxmind.com/app/minfraud
78 *
8 - * To install:
9 - * require_once( "$IP/extensions/DonationInterface/payflowpro_gateway/extras/minfraud/minfraud.php" );
10 - *
 9+ * To install the DontaionInterface extension, put the following line in LocalSettings.php:
 10+ * require_once( "\$IP/extensions/DonationInterface/donationinterface.php" );
 11+ *
 12+ * TODO: Outline required globals to include this bad boy!
 13+ *
1114 */
12 -
1315 if ( !defined( 'MEDIAWIKI' ) ) {
14 - die( "This file is part of the MinFraud for PayflowPro Gateway extension. It is not a valid entry point.\n" );
 16+ die( "This file is part of the MinFraud for Gateway extension. It is not a valid entry point.\n" );
1517 }
1618
17 -$wgExtensionCredits['payflowprogateway_extras_minfraud'][] = array(
 19+$wgExtensionCredits['gateway_extras_minfraud'][] = array(
1820 'name' => 'minfraud',
1921 'author' => 'Arthur Richards',
2022 'url' => '',
21 - 'description' => 'This extension uses the MaxMind minFraud service as a validator for the Payflow Pro gateway.'
 23+ 'description' => 'This extension uses the MaxMind minFraud service as a validator for the gateway.'
2224 );
2325
24 -/**
25 - * Your minFraud license key.
26 - */
27 -$wgMinFraudLicenseKey = '';
28 -
29 -/**
30 - * Set the risk score ranges that will cause a particular 'action'
31 - *
32 - * The keys to the array are the 'actions' to be taken (eg 'process').
33 - * The value for one of these keys is an array representing the lower
34 - * and upper bounds for that action. For instance,
35 - * $wgMinFraudActionRagnes = array(
36 - * 'process' => array( 0, 100)
37 - * ...
38 - * );
39 - * means that any transaction with a risk score greather than or equal
40 - * to 0 and less than or equal to 100 will be given the 'process' action.
41 - *
42 - * These are evauluated on a >= or <= basis. Please refer to minFraud
43 - * documentation for a thorough explanation of the 'riskScore'.
44 - */
45 -$wgMinFraudActionRanges = array(
46 - 'process' => array( 0, 100 ),
47 - 'review' => array( -1, -1 ),
48 - 'challenge' => array( -1, -1 ),
49 - 'reject' => array( -1, -1 )
50 -);
51 -
52 -// Timeout in seconds for communicating with MaxMind
53 -$wgMinFraudTimeout = 2;
54 -
55 -/**
56 - * Define whether or not to run minFraud in stand alone mode
57 - *
58 - * If this is set to run in standalone, these scripts will be
59 - * accessed directly via the "PayflowGatewayValidate" hook.
60 - * You may not want to run this in standalone mode if you prefer
61 - * to use this in conjunction with Custom Filters. This has the
62 - * advantage of sharing minFraud info with other filters.
63 - */
64 -$wgMinFraudStandalone = TRUE;
65 -
66 -$dir = dirname( __FILE__ ) . "/";
67 -$wgAutoloadClasses['PayflowProGateway_Extras_MinFraud'] = $dir . "minfraud.body.php";
68 -
69 -$wgExtensionFunctions[] = 'efMinFraudSetup';
70 -
7126 function efMinFraudSetup() {
72 - // if we're in standalone mode, use the PayflowGatewayValidate hook
 27+ // if we're in standalone mode, use the GatewayValidate hook
7328 global $wgMinFraudStandalone, $wgHooks;
74 - if ( $wgMinFraudStandalone ) $wgHooks["PayflowGatewayValidate"][] = array( 'PayflowProGateway_Extras_MinFraud::onValidate' );
 29+ if ( $wgMinFraudStandalone )
 30+ $wgHooks["GatewayValidate"][] = array( 'Gateway_Extras_MinFraud::onValidate' );
7531 }
Index: trunk/extensions/DonationInterface/extras/conversion_log/conversion_log.php
@@ -1,26 +0,0 @@
2 -<?php
3 -/**
4 - * Extra to log payflow response during post processing hook
5 - *
6 - * @fixme Class/file names should likely change to reflect change in purpose...
7 - *
8 - * To install:
9 - * require_once( "$IP/extensions/DonationInterface/payflowpro_gateway/extras/conversion_log/conversion_log.php"
10 - */
11 -
12 -if ( !defined( 'MEDIAWIKI' ) ) {
13 - die( "This file is part of the Conversion Log for PayflowPro Gateway extension. It is not a valid entry point.\n" );
14 -}
15 -
16 -$wgExtensionCredits['payflowprogateway_extras_conversionLog'][] = array(
17 - 'name' => 'conversion log',
18 - 'author' => 'Arthur Richards',
19 - 'url' => '',
20 - 'description' => "This extension handles logging for Payflow Gateway extension 'extras'"
21 -);
22 -
23 -$dir = dirname( __FILE__ ) . "/";
24 -$wgAutoloadClasses['PayflowProGateway_Extras_ConversionLog'] = $dir . "conversion_log.body.php";
25 -
26 -// Sets the 'conversion log' as logger for post-processing
27 -$wgHooks["PayflowGatewayPostProcess"][] = array( "PayflowProGateway_Extras_ConversionLog::onPostProcess" );
Index: trunk/extensions/DonationInterface/extras/conversion_log/conversion_log.body.php
@@ -1,39 +1,41 @@
22 <?php
3 -class PayflowProGateway_Extras_ConversionLog extends PayflowProGateway_Extras {
 3+
 4+class Gateway_Extras_ConversionLog extends Gateway_Extras {
 5+
46 static $instance;
57
68 /**
7 - * Logs the response from a payflow transaction
 9+ * Logs the response from a transaction
810 */
9 - public function post_process( &$pfp_gateway_object, &$data ) {
 11+ public function post_process() {
1012 // if the trxn has been outright rejected, log it
11 - if ( $pfp_gateway_object->action == 'reject' ) {
 13+ if ( $this->gateway_adapter->action == 'reject' ) {
1214 $this->log(
13 - $data[ 'contribution_tracking_id' ],
14 - 'Rejected'
 15+ $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Rejected'
1516 );
1617 return TRUE;
1718 }
1819
19 - // make sure the payflow response property has been set (signifying a transaction has been made)
20 - if ( !$pfp_gateway_object->payflow_response ) return FALSE;
 20+ // make sure the response property has been set (signifying a transaction has been made)
 21+ if ( !$this->gateway_adapter->getTransactionAllResults() )
 22+ return FALSE;
2123
2224 $this->log(
23 - $data[ 'contribution_tracking_id' ],
24 - "Payflow response: " . addslashes( $pfp_gateway_object->payflow_response[ 'RESPMSG' ] ),
25 - '"' . addslashes( json_encode( $pfp_gateway_object->payflow_response ) ) . '"'
 25+ $this->gateway_adapter->getData( 'contribution_tracking_id' ), "Gateway response: " . addslashes( $this->gateway_adapter->getTransactionMessage() ), '"' . addslashes( json_encode( $this->gateway_adapter->getTransactionData() ) ) . '"'
2626 );
2727 return TRUE;
2828 }
2929
30 - static function onPostProcess( &$pfp_gateway_object, &$data ) {
31 - return self::singleton()->post_process( $pfp_gateway_object, $data );
 30+ static function onPostProcess( &$gateway_adapter ) {
 31+ $gateway_adapter->debugarray[] = 'conversion log onPostProcess hook!';
 32+ return self::singleton( $gateway_adapter )->post_process();
3233 }
3334
34 - static function singleton() {
 35+ static function singleton( &$gateway_adapter ) {
3536 if ( !self::$instance ) {
36 - self::$instance = new self;
 37+ self::$instance = new self( $gateway_adapter );
3738 }
3839 return self::$instance;
3940 }
 41+
4042 }
Index: trunk/extensions/DonationInterface/extras/extras.body.php
@@ -1,19 +1,24 @@
22 <?php
 3+
34 /**
4 - * An abstract class for payflowpro gateway 'extras'
 5+ * An abstract class for gateway 'extras'
56 */
 7+abstract class Gateway_Extras {
68
7 -abstract class PayflowProGateway_Extras {
89 /**
910 * File handle for log file
1011 * @var public
1112 */
1213 public $log_fh = NULL;
 14+ public $gateway_adapter;
1315
14 - public function __construct() {
15 - global $wgPayflowGatewayLog;
 16+ public function __construct( &$gateway_adapter ) {
 17+ $this->gateway_adapter = &$gateway_adapter;
 18+
 19+ $extrasLog = $this->gateway_adapter->getGlobal( 'ExtrasLog' );
1620 // prepare the log file if the user has specified one
17 - if ( strlen( $wgPayflowGatewayLog ) > 0 ) $this->prepare_log_file( $wgPayflowGatewayLog );
 21+ if ( strlen( $extrasLog ) > 0 )
 22+ $this->prepare_log_file( $extrasLog );
1823 }
1924
2025 /**
@@ -25,19 +30,16 @@
2631 * @param string path to log file
2732 */
2833 protected function prepare_log_file( $log_file ) {
29 -
 34+
3035 if ( strtolower( $log_file ) == "syslog" ) {
3136
32 - $this->log_fh = 'syslog';
33 -
34 - } elseif( is_file( $log_file )) {
35 -
 37+ $this->log_fh = 'syslog';
 38+ } elseif ( is_file( $log_file ) ) {
 39+
3640 $this->log_fh = fopen( $log_file, 'a+' );
37 -
3841 } else {
3942
4043 $this->log_fh = null;
41 -
4244 }
4345 }
4446
@@ -54,26 +56,20 @@
5557 echo "what log file?";
5658 return;
5759 }
58 -
 60+
5961 // format the message
6062 $msg = '"' . date( 'c' ) . '"';
6163 $msg .= "\t" . '"' . $id . '"';
6264 $msg .= "\t" . '"' . $status . '"';
6365 $msg .= "\t" . $data . "\n";
64 -
 66+
6567 // write to the log
6668 if ( $this->log_fh == 'syslog' ) { //use syslog facility
6769 // replace tabs with spaces - maybe do this universally? cuz who needs tabs.
6870 $msg = str_replace( "\t", " ", $msg );
69 -
70 - openlog( "payflowpro_gateway_trxn", LOG_ODELAY, LOG_SYSLOG );
71 - syslog( $log_level, $msg );
72 - closelog();
73 -
 71+ $this->gateway_adapter->log( $msg, $log_level, '_trxn' );
7472 } else { //write to file
75 -
7673 fwrite( $this->log_fh, $msg );
77 -
7874 }
7975 }
8076
@@ -83,8 +79,8 @@
8480 * @return string The hash of the data
8581 */
8682 public function generate_hash( $data ) {
87 - global $wgPayflowGatewaySalt;
88 - return hash( "sha512", $wgPayflowGatewaySalt . $data );
 83+ $salt = $this->gateway_adapter->getGlobal( 'Salt' );
 84+ return hash( "sha512", $salt . $data );
8985 }
9086
9187 /**
@@ -105,6 +101,8 @@
106102 * Close the open log file handler if it's open
107103 */
108104 public function __destruct() {
109 - if ( is_resource( $this->log_fh ) ) fclose( $this->log_fh );
 105+ if ( is_resource( $this->log_fh ) )
 106+ fclose( $this->log_fh );
110107 }
 108+
111109 }
Index: trunk/extensions/DonationInterface/extras/recaptcha/recaptcha.php
@@ -1,55 +0,0 @@
2 -<?php
3 -/**
4 - * Extra to expose a recaptcha for 'challenged' transactions
5 - *
6 - * To install:
7 - * require_once( "$IP/extensions/DonationInterface/payflowpro_gateway/extras/recaptcha/recaptcha.php"
8 - */
9 -
10 -if ( !defined( 'MEDIAWIKI' ) ) {
11 - die( "This file is part of the ReCaptcha for PayflowPro Gateway extension. It is not a valid entry point.\n" );
12 -}
13 -
14 -$wgExtensionCredits['payflowgateway_extras_recaptcha'][] = array(
15 - 'name' => 'reCaptcha',
16 - 'author' => 'Arthur Richards',
17 - 'url' => '',
18 - 'description' => "This extension exposes a reCpathca for 'challenged' transactions in the Payflowpro Gateway"
19 -);
20 -
21 -/**
22 - * Public and Private reCaptcha keys
23 - *
24 - * These can be obtained at:
25 - * http://www.google.com/recaptcha/whyrecaptcha
26 - */
27 -$wgPayflowRecaptchaPublicKey = '';
28 -$wgPayflowRecaptchaPrivateKey = '';
29 -
30 -// Timeout (in seconds) for communicating with reCatpcha
31 -$wgPayflowRecaptchaTimeout = 2;
32 -
33 -/**
34 - * HTTP Proxy settings
35 - *
36 - * Default to settings in PayflowPro Gateway
37 - */
38 -$wgPayflowRecaptchaUseHTTPProxy = $wgPayflowGatewayUseHTTPProxy;
39 -$wgPayflowRecaptchaHTTPProxy = $wgPayflowGatewayHTTPProxy;
40 -
41 -/**
42 - * Use SSL to communicate with reCaptcha
43 - */
44 -$wgPayflowRecaptchaUseSSL = 1;
45 -
46 -/**
47 - * The # of times to retry communicating with reCaptcha if communication fails
48 - * @var int
49 - */
50 -$wgPayflowRecaptchaComsRetryLimit = 3;
51 -
52 -$dir = dirname( __FILE__ ) . "/";
53 -$wgAutoloadClasses['PayflowProGateway_Extras_ReCaptcha'] = $dir . "recaptcha.body.php";
54 -
55 -// Set reCpatcha as plugin for 'challenge' action
56 -$wgHooks["PayflowGatewayChallenge"][] = array( "PayflowProGateway_Extras_ReCaptcha::onChallenge" );
Index: trunk/extensions/DonationInterface/extras/recaptcha/recaptcha-php/recaptchalib.php
@@ -42,8 +42,7 @@
4343 */
4444
4545 // global MW variables that should be available
46 -global $wgPayflowRecaptchaUseHTTPProxy, $wgPayflowRecaptchaHTTPProxy,
47 - $wgPayflowRecaptchaTimeout, $wgPayflowRecaptchaUseSSL, $wgPayflowRecaptchaComsRetryLimit;
 46+global $wgReCaptchaConfData;
4847
4948 /**
5049 * The reCAPTCHA server URL's
@@ -55,16 +54,18 @@
5655 /**
5756 * Proxy settings
5857 */
59 -define( "RECAPTCHA_USE_HTTP_PROXY", $wgPayflowRecaptchaUseHTTPProxy );
60 -define( "RECAPTCHA_HTTP_PROXY", $wgPayflowRecaptchaHTTPProxy );
 58+define( "RECAPTCHA_USE_HTTP_PROXY", $wgReCaptchaConfData['UseHTTPProxy'] );
 59+define( "RECAPTCHA_HTTP_PROXY", $wgReCaptchaConfData['HTTPProxy'] );
6160
6261 /**
6362 * Other reCAPTCHA settings
6463 */
65 -define( "RECAPTCHA_TIMEOUT", $wgPayflowRecaptchaTimeout );
66 -define( "RECAPTCHA_PROTOCOL", $wgPayflowRecaptchaUseSSL ); //http or https
67 -define( "RECAPTCHA_RETRY_LIMIT", $wgPayflowRecaptchaComsRetryLimit );
 64+define( "RECAPTCHA_TIMEOUT", $wgReCaptchaConfData['UseHTTPProxy'] );
 65+define( "RECAPTCHA_PROTOCOL", $wgReCaptchaConfData['UseSSL'] ); //http or https
 66+define( "RECAPTCHA_RETRY_LIMIT", $wgReCaptchaConfData['ComsRetryLimit'] );
6867
 68+define( "RECAPTCHA_GATEWAY", $wgReCaptchaConfData['GatewayClass'] );
 69+
6970 /**
7071 * Encodes the given data into a query string format
7172 * @param $data - array of string elements to be encoded
@@ -125,7 +126,8 @@
126127
127128 $response = '';
128129 if ( false == ( $fs = @fsockopen( $host, $port, $errno, $errstr, 10 ) ) ) {
129 - PayflowProGateway::log( 'Failed communicating with reCaptcha.' );
 130+ $c = RECAPTCHA_GATEWAY;
 131+ $c::log( 'Failed communicating with reCaptcha.' );
130132 die ( 'Could not open socket' );
131133 }
132134
@@ -158,20 +160,22 @@
159161 curl_setopt( $ch, CURLOPT_HEADER, true );
160162 curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "Host: " . $host ) );
161163
 164+ $c = RECAPTCHA_GATEWAY;
 165+
162166 // set proxy settings if necessary
163167 if ( RECAPTCHA_USE_HTTP_PROXY ) {
164 - PayflowProGateway::log( 'Using http proxy ' . RECAPTCHA_HTTP_PROXY );
 168+ $c::log( 'Using http proxy ' . RECAPTCHA_HTTP_PROXY );
165169 curl_setopt( $ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP );
166170 curl_setopt( $ch, CURLOPT_PROXY, RECAPTCHA_HTTP_PROXY );
167171 }
168172
169173 // try up to three times
170174 for ( $i = 0; $i < RECAPTCHA_RETRY_LIMIT; $i++ ) {
171 - PayflowProGateway::log( 'Preparing to communicate with reCaptcha via cURL at ' . $url . '.' );
 175+ $c::log( 'Preparing to communicate with reCaptcha via cURL at ' . $url . '.' );
172176 $response = curl_exec( $ch );
173 - PayflowProGateway::log( "Finished communicating with reCaptcha." );
 177+ $c::log( "Finished communicating with reCaptcha." );
174178 if ( $response ) {
175 - PayflowProGateway::log( 'Response from reCaptcha: ' . $response );
 179+ $c::log( 'Response from reCaptcha: ' . $response );
176180 break;
177181 }
178182 }
@@ -186,7 +190,7 @@
187191 * the user entered the correct values.
188192 */
189193 if ( !$response ) {
190 - PayflowProGateway::log( 'Failed communicating with reCaptcha: ' . curl_error( $ch ) );
 194+ $c::log( 'Failed communicating with reCaptcha: ' . curl_error( $ch ) );
191195 $response = "true\r\n\r\nsuccess";
192196 }
193197
Index: trunk/extensions/DonationInterface/extras/recaptcha/recaptcha.body.php
@@ -1,10 +1,10 @@
22 <?php
 3+
34 /**
45 * Validates a transaction against MaxMind's minFraud service
56 */
 7+class Gateway_Extras_reCaptcha extends Gateway_Extras {
68
7 -class PayflowProGateway_Extras_reCaptcha extends PayflowProGateway_Extras {
8 -
99 /**
1010 * Container for singelton instance of self
1111 */
@@ -16,9 +16,18 @@
1717 */
1818 public $recap_err;
1919
20 - public function __construct() {
21 - parent::__construct();
 20+ public function __construct( &$gateway_adapter ) {
 21+ parent::__construct( $gateway_adapter );
2222
 23+ //stash all the vars that reCaptcha is going to need in a global just for it.
 24+ //I know this is vaguely unpleasant, but it's the quickest way back to zero.
 25+ global $wgReCaptchaConfData;
 26+ $wgReCaptchaConfData['UseHTTPProxy'] = $this->gateway_adapter->getGlobal( 'RecaptchaUseHTTPProxy' );
 27+ $wgReCaptchaConfData['HTTPProxy'] = $this->gateway_adapter->getGlobal( 'RecaptchaHTTPProxy' );
 28+ $wgReCaptchaConfData['Timeout'] = $this->gateway_adapter->getGlobal( 'RecaptchaTimeout' );
 29+ $wgReCaptchaConfData['UseSSL'] = $this->gateway_adapter->getGlobal( 'RecaptchaUseSSL' );
 30+ $wgReCaptchaConfData['ComsRetryLimit'] = $this->gateway_adapter->getGlobal( 'RecaptchaComsRetryLimit' );
 31+ $wgReCaptchaConfData['GatewayClass'] = $this->gateway_adapter->getGatewayAdapterClass(); //for properly routing the logging
2332 // load the reCaptcha API
2433 require_once( dirname( __FILE__ ) . '/recaptcha-php/recaptchalib.php' );
2534 }
@@ -26,45 +35,53 @@
2736 /**
2837 * Handle the challenge logic
2938 */
30 - public function challenge( &$pfp_gateway_object, &$data ) {
 39+ public function challenge() {
3140 // if captcha posted, validate
32 - if ( isset( $_POST[ 'recaptcha_response_field' ] ) ) {
 41+ if ( isset( $_POST['recaptcha_response_field'] ) ) {
3342 // check the captcha response
3443 $captcha_resp = $this->check_captcha();
3544 if ( $captcha_resp->is_valid ) {
3645 // if validated, update the action and move on
37 - $this->log( $data[ 'contribution_tracking_id' ], 'Captcha passed' );
38 - $pfp_gateway_object->action = "process";
 46+ $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Captcha passed' );
 47+ $this->gateway_adapter->action = "process";
3948 return TRUE;
4049 } else {
4150 $this->recap_err = $captcha_resp->error;
42 - $this->log( $data[ 'contribution_tracking_id' ], 'Captcha failed' );
 51+ $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Captcha failed' );
4352 }
4453 }
4554 // display captcha
46 - $this->display_captcha( $pfp_gateway_object, $data );
 55+ $this->display_captcha();
4756 return TRUE;
4857 }
4958
5059 /**
5160 * Display the submission form with the captcha injected into it
5261 */
53 - public function display_captcha( &$pfp_gateway_object, &$data ) {
54 - global $wgOut, $wgPayflowRecaptchaPublicKey, $wgPayflowRecaptchaUseSSL;
 62+ public function display_captcha() {
 63+ global $wgOut;
 64+ $publicKey = $this->gateway_adapter->getGlobal( 'RecaptchaPublicKey' );
 65+ $useSSL = $this->gateway_adapter->getGlobal( 'RecaptchaUseSSL' );
5566
5667 // log that a captcha's been triggered
57 - $this->log( $data[ 'contribution_tracking_id' ], 'Captcha triggered' );
 68+ $this->log( $this->gateway_adapter->getData( 'contribution_tracking_id' ), 'Captcha triggered' );
5869
5970 // construct the HTML used to display the captcha
6071 $captcha_html = Xml::openElement( 'div', array( 'id' => 'mw-donate-captcha' ) );
61 - $captcha_html .= recaptcha_get_html( $wgPayflowRecaptchaPublicKey, $this->recap_err, $wgPayflowRecaptchaUseSSL );
62 - $captcha_html .= '<span class="creditcard-error-msg">' . wfMsg( 'payflowpro_gateway-error-msg-captcha-please' ) . '</span>';
 72+ $captcha_html .= recaptcha_get_html( $publicKey, $this->recap_err, $useSSL );
 73+ $captcha_html .= '<span class="creditcard-error-msg">' . wfMsg( $this->gateway_adapter->getIdentifier() . '_gateway-error-msg-captcha-please' ) . '</span>';
6374 $captcha_html .= Xml::closeElement( 'div' ); // close div#mw-donate-captcha
64 -
6575 // load up the form class
66 - $form_class = $pfp_gateway_object->getFormClass();
67 - $form_obj = new $form_class( $data, $pfp_gateway_object->errors );
 76+ $form_class = $this->gateway_adapter->getFormClass();
6877
 78+ //hmm. Looking at this now, makes me want to say
 79+ //TODO: Refactor the Form Class constructors. Again. Because the next three lines of code anger me deeply.
 80+ //#1 - all three things are clearly in the gateway adapter, and we're passing that already.
 81+ //#2 - I have to stuff them in variables because Form wants parameters by reference.
 82+ $data = $this->gateway_adapter->getData();
 83+ $erros = $this->gateway_adapter->getValidationErrors();
 84+ $form_obj = new $form_class( $data, $errors, $this->gateway_adapter );
 85+
6986 // set the captcha HTML to use in the form
7087 $form_obj->setCaptchaHTML( $captcha_html );
7188
@@ -76,23 +93,23 @@
7794 * Check recaptcha answer
7895 */
7996 public function check_captcha() {
80 - global $wgPayflowRecaptchaPrivateKey, $wgRequest;
81 - $resp = recaptcha_check_answer( $wgPayflowRecaptchaPrivateKey,
82 - wfGetIP(),
83 - $wgRequest->getText( 'recaptcha_challenge_field' ),
84 - $wgRequest->getText( 'recaptcha_response_field' ) );
 97+ global $wgRequest;
 98+ $privateKey = $this->gateway_adapter->getGlobal( 'RecaptchaPrivateKey' );
 99+ $resp = recaptcha_check_answer( $privateKey, wfGetIP(), $wgRequest->getText( 'recaptcha_challenge_field' ), $wgRequest->getText( 'recaptcha_response_field' ) );
85100
86101 return $resp;
87102 }
88103
89 - static function onChallenge( &$pfp_gateway_object, &$data ) {
90 - return self::singleton()->challenge( $pfp_gateway_object, $data );
 104+ static function onChallenge( &$gateway_adapter ) {
 105+ $gateway_adapter->debugarray[] = 'recaptcha onChallenge hook!';
 106+ return self::singleton( $gateway_adapter )->challenge();
91107 }
92108
93 - static function singleton() {
 109+ static function singleton( &$gateway_adapter ) {
94110 if ( !self::$instance ) {
95 - self::$instance = new self;
 111+ self::$instance = new self( $gateway_adapter );
96112 }
97113 return self::$instance;
98114 }
 115+
99116 }
Property changes on: trunk/extensions/DonationInterface/extras
___________________________________________________________________
Added: svn:mergeinfo
100117 Merged /branches/fundraising/extensions/DonationInterface/extras:r98263-100243
Index: trunk/extensions/DonationInterface/gateway_forms/TwoStepTwoColumn.php
@@ -7,6 +7,7 @@
88
99 parent::__construct( $form_data, $form_errors, $gateway );
1010 // load validation and placeholder JS
 11+ $this->loadValidateJs();
1112 $this->loadPlaceholders();
1213 }
1314
Index: trunk/extensions/DonationInterface/gateway_forms/RapidHtml.php
@@ -83,6 +83,8 @@
8484 global $wgRequest;
8585 parent::__construct( $form_data, $form_errors, $gateway );
8686
 87+ $this->loadValidateJs();
 88+
8789 $country = $wgRequest->getText( 'country', '' );
8890
8991 if ( $country != '' ){

Follow-up revisions

RevisionCommit summaryAuthorDate
r100466Fixes for all the custom filters extras....khorn22:26, 21 October 2011
r100472Even more fixes for all the custom filters extras....khorn23:05, 21 October 2011
r100484Debugging minfraud as a filter: Made sure we're passing in the contribution_t...khorn01:41, 22 October 2011

Status & tagging log