Example #1
0
/**
 * A function to fetch a cache entry.
 *
 * @param string $name The cache entry name
 * @param bool $isHash Is $name a hash already or should hash be created from it?
 * @param bool $expiryTime If null uses default expiry time (from config) but
 *                         Determine how long cache is valid
 * @return mixed False on error, or the cache content as a string
 */
function OA_Delivery_Cache_fetch($name, $isHash = false, $expiryTime = null)
{
    $filename = OA_Delivery_Cache_buildFileName($name, $isHash);
    $aCacheVar = OX_Delivery_Common_hook('cacheRetrieve', array($filename), $GLOBALS['_MAX']['CONF']['delivery']['cacheStorePlugin']);
    if ($aCacheVar !== false) {
        if ($aCacheVar['cache_name'] != $name) {
            OX_Delivery_logMessage("Cache ERROR: {$name} != {$aCacheVar['cache_name']}", 7);
            return false;
        }
        // The method used to implement cache expiry imposes two cache writes if the cache is
        // expired and the database is available, but avoid the need to check for file existence
        // and modification time.
        if ($expiryTime === null) {
            $expiryTime = $GLOBALS['OA_Delivery_Cache']['expiry'];
        }
        $now = MAX_commonGetTimeNow();
        if (isset($aCacheVar['cache_time']) && $aCacheVar['cache_time'] + $expiryTime < $now || isset($aCacheVar['cache_expire']) && $aCacheVar['cache_expire'] < $now) {
            // Update expiry, needed to enable permanent caching if needed
            OA_Delivery_Cache_store($name, $aCacheVar['cache_contents'], $isHash);
            OX_Delivery_logMessage("Cache EXPIRED: {$name}", 7);
            return false;
        }
        OX_Delivery_logMessage("Cache HIT: {$name}", 7);
        return $aCacheVar['cache_contents'];
    }
    OX_Delivery_logMessage("Cache MISS {$name}", 7);
    return false;
}
Example #2
0
/**
 * The function to pass a query to a database link
 *
 * @param string $query    The SQL query to execute
 * @param string $database The database to use for this query
 *                         (Must match the database section name in the conf file)
 * @return resource|false  The MySQL resource if the query suceeded
 *                          or false on failure
 */
function OA_Dal_Delivery_query($query, $database = 'database')
{
    // Connect to the database if necessary
    $dbName = $database == 'rawDatabase' ? 'RAW_DB_LINK' : 'ADMIN_DB_LINK';
    if (empty($GLOBALS['_MAX'][$dbName])) {
        $GLOBALS['_MAX'][$dbName] = OA_Dal_Delivery_connect($database);
    }
    if (is_resource($GLOBALS['_MAX'][$dbName])) {
        $result = @mysql_query($query, $GLOBALS['_MAX'][$dbName]);
        if (!$result) {
            OX_Delivery_logMessage('DB query error: ' . mysql_error(), 4);
            OX_Delivery_logMessage(' - failing query: ' . $query, 5);
        }
        return $result;
    } else {
        return false;
    }
}
Example #3
0
function OA_Delivery_Cache_fetch($name, $isHash = false, $expiryTime = null)
{
    $filename = OA_Delivery_Cache_buildFileName($name, $isHash);
    $aCacheVar = OX_Delivery_Common_hook('cacheRetrieve', array($filename), $GLOBALS['_MAX']['CONF']['delivery']['cacheStorePlugin']);
    if ($aCacheVar !== false) {
        if ($aCacheVar['cache_name'] != $name) {
            OX_Delivery_logMessage("Cache ERROR: {$name} != {$aCacheVar['cache_name']}", 7);
            return false;
        }
        if ($expiryTime === null) {
            $expiryTime = $GLOBALS['OA_Delivery_Cache']['expiry'];
        }
        $now = MAX_commonGetTimeNow();
        if (isset($aCacheVar['cache_time']) && $aCacheVar['cache_time'] + $expiryTime < $now || isset($aCacheVar['cache_expire']) && $aCacheVar['cache_expire'] < $now) {
            OA_Delivery_Cache_store($name, $aCacheVar['cache_contents'], $isHash);
            OX_Delivery_logMessage("Cache EXPIRED: {$name}", 7);
            return false;
        }
        OX_Delivery_logMessage("Cache HIT: {$name}", 7);
        return $aCacheVar['cache_contents'];
    }
    OX_Delivery_logMessage("Cache MISS {$name}", 7);
    return false;
}
Example #4
0
function _adSelectDiscardNonMatchingAds(&$aAds, $aContext, $source, $richMedia)
{
    if (empty($GLOBALS['_MAX']['CONF']['delivery']['aclsDirectSelection']) && !empty($GLOBALS['_MAX']['DIRECT_SELECTION'])) {
        return;
    }
    foreach ($aAds as $adId => $aAd) {
        OX_Delivery_logMessage('_adSelectDiscardNonMatchingAds: checking bannerid ' . $aAd['ad_id'], 7);
        if (!_adSelectCheckCriteria($aAd, $aContext, $source, $richMedia)) {
            OX_Delivery_logMessage('failed _adSelectCheckCriteria: bannerid ' . $aAd['ad_id'], 7);
            unset($aAds[$adId]);
        } else {
            OX_Delivery_logMessage('passed _adSelectCheckCriteria: bannerid ' . $aAd['ad_id'], 7);
        }
    }
    return;
}
Example #5
0
/**
 * This function implements the hook mechanism in the delivery engine
 * It allows for a series of registered (stackable) hooks to be executed sequentially
 * Or it allows a single
 *
 * @param string $hookName      The name of the hook to be executed
 * @param array $aParams        An (optional) array of parameters to be passed to the component-hook(s)
 * @param string $functionName  Optional functionName to execute, if this is not passed in, then all components
 *                              which are registered at this hook will be executed sequentially
 * @return mixed                If a functionName was passed in, then the return value from executing the
 *                              function gets returned, otherwise (stackable hooks) true
 */
function OX_Delivery_Common_hook($hookName, $aParams = array(), $functionName = '')
{
    $return = null;
    // When a $functionname is passed in we use that function/component-identifier and execute the hook
    if (!empty($functionName)) {
        // Right now, we're allowing either a plain function to be executed, or a component-identifier
        // we may remove the ability to pass a plain function in the future
        $aParts = explode(':', $functionName);
        if (count($aParts) === 3) {
            $functionName = OX_Delivery_Common_getFunctionFromComponentIdentifier($functionName, $hookName);
        }
        if (function_exists($functionName)) {
            $return = call_user_func_array($functionName, $aParams);
        }
    } else {
        // When no $functionName is passed in, we execute all components which are registered for this hook
        if (!empty($GLOBALS['_MAX']['CONF']['deliveryHooks'][$hookName])) {
            $return = array();
            $hooks = explode('|', $GLOBALS['_MAX']['CONF']['deliveryHooks'][$hookName]);
            foreach ($hooks as $identifier) {
                $functionName = OX_Delivery_Common_getFunctionFromComponentIdentifier($identifier, $hookName);
                if (function_exists($functionName)) {
                    OX_Delivery_logMessage('calling on ' . $functionName, 7);
                    $return[$identifier] = call_user_func_array($functionName, $aParams);
                }
            }
        }
    }
    return $return;
}
$conf = $GLOBALS['_MAX']['CONF'];
// Set this script's identifier (from the config file) in the global scope
$GLOBALS['_OA']['invocationType'] = array_search(basename($_SERVER['SCRIPT_FILENAME']), $conf['file']);
// Disable all notices and warnings,
// as some PAN code still generates PHP warnings in places
if (!empty($conf['debug']['production'])) {
    error_reporting(E_ALL & ~(E_NOTICE | E_WARNING | E_DEPRECATED | E_STRICT));
} else {
    // show all errors when developing
    error_reporting(E_ALL & ~(E_DEPRECATED | E_STRICT));
}
require_once MAX_PATH . '/lib/max/Delivery/common.php';
require_once MAX_PATH . '/lib/max/Delivery/cache.php';
OX_Delivery_logMessage('starting delivery script: ' . basename($_SERVER['REQUEST_URI']), 7);
if (!empty($_REQUEST[$conf['var']['trace']])) {
    OX_Delivery_logMessage('trace enabled: ' . $_REQUEST[$conf['var']['trace']], 7);
}
// Set the viewer's remote information used in logging and delivery limitation evaluation
MAX_remotehostSetInfo();
// Set common delivery parameters in the global scope
MAX_commonInitVariables();
// Load cookie data from client/plugin
MAX_cookieLoad();
// Unpack the packed capping cookies
MAX_cookieUnpackCapping();
// Run any plugins which have registered themselves at postInit,
// with the exception of XML-RPC invocation that will call the hook
// explicitly after overriding the $_SERVER variables
if (empty($GLOBALS['_OA']['invocationType']) || $GLOBALS['_OA']['invocationType'] != 'xmlrpc') {
    OX_Delivery_Common_hook('postInit');
}
/**
 * A function to convert the $_SERVER['REMOTE_ADDR'] global variable
 * from the current value to the real remote viewer's value, should
 * that viewer be coming via an HTTP proxy.
 *
 * Only performs this conversion if the option to do so is set in the
 * configuration file.
 */
function MAX_remotehostProxyLookup()
{
    $conf = $GLOBALS['_MAX']['CONF'];
    // Should proxy lookup conversion be performed?
    if ($conf['logging']['proxyLookup']) {
        OX_Delivery_logMessage('checking remote host proxy', 7);
        // Determine if the viewer has come via an HTTP proxy
        $proxy = false;
        if (!empty($_SERVER['HTTP_VIA']) || !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $proxy = true;
        } elseif (!empty($_SERVER['REMOTE_HOST'])) {
            $aProxyHosts = array('proxy', 'cache', 'inktomi');
            foreach ($aProxyHosts as $proxyName) {
                if (strpos($_SERVER['REMOTE_HOST'], $proxyName) !== false) {
                    $proxy = true;
                    break;
                }
            }
        }
        // Has the viewer come via an HTTP proxy?
        if ($proxy) {
            OX_Delivery_logMessage('proxy detected', 7);
            // Try to find the "real" IP address the viewer has come from
            $aHeaders = array('HTTP_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP');
            foreach ($aHeaders as $header) {
                if (!empty($_SERVER[$header])) {
                    $ip = $_SERVER[$header];
                    break;
                }
            }
            if (!empty($ip)) {
                // The "remote IP" may be a list, ensure that
                // only the FIRST non-private value is used in that case
                // See http://en.wikipedia.org/wiki/X-Forwarded-For#Format
                foreach (explode(',', $ip) as $ip) {
                    $ip = trim($ip);
                    // If the found address is not unknown or a private network address
                    if ($ip != 'unknown' && !MAX_remotehostPrivateAddress($ip)) {
                        // Set the "real" remote IP address, and unset
                        // the remote host (as it will be wrong for the
                        // newly found IP address) and HTTP_VIA header
                        // (so that we don't accidently do this twice)
                        $_SERVER['REMOTE_ADDR'] = $ip;
                        $_SERVER['REMOTE_HOST'] = '';
                        $_SERVER['HTTP_VIA'] = '';
                        OX_Delivery_logMessage('real address set to ' . $ip, 7);
                        break;
                    }
                }
            }
        }
    }
}
Example #8
0
$aBlockLoggingClick = isset($_REQUEST[$conf['var']['blockLoggingClick']]) ? $_REQUEST[$conf['var']['blockLoggingClick']] : array();
if (!empty($conf['deliveryLog']['enabled'])) {
    foreach ($adId as $k => $v) {
        OX_Delivery_logMessage('$adId[' . $k . ']=' . $v, 7);
    }
    foreach ($zoneId as $k => $v) {
        OX_Delivery_logMessage('$zoneId[' . $k . ']=' . $v, 7);
    }
    foreach ($creativeId as $k => $v) {
        OX_Delivery_logMessage('$creativeId[' . $k . ']=' . $v, 7);
    }
    foreach ($lastClick as $k => $v) {
        OX_Delivery_logMessage('$lastClick[' . $k . ']=' . $v, 7);
    }
    foreach ($aBlockLoggingClick as $k => $v) {
        OX_Delivery_logMessage('$aBlockLoggingClick[' . $k . ']=' . $v, 7);
    }
}
if (empty($adId) && !empty($zoneId)) {
    foreach ($zoneId as $index => $zone) {
        $adId[$index] = _getZoneAd($zone);
        $creativeId[$index] = 0;
    }
}
for ($i = 0; $i < count($adId); $i++) {
    $adId[$i] = intval($adId[$i]);
    $zoneId[$i] = intval($zoneId[$i]);
    if (isset($creativeId[$i])) {
        $creativeId[$i] = intval($creativeId[$i]);
    } else {
        $creativeId[$i] = 0;
Example #9
0
/**
 * This function check if the click logging for an add is blocked
 * when the block logging is active
 *
 * @param integer $adId              The add's id of the add that the function checks
 *                                   if is blocked for click logging
 * @param array $aBlockLoggingClick  And array with the timestamps of the last click logged
 *                                   for every add that has been clicked
 * @return boolean                   Returns true when the click block logging window for
 *                                   and add hasn't expired yet
 */
function MAX_Delivery_log_isClickBlocked($adId, $aBlockLoggingClick)
{
    if (isset($GLOBALS['conf']['logging']['blockAdClicksWindow']) && $GLOBALS['conf']['logging']['blockAdClicksWindow'] != 0) {
        if (isset($aBlockLoggingClick[$adId])) {
            $endBlock = MAX_commonUnCompressInt($aBlockLoggingClick[$adId]) + $GLOBALS['conf']['logging']['blockAdClicksWindow'];
            if ($endBlock >= MAX_commonGetTimeNow()) {
                OX_Delivery_logMessage('adID ' . $adId . ' click is still blocked by block logging window ', 7);
                return true;
            }
        }
    }
    return false;
}
     $thisZoneid = $varname = $thisZone;
 }
 ###START_STRIP_DELIVERY
 appendClientMessage("Processing zoneid:|{$thisZoneid}| zonename:|{$varname}|");
 ###END_STRIP_DELIVERY
 $what = 'zone:' . $thisZoneid;
 ###START_STRIP_DELIVERY
 OX_Delivery_logMessage('$what=' . $what, 7);
 OX_Delivery_logMessage('$context=' . print_r($context, true), 7);
 ###END_STRIP_DELIVERY
 // Get the banner
 $output = MAX_adSelect($what, $clientid, $target, $source, $withtext, $charset, $context, true, $ct0, $GLOBALS['loc'], $GLOBALS['referer']);
 ###START_STRIP_DELIVERY
 OX_Delivery_logMessage('$block=' . $block, 7);
 //OX_Delivery_logMessage(print_r($output, true), 7);
 OX_Delivery_logMessage('output bannerid=' . (empty($output['bannerid']) ? ' NO BANNERID' : $output['bannerid']), 7);
 ###END_STRIP_DELIVERY
 // BM - output format is vast xml
 if ($format == 'vast') {
     if ($output['html'] && ($output['width'] != VAST_OVERLAY_DIMENSIONS && $output['width'] != VAST_INLINE_DIMENSIONS)) {
         $badZoneId = $output['aRow']['zoneid'];
         $badBannerId = $output['bannerid'];
         // Store the html2js'd output for this ad
         $spc_output .= "<!-- You are requesting vast xml for zone {$badZoneId} which does not apear to be a video overlay banner nor a vast inline banner. -->\n";
     } else {
         // Store the html2js'd output for this ad
         $spc_output .= $output['html'] . "\n";
     }
     // Help the player (requestor of VAST) to match the ads in the response with his request by using his id in the Ad xml node
     $spc_output = str_replace('{player_allocated_ad_id}', $varname, $spc_output);
 } else {
}
function getTimeNow()
{
    if (empty($GLOBALS['_MAX']['NOW'])) {
        $GLOBALS['_MAX']['NOW'] = time();
    }
    $time = $GLOBALS['_MAX']['NOW'];
    return $time;
}
function bumpVastEventTrackingBucketCounter($data)
{
    $aQuery = array('interval_start' => $data['interval_start'], 'creative_id' => $data['creative_id'], 'zone_id' => $data['zone_id'], 'vast_event_id' => $data['vast_event_id']);
    return OX_bucket_updateTable('data_bkt_vast_e', $aQuery);
}
###START_STRIP_DELIVERY
OX_Delivery_logMessage('starting delivery script ' . __FILE__, 7);
###END_STRIP_DELIVERY
MAX_commonRegisterGlobalsArray(array('vast_event'));
// if its a vast tracking event
if ($vast_event) {
    // NB: videotimeposn is not yet supported by the player
    MAX_commonRegisterGlobalsArray(array('video_time_posn', 'banner_id', 'zone_id'));
    // Prevent the logging beacon from being cached by browsers
    MAX_commonSetNoCacheHeaders();
    // Remove any special characters from the request variables
    MAX_commonRemoveSpecialChars($_REQUEST);
    $time = getTimeNow();
    $oi = $GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'];
    $intervalStart = gmdate('Y-m-d H:i:s', $time - $time % ($oi * 60));
    $viewerIsOkToLog = _viewersHostOkayToLog();
    $aQuery = array('creative_id' => intVal($banner_id), 'zone_id' => intVal($zone_id), 'vast_event_id' => getVastEventIdFromVastEventStr($vast_event), 'interval_start' => $intervalStart, 'is_host_ok' => $viewerIsOkToLog);