From 5df366341b8e96fddf33631e400a710bc02dcc64 Mon Sep 17 00:00:00 2001 From: Pratik Joshi Date: Thu, 29 Aug 2013 20:44:16 +0530 Subject: [PATCH] CRM-13276 fix --- CRM/Contribute/Form/Contribution/Confirm.php | 7 ++--- CRM/Utils/System.php | 28 +++++++++++++------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index dfd6771ffd..a4f6ba5033 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -141,11 +141,8 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params); $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params); } - $this->_params['ip_address'] = $_SERVER['REMOTE_ADDR']; - // hack for safari - if ($this->_params['ip_address'] == '::1') { - $this->_params['ip_address'] = '127.0.0.1'; - } + + $this->_params['ip_address'] = CRM_Utils_System::ipAddress(); $this->_params['amount'] = $this->get('amount'); $this->_useForMember = $this->get('useForMember'); diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index 00ea475a35..63b218e854 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -993,21 +993,20 @@ class CRM_Utils_System { } /* - * Get logged in user's IP address. - * - * Get IP address from HTTP Header. If the CMS is Drupal then use the Drupal function - * as this also handles reverse proxies (based on proper configuration in settings.php) - * - * @return string ip address of logged in user - */ - - static function ipAddress() { + * Get logged in user's IP address. + * + * Get IP address from HTTP Header. If the CMS is Drupal then use the Drupal function + * as this also handles reverse proxies (based on proper configuration in settings.php) + * + * @return string ip address of logged in user + */ + static function ipAddress($strictIPV4 = TRUE) { $address = CRM_Utils_Array::value('REMOTE_ADDR', $_SERVER); $config = CRM_Core_Config::singleton(); if ($config->userSystem->is_drupal) { //drupal function handles the server being behind a proxy securely - return ip_address(); + $address = ip_address(); } // hack for safari @@ -1015,6 +1014,15 @@ class CRM_Utils_System { $address = '127.0.0.1'; } + // when we need to have strictly IPV4 ip address + // convert ipV6 to ipV4 + if ($strictIPV4) { + // this converts 'IPV4 mapped IPV6 address' to IPV4 + if (filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) && strstr($address, '::ffff:')) { + $address = ltrim($address, '::ffff:'); + } + } + return $address; } -- 2.25.1