prepare($query); $stmt->bindValue(':entity', $entity, SQLITE3_TEXT); $stmt->bindValue(':offerid', $offerid, SQLITE3_INTEGER); // Execute the query $result = $stmt->execute(); // Fetch the result if ($result) { $row = $result->fetchArray(SQLITE3_ASSOC); if ($row) { // Return all relevant details in an array return [ 'offerid' => $row['offerid'], 'entity' => $row['entity'], 'redlink' => $row['redlink'], 'unsublink' => $row['unsublink'], 'offername' => $row['offername'], 'vertical' => $row['vertical'], 'sponsor' => $row['sponsor'] ]; } else { return "Error: No record found for entity '$entity' and offerid '$offerid'."; } } else { return "Error executing query: " . $db->lastErrorMsg(); } // Close the database $db->close(); } function getIPInfo($ipAddress) { // Path to SQLite database $dbPath = '/home/db/ipv4.db'; // Ensure the database file exists if (!file_exists($dbPath)) { return "Error: Database file not found."; } // Open SQLite database $db = new SQLite3($dbPath); // Convert IP address to decimal format $ipDecimal = ip2long($ipAddress); if ($ipDecimal === false) { return "Error: Invalid IP address."; } // Use a prepared statement to avoid SQL injection $query = "SELECT country, asnum, asname, hosting FROM list WHERE ip1 <= :ipDecimal AND ip2 >= :ipDecimal"; $stmt = $db->prepare($query); $stmt->bindValue(':ipDecimal', $ipDecimal, SQLITE3_INTEGER); // Execute the query $result = $stmt->execute(); if ($result) { // Fetch the first matching row $row = $result->fetchArray(SQLITE3_ASSOC); $result->finalize(); // Finalize the result set if ($row) { // Return structured data $db->close(); return [ 'country' => $row['country'] ?? null, 'asnum' => $row['asnum'] ?? null, 'asname' => $row['asname'] ?? null, 'hosting' => $row['hosting'] ?? null ]; } else { $db->close(); return null; // IP not found } } else { $errorMsg = $db->lastErrorMsg(); $db->close(); return "Error executing query: " . $errorMsg; } } function getDomainFromUrl($url) { // Parse the URL to extract the host (domain) $parsedUrl = parse_url($url); return $parsedUrl['host'] ?? null; } function getActionType($char) { // Define the arrays $click_indice = ['s', 'c', 'd', 'a']; $open_indice = ['e', 'm', 't', 'w']; $unsub_indice = ['b', 'y', 'r', 'f']; $ourunsub_indice = ['p', 'v', 'n', 'h']; // Check which array the character belongs to if (in_array($char, $click_indice)) { return 'click'; } elseif (in_array($char, $open_indice)) { return 'open'; } elseif (in_array($char, $unsub_indice)) { return 'unsub'; } elseif (in_array($char, $ourunsub_indice)) { return 'globunsub'; } // Return null if the character is not found in any array return null; } function get_main_domain($domain) { // Comprehensive list of valid TLDs $tlds = array('.biz', '.casino', '.cc', '.club', '.co', '.com', '.de', '.digital', '.in', '.info', '.io', '.life', '.live', '.market', '.me', '.net', '.nl', '.online', '.org', '.pro', '.pw', '.shop', '.site', '.space', '.team', '.uk', '.uno', '.us', '.vip', '.voyage', '.website', '.work', '.xyz', '.co.in', '.co.uk', '.org.uk', 'jp.net'); // Validate the domain format if (!filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) { return 'Error: Invalid domain format'; } // Split the domain into parts $parts = explode('.', $domain); $numParts = count($parts); // Ensure there are at least two parts (e.g., "example.com") if ($numParts < 2) { return 'Error: Domain must have at least a second-level domain (e.g., example.com)'; } // Extract the TLD and check if it's valid $tld = '.' . $parts[$numParts - 1]; $secondTLD = '.' . $parts[$numParts - 2] . $tld; // Determine if it's a second-level TLD if (in_array($secondTLD, $tlds)) { // Main domain is the part before the second-level TLD return $parts[$numParts - 3] . $secondTLD; } else { // Main domain is the part before the TLD return $parts[$numParts - 2] . $tld; } } function getKeyword1($url) { // Parse the URL and extract the path $parsedUrl = parse_url($url); $path = $parsedUrl['path'] ?? ''; // Extract the first keyword (keyword1) $segments = explode('/', trim($path, '/')); // Trim slashes and split by '/' return $segments[0] ?? null; // Return the first segment or null if not found } function getKeyword2($url) { // Parse the URL and extract the query string $parsedUrl = parse_url($url); $query = $parsedUrl['query'] ?? ''; // Parse the query string into an associative array parse_str($query, $queryParams); // Return the first key (keyword2) or null if no query parameter exists return array_key_first($queryParams); } function getBase64Chain($url) { // Parse the URL and extract the query string $parsedUrl = parse_url($url); $query = $parsedUrl['query'] ?? ''; // Parse the query string into an associative array parse_str($query, $queryParams); // Return the first value (base64chain) or null if no query parameter exists return array_values($queryParams)[0] ?? null; } function getFirstCharacter($keyword) { // Trim the keyword to remove unwanted spaces and return the first character return $keyword ? $keyword[0] : null; } function decodeBase64($encodedString) { // Decode the Base64 string $decodedString = base64_decode($encodedString, true); // Check if decoding was successful if ($decodedString === false) { return "Error: Invalid Base64 string."; } return $decodedString; } function getDevice() { $ua = strtolower($_SERVER["HTTP_USER_AGENT"]); // Check for common mobile indicators $isMobile = preg_match('/mobile|android|iphone|ipad|ipod|blackberry|opera mini|opera mobi|nokia|windows phone|tablet|kindle|silk|webos/i', $ua); // Determine the device type if ($isMobile) { $device = 'mobile'; } else { $device = 'desktop'; } return $device; } function getOSFromUserAgent() { // Define an array of OS patterns and their corresponding names $userAgent = strtolower($_SERVER["HTTP_USER_AGENT"]); $osArray = [ '/android/i' => 'Android', // Prioritize Android before Linux '/windows nt 10/i' => 'Windows10', '/windows nt 6.3/i' => 'Windows8.1', '/windows nt 6.2/i' => 'Windows8', '/windows nt 6.1/i' => 'Windows7', '/windows nt 6.0/i' => 'WindowsVista', '/windows nt 5.2/i' => 'WindowsServer2003/XPx64', '/windows nt 5.1/i' => 'WindowsXP', '/windows xp/i' => 'WindowsXP', '/windows nt 5.0/i' => 'Windows2000', '/macintosh|mac os x/i' => 'MacOSX', '/mac_powerpc/i' => 'MacOS9', '/iphone/i' => 'iOS', '/ipod/i' => 'iOS', '/ipad/i' => 'iOS', '/linux/i' => 'Linux', // Linux should come after Android '/ubuntu/i' => 'Ubuntu', '/blackberry/i' => 'BlackBerry', '/webos/i' => 'WebOS', ]; // Default to unknown $os = 'unkos'; // Check against each pattern foreach ($osArray as $regex => $value) { if (preg_match($regex, $userAgent)) { $os = $value; break; } } return $os; } function getBrowser() { $userAgent = $_SERVER["HTTP_USER_AGENT"]; $browser = "unkbrowser"; // Check the User-Agent string for known browser patterns if (preg_match('/OPR\/([0-9.]+)/', $userAgent) || preg_match('/Opera\/([0-9.]+)/', $userAgent)) { $browser = "Opera"; } elseif (preg_match('/Edg\/([0-9.]+)/', $userAgent)) { $browser = "Edge"; } elseif (preg_match('/Chrome\/([0-9.]+)/', $userAgent) && !preg_match('/Edg/', $userAgent)) { $browser = "Chrome"; } elseif (preg_match('/Firefox\/([0-9.]+)/', $userAgent)) { $browser = "Firefox"; } elseif (preg_match('/Safari\/([0-9.]+)/', $userAgent) && preg_match('/Version\/([0-9.]+)/', $userAgent) && !preg_match('/Chrome/', $userAgent)) { $browser = "Safari"; } elseif (preg_match('/MSIE ([0-9.]+)/', $userAgent) || preg_match('/Trident\/.*rv:([0-9.]+)/', $userAgent)) { $browser = "InternetExplorer"; } return $browser; } function getparams($chain) { // Step 1: Split by lowercase letters [a-z], but only first 10 parts $elements = preg_split('/[a-z]/', $chain, 12); // Remove empty parts that can result from consecutive letters $elements = array_values(array_filter($elements, fn($e) => $e !== '')); // Step 2: Map to expected fields $result = [ 'cmp' => $elements[0] ?? null, 'subcmp' => $elements[1] ?? null, 'server' => $elements[2] ?? null, 'ip' => $elements[3] ?? null, 'offer' => $elements[4] ?? null, 'entity' => $elements[5] ?? null, 'list' => $elements[6] ?? null, 'emailid' => $elements[7] ?? null, 'timy' => $elements[8] ?? null, 'cmptrk' => $elements[9] ?? null, 'ispdomainid' => $elements[10] ?? null, 'fromdom' => $elements[11] ?? null, // ⬅️ Keeps lowercase letters like domains ]; //print_r($result); return $result; } function callApiInBackground($url, $data) { $ch = curl_init(); // cURL configuration curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); // Ensure data is correctly encoded curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Wait for the response curl_setopt($ch, CURLOPT_TIMEOUT, 5); // Allow a reasonable timeout curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $response = curl_exec($ch); // Execute the API call and get the response $error = curl_error($ch); // Check for errors curl_close($ch); // Close the connection if ($error) { return "Error: " . $error; } return $response; // Return the API response } function callApiInBackgroundold($url, $data) { $ch = curl_init(); // cURL configuration curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // Pass the string directly curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); // Do not wait for the response curl_setopt($ch, CURLOPT_TIMEOUT, 1); // Set a very short timeout curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_NOBODY, true); // Skip response body curl_exec($ch); // Execute the API call curl_close($ch); // Close the connection } $currentdate = date("Y-m-d"); $filedate=date('mdY'); $dayname = date('l', strtotime($currentdate)); $hourMin = date('H:i'); $botflag = 0; $geook = 1; $country = ""; $asnum = ""; $asname = "unkoper"; $hosting = ""; $asnamedata = [ "cloudflare", "cloudflare london", "cloudflare sydney", "akamai international", "akamai technologies", "akamai technologies tokyo", "akamai connected cloud", "akamai banglore office", "microsoft corporation", "microsoft deutschland mcio", "microsoft", "microsoft china co", "microsoft do brasil imp e com software video g", "yahoo! taiwan holdings branch", "yahoo japan", "yahoo de mexico cv", "yahoo! uk services", "yahoo", "yahoo japan corporation", "idc18140 yahoo japan corporation", "yahoo bangalore network monitoring center", "yahoo network", "yahoo china datacenter", "yahoo do brasil internet", "fastly", "stackpath", "limelight networks", "limelight networks india", "limelight networks australia", "limelight networks new delhi" ]; $clientip = $_SERVER['REMOTE_ADDR']; $ipInfo = getIPInfo($clientip); if ($ipInfo) { $country = strtolower($ipInfo['country']); $asnum = $ipInfo['asnum']; $asname = strtolower($ipInfo['asname']); $hosting = strtolower($ipInfo['hosting']); } if (in_array($asname, $asnamedata)) { $botflag = 1; } $url = curPageURL(); $domain = getDomainFromUrl($url); $maindom = get_main_domain($domain); $kw1 = getKeyword1($url); $kw2 = getKeyword2($url); $chain = getBase64Chain($url); $chaindecode = decodeBase64($chain); $fc = getFirstCharacter($kw1); $actiontype = getActionType($fc); $browser = sanitizeToKeyword(getBrowser()); $device = sanitizeToKeyword(getDevice()); $os = sanitizeToKeyword(getOSFromUserAgent()); $result_link = getparams($chaindecode); $cmpid = $result_link['cmp']; $subcmpid = $result_link['subcmp']; $serverid = $result_link['server']; $ip = $result_link['ip']; $offerid = $result_link['offer']; $entityid = $result_link['entity']; $listid = $result_link['list']; $emailid = $result_link['emailid']; $istest = "no"; if (preg_match('/^369/', $emailid)) { $istest = "yes"; } $timy = $result_link['timy']; $cmptrk = $result_link['cmptrk']; $ispdomainid = $result_link['ispdomainid']; $fromdom = $result_link['fromdom'] ?? 'no@no'; $entityname = "nps_".$entityid; $result_offer = getLinkDetails($entityname, $offerid); $infobase = $cmpid."_".$subcmpid."_".$cmptrk."_".$ip."_".$serverid."_".$listid."_".$entityid; $infobasetrk = $cmpid."_".$subcmpid."_".$cmptrk."_".$ip."_".$serverid."_".$listid."_".$entityid."_".$timy; $oper = sanitizeToKeyword($asname); $all_infobase = $infobase."_".$emailid."_".$clientip."_".$device."_".$browser."_".$os."_".$dayname."_".$hourMin."_".$botflag."_".$timy."_".$domain."_".$istest."_".sanitizeToKeyword($result_offer['offername'])."_".sanitizeToKeyword($result_offer['vertical'])."_".$oper."_".$fromdom."_".$ispdomainid."_".sanitizeToKeyword($result_offer['sponsor']); $info = base64_encode($infobasetrk); $redirect_link = str_replace('[info]',$info , $result_offer['redlink']); $redirect_link = str_replace('[idc]',$emailid , $redirect_link); $unsub_link = $result_offer['unsublink']; $mainredirect = "https://$maindom"; $glob_unsub_link = "http://$domain/unsub/unsub.php"; if($actiontype == "click") { $all_infobase = "click_".$all_infobase; $mainredirect = $redirect_link; } elseif($actiontype == "open") { $all_infobase = "open_".$all_infobase; } elseif($actiontype == "unsub") { $all_infobase = "unsub_".$all_infobase; $mainredirect = $unsub_link; } elseif($actiontype == "globunsub") { $all_infobase = "globunsub_".$all_infobase; $mainredirect = $glob_unsub_link; } if($botflag == 1) { $mainredirect = "https://$maindom"; } //Stat $apiUrl1 = "http://api.ilist-app.site:8001/tracking.php?token=Octopus159632@7532141"; //Data $apiUrl2 = "http://api.ilist-app.site:8002/action.php?token=Octopus159632@7532141"; // Call the API in the background $postData = ['data' => $all_infobase]; callApiInBackground($apiUrl1, $postData); callApiInBackground($apiUrl2, $postData); header ("location: $mainredirect"); ?>