<?php

/******************************************************************************
 *
 *	PROJECT: Flynax Classifieds Software
 *	VERSION: 4.X
 *	LICENSE: FL0M2SG681CQ - http://www.flynax.com/license-agreement.html
 *	PRODUCT: Pets Classifieds
 *	DOMAIN: pupsnshop.com
 *	FILE: REQUEST.PHP
 *
 *	The software is a commercial product delivered under single, non-exclusive, 
 *	non-transferable license for one domain or IP address. Therefore distribution, 
 *	sale or transfer of the file in whole or in part without permission of Flynax 
 *	respective owners is considered to be illegal and breach of Flynax License End 
 *	User Agreement. 
 *
 *	You are not allowed to remove this information from the file without permission
 *	of Flynax respective owners.
 *
 *	Flynax Classifieds Software 2014 |  All copyrights reserved. 
 *
 *	http://www.flynax.com/
 *
 ******************************************************************************/

session_start();

$challenge = $_POST['challenge'];

if ( $_SESSION['recaptcha_last_challenge'] == $challenge )
	exit;

$response = $_POST['response'];
$id = $_POST['id'];
$sess_key = 'ses_security_code'. $id;

$_SESSION['recaptcha_last_challenge'] = $challenge;
$_SESSION[$sess_key] = mt_rand();

/* load libs */
include_once( dirname(__FILE__) . "/../../includes/config.inc.php");
require_once( RL_CLASSES . 'rlDb.class.php' );
require_once( RL_CLASSES . 'reefless.class.php' );

$rlDb = new rlDb();
$reefless = new reefless();
$reefless -> connect(RL_DBHOST, RL_DBPORT, RL_DBUSER, RL_DBPASS, RL_DBNAME);

$config['reCaptcha_private_key'] = $rlDb -> getOne('Default', "`Key` = 'reCaptcha_private_key'", 'config');

if ( !extension_loaded('curl') ) {
	echo "cURL doesn't support";
}

$url = 'http://www.google.com/recaptcha/api/verify';
$url .= '?privatekey='. trim($config['reCaptcha_private_key']);
$url .= '&remoteip='. $_SERVER['REMOTE_ADDR'];
$url .= '&challenge='. $challenge;
$url .= '&response='. str_replace(' ', '', $response);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);

$content = curl_exec($ch);
curl_close($ch);

preg_match('/^([true|false]+)/', $content, $matches);

if ( $matches[0] == 'true' ) {
	$_SESSION[$sess_key] = $response;
}
else {
	$_SESSION[$sess_key] = empty($_SESSION[$sess_key]) ? mt_rand() : $_SESSION[$sess_key];
}