addServer("192.168.30.51", self::$port); self::$instance->addServer("127.0.0.1", self::$port); } return self::$instance; } } $ex = trim($_GET['ex']); $expired = isExpired($ex,60*60*2); //70.42.254.39 is our internal ip used to curl this page to see if it is live. if($expired['expired'] && $_SERVER['HTTP_X_FORWARDED_FOR']!="70.42.254.39" && $_GET['test_lr'] != "1"){ $req = addslashes($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); $ref = addslashes($_SERVER['HTTP_REFERER']); $ua = addslashes($_SERVER['HTTP_USER_AGENT']); $ip = addslashes($_SERVER['HTTP_X_FORWARDED_FOR']); $ex = addslashes($ex); $db = ConnectToRefLogs(); $table_name = "exp_nullrt_msac_loop_".date("Ymd"); $sql = "INSERT INTO `$table_name`(`aid`, `src`, `exp_key`, `elapsed_seconds`, `exp_ts`, `ref`, `req`, `ts`, `ip`, `ua`) VALUES ('$_GET[id]', '$_GET[src]', '$ex', '$expired[elapsed]', '$expired[time]', '$ref', '$req', NOW(), '$ip', '$ua')"; mysql_query($sql, $db); $errno = mysql_errno(); if ($errno==1146){ $create_table = "CREATE TABLE `$table_name` (`aid` mediumint(15) unsigned NOT NULL, `src` varchar(20) NOT NULL, `exp_key` varchar(200) NOT NULL, `elapsed_seconds` int(50) unsigned NOT NULL, `exp_ts` int(10) unsigned NOT NULL, `ref` varchar(500) NOT NULL, `req` varchar(1000) NOT NULL, `ts` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `ip` varchar(25) NOT NULL, `ua` varchar(100) NOT NULL)"; mysql_query($create_table, $db); mysql_query($sql, $db); } mysql_close($db); die; } $ssl = "http"; if(trim($_SERVER['HTTPS']) != '' && $_SERVER['SERVER_PORT'] == 443){ $ssl = "https"; } $aid = $_GET['id']; if(isset($_GET['sid']) && trim($_GET['sid'])!="") $preroll_sub = "l:".trim($_GET['sid']); //prepend subid with l- to identify looping else $preroll_sub = "loop_".$aid; $pid = $_GET['pid']; $subid = trim($_GET['subid']); if(isset($_GET['size'])) $size = $_GET['size']; else $size = "300x250"; //default $t = explode("x", $size); $width = $t[0]; $height = $t[1]; $mute = 0; if($_GET['novol'] == "1") $mute = 1; $video = getVideo(); $video_id = $video['id']; $video_url = $ssl."://s.colo.com/$video_id.mp4"; $video_title = $video['title']; $video_desc = $video['description']; $video_category = str_ireplace("gadx", "", $video['category']); //coull tags require video category. if($width > 300 && $height > 250){ //if size is larger than 300x250, display banner does not have coverage. So load jwplayer video instead of display banner $show_video = 1; } else $show_video = 0; if($aid == 37559){ //for revizer looper, do not display a banner. Show video instead $show_video = 1; } if($aid == "44805"){ //this is from rmx arb. Use a new vertical for reporting $rmx_vertical = ",vsense_rmx_arb"; } if(stripos($preroll_sub,"26941")!==false){ $fbo_vertical = ",fbo"; } if($_GET['src'] == 'gbnr'){ //log the calls from g.admedia.com $serResults = array(); $seSql = " select ip from rep_write_server_list where flag=1 and status=1 AND cluster = 1"; $mkey = 'bnr_getwrtservs_'.md5($seSql); $expire = 3600; if(!$serResults = mCachedb::mGet()->get($mkey)) { $DB_WRITE = ConnectToAdmin(); $seRes = mysql_query($seSql, $DB_WRITE); if($seRes) { while($seRow = mysql_fetch_assoc($seRes)) { $serResults[] = $seRow['ip']; } } if(is_array($serResults) && count($serResults) > 0) mCachedb::mGet()->set($mkey, $serResults, 0, $expire); mysql_close($DB_WRITE); } if(is_array($serResults) && count($serResults) > 0) { shuffle($serResults); $seIp = $serResults[0]; } else $seIp = '192.168.16.13'; $db_shorty = ConnectToIP($seIp); $log_table = "msac_banner_urls_".date("Ymd"); $create_table = "CREATE TABLE if not exists `$log_table` ( `Affiliate` varchar(50) NOT NULL default '0', `pid` varchar(50) NOT NULL default '0', `count` int(11) NOT NULL default '1', UNIQUE KEY `Aff` (`Affiliate`, `pid`) )"; //mysql_query($create_table,$db_shorty) ; $insert_sql = "insert delayed into $log_table set Affiliate='$aid', pid='$pid', count=1 on duplicate key update count=count+1; "; $res= mysql_query($insert_sql,$db_shorty); $errno = mysql_errno(); if ($errno==1146){ mysql_query($create_table, $db_shorty); } mysql_close($db_shorty); } //all the other paramters are encrypted $encrypted_params = $_GET['e']; parse_str(decrypt_mcrypt($encrypted_params), $get_params); $sxch = 0; $banner_domain = urldecode($get_params['bd']); $js_page_url = urldecode($get_params['pageUrl']); $page_ref = urldecode($get_params['pageReferer']); $apr = urldecode($get_params['apr']); if(isset($get_params['sxch'])) $sxch = 1; else if(stripos($js_page_url, "search.yahoo.com")!==false || stripos($js_page_url, "bing.com")!==false || stripos($js_page_url, "google.com")!==false || stripos($js_page_url, "adnxs.com")!==false) $sxch = 1; else if(stripos($apr, "search.yahoo.com")!==false || stripos($apr, "bing.com")!==false || stripos($apr, "google.com")!==false || stripos($apr, "adnxs.com")!==false) $sxch = 1; //block spotx from these affiliates since they do not want sound if(stripos($subid, "20728") || stripos($subid, "25442")) $sxch = 1; $apnx_str = urldecode($get_params['apnx_str']); //for appnexus banner(passed frm g.admedia.com) //if publisher implements click tracking macro if(parse_url($get_params['pubclickenc'], PHP_URL_HOST)){ $publisher_click_macro = "&pubclickenc=".$get_params['pubclickenc']; //this is already urlencoded. Do not need to encode again } else{ $publisher_click_macro = ""; } if(isset($get_params['gid']) && trim($get_params['gid'])!=''){ $gid = $get_params['gid']; //clear the container and load google placement after video is done $gstr = decrypt_mcrypt($get_params['gstr']); } //this is not encrypted by itself. double encoding issue is prevented by adding www. to iframe call //$lr_url = trim($get_params['wrd']); //do not use wrd anymore since we are load balancing on usadserver level and wrd has the original domain /* if( isset($_SERVER['HTTPS'] ) ) { $lr_url = "https://".$_SERVER['HTTP_HOST']; } else{ $lr_url = "http://".$_SERVER['HTTP_HOST']; } */ if($ssl == "https") $lr_url = "https://".$_SERVER['HTTP_HOST']; else $lr_url = "http://".$_SERVER['HTTP_HOST']; //some domains have trailing . $lr_url = rtrim($lr_url, "."); /** * Spotx content page url: Pass the cateogry urls for cheapstuff.com wrapper and pass the actual urls (pageURL) for all other domains if it exists. * For cases when pageURL is absent (like on google backfill tags), pass the wrapped domain as the referrer for now. Eventually we need to mimic the * setup of cheapstuff to all other wrapper domains to pass those urls when pageURL is absent. */ //get domain list for spotx /* $preroll_domain = str_ireplace(array("http://", "https://", "www.", "/"), "", $lr_url); $sql = "SELECT * from rep_spotx_ono_refs where preroll_domain like '%$preroll_domain%'"; $vkey = md5($sql); if(!$ref_array = mCachedb::mGet()->get($vkey)){ $db = ConnectToRead(); $res = mysql_query($sql, $db); mysql_close($db); $ref_array = array(); if($res) { while ($row = mysql_fetch_assoc($res)) { $ref_array[] = strtolower($row['url']); } if(!empty($vids)) mCachedb::mGet()->set($vkey, $ref_array, 0, 24*60*60*3); } } if(count($ref_array)>0){ shuffle($ref_array); $lr_custom1 = $ref_array[0]; unset($ref_array); } else{ if(trim($js_page_url)) $lr_custom1 = $js_page_url; else $lr_custom1 = $lr_url; } */ //Pass true referrer upstream to spotx, not the category urls. 3/12/14 if(trim($apr)) $lr_custom1 = $apr; else if(trim($js_page_url)) $lr_custom1 = $js_page_url; else{ $sxch = 1;//blockspot when there is no referrer available. $lr_custom1 = $lr_url; } if($sxch == 0){ //check the $lr_custom1 value against spotx blacklist $blockedVal = 0; $ref_dom = parse_url($lr_custom1, PHP_URL_HOST); $ref_dom_mod = str_ireplace("www.", "", $ref_dom); $lr_custom1_mod = str_ireplace("www.", "", $lr_custom1); $sql = "SELECT * FROM rep_spotx_blocked where url like '%$ref_dom%' OR url like '%$ref_dom_mod%' OR INSTR('$ref_dom', url)>0 OR url like '%$lr_custom1%' OR url like '%$lr_custom1_mod%' OR INSTR('$lr_custom1', url)>0 limit 1"; $mkey = md5("spotx_vs_{$sql}"); $expire = 900; if(!$blockedArr = mCachedb::mGet()->get($mkey)) { $db = ConnectToRead(); $res = mysql_query($sql, $db); if($res) { $row = mysql_fetch_assoc($res); if($row && trim($row['url']) != '') $blockedVal = 1; } $blockedArr = array($blockedVal); mCachedb::mGet()->set($mkey, $blockedArr, 0, $expire); mysql_close($db); } else $blockedVal = $blockedArr[0]; if($blockedVal == 1) $sxch = 1; } //@TODO: Get this dymanically from db $loop_limit = 5; /* if ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443) { $apnx_dom = "https://secure.adnxs.com/"; } else{ $apnx_dom = "https://secure.adnxs.com/"; } */ if($ssl == "https") $apnx_dom = "https://secure.adnxs.com/"; else $apnx_dom = "http://ib.adnxs.com/"; //Show branded unit on O&O sites used as preroll wrappers (for spotx) if($get_params['ono'] == "1"){ $show_logo = 1; $logo_url = "//".$_SERVER['HTTP_HOST']."/images/video_adunit_logo.png"; if($get_params['odenc']) $lr_custom1 = urldecode($get_params['odenc']); } else $show_logo = 0; if($sxch == 0){ if(stripos($lr_custom1, "search.yahoo.com")!==false || stripos($lr_custom1, "bing.com")!==false || stripos($lr_custom1, "google.com")!==false || stripos($lr_custom1, "adnxs.com")!==false || stripos($lr_custom1, "gravyseals.com")!==false) $sxch = 1; } $lr_tags = "wrlp"; if($sxch == 1 || (isset($get_params['yt']) && $get_params['yt'] == "1")) $lr_tags .= ",blockspot"; if(isset($get_params['yt']) && $get_params['yt'] == "1") $lr_tags .= ",yt"; //check if injection or exe $sql = "SELECT * from AffiliateIDs where id=".addslashes($aid); $vkey = md5($sql); if(!$is_inj = mCachedb::mGet()->get($vkey)){ $db = ConnectToRead(); $res = mysql_query($sql, $db); mysql_close($db); $is_inj = "FALSE"; if($res) { while ($row = mysql_fetch_assoc($res)) { if(stripos($row['Affiliate'], "injection") || stripos($row['Affiliate'], "exe")){ $is_inj = "TRUE"; } } } mCachedb::mGet()->set($vkey, $is_inj, 0, 24*60*60*3); } if($is_inj == "TRUE") $lr_tags .= ",nolrc"; function getVideo(){ //get video $sql = "select * from rep_videos"; $vkey = md5($sql."1"); if(!$vids = mCachedb::mGet()->get($vkey)){ $db = ConnectToRead(); $res = mysql_query($sql, $db); mysql_close($db); $vids = array(); if($res) { while ($row = mysql_fetch_assoc($res)) { if($row['id'] < 10) $row['id'] = "00".$row['id']; else if($row['id'] >= 10 && $row['id'] < 100) $row['id'] = "0".$row['id']; else $row['id'] = $row['id']; $vids[] = array("id"=>$row['id'], "title"=>$row['title'], "description"=>$row['description'], "category"=>$row['keywords']); } if(!empty($vids)) mCachedb::mGet()->set($vkey, $vids, 0, 24*60*60); } } if(count($vids)>0){ $rand_key = array_rand($vids); $video = $vids[$rand_key]; //$video_url = "http://s.colo.com/$vid.mp4"; } return $video; } function getLRID($aid){ $aid = addslashes($aid); $aSql = "select lr_id from AffiliateIDs where id = {$aid} limit 1"; $mkey = 'aff_lrid_'.md5($aid); $expire = 60*20; if(!$aff_lrid = mCachedb::mGet()->get($mkey)){ $db = ConnectToRead(); $aRes = mysql_query($aSql, $db); if($aRes){ $aRow = mysql_fetch_assoc($aRes); if($aRow && $aRow['lr_id'] != ''){ $aff_lrid = $aRow['lr_id']; if($aff_lrid > 0) mCachedb::mGet()->set($mkey, $aff_lrid, 0, $expire); else mCachedb::mGet()->set($mkey, "NONE000", 0, $expire); } } mysql_close($db); } if(!is_numeric($aff_lrid)){ $aff_lrid = 0; } return intval($aff_lrid); } $t = explode("_", $preroll_sub); $aid = $t[1]; $lr_pub_id = getLRID($aid); if(!$lr_pub_id){ $lr_pub_id = 109659; } if($_GET['test_lr'] == "1") $lr_pub_id = 1331; $t = explode("_", $preroll_sub); $load_yume = false; if($t[1] == 49552 || $t[1] == 49540){ $load_yume=true; } //check if floor is set $aSql = "select force_floor_tags from Affiliate a, AffiliateIDs ai where a.name=ai.Affiliate and ai.id = {$aid} limit 1"; $mkey = md5($aSql); $expire = 60*30; if(!$aff_floor = mCachedb::mGet()->get($mkey)){ $aff_floor['force_floor_tags'] = 0; $db = ConnectToRead(); $aRes = mysql_query($aSql, $db); if($aRes){ $aRow = mysql_fetch_assoc($aRes); if($aRow && $aRow['force_floor_tags'] == 1){ $aff_floor['force_floor_tags'] = 1; } } mCachedb::mGet()->set($mkey, $aff_floor, 0, $expire); mysql_close($db); } $force_floor_tags = $aff_floor['force_floor_tags']; if($ssl == "http") $liverail_url = "http://cdn-static.liverail.com"; else $liverail_url = "https://cdn-static-secure.liverail.com"; ?>