0) { $mem_ip_data = unserialize($mem_str); if (!is_array($mem_ip_data)) { $mem_ip_data = Array(); $mem_ip_data['ttl'] = time()+3600; // inicialize TTL } } else { $mem_ip_data = Array(); $mem_ip_data['ttl'] = time()+3600; // inicialize TTL } $mem_ip_data['country'] = $_SERVER["GEOIP_COUNTRY_CODE"]; $mem_ip_data['is_proxy'] = ((checkProxy())?'1':'0'); $mem_ip_data['agent'] = $_SERVER["HTTP_USER_AGENT"]; $ttl = $mem_ip_data['ttl'] - time(); $ttl = (($ttl<1)?1:$ttl); $visits = $mem_ip_data['visits']; $visit_time = 0; if (is_array($visits) && count($visits)>0) { ksort($visits); foreach($visits as $time=>$visit) { if ($visit['sent_to_niche']==$click['niche']) { $visit_time = $time; } } $visit_time = ($visit_time==0)?$time:$visit_time; // if there is no match then use last time value } if (intval($mem_ip_data['visits'][$visit_time]['id'])>0 && $mem_ip_data['visits'][$visit_time]['is_nocookie']!=$click['is_nocookie']) { $mem_ip_data['visits'][$visit_time]['update_visit'] = 1; } $mem_ip_data['visits'][$visit_time]['is_nocookie'] = $click['is_nocookie']; $mem_ip_data['visits'][$visit_time]['clicks'][time()] = $click; $mem_val_str = serialize($mem_ip_data); eaccelerator_put(DB_DBASE.'_visit_'.$_SERVER['REMOTE_ADDR'],$mem_val_str,$ttl); } /***************************************************************************** * Function validates visitor key * * @param string key * @return bool Valid/Not valid ****************************************************************************/ function validateKey($passed_key) { global $cookie_names; $prefix = "_super_secret_"; $ip = $_SERVER['REMOTE_ADDR']; $datetime1 = date("Y.m.d"); $datetime2 = date("Y.m.d",time()-24*3600); // yesterday $key1 = md5($prefix.$ip.$datetime1); $key2 = md5($prefix.$ip.$datetime2); if ($passed_key==$key1 || $passed_key==$key2) { return true; } else { return false; } } /***************************************************************************** * Function validates visitor key * * @param string key * @return bool Valid/Not valid ****************************************************************************/ function isClicksGood($clicks, $seconds) { global $cookie_names; if ($clicks<1||$seconds<0) { return true; } $mem_str = eaccelerator_get(DB_DBASE.'_visit_'.$_SERVER['REMOTE_ADDR']); if (strlen($mem_str)>0) { $mem_ip_data = unserialize($mem_str); } if (!is_array($mem_ip_data)) { $mem_ip_data = Array(); } $visits = $mem_ip_data['visits']; $all_clicks = Array(); if (is_array($visits) && count($visits)>0) { foreach($visits as $visit_time=>$visit) { if (count($visit['clicks'])>0) { foreach($visit['clicks'] as $click_time=>$click) { $all_clicks[] = $click_time; } } } } if (count($all_clicks)>$clicks) { sort($all_clicks); $size = count($all_clicks)-$clicks; for($i=0;$i<$size;$i++) { if (($all_clicks[($i+$clicks)]-$all_clicks[$i])<$seconds) { return false; } } } return true; } /***************************************************************************** * Function validates visitor key * * @param string key * @return bool Valid/Not valid ****************************************************************************/ function isImgOK($clicker) { global $cookie_names; $mem_str = eaccelerator_get(DB_DBASE.'_visit_'.$_SERVER['REMOTE_ADDR']); if (strlen($mem_str)>0) { $mem_ip_data = unserialize($mem_str); } if (!is_array($mem_ip_data)) { $mem_ip_data = Array(); } $visits = $mem_ip_data['visits']; $visit_time = 0; if (is_array($visits) && count($visits)>0) { ksort($visits); foreach($visits as $time=>$visit) { if ($visit['sent_to_niche']==$clicker['niche']) { $visit_time = $time; } } $visit_time = ($visit_time==0)?$time:$visit_time; } if ($mem_ip_data['visits'][$visit_time]['is_cht2']===0) { return true; // passed } else { return false; // check not passed } } /***************************************************************************** * Function gets trade_id from referer * * @return array settings ****************************************************************************/ function getTrade($refdomain) { global $cookie_names; if (strlen(trim($refdomain))==0) { return 0; } $trades_str = eaccelerator_get(DB_DBASE.'_trades'); if (strlen($trades_str)>0) { $trades = unserialize($trades_str); if (!is_array($trades)||count($trades)==0) { return 0; } foreach($trades as $trade) { if (trim($trade['domain'])==trim($refdomain)) { return $trade['id']; } } } return 0; } /***************************************************************************** * Function gets click data * * @return array click params ****************************************************************************/ function getClickData() { global $cookie_names; if (strlen($_REQUEST['req_id'])>0) { $req_id = intval(trim($_REQUEST['req_id'])); $se_friendly = getMemoryArray('se_friendly'); if (strlen($se_friendly[$req_id])>0) { $my_request = $se_friendly[$req_id]; } else { $se_file = file('tmanager7/pages/se_friendly_urls'); if (count($se_file)>0) { foreach($se_file as $item) { list($id,$ttl,$url) = split('\|',$item,3); $se_friendly[$id] = $url; } storeMemoryArray('se_friendly',$se_friendly); $my_request = $se_friendly[$req_id]; } } if (strpos($my_request,'&')===false && strpos($my_request,'v=')!==false) { $my_request = base64_decode(substr($my_request, strpos($my_request, 'v=')+2)); } if (strpos($my_request,'&')!==false) { $vars = explode('&',$my_request); foreach($vars as $var) { list($name,$val) = split("=",$var); $request[$name] = $val; } } else { $request = $_REQUEST; // (error?) } } else if (strlen($_REQUEST['v'])>0) { /// do we have variables encoded? if (($var_str = base64_decode($_REQUEST['v'])) !== false) { $vars = explode('&',$var_str); foreach($vars as $var) { list($name,$val) = split("=",$var); $request[$name] = $val; } } else { $request = $_REQUEST; // we shouldn't be here (base64_decode error?) } } else { $request = $_REQUEST; // variables not encoded, use them from $_REQUEST if (strlen($_SERVER['QUERY_STRING'])>0 && strpos($_SERVER['QUERY_STRING'],'u=') !== false) { $request['u'] = substr($_SERVER['QUERY_STRING'],strpos($_SERVER['QUERY_STRING'],'u=')+2); } } if(!empty($GLOBALS['urllocal'])){ $request['u']=$GLOBALS['urllocal']; } $click['ip'] = $_SERVER['REMOTE_ADDR']; $click['country'] = $_SERVER["GEOIP_COUNTRY_NAME"]; $click['country_short'] = $_SERVER["GEOIP_COUNTRY_CODE"]; $click['referer'] = $_COOKIE[$cookie_names['tm_refdomain']]; $click['click_num'] = intval($_COOKIE[$cookie_names['tm_click_num']])+1; $click['is_cookie'] = (strlen($_COOKIE[$cookie_names['tm_visit']])>0)?true:false; $click['is_cheat'] = ($request['c']=='1')?true:false; $click['click_again'] = (strlen($_COOKIE[$cookie_names['clicked_thumbs']])>0)?1:0; $click['content'] = urldecode($request['u']); $click['link_track'] = trim($_REQUEST['l']); $click['thumb'] = intval($request['t']); $click['niche'] = (intval($request['n'])>0)?intval($request['n']):1; $click['thube_thumb'] = intval($request['t']); $click['click_type'] = intval($request['ct']); $click['spot'] = intval($request['sp']); $click['key'] = (strlen($_COOKIE[$cookie_names['tm_key']])>0)?$_COOKIE[$cookie_names['tm_key']]:'nocookie'; $click['key2'] = (strlen($_COOKIE[$cookie_names['tm_key2']])>0)?$_COOKIE[$cookie_names['tm_key2']]:''; $click['pct'] = ((strlen($request['pct'])>0)?intval($request['pct']):""); $clicked_ids = explode("%7C", $_COOKIE[$cookie_names['tm_clicked_thumbs']]); $click['clicked_thumbs'] = (is_array($clicked_ids))?$clicked_ids:Array(); $clicked_trades = explode("%7C", $_COOKIE[$cookie_names['tm_clicked_trades']]); $click['clicked_trades'] = (is_array($clicked_trades))?$clicked_trades:Array(); $external_trades = explode("\.", $_COOKIE[$cookie_names['external_info']]); $click['external_trades'] = (is_array($external_trades))?$external_trades:Array(); $click['trade_id'] = 3; // default trade = content if ($click['is_cookie']) { //set cookies setcookie($cookie_names['tm_click_num'], "".$click['click_num'], time()+86400,"/"); if ($click['thumb']>0) { $clicked_thumbs_cookie = (strlen($_COOKIE[$cookie_names['clicked_thumbs']])>0)?$_COOKIE[$cookie_names['clicked_thumbs']]."%7C":""; setcookie($cookie_names['clicked_thumbs'], $clicked_thumbs_cookie.$click['thumb'], time()+86400,"/"); } } return $click; } /***************************************************************************** * Function gets memory cached array * * @param string variable name * @return array cached array ****************************************************************************/ function getMemoryArray($name) { global $cookie_names; $arr_str = eaccelerator_get(DB_DBASE.'_'.$name); if (strlen($arr_str)>0) { $arr = unserialize($arr_str); if (!is_array($arr)) { $arr = Array(); } } return $arr; } /***************************************************************************** * Function stores memory cached array * * @param string variable name * @param array array for cache ****************************************************************************/ function storeMemoryArray($name,$arr,$ttl = 3600) { global $cookie_names; if (!is_array($arr)) { $arr = Array(); } $arr_str = serialize($arr); eaccelerator_put(DB_DBASE.'_'.$name,$arr_str,$ttl); } /***************************************************************************** * Function adds click for thumb * * @param array click data ****************************************************************************/ function addClick($click) { global $cookie_names; if ($click['click_num']==1) { $var_name = 'thumb_fclicks'; // we got fclick } else if ($click['click_num']<6) { $var_name = 'thumb_clicks'; // we got click } else { return; // too many clicks (don't count any more) } $id = intval($click['thumb']); $clicks = getMemoryArray($var_name); $clicks[$id] = intval($clicks[$id]) + 1; storeMemoryArray($var_name,$clicks); } /***************************************************************************** * Function adds view for thumb * * @param array view data ****************************************************************************/ function addView($click) { global $cookie_names; if ($click['click_num']<6) { $var_name = 'views'; // we got click to gallery } else { return; // too many clicks (don't count any more) } $id = intval($click['thumb']); $views = getMemoryArray($var_name); $views[$id] = intval($views[$id]) + 1; storeMemoryArray($var_name,$views); } /***************************************************************************** * Function saves script exec time * * @param time start time ****************************************************************************/ function saveExecTime($start_time) { global $cookie_names; $time_end = microtime(true); $time = $time_end - $start_time; if ($time>100) { // bugfix? return; // return if number too large } $val_str = "('".date("Y-m-d H:i:s")."','out.php','".strtolower(TRADESCRIPT_VERSION)."',".$time.")"; $load_stats = eaccelerator_get(DB_DBASE.'_load_stats'); if (strlen($load_stats)==0) { eaccelerator_put(DB_DBASE.'_load_stats',$val_str); } else { eaccelerator_put(DB_DBASE.'_load_stats',$load_stats.",".$val_str); } } /***************************************************************************** * Function checks visitor for using proxy * * @return boolean proxy status ****************************************************************************/ function checkProxy() { $PROXY_VARS = array(); $PROXY_VARS[0] = "HTTP_X_FORWARDED_FOR"; $PROXY_VARS[1] = "HTTP_VIA"; $PROXY_VARS[2] = "HTTP_PROXY_CONNECTION"; $PROXY_VARS[3] = "HTTP_CLIENT_IP"; $PROXY_VARS[4] = "HTTP_X_COMING_FROM"; $PROXY_VARS[5] = "HTTP_X_FORWARDED"; $PROXY_VARS[6] = "HTTP_COMING_FROM"; $PROXY_VARS[7] = "HTTP_PROXY"; $PROXY_VARS[8] = "HTTP_XPROXY"; $PROXY_VARS[9] = "HTTP_FORWARDED_FOR"; $PROXY_VARS[10] = "HTTP_FORWARDED"; $PROXY_VARS[11] = "ZHTTP_CACHE_CONTROL"; $PROXY_VARS[12] = "HTTP_CACHE_INFO"; $PROXY_VARS[13] = "HTTP_XONNECTION"; $PROXY_VARS[14] = "HTTP_PRAGMA"; $PROXY_VARS[15] = "X-Cache"; foreach($PROXY_VARS as $k=>$val) { if(getenv($val)) { return true; // using proxy } } return false; } /***************************************************************************** * Function saves script exec time * * @param time start time ****************************************************************************/ function showPage($click,$cache='') { global $cookie_names; global $settings,$start_time,$trades,$mem_visitor; //***** [1.1] Format url if(is_numeric($click['url'])){ $newcontent=FormatUrl($click['url']); $click['url']=$newcontent; } if($cache=="googlebot") { //show page, no stats header("Location: ".$click['url']); return; } if ($cache=='no_cache') { // no memory cache, just send to content and exit header("Pragma: no-cache"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Location: ".$click['url']); return; } //add trade data $val_str = "('".date("Y-m-d H:i:s")."',".$click['trade_id'].",'".$click['ip']."','".addslashes($click['country'])."','".$click['country_short']."','".addslashes($click['referer'])."',".intval($click['click_num']).",".(($click['is_cookie'])?"1":"0").",".(($click['free_hit'])?"1":"0").",".(($click['is_cheat'])?"1":"0").",".(($click['click_again'])?"1":"0").",'".addslashes($click['link_track'])."')"; $out_data = eaccelerator_get(DB_DBASE.'_out_data'); if (strlen($out_data)==0) { eaccelerator_put(DB_DBASE.'_out_data',$val_str); } else { eaccelerator_put(DB_DBASE.'_out_data',$out_data.','.$val_str); } /* if ($click['trade_id']>4) { $click['click']['sent_to_trade'] = $click['trade_id']; } else { $click['click']['sent_to_content'] = '1'; } */ saveClickData($click); // Add click into visitor memory tree /* $cur_click = Array(); $cur_click['trade_id'] = $click['trade_id']; $cur_click['referer'] = $click['referer']; $cur_click['click_num'] = count($mem_visitor['clicks'])+1; $cur_click['is_cookie'] = (($click['is_cookie'])?"1":"0"); $cur_click['is_freehit'] = (($click['free_hit'])?"1":"0"); $cur_click['is_cheat'] = (($click['is_cheat'])?"1":"0"); $cur_click['click_again'] = (($click['click_again'])?"1":"0"); $cur_click['link_track'] = $click['link_track']; $mem_visitor['clicks'][time()] = $cur_click; $mem_ip_data[$visitor['key']] = $mem_visitor; addMemIpData($mem_ip_data,$mem_visitor); */ // set visited trade cookie if ($click['trade_id']>4) { if (count($click['clicked_trades'])>0) { $trades_cookie = implode("%7C",$click['clicked_trades'])."%7C".$click['trade_id']; } else { $trades_cookie = $click['trade_id']; } setcookie($cookie_names['tm_clicked_trades'],$trades_cookie , time()+86400,"/"); // set visited trades cookie if ($settings['external_info']=="1" && $trades[$click['trade_id']]['external_info']=="1") { $out_crc = substr(crc32($_SERVER['SERVER_NAME']), -4); $external_str = "x=".((strlen($_COOKIE[$cookie_names['external_info']])>0)?$_COOKIE[$cookie_names['external_info']].".".$out_crc:$out_crc); $url_info = parse_url($click['url']); $click['url'] = $url_info['scheme']."://".$url_info['host'].$url_info['path']."?".((strlen($url_info['query'])>0)?$url_info['query']."&":"").$external_str; // $click['url'] = (substr($click['url'],-3)=='com')?$click['url'].'/':$click['url']; // $click['url'] = (!strstr($click['url'],"?") && substr($click['url'],-1)!='/')?$click['url'].'/':$click['url']; // $click['url'] = (strstr($click['url'],"?"))?$click['url']."&x=".$external_str:$click['url']."?x=".$external_str; } } // modify content URL setting if ($click['trade_id']==3 && strlen($settings['modify_content'])>0 && $settings['modify_content']!='%%GALLERY_URL%%') { $click['url'] = str_ireplace('%%GALLERY_URL%%',$click['url'],$settings['modify_content']); } // show page if ($click['trade_id']==3&&($settings['top_frame_enable']==1||$settings['bottom_frame_enable']==1)&&(file_exists(TMANAGER_DIR."/pages/niche1/top_frame.html")||file_exists(TMANAGER_DIR."/pages/niche1/bottom_frame.html"))) { echo "\n\n"; if (file_exists(TMANAGER_DIR."/pages/niche1/top_frame.html")&&$settings['top_frame_enable']==1) { echo "\n"; } echo "\n"; if (file_exists(TMANAGER_DIR."/pages/niche1/bottom_frame.html")&&$settings['bottom_frame_enable']==1) { echo "\n"; } echo "\n"; } else { setcookie($cookie_names['tm_click'],$click['click_num'] , time()+86400,"/"); // set click cookie header("Pragma: no-cache"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Location: ".$click['url']); } saveExecTime($start_time); // save page exec time } /***************************************************************************** * Function calculates random weighted value ****************************************************************************/ function weighted_rand($weights) { global $cookie_names; $total_weight = 0; if (count($weights)==0) return; foreach ($weights as $val=>$weight) { $total_weight += $weight; } if ($total_weight<1) { return $val; } $rand = mt_rand(1, $total_weight); $total_weight = 0; foreach ($weights as $value => $weight) { $total_weight += $weight; if ($rand <= $total_weight) return $value; } } /***************************************************************************** * Function checks user IP address against ban-list * * @param string visitor IP address * @return boolean IP ban status ****************************************************************************/ function checkIpBan($ip) { global $cookie_names; $ip = ip2long($ip); $banned_ips_str = eaccelerator_get(DB_DBASE.'_ip_ban'); if (strlen($banned_ips_str)>0) { $banned_ips = unserialize($banned_ips_str); if (is_array($banned_ips) && count($banned_ips)>0) { foreach($banned_ips as $banned_ip) { if ($banned_ip['ip_from']<=$ip && $ip<=$banned_ip['ip_to']) { return true; // IP banned } } } } return false; } /***************************************************************************** * Function checks referer against ban-list * * @param string visitor domain name * @return boolean domain ban status ****************************************************************************/ function checkRefBan($host) { global $cookie_names; $banned_refs_str = eaccelerator_get(DB_DBASE.'_ref_ban'); if (strlen($banned_refs_str)>0) { $banned_refs = unserialize($banned_refs_str); if (is_array($banned_refs) && count($banned_refs)>0) { if (in_array($host,$banned_refs)) { return true; // referer banned } } } return false; } /**************************************************************************** * Format url from id to real */ function FormatUrl($u){ global $memcashed_server,$memcashed_port,$thumblocal; //***** banned gallery hosts if(is_file("bannedhost")){ $fp=fopen("bannedhost","r"); while($str=fgets($fp)){ $str=trim($str); if(!empty($str)){ $bannedhost[]=$str; } } fclose($fp); } else { $bannedhost=array(); } $u=intval($u); $ip=$_SERVER['REMOTE_ADDR']; include(RT_DIR."lib/mysql/db_config.php"); if(@mysql_connect($db_host,$db_user,$db_passwd)){ if(mysql_select_db($db_name)) { if(!empty($u)) { $res=mysql_query("SELECT url,localurl FROM htm_gallery WHERE gid=".$u); $row=mysql_fetch_array($res); if(count($row)){ $url=$row[0]; $localurl=$row[1]; $host=parse_url($url,PHP_URL_HOST); $host=str_replace("www.", "", $host); if (! empty($localurl)) { if (! empty($memcashed_server) && ! empty($memcashed_port)) { $memcache_obj = new Memcache(); if ($memcache_obj->connect($memcashed_server, $memcashed_port)) { $visit = @$memcache_obj->get("gal_" . $host . "_" . $ip); if(in_array($host, $bannedhost)){ $banned=1; } else { $banned=0; } if (empty($visit) && !$banned) { // первый заход $memcache_obj->set("gal_" . $host . "_" . $ip, "1", false, 86400); $u = $url; /* $fp=fopen("iplog","a"); fputs($fp, $ip." ".$host." 1\n"); fclose($fp);*/ } else { // повторный заход $u=$localurl; if(!empty($thumblocal)){ $u.="?".$thumblocal; } /*$fp=fopen("iplog","a"); fputs($fp, $ip." ".$host." 2\n"); fclose($fp);*/ } } else { $u = $url; } } else { $u = $url; } } else { $u = $url; } } else { $u="http://google.com"; } } else { $u="http://google.com"; } } else { $u="http://google.com"; } } else { $u="http://google.com"; } return $u; } Function decbin32 ($dec) { return str_pad(decbin($dec), 32, '0', STR_PAD_LEFT); } // ip_in_range // This function takes 2 arguments, an IP address and a "range" in several // different formats. // Network ranges can be specified as: // 1. Wildcard format: 1.2.3.* // 2. CIDR format: 1.2.3/24 OR 1.2.3.4/255.255.255.0 // 3. Start-End IP format: 1.2.3.0-1.2.3.255 // The function will return true if the supplied IP is within the range. // Note little validation is done on the range inputs - it expects you to // use one of the above 3 formats. Function ip_in_range($ip, $range) { if (strpos($range, '/') !== false) { // $range is in IP/NETMASK format list($range, $netmask) = explode('/', $range, 2); if (strpos($netmask, '.') !== false) { // $netmask is a 255.255.0.0 format $netmask = str_replace('*', '0', $netmask); $netmask_dec = ip2long($netmask); return ( (ip2long($ip) & $netmask_dec) == (ip2long($range) & $netmask_dec) ); } else { // $netmask is a CIDR size block // fix the range argument $x = explode('.', $range); while(count($x)<4) $x[] = '0'; list($a,$b,$c,$d) = $x; $range = sprintf("%u.%u.%u.%u", empty($a)?'0':$a, empty($b)?'0':$b,empty($c)?'0':$c,empty($d)?'0':$d); $range_dec = ip2long($range); $ip_dec = ip2long($ip); # Strategy 1 - Create the netmask with 'netmask' 1s and then fill it to 32 with 0s #$netmask_dec = bindec(str_pad('', $netmask, '1') . str_pad('', 32-$netmask, '0')); # Strategy 2 - Use math to create it $wildcard_dec = pow(2, (32-$netmask)) - 1; $netmask_dec = ~ $wildcard_dec; return (($ip_dec & $netmask_dec) == ($range_dec & $netmask_dec)); } } else { // range might be 255.255.*.* or 1.2.3.0-1.2.3.255 if (strpos($range, '*') !==false) { // a.b.*.* format // Just convert to A-B format by setting * to 0 for A and 255 for B $lower = str_replace('*', '0', $range); $upper = str_replace('*', '255', $range); $range = "$lower-$upper"; } if (strpos($range, '-')!==false) { // A-B format list($lower, $upper) = explode('-', $range, 2); $lower_dec = (float)sprintf("%u",ip2long($lower)); $upper_dec = (float)sprintf("%u",ip2long($upper)); $ip_dec = (float)sprintf("%u",ip2long($ip)); return ( ($ip_dec>=$lower_dec) && ($ip_dec<=$upper_dec) ); } return false; } } function isGoogleBot($ip){ if(stristr($_SERVER['HTTP_USER_AGENT'], "Googlebot")) { return true; } if(is_file("googleip")){ $fp=fopen("googleip", "r"); while ($str=fgets($fp)){ $range=trim($str); if(ip_in_range($ip,$range)){ return true; } } fclose($fp); } return false; } /***************************************************************************** * Main() ****************************************************************************/ //***** [0] rolling info if(!empty($_GET['id'])){ if ($f = fopen(RT_DIR . 'engine/temp/log.dat', 'ab')) { if(stristr($_GET['id'], "|")){ list ($x1, $x2, $x3) = explode('|', $_GET['id']); } else { list ($x1, $x2, $x3) = explode('l', $_GET['id']); } if (! empty($x1) && ! empty($x2) && ! empty($x3)) { $s = pack('III', $x1, $x2, $x3); fwrite($f, $s); fclose($f); chmod(RT_DIR . 'log.dat', 0666); } } } //with rewrite if(!empty($_GET['local'])){ if(stristr($_GET['local'],"l") && substr_count($_GET['local'],"l")>1){ //have clickid for rolling stats if ($f = fopen(RT_DIR . 'engine/temp/log.dat', 'ab')) { list ($x1, $x2, $x3 ,$urlid,$thumblocal) = explode('l', $_GET['local']); if (! empty($x1) && ! empty($x2) && ! empty($x3)) { $s = pack('III', $x1, $x2, $x3); fwrite($f, $s); fclose($f); chmod(RT_DIR . 'log.dat', 0666); } } }elseif(stristr($_GET['local'],"l") && substr_count($_GET['local'],"l")==1){ //archive click list ($urlid,$thumblocal) = explode('l', $_GET['local']); }else { $urlid=$_GET['local']; } $GLOBALS['urllocal']=intval($urlid); $GLOBALS['thumblocal']=intval($thumblocal); } //***** [1] Get click data $click = getClickData(); if(empty($_GET['l'])){ $click['pct']="60"; } if(is_numeric($click['content'])){ $newcontent=FormatUrl($click['content']); $click['content']=$newcontent; } if(stristr($click['content'], "pornhub.com")){ $click['content']=""; } //***** [2] Check memory cache status if (!checkMemoryCache()) { // memory cache not enabled - show content & exit $click['url'] = $click['content']; // send to content showPage($click,'no_cache'); exit; } //***** [2.1] Check GoogleBot //$click['ip']="74.125.184.15"; if (isGoogleBot($click['ip'])) { // if google bot - send to content $click['url'] = $click['content']; // send to content showPage($click,'googlebot'); exit; } //***** [3] Get site settings $settings = getMemoryArray('settings'); //***** [3] Get site settings $geoip = getMemoryArray('geoip'); //***** [4] Check IP ban if (checkIpBan($click['ip'])) { $click['click']['ip_ban'] = '1'; $click['click']['sent_to_url'] = $settings['exout_url']; // saveClickData($click); header("Location: ".$settings['exout_url']); // send to "exout" URL exit; } //***** [5] Check referer ban if (checkRefBan($click['referer'])) { $click['click']['ref_ban'] = '1'; $click['click']['sent_to_url'] = $settings['exout_url']; // saveClickData($click); header("Location: ".$settings['exout_url']); // send to "exout" URL exit; } //***** [4] Add thumb click data if ($click['is_cookie'] && intval($click['thumb'])>0) { addClick($click); } //***** ANTICHEAT CHEKS $traffic_matched = false; if (intval($settings['cht1_action'])>0 && !validateKey($click['key2'])) { $click['click']['is_cht1'] = 1; if (!$traffic_matched) { switch($settings['cht1_action']) { case "1": $click['trade_id'] = 3; // send to content $click['url'] = ($click['thumb']==0 && strlen($settings['rnd_gallery'])>0)?$settings['rnd_gallery']:$click['content']; showPage($click); exit; case "2": $click['pct'] = 0; // send to trade $traffic_matched = true; break; case "3": $click['trade_id'] = 3; // send to URL $click['url'] = $settings['cht1_force_url']; showPage($click); exit; case "4": $click['pct'] = $settings['cht1_force_skim']; // change skim $traffic_matched = true; break; } } } if (intval($settings['cht2_action'])>0 && !isImgOK($click)) { $click['click']['is_cht2'] = 1; if (!$traffic_matched) { switch($settings['cht2_action']) { case "1": $click['trade_id'] = 3; // send to content $click['url'] = ($click['thumb']==0 && strlen($settings['rnd_gallery'])>0)?$settings['rnd_gallery']:$click['content']; showPage($click); exit; case "2": $click['pct'] = 0; // send to trade $traffic_matched = true; break; case "3": $click['trade_id'] = 3; // send to URL $click['url'] = $settings['cht2_force_url']; showPage($click); exit; case "4": $click['pct'] = $settings['cht2_force_skim']; // change skim $traffic_matched = true; break; } } } if (0&&intval($settings['cht3_action'])>0 && $click['is_cheat']) { $click['click']['is_cht3'] = 1; if (!$traffic_matched) { switch($settings['cht3_action']) { case "1": $click['trade_id'] = 3; // send to content $click['url'] = ($click['thumb']==0 && strlen($settings['rnd_gallery'])>0)?$settings['rnd_gallery']:$click['content']; showPage($click); exit; case "2": $click['pct'] = 0; // send to trade $traffic_matched = true; break; case "3": $click['trade_id'] = 3; // send to URL $click['url'] = $settings['cht3_force_url']; showPage($click); exit; case "4": $click['pct'] = $settings['cht3_force_skim']; // change skim $traffic_matched = true; break; } } } if (intval($settings['cht4_action'])>0 && !isClicksGood($settings['cht4_clicks'],$settings['cht4_seconds'])) { $click['click']['is_cht4'] = 1; if (!$traffic_matched) { switch($settings['cht4_action']) { case "1": $click['trade_id'] = 3; // send to content $click['url'] = ($click['thumb']==0 && strlen($settings['rnd_gallery'])>0)?$settings['rnd_gallery']:$click['content']; showPage($click); exit; case "2": $click['pct'] = 0; // send to trade $traffic_matched = true; break; case "3": $click['trade_id'] = 3; // send to URL $click['url'] = $settings['cht4_force_url']; showPage($click); exit; case "4": $click['pct'] = $settings['cht4_force_skim']; // change skim $traffic_matched = true; break; } } } if (0&&intval($settings['traf1_action'])>0 && $click['is_cookie']===false) { if (!$traffic_matched) { switch($settings['traf1_action']) { case "1": $click['trade_id'] = 3; // send to content $click['url'] = ($click['thumb']==0 && strlen($settings['rnd_gallery'])>0)?$settings['rnd_gallery']:$click['content']; showPage($click); exit; case "2": $click['pct'] = 0; // send to trade $traffic_matched = true; break; case "3": $click['trade_id'] = 3; // send to URL $click['url'] = $settings['traf1_force_url']; showPage($click); exit; case "4": $click['pct'] = $settings['traf1_force_skim']; // change skim $traffic_matched = true; break; } } } if (intval($settings['traf2_action'])>0 && strlen($click['referer'])==0) { if (!$traffic_matched) { switch($settings['traf2_action']) { case "1": $click['trade_id'] = 3; // send to content $click['url'] = ($click['thumb']==0 && strlen($settings['rnd_gallery'])>0)?$settings['rnd_gallery']:$click['content']; showPage($click); exit; case "2": $click['pct'] = 0; // send to trade $traffic_matched = true; break; case "3": $click['trade_id'] = 3; // send to URL $click['url'] = $settings['traf2_force_url']; showPage($click); exit; case "4": $click['pct'] = $settings['traf2_force_skim']; // change skim $traffic_matched = true; break; } } } if (intval($settings['traf3_action'])>0 && checkProxy()) { if (!$traffic_matched) { switch($settings['traf3_action']) { case "1": $click['trade_id'] = 3; // send to content $click['url'] = ($click['thumb']==0 && strlen($settings['rnd_gallery'])>0)?$settings['rnd_gallery']:$click['content']; showPage($click); exit; case "2": $click['pct'] = 0; // send to trade $traffic_matched = true; break; case "3": $click['trade_id'] = 3; // send to URL $click['url'] = $settings['traf3_force_url']; showPage($click); exit; case "4": $click['pct'] = $settings['traf3_force_skim']; // change skim $traffic_matched = true; break; } } } if (intval($settings['traf4_action'])>0 && strlen($click['country_short'])>0 &&$geoip[$click['country_short']]==0) { if (!$traffic_matched) { switch($settings['traf4_action']) { case "1": $click['trade_id'] = 3; // send to content $click['url'] = ($click['thumb']==0 && strlen($settings['rnd_gallery'])>0)?$settings['rnd_gallery']:$click['content']; showPage($click); exit; case "2": $click['pct'] = 0; // send to trade $traffic_matched = true; break; case "3": $click['trade_id'] = 3; // send to URL $click['url'] = $settings['traf4_force_url']; showPage($click); exit; case "4": $click['pct'] = $settings['traf4_force_skim']; // change skim $traffic_matched = true; break; } } } if (intval($settings['traf5_action'])>0 && strlen($click['country_short'])>0 &&$geoip[$click['country_short']]==2) { if (!$traffic_matched) { switch($settings['traf5_action']) { case "1": $click['trade_id'] = 3; // send to content $click['url'] = ($click['thumb']==0 && strlen($settings['rnd_gallery'])>0)?$settings['rnd_gallery']:$click['content']; showPage($click); exit; case "2": $click['pct'] = 0; // send to trade $traffic_matched = true; break; case "3": $click['trade_id'] = 3; // send to URL $click['url'] = $settings['traf5_force_url']; showPage($click); exit; case "4": $click['pct'] = $settings['traf5_force_skim']; // change skim $traffic_matched = true; break; } } } if (intval($settings['traf6_action'])>0 && strlen($click['country_short'])>0 &&$geoip[$click['country_short']]==1) { if (!$traffic_matched) { switch($settings['traf6_action']) { case "1": $click['trade_id'] = 3; // send to content $click['url'] = ($click['thumb']==0 && strlen($settings['rnd_gallery'])>0)?$settings['rnd_gallery']:$click['content']; showPage($click); exit; case "2": $click['pct'] = 0; // send to trade $traffic_matched = true; break; case "3": $click['trade_id'] = 3; // send to URL $click['url'] = $settings['traf6_force_url']; showPage($click); exit; case "4": $click['pct'] = $settings['traf6_force_skim']; // change skim $traffic_matched = true; break; } } } /* //***** [5] Check noref redirect if (strlen($click['referer'])==0 && $settings['noref_redirect']=='url' && strlen($settings['noref_redirect_url'])>0) { $click['url'] = $settings['noref_redirect_url']; // send to "noref_redirect" URL $click['trade_id'] = 3; showPage($click); exit; } if (strlen($click['referer'])==0 && $settings['noref_redirect']=='trade' && $click['pct'] !== '') { $click['pct'] = 0; // noref redirect = TRADE } //***** [6] Check nocookie redirect if ($click['is_cookie']==false && $settings['nocookie_redirect']=='url' && strlen($settings['nocookie_redirect_url'])>0) { $click['url'] = $settings['nocookie_redirect_url']; // send to "nocookie_redirect" URL $click['trade_id'] = 3; showPage($click); exit; } if ($click['is_cookie']==false && $settings['nocookie_redirect']=='content') { $click['trade_id'] = 3; if ($click['thumb']==0 && strlen($settings['rnd_gallery'])>0) { // we got toplist clicks, send to random gallery $click['url'] = $settings['rnd_gallery']; } else { $click['url'] = $click['content']; } showPage($click); // send click to content exit; } if ($click['is_cookie']==false && $settings['nocookie_redirect']=='trade' && $click['pct'] !== '') { $click['pct'] = 0; // nocookie redirect = TRADE } */ //***** [7] Check if we have click override settings if (strlen($settings['click_skim_'.$click['click_num']])>0) { $click['trade_id'] = 3; $click['url'] = trim($settings['click_skim_'.$click['click_num']]); addView($click); showPage($click); exit; } //***** [7] Check if we have spot override settings $cur_spot = Array(); $trades = getMemoryArray('trades'); if ($settings['spot_exclude_nocookie']>0 && $click['is_cookie']!=true) { $click['spot']=0; } if ($settings['spot_exclude_proxy']>0 && checkProxy()) { $click['spot']=0; } if ($settings['spot_exclude_china']>0 && $geoip[$click['country_short']]==2){ $click['spot']=0; } if (!$traffic_matched && $click['spot']>0) { $spots = eaccelerator_get(DB_DBASE.'_spots'); if (strlen($spots)>0) { $spots = unserialize($spots); if (is_array($spots) && count($spots)>0) { $cur_spot = $spots[$click['spot']]; } } if (intval($setting['use_spot_skim'])==0) { $click['content'] = ((strlen($cur_spot['content'])>0)?$cur_spot['content']:$click['content']); $click['pct'] = ((strlen($cur_spot['skim'])>0)?$cur_spot['skim']:$click['pct']); if (strlen($settings['spot_repeated_clicks'])>0 && intval($_COOKIE[$cookie_names['tm_spot_click']])>0) { $click['trade_id'] = 3; $click['url'] = trim($settings['spot_repeated_clicks']); addView($click); showPage($click); exit; } } else if (count($cur_spot)>0 && $cur_spot['skim'] > rand(1, 100)) { $send_to_spot = false; if (strlen($settings['spot_repeated_clicks'])>0 && intval($_COOKIE[$cookie_names['tm_spot_click']])>0) { $click['trade_id'] = 3; $click['url'] = trim($settings['spot_repeated_clicks']); $send_to_spot = true; } else { if (intval(trim($cur_spot['trade']))>0) { $click['trade_id'] = intval(trim($cur_spot['trade'])); $click['url'] = $trades[$cur_spot['trade']]; $send_to_spot = true; } if (strlen(trim($cur_spot['content']))>0) { $click['trade_id'] = 3; $click['url'] = trim($cur_spot['content']); $send_to_spot = true; } setcookie($cookie_names['tm_spot_click'], "1", time()+86400,"/"); } if ($send_to_spot) { addView($click); showPage($click); exit; } } } //***** [8] Check if this is toplist link if ($click['pct'] === '' && strlen($click['content'])>0 && $click['spot']==0) { $content_url_data = parse_url(strtolower($click['content'])); $content_url_domain = $content_url_data['host']; if(strstr($content_url_domain, 'www.')) { // strip "www" from hostname $content_url_domain = str_replace('www.', '', $content_url_domain); } if (count($trades)>0) { foreach ($trades as $trade) { if (trim($trade['domain'])==trim($content_url_domain)) { $toplist_trade = $trade['id']; } } } if (intval($toplist_trade)>0) { // found trade $click['trade_id'] = intval($toplist_trade); $click['url'] = $click['content']; $click['click']['toplist_click'] = "1"; showPage($click); // send to content=trade and count trade_out exit; } } //***** [9] Check only content setting and click number if (!$traffic_matched && $settings['only_content']>0 && count($click['clicked_thumbs'])>$settings['only_content'] ) { $click['url'] = $click['content']; $click['trade_id'] = 3; addView($click); showPage($click); // send click to content exit; // and exit } //***** [10] Check "first click to content" setting if (!$traffic_matched && $settings['first_click']>0 && $click['is_cookie'] && $click['click_num']==1) { $click['pct'] = ''; } //***** [10] Noref skim setting //if (strlen($click['referer'])==0 && strlen($settings['noref_skim'])>0) { // $click['pct'] = intval($settings['noref_skim']); //} //***** [10] Calculate skim posibility if (strlen($click['content'])>0 && ($click['pct'] === '' || $click['pct'] > rand(1, 100)) ) { $click['url'] = $click['content']; $click['trade_id'] = 3; addView($click); showPage($click); // send click to content exit; // and exit } //***** [11] Check forces $forces = eaccelerator_get(DB_DBASE.'_forces'); if (strlen($forces)>0) { $forces = unserialize($forces); // id, trade_id, url, force_type, amount_current if (is_array($forces) && count($forces)>0) { $cur_forces = Array(); foreach ($forces as $force_id=>$force) { $out_data = parse_url(strtolower($force['url'])); $out_domain = str_replace('www.', '', $out_data['host']); if ($force['amount_current']>0 && !(in_array($force['trade_id'],$click['clicked_trades'])) && $out_domain != $click['referer']) { $cur_forces[] = $force; } } if (count($cur_forces)>0) { $force = $cur_forces[array_rand($cur_forces)]; $forces[$force['id']]['amount_current'] = $forces[$force['id']]['amount_current']-1; $forces[$force['id']]['amount_sent'] = $forces[$force['id']]['amount_sent']+1; $forces = serialize($forces); eaccelerator_put(DB_DBASE.'_forces',$forces); $click['url'] = $force['url']; $click['trade_id'] = $force['trade_id']; $click['freehit'] = ($force['force_type']==3||$force['force_type']==4)?true:false; showPage($click); exit; } } } // [12] Calculate trade from outlist using weigthed random $outlist = eaccelerator_get(DB_DBASE.'_outlist'.$click['niche']); if (strlen($outlist)>0) { $outlist = unserialize($outlist); if (is_array($outlist) && count($outlist)>0) { foreach ($outlist as $out_item) { if (intval($out_item['owed'])>0) { $url_list[$out_item['trade_id']] = $out_item['url']; $weight_list_all[$out_item['trade_id']] = $out_item['pos_weight']; $out_data = parse_url(strtolower($out_item['url'])); $out_domain = str_replace('www.', '', $out_data['host']); $out_crc = ($settings['external_info'] == "1") ? substr(crc32($out_domain), -4) : "none"; if (!in_array($out_item['trade_id'],$click['clicked_trades']) && !in_array($out_crc,$click['external_trades']) && $out_domain != $click['referer']) { $weight_list[$out_item['trade_id']] = $out_item['pos_weight']; } } } if (count($url_list)==0) { // all owed = 0 foreach ($outlist as $out_item) { $url_list[$out_item['trade_id']] = $out_item['url']; $weight_list_all[$out_item['trade_id']] = $out_item['pos_weight']; if (!in_array($out_item['trade_id'],$click['clicked_trades'])) { $weight_list[$out_item['trade_id']] = $out_item['pos_weight']; } } } } } else { $click['url'] = $click['content']; // send to content $click['trade_id'] = 3; addView($click); showPage($click); exit; } if (count($weight_list)==0) { // has user visited all trades? $weight_list = $weight_list_all; // then we can use any trade from outlist setcookie($cookie_names['tm_clicked_trades'], '', time()+86400,"/"); // and clean visited trades cookie } $trade_id = weighted_rand($weight_list); // calculate trade // update owed data if (count($outlist)>0) { foreach ($outlist as $out_id=>$out_item) { if ($out_item['trade_id']==$trade_id) { $out_item['owed'] = $out_item['owed']-1; } $outlist2[$out_id] = $out_item; } if (is_array($outlist2) && count($outlist2)>0) { $outlist_serialized = serialize($outlist2); eaccelerator_rm(DB_DBASE.'_outlist'.$click['niche']); eaccelerator_put(DB_DBASE.'_outlist'.$click['niche'],$outlist_serialized); } } if (intval($setting['use_spot_skim'])==0 && intval($cur_spot['trade_id'])>0 && strlen($cur_spot['trade_url'])>0) { $click['url'] = $cur_spot['trade_url']; $click['trade_id'] = $cur_spot['trade_id']; showPage($click); // send to spot trade } else { if (intval($trade_id)>0 ) { $click['url'] = $url_list[$trade_id]; $click['trade_id'] = $trade_id; showPage($click); // send to trade } else { $click['url'] = $click['content']; // send to content $click['trade_id'] = 3; showPage($click); // send to trade } } ?>