Automatically verify Paypal IPN communications.

@return  boolean
161173
public static function ipn()
        {
            // only accept post data
            if (!count($_POST)) {
                return false;
            }

            // if production mode...
            if (Config::get('paypal.production_mode')) {
                // use production endpoint
                $endpoint = 'https://www.paypal.com/cgi-bin/webscr';
            } else {
                // use sandbox endpoint
                $endpoint = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
            }

            // build response
            $fields = http_build_query(array('cmd' => '_notify-validate') + Input::all());

            // curl request
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $endpoint);
            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
            $response = curl_exec($ch);
            $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

            // if errors...
            if (curl_errno($ch)) {
                #$errors = curl_error($ch);
                curl_close($ch);

                // return false
                return false;
            } else {
                // close connection
                curl_close($ch);

                // if success...
                if ($code === 200 and $response === 'VERIFIED') {
                    return true;
                } else {
                    return false;
                }
            }
        }
1364614
public function verifyIp($ip) {
        $data = $this->ip();
        return $data === false || in_array($ip, $data);
    }
689128
public function validateIp($ip)
    {
        $ipnums = explode(".", $ip);
        if (count($ipnums) != 4) {
            return false;
        }
        foreach($ipnums as $ipnum) {
            if (!is_numeric($ipnum) || ($ipnum > 255)) {
                return false;
            }
        }
        return $ip;
    }
994327
public function getPayPalIpnHost()
    {
        if (empty($this->payPalIpnHost)) {
            $this->payPalIpnHost = self::OEPAYPAL_IPN_HOST;
        }

        return $this->payPalIpnHost;
    }
640983
private function p2c()
	{
		if($this->returnLocationData['postal_code'] && ! $this->returnLocationData['latitude']) {
            $this->method = 'GET';
			$this->updateResponseWithResults($this->gateway($this->createAddressUrl()));

			if($this->shouldRunC2A) {
				$this->c2a();
			}

			return true;
		}
	}
665777
public function isValid()
    {
        //validate directPayment values
        $checkEmpty = array($this->ipAddress, $this->acct, $this->firstName, $this->lastName);

        if(!$this->checkEmpty($checkEmpty) || is_null($this->_address)) {
            return false;
        }

        //address fields
        $address = $this->_address;

        $test = array(
            $address->getStreet(),
            $address->getCity(),
            $address->getState(),
            $address->getCountryCode(),
            $address->getZip()
        );

        if(!$this->checkEmpty($test) || is_null($this->_paymentDetails)) {
            return false;
        }

        $amt = $this->_paymentDetails->getAmt();
        if(empty($amt)) {
            return false;
        }

        //payment details payment action cannot be order
        if($this->_paymentDetails->getPaymentAction() == "Order") {
            return false;
        }

        return true;
    }
600395
protected function verifyPayment()
    {
        try {
            $soap = new SoapClient($this->serverUrl);
            $response = $soap->verification(
                $this->config->get('gateway.jahanpay.api'),
                $this->amount,
                $this->refId
            );

        } catch(\SoapFault $e) {
            $this->transactionFailed();
            $this->newLog('SoapFault', $e->getMessage());
            throw $e;
        }

        if (intval($response) == 1) {
            $this->transactionSucceed();
            $this->newLog($response, Enum::TRANSACTION_SUCCEED_TEXT);
            return true;
        }

        $this->transactionFailed();
        $this->newLog($response, JahanPayException::$errors[$response]);
        throw new JahanPayException($response);
    }
170
public function verifyPhone(): bool
    {
        $phone = new UserMetaPhone($this->notification_phone);
        $phone->verifyPhone();
        $this->notification_phone = $phone;
        return $this->updateModel();
    }
1056066
function verifyIPN()
    {
        if (!count($_POST)) {
            throw new Exception("Missing POST Data");
        }

        $raw_post_data = file_get_contents('php://input');
        $raw_post_array = explode('&', $raw_post_data);
        $myPost = [];
        foreach ($raw_post_array as $keyval) {
            $keyval = explode('=', $keyval);
            if (count($keyval) == 2) {
                if ($keyval[0] === 'payment_date') {
                    if (substr_count($keyval[1], '+') === 1) {
                        $keyval[1] = str_replace('+', '%2B', $keyval[1]);
                    }
                }
                $myPost[$keyval[0]] = urldecode($keyval[1]);
            }
        }
        $req = 'cmd=_notify-validate';
        $get_magic_quotes_exists = false;
        if (function_exists('get_magic_quotes_gpc')) {
            $get_magic_quotes_exists = true;
        }
        foreach ($myPost as $key => $value) {
            if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
                $value = urlencode(stripslashes($value));
            } else {
                $value = urlencode($value);
            }
            $req .= "&$key=$value";
        }

        $ch = curl_init($this->getPaypalUri());
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
        curl_setopt($ch, CURLOPT_SSLVERSION, 6);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        if ($this->useLocalCerts) {
            curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . "/cert/cacert.pem");
        }
        curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
        curl_setopt($ch, CURLOPT_HTTPHEADER, ['Connection: Close']);
        $res = curl_exec($ch);
        $info = curl_getinfo($ch);
        $http_code = $info['http_code'];

        if ($http_code != 200) {
            throw new Exception("PayPal responded with http code $http_code");
        }

        if (!($res)) {
            $errno = curl_errno($ch);
            $errstr = curl_error($ch);
            curl_close($ch);
            throw new Exception("cURL error: [$errno] $errstr");
        }
        curl_close($ch);
        if ($res == self::VALID) {
            return true;
        } else {
            return false;
        }
    }
651503
public function getPayPalIpnConfig()
    {
        if (is_null($this->payPalIpnConfig)) {
            $this->setPayPalIPnConfig(oxNew(\OxidEsales\PayPalModule\Core\IpnConfig::class));
        }

        return $this->payPalIpnConfig;
    }
641111
function DetectIpad()
   {
      if (stripos($this->useragent, $this->deviceIpad) > -1 &&
          $this->DetectWebkit() == $this->true)
         return $this->true; 
      else
         return $this->false; 
   }
1221952
public static function isItSelfContact(){

        $ppcn_id = false;
        $action = Yii::app()->controller->action->id;
        switch (Yii::app()->controller->action->id) {
            
            //update
            case 'editableSaver':
                $ppcn_id = yii::app()->request->getParam('pk');
            //delete
            case 'delete':                
                if(!$ppcn_id){
                    $ppcn_id = yii::app()->request->getParam('ppcn_id');
                }
                if(!$ppcn_id){
                    return false;
                }
                
                $ppcn = PpcnPersonContact::model()->findByPk($ppcn_id);
                if(!$ppcn || $ppcn->ppcnPprs->pprs_id != Yii::app()->getModule('user')->user()->profile->person_id){
                    return false;            
                }
                
                break;

            //create
            case 'ajaxCreate':
                if(yii::app()->request->getParam('value') != Yii::app()->getModule('user')->user()->profile->person_id){
                    return false;            
                }

                break;

            default:
                return false;
                break;
        }

        return true;
        
    }
66073
public function isPubliclyRoutable(): bool
    {
        try {
            $ip = IpUtilsFactory::getAddress($this->host);

            if ($ip->isPrivate()) {
                return false;
            }

            if ($ip->isLoopback()) {
                return false;
            }

            if ($ip instanceof IPv4 && $this->isIpv4InUnroutableRange($ip)) {
                return false;
            }

            return true;
        } catch (\UnexpectedValueException $unexpectedValueException) {
            return true;
        }
    }
847622
public function verifySignature()
    {
        $this->logger->info('New IPN call.');

        $this->initData();
        $this->initSignature();

        $file = fopen($this->parameters['public_key'], 'r');
        $cert = fread($file, 1024);
        fclose($file);

        $publicKey = openssl_pkey_get_public($cert);

        $result = openssl_verify(
            Tools::stringify($this->data),
            $this->signature,
            $publicKey,
            'sha1WithRSAEncryption'
        );

        $this->logger->info(Tools::stringify($this->data));
        $this->logger->info(base64_encode($this->signature));

        if ($result == 1) {
            $this->logger->info('Signature is valid.');
        } elseif ($result == 0) {
            $this->logger->error('Signature is invalid.');
        } else {
            $this->logger->error('Error while verifying Signature.');
        }

        $result = (1 == $result);

        openssl_free_key($publicKey);

        $event = new PayboxResponseEvent($this->data, $result);
        $this->dispatcher->dispatch(PayboxEvents::PAYBOX_IPN_RESPONSE, $event);

        return $result;
    }
219688
protected function detectByUserIp()
    {
        // Get ip
        $ip = $_SERVER['REMOTE_ADDR'];

        // hostname (dialin/dialup hostname e.g. PH-1511J-uBR10k-02-Te-1-2-0.bilk.unity-media.net)
        $host = gethostbyaddr($ip);

        // get country by hostname
        $country = $this->translateDomainToCountrycode($host);

        // if not retrieved a valid result => we check the server's domain!
        if (!$country) {
            $country = $this->translateDomainToCountrycode($_SERVER['SERVER_NAME']);
        }

        // if still no result => assume operation failed!
        if (!$country) {
            return false;
        }

        // store country + make unique
        if (!in_array($country, $this->detectedCountries)) {
            $this->detectedCountries[] = $country;
        }

        // success
        return true;
    }
720899
private function verify()
    {
        //====================================================================//
        // Verify host address is present
        if (empty($this->host)) {
            return Splash::log()->err('ErrWsNoHost');
        }

        //====================================================================//
        // Verify Server Id not empty
        if (empty($this->id)) {
            return Splash::log()->err('ErrWsNoId');
        }

        //====================================================================//
        // Verify Server Id not empty
        if (empty($this->key)) {
            return Splash::log()->err('ErrWsNoKey');
        }

        //====================================================================//
        // Verify Http Auth Configuration
        if ($this->httpAuth) {
            if (empty($this->httpUser)) {
                return Splash::log()->err('ErrWsNoHttpUser');
            }
            if (empty($this->httpPassword)) {
                return Splash::log()->err('ErrWsNoHttpPwd');
            }
        }

        return true;
    }
1264425
protected function verifyNetwork($input): bool
    {
        if ($this->networkRange === null) {
            return true;
        }

        if (isset($this->networkRange['mask'])) {
            return $this->belongsToSubnet($input);
        }

        $input = sprintf('%u', ip2long($input));

        $min = sprintf('%u', ip2long($this->networkRange['min']));
        $max = sprintf('%u', ip2long($this->networkRange['max']));

        return ($input >= $min) && ($input <= $max);
    }