-
-
Save hauzlife/89a4db279ba05df8531b1e9a917a03ae to your computer and use it in GitHub Desktop.
Full proxy of any simple website for Keitaro Tracker. Use it for safe pages. Description: https://vk.com/@npprteam-nppr-keitaro-curl-polnoe-proksirovanie-saitov-bonus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// settings | |
$API_KEY = 'API-KEY'; | |
$SUB_ID = 'sub_id_15'; | |
// main logic | |
$site = isset($_GET['site']) ? trim(strip_tags($_GET['site'])) : ''; | |
$campaign_id = isset($_GET['campaign_id']) ? trim(strip_tags($_GET['campaign_id'])) : ''; | |
$stream_id = isset($_GET['stream_id']) ? trim(strip_tags($_GET['stream_id'])) : ''; | |
$sub_id = isset($_GET[$SUB_ID]) ? trim(strip_tags($_GET[$SUB_ID])) : ''; | |
$useragent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; | |
if ($useragent === '') { | |
$useragent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36'; | |
} | |
if ($site === '' || !filter_var($site, FILTER_VALIDATE_URL)) { | |
die('Enter valid site'); | |
} | |
$site = rtrim($site, '/') . '/'; | |
if ($campaign_id === '') { | |
die('Enter valid campaign_id'); | |
} | |
[$campaign, $error] = keitaro_api('admin_api/v1/campaigns/' . $campaign_id); | |
if ($error !== '') { | |
die($error); | |
} | |
$domain = isset($campaign['domain']) ? $campaign['domain'] : ''; | |
if ($domain === '') { | |
die('Cannot find domain in campaign'); | |
} | |
if ($stream_id === '') { | |
die('Enter valid stream_id'); | |
} | |
[$stream, $error] = keitaro_api('admin_api/v1/streams/' . $stream_id); | |
if ($error !== '') { | |
die($error); | |
} | |
$comments = isset($stream['comments']) ? $stream['comments'] : ''; | |
$alias = isset($campaign['alias']) ? trim($campaign['alias']) : ''; | |
$parameters = isset($campaign['parameters']) ? $campaign['parameters'] : []; | |
if (isset($parameters[$SUB_ID])) { | |
unset($parameters[$SUB_ID]); | |
} | |
$parameters = array_map(function ($parameter) { | |
return $parameter['name'] . '=' . $parameter['placeholder']; | |
}, array_filter(array_values($parameters), function ($parameter) { | |
return $parameter['placeholder'] !== ''; | |
})); | |
$final_url = $domain . $alias . '?' . implode('&', $parameters); | |
$proxy_url = $site . ltrim($sub_id, '/'); | |
$filters = isset($stream['filters']) ? $stream['filters'] : []; | |
$filters = array_values(array_filter($filters, function ($filter) { | |
return $filter['name'] === 'referrer'; | |
})); | |
$referrer = count($filters) > 0 ? $filters[0]['payload'][0] : ''; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $proxy_url); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); | |
if ($referrer !== '') { | |
curl_setopt($ch, CURLOPT_REFERER, $referrer); | |
} | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 10); | |
curl_setopt($ch, CURLOPT_MAXREDIRS, 2); | |
$page = curl_exec($ch); | |
$page = preg_replace_callback('/\shref\s?=\s?["\']([^"^\']*?)["\']/', 'changeAnchors', $page, 300); | |
header('Content-Type: text/html; charset=UTF-8'); | |
echo str_replace('</body>', $comments . '</body>', $page); | |
function keitaro_api($method) { | |
global $API_KEY; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1/' . $method); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Api-Key: ' . $API_KEY]); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 10); | |
curl_setopt($ch, CURLOPT_MAXREDIRS, 2); | |
$response = @json_decode(curl_exec($ch), true); | |
$error = isset($response['error']) ? $response['error'] : ''; | |
return [$response, $error]; | |
} | |
function changeAnchors($m) { | |
global $site, $final_url, $SUB_ID; | |
$str = $m[0]; | |
$url = $m[1]; | |
if (( | |
stripos($url, '//') === 0 || | |
stripos($url, 'http://') === 0 || | |
stripos($url, 'https://') === 0 || | |
stripos($url, '#') === 0 || | |
stripos($url, 'javascript:') === 0 | |
) && stripos($url, rtrim($site, '/')) !== 0) { | |
return $str; | |
} | |
$new_url = str_replace(rtrim($site, '/'), '', $url); | |
$new_url = explode('#', $new_url); | |
$hash = ''; | |
if (count($new_url) > 1) { | |
$hash = $new_url[count($new_url) - 1]; | |
unset($new_url[count($new_url) - 1]); | |
} | |
$new_url = implode('#', $new_url); | |
$new_url = explode('?', $new_url); | |
$query = ''; | |
if (count($new_url) > 1) { | |
$query = $new_url[count($new_url) - 1]; | |
unset($new_url[count($new_url) - 1]); | |
} | |
$new_url = implode('?', $new_url); | |
$ext = explode('.', $new_url); | |
$ext = count($ext) > 1 ? strtolower($ext[count($ext) - 1]) : ''; | |
if (in_array($ext, ['', 'php', 'html', 'htm'])) { | |
$new_url = trim($new_url, '/'); | |
if ($new_url === '') { | |
$new_url = $final_url; | |
} else { | |
$new_url_param = '/' . $new_url; | |
if ($query !== '') { | |
$new_url_param .= '?' . $query; | |
} | |
if ($hash !== '') { | |
$new_url_param .= '#' . $hash; | |
} | |
} | |
return str_replace($url, $final_url . '&' . $SUB_ID . '=' . urlencode($new_url_param), $str); | |
} | |
return $str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment