/** * Class constructor * * @param string $id * @param string $group * @param int $lifeTime * @param string $cacheDir // can be used to read cache backups from different directory * @return OA_Cache */ function __construct($id, $group, $lifeTime = null, $cacheDir = null) { if (!isset($cacheDir)) { $cacheDir = MAX_PATH . '/var/cache/'; } $this->oCache = new Cache_Lite(array('cacheDir' => $cacheDir, 'lifeTime' => $lifeTime, 'readControlType' => 'md5', 'automaticSerialization' => true)); $this->id = $id; $this->group = OX_getHostName() . (!empty($group) ? '_' . $group : ''); }
/** * The delivery engine's function to parse the configuration .ini file * * @param $configPath The path to the config file * @param $configFile Optional - The suffix of the config file * @param $sections Optional - process sections to get a multidimensional array * * @return mixed The array resulting from the call to parse_ini_file(), with * the appropriate .ini file for the installation. */ function parseDeliveryIniFile($configPath = null, $configFile = null, $sections = true) { // Set up the configuration .ini file path location if (!$configPath) { $configPath = MAX_PATH . '/var'; } if ($configFile) { $configFile = '.' . $configFile; } $host = OX_getHostName(); $configFileName = $configPath . '/' . $host . $configFile . '.conf.php'; $conf = @parse_ini_file($configFileName, $sections); if (isset($conf['realConfig'])) { // added for backward compatibility - realConfig points to different config $realconf = @parse_ini_file(MAX_PATH . '/var/' . $conf['realConfig'] . '.conf.php', $sections); $conf = mergeConfigFiles($realconf, $conf); } if (!empty($conf)) { return $conf; } elseif ($configFile === '.plugin') { // For plugins, if no configuration file is found, return the sane default values $pluginType = basename($configPath); $defaultConfig = MAX_PATH . '/plugins/' . $pluginType . '/default.plugin.conf.php'; $conf = @parse_ini_file($defaultConfig, $sections); if ($conf !== false) { // check for false here - it's possible file doesn't exist return $conf; } echo "Revive Adserver could not read the default configuration file for the {$pluginType} plugin"; exit(1); } // Check for a 'default.conf.php' file $configFileName = $configPath . '/default' . $configFile . '.conf.php'; $conf = @parse_ini_file($configFileName, $sections); if (isset($conf['realConfig'])) { // added for backward compatibility - realConfig points to different config $conf = @parse_ini_file(MAX_PATH . '/var/' . $conf['realConfig'] . '.conf.php', $sections); } if (!empty($conf)) { return $conf; } // Check to ensure Max hasn't been installed if (file_exists(MAX_PATH . '/var/INSTALLED')) { echo "Revive Adserver has been installed, but no configuration file was found.\n"; exit(1); } // Revive Adserver hasn't been installed, so delivery engine can't run echo "Revive Adserver has not been installed yet -- please read the INSTALL.txt file.\n"; exit(1); }
/** * A method to test the getConfigVersion() method. */ function test_parseDeliveryIniFile() { $host = OX_getHostName(); copy(MAX_PATH . '/lib/OA/tests/data/test.demo.conf.php', MAX_PATH . '/var/' . $host . '.test.demo.conf.php'); copy(MAX_PATH . '/lib/OA/tests/data/test.real.conf.php', MAX_PATH . '/var/test.real.conf.php'); $result = parseDeliveryIniFile('', 'test.demo'); $this->assertIsA($result, 'array'); $this->assertTrue(isset($result['database'])); $this->assertEqual($result['database']['username'], 'demo_user'); $this->assertEqual($result['database']['password'], 'demo_pass'); $this->assertEqual($result['database']['name'], 'demo_name'); $this->assertTrue(isset($result['real'])); $this->assertEqual($result['real']['key1'], 'val1'); $this->assertEqual($result['real']['key2'], 'val2'); @unlink(MAX_PATH . '/var/' . $host . '.test.demo.conf.php'); @unlink(MAX_PATH . '/var/test.real.conf.php'); }
function testCreateGeoTargetingConfiguration() { if (file_exists(GEOCONFIG_PATH)) { rename(GEOCONFIG_PATH, TMP_GEOCONFIG_PATH); } $upgradeConfig = new OA_Upgrade_Config(); $host = OX_getHostName(); $migration = new Migration_108(); $migration->init($this->oDbh, MAX_PATH . '/var/DB_Upgrade.test.log'); $this->checkNoGeoTargeting($migration, $host); $this->checkGeoIp($migration, $host); $this->checkModGeoIP($migration, $host); Util_File_remove(GEOCONFIG_PATH); if (file_exists(TMP_GEOCONFIG_PATH)) { rename(TMP_GEOCONFIG_PATH, GEOCONFIG_PATH); } }
/** * A method to return the path to the configuration file of a given plugin. * * @static * @param string $module The plugin module name (i.e. /plugins/module directory). * @param string $package An optional plugin package name (i.e. /plugins/module/package * directory). If not given, generates the module level * configuration file path. * @param string $name An optional plugin name (i.e. /plugins/module/package/plugin.plugin.php). * If not given, generates the package level configuration file path, or * the module level configuration file path, depending on the $package * parameter. * @param boolean $defaultConfig Optional flag. When true, returns the path to the default * configuration file distributed with Max; when false, the * path to the "real" configuration file for the plugin that * has been written previously is returned. * @param string $host An optional parameter to override the host name via which the Max * installation is currently being accessed. * @return string The path to the configuration file. */ function getConfigFileName($module, $package = null, $name = null, $defaultConfig = false, $host = null) { $aConf = $GLOBALS['_MAX']['CONF']; if ($defaultConfig) { if (is_null($host)) { $host = 'default'; } $startPath = MAX_PATH . '/plugins/'; } else { if (is_null($host)) { $host = OX_getHostName(); } $startPath = MAX_PATH . $aConf['pluginPaths']['var'] . 'config/'; } $configName = $host . '.plugin.conf.php'; if ($package === null) { $configPath = $module . '/'; } elseif ($name === null) { $configPath = $module . '/' . $package . '/'; } else { $configPath = $module . '/' . $package . '/' . $name . '.'; } return $startPath . $configPath . $configName; }
/** * This method creates config if it doesn't exist so test won't fail * */ function createConfigIfNotExists() { if (!file_exists(MAX_PATH . '/var/' . OX_getHostName() . '.conf.php')) { $oConfig = new OA_Upgrade_Config(); $oConfig->writeConfig(true); } }
/** * A function to handle XML-RPC advertisement SPC requests. * * @param XML_RPC_Message $params An XML_RPC_Message containing the parameters. The expected parameters * are (in order): * - An XML_RPC_Value of type "struct" containing remote informations * which needs at least two members: * - remote_addr (string) and * - cookies (struct); * - An XML_RPC_Value of type "string" containing the "what" value; * - An XML_RPC_Value of type "string" containing the "target" value; * - An XML_RPC_Value of type "string" containing the "source" value; * - An XML_RPC_Value of type "boolean" containing the "withtext" value; * - An XML_RPC_Value of type "boolean" containing the "block" value; * - An XML_RPC_Value of type "boolean" containing the "blockcampaign" value; * @return XML_RPC_Response The response. The XML_RPC_Value of the response can be one of * a number of different values: * - Error Code 21: wrong number of parameters. * - Error Code 22: remote_addr element missing from the remote info struct. * - Error Code 23: cookies element missing from the remote info struct. * - An XML_RPC_Value of type "struct" with the HTML details required * for displaying the advertisement stored as in XML_RPC_Value of * type "string" in the "html" index, and other elements returned by the * MAX_asSelect call. A special "cookies" element is either: * - An empty XML_RPC_Value if there are no cookies to be set, or * - An XML_RPC_Value of type "array", containing a number of XML_RPC_Values * of tpye "array", each with 3 items: * - An XML_RPC_Value of type "string" with the cookie name; * - An XML_RPC_Value of type "string" with the cookie value; and * - An XML_RPC_Value of type "string" with the cookie expiration time. */ function OA_Delivery_XmlRpc_SPC($params) { global $XML_RPC_erruser; global $XML_RPC_String, $XML_RPC_Struct, $XML_RPC_Array; // Check the parameters exist $numParams = $params->getNumParams(); if ($numParams != 7) { // Return an error $errorCode = $XML_RPC_erruser + 21; $errorMsg = 'Incorrect number of parameters'; return new XML_RPC_Response(0, $errorCode, $errorMsg); } // Set the XML values into their correct variables to make life easier $vars = array(1 => 'what', 2 => 'target', 3 => 'source', 4 => 'withtext', 5 => 'block', 6 => 'blockcampaign'); // Parse parameters for ($i = 0; $i < $numParams; $i++) { $p = $params->getParam($i); if ($i) { // Put the decoded value the view arg array ${$vars}[$i] = XML_RPC_decode($p); } else { // First parameter: environment information supplied be XML-RPC client $p = XML_RPC_decode($p); if (!isset($p['remote_addr'])) { // Return an error $errorCode = $XML_RPC_erruser + 22; $errorMsg = "Missing 'remote_addr' member"; return new XML_RPC_Response(0, $errorCode, $errorMsg); } if (!isset($p['cookies']) || !is_array($p['cookies'])) { // Return an error $errorCode = $XML_RPC_erruser + 23; $errorMsg = "Missing 'cookies' member"; return new XML_RPC_Response(0, $errorCode, $errorMsg); } $aServerVars = array('remote_addr' => 'REMOTE_ADDR', 'remote_host' => 'REMOTE_HOST', 'request_uri' => 'REQUEST_URI', 'https' => 'HTTPS', 'server_name' => 'SERVER_NAME', 'http_host' => 'HTTP_HOST', 'accept_language' => 'HTTP_ACCEPT_LANGUAGE', 'referer' => 'HTTP_REFERER', 'user_agent' => 'HTTP_USER_AGENT', 'via' => 'HTTP_VIA', 'forwarded' => 'HTTP_FORWARDED', 'forwarded_for' => 'HTTP_FORWARDED_FOR', 'x_forwarded' => 'HTTP_X_FORWARDED', 'x_forwarded_for' => 'HTTP_X_FORWARDED_FOR', 'client_ip' => 'HTTP_CLIENT_IP'); // Extract environment vars to $_SERVER foreach ($aServerVars as $xmlName => $varName) { if (isset($p[$xmlName])) { $_SERVER[$varName] = $p[$xmlName]; } } // Extract cookie vars to $_COOKIE foreach ($p['cookies'] as $key => $value) { $_COOKIE[$key] = MAX_commonAddslashesRecursive($value); } MAX_cookieUnpackCapping(); } } // Add defaults for not-applicable values $richmedia = true; $ct0 = ''; $context = array(); // Make loc and referer global to ensure that the delivery limitations work correctly global $loc, $referer; $loc = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http') . '://' . OX_getHostName() . $_SERVER['REQUEST_URI']; // Add $referer parameter $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; // If the what parameter is an int, it is the affiliateid, otherwise it's a serialized array of name=zone pairs // This convention is inline with the parameters passed into local-mode SPC if (is_numeric($what)) { $zones = OA_cacheGetPublisherZones($what); $nz = false; } else { $zones = unserialize($what); $nz = true; } $spc_output = array(); foreach ($zones as $zone => $data) { if (empty($zone)) { continue; } // nz is set when "named zones" are being used, this allows a zone to be selected more than once if ($nz) { $varname = $zone; $zoneid = $data; } else { $varname = $zoneid = $zone; } // Get the banner $output = MAX_adSelect('zone:' . $zoneid, '', $target, $source, $withtext, '', $context, $richmedia, $ct0, $GLOBALS['loc'], $GLOBALS['referer']); $spc_output[$varname] = $output; // Block this banner for next invocation if (!empty($block) && !empty($output['bannerid'])) { $output['context'][] = array('!=' => 'bannerid:' . $output['bannerid']); } // Block this campaign for next invocation if (!empty($blockcampaign) && !empty($output['campaignid'])) { $output['context'][] = array('!=' => 'campaignid:' . $output['campaignid']); } // Pass the context array back to the next call, have to iterate over elements to prevent duplication if (!empty($output['context'])) { foreach ($output['context'] as $id => $contextArray) { if (!in_array($contextArray, $context)) { $context[] = $contextArray; } } } } return new XML_RPC_Response(XML_RPC_encode($spc_output)); // Now we have all the parameters we need to select the ad // Call MAX_adSelect with supplied parameters $output = call_user_func_array('MAX_adSelect', $view_params); // Prepare output as PHP array if (!is_array($output)) { $output = array(); } elseif (isset($output['contenttype']) && $output['contenttype'] == 'swf') { $output['html'] = MAX_flashGetFlashObjectExternal() . $output['html']; } MAX_cookieFlush(); // Add cookie information $output['cookies'] = $GLOBALS['_OA']['COOKIE']['XMLRPC_CACHE']; // Return response return new XML_RPC_Response(XML_RPC_encode($output)); }
} $oStartDate = new Date($oConnectionDate->format('%Y-%m-%d %H:00:00')); $oEndDate = new Date($oConnectionDate->format('%Y-%m-%d %H:00:00')); $oDal->_saveSummaryUpdateWithFinanceInfo($oStartDate, $oEndDate, $data_summary_table); if (!is_null($plugin)) { $plugin->serviceLocatorRemove(); } } } } if ($modified) { // Clear cache include_once 'Cache/Lite.php'; $options = array('cacheDir' => MAX_CACHE); $cache = new Cache_Lite($options); $cache->clean(OX_getHostName() . 'stats'); } } $addUrl = "entity=conversions&clientid={$clientId}&campaignid={$campaignId}&bannerid={$bannerId}&affiliateid={$affiliateId}&zoneid={$zoneId}"; if (!empty($period_preset)) { $addUrl .= "&period_preset={$period_preset}&period_start={$period_start}&period_end={$period_end}"; } if (!empty($day)) { $addUrl .= "&day={$day}"; } if (!empty($howLong)) { $addUrl .= "&howLong={$howLong}"; } if (!empty($hour)) { $addUrl .= "&hour={$hour}"; }
function write_sim_ini_file($confAll) { if (array_key_exists('realConfig', $_REQUEST)) { $conf['realConfig'] = $_REQUEST['realConfig']; } else { if (array_key_exists('realConfig', $confAll)) { $conf['realConfig'] = $confAll['realConfig']; } } if (array_key_exists('simdb', $_REQUEST)) { $conf['simdb'] = $_REQUEST['simdb']; } else { if (array_key_exists('simdb', $confAll)) { $conf['simdb'] = $confAll['simdb']; } } if (array_key_exists('scenario', $_REQUEST)) { $conf['scenario'] = $_REQUEST['scenario']; } else { if (array_key_exists('scenario', $confAll)) { $conf['scenario'] = $confAll['scenario']; } } if (array_key_exists('request', $_REQUEST)) { $conf['request'] = $_REQUEST['request']; } else { if (array_key_exists('request', $confAll)) { $conf['request'] = $confAll['request']; } } if (array_key_exists('delivery', $_REQUEST)) { $conf['delivery'] = $_REQUEST['delivery']; } else { if (array_key_exists('delivery', $confAll)) { $conf['delivery'] = $confAll['delivery']; } } if (array_key_exists('delivery', $_REQUEST)) { $conf['logging'] = $_REQUEST['logging']; } else { if (array_key_exists('logging', $confAll)) { $conf['logging'] = $confAll['logging']; } } $content = ''; if (isset($conf['realConfig'])) { if ($conf['realConfig']) { $content .= "realConfig = \"{$conf['realConfig']}\"\n"; } unset($conf['realConfig']); } require_once MAX_PATH . '/lib/max/other/common.php'; $conf = MAX_commonSlashArray($conf); $content = parse_conf_for_ini_file($conf, $content, true); if ($handle = fopen(MAX_PATH . '/var/' . OX_getHostName() . '.conf.php', 'w')) { fwrite($handle, $content); fclose($handle); } return get_conf(); }
if (isset($GLOBALS['_MAX']['FILES'][$file])) { return; } ###END_STRIP_DELIVERY $GLOBALS['_MAX']['FILES'][$file] = true; /** * Constant used for permanent caching * */ define('OA_DELIVERY_CACHE_FUNCTION_ERROR', 'Function call returned an error'); /** * Global variable to keep cache informations * * @var array */ $GLOBALS['OA_Delivery_Cache'] = array('prefix' => 'deliverycache_', 'host' => OX_getHostName(), 'expiry' => $GLOBALS['_MAX']['CONF']['delivery']['cacheExpire']); /** * 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) {
static function getConfigFilename() { if (isset($_SERVER['SERVER_NAME'])) { // If test runs from web-client first check if host test config exists // This could be used to have different tests for different configurations $host = OX_getHostName(); $testFilePath = MAX_PATH . '/var/' . $host . '.test.conf.php'; if (file_exists($testFilePath)) { return $testFilePath; } } // Look into default location $testFilePath = MAX_PATH . '/var/test.conf.php'; if (file_exists($testFilePath)) { return $testFilePath; } }
function fromCache() { // parse variable args // method, id, timeout // method, aParams, allFields, key, timeout $numArgs = func_num_args(); if ($numArgs < 2 || $numArgs > 5) { return PEAR::raiseError('incorrect args passed'); } $aArgs = func_get_args(); // initialise cache object $conf = $GLOBALS['_MAX']['CONF']; require_once 'Cache/Lite/Function.php'; // manually determine timeout required to instantiate cache object switch ($numArgs) { case 3: $timeout = $aArgs[2]; break; case 5: $timeout = $aArgs[4]; break; default: $timeout = null; } $method = $aArgs[0]; $options = array('cacheDir' => MAX_CACHE, 'lifeTime' => isset($timeout) ? $timeout : $conf['delivery']['cacheExpire']); // check if this method has defined different cache group $cacheGroups = $GLOBALS['_MAX']['Admin_DA']['cacheGroups']; // Note: if you change this key, also change the key when clearing the cache in connections-modify.php $options['defaultGroup'] = OX_getHostName(); if (isset($cacheGroups[$method])) { $options['defaultGroup'] .= $cacheGroups[$method]; } $cache = new Cache_Lite_Function($options); switch ($numArgs) { case 2: case 3: $id = $aArgs[1]; $timeout = @$aArgs[2]; // timeout may not be supplied // catch stats case if (is_array($aArgs[1])) { $aParams = $aArgs[1]; $allFields = isset($aArgs[2]) ? $aArgs[2] : false; $ret = $cache->call("Admin_DA::" . $method, $aParams, $allFields); } else { $ret = $cache->call("Admin_DA::" . $method, $id); } break; case 4: case 5: $aParams = $aArgs[1]; $allFields = $aArgs[2]; $key = @$aArgs[3]; $timeout = @$aArgs[4]; $ret = $cache->call("Admin_DA::" . $method, $aParams, $allFields, $key); break; default: return PEAR::raiseError('incorrect args passed'); } return $ret; }
function OX_Delivery_Common_getFunctionFromComponentIdentifier($identifier, $hook = null) { $aInfo = explode(':', $identifier); $functionName = 'Plugin_' . implode('_', $aInfo) . '_Delivery' . (!empty($hook) ? '_' . $hook : ''); if (!function_exists($functionName)) { if (!empty($GLOBALS['_MAX']['CONF']['pluginSettings']['useMergedFunctions'])) { _includeDeliveryPluginFile('/var/cache/' . OX_getHostName() . '_mergedDeliveryFunctions.php'); } if (!function_exists($functionName)) { _includeDeliveryPluginFile($GLOBALS['_MAX']['CONF']['pluginPaths']['plugins'] . '/' . implode('/', $aInfo) . '.delivery.php'); if (!function_exists($functionName)) { _includeDeliveryPluginFile('/lib/OX/Extension/' . $aInfo[0] . '/' . $aInfo[0] . 'Delivery.php'); $functionName = 'Plugin_' . $aInfo[0] . '_delivery'; if (!empty($hook) && function_exists($functionName . '_' . $hook)) { $functionName .= '_' . $hook; } } } } return $functionName; }
function guessWebpath() { $path = dirname($_SERVER['SCRIPT_NAME']); if (preg_match('#/www/admin$#', $path)) { // User has web root configured as Openads' root directory so can guess at all locations $subpath = preg_replace('#/www/admin$#', '', $path); $basepath = OX_getHostNameWithPort() . $subpath . '/www/'; $this->setValue('webpath', 'admin', $basepath . 'admin'); $this->setValue('webpath', 'delivery', $basepath . 'delivery'); $this->setValue('webpath', 'deliverySSL', $basepath . 'delivery'); $this->setValue('webpath', 'images', $basepath . 'images'); $this->setValue('webpath', 'imagesSSL', $basepath . 'images'); } else { if (preg_match('#/admin$#', $path)) { // User has web root configured as Openads' /www directory so can guess at all locations $subpath = preg_replace('#/admin$#', '', $path); $basepath = OX_getHostName() . $subpath . ''; $this->setValue('webpath', 'admin', $basepath . '/admin'); $this->setValue('webpath', 'delivery', $basepath . '/delivery'); $this->setValue('webpath', 'deliverySSL', $basepath . '/delivery'); $this->setValue('webpath', 'images', $basepath . '/images'); $this->setValue('webpath', 'imagesSSL', $basepath . '/images'); } else { // User has web root configured as Openads' www/admin directory so can only guess the admin location $this->setValue('webpath', 'admin', OX_getHostName()); $this->setValue('webpath', 'delivery', OX_getHostName()); $this->setValue('webpath', 'images', OX_getHostName()); $this->setValue('webpath', 'deliverySSL', OX_getHostName()); $this->setValue('webpath', 'imagesSSL', OX_getHostName()); } } }
function createGeoTargetingConfiguration($geotracking_type, $geotracking_location, $geotracking_stats) { $upgradeConfig = new OA_Upgrade_Config(); $host = OX_getHostName(); if (empty($geotracking_type) || $geotracking_type == 'ip2country') { return $this->writeGeoPluginConfig('"none"', $geotracking_stats, $host); } elseif ($geotracking_type == 'mod_geoip') { return $this->writeGeoPluginConfig('ModGeoIP', $geotracking_stats, $host) && $this->writeGeoSpecificConfig('ModGeoIP', '', $host); } elseif ($geotracking_type == 'geoip') { $databaseSetting = $this->getDatabaseSetting($geotracking_location); if ($databaseSetting === false) { $this->_logError('Unable to configure geoip'); return $this->writeGeoPluginConfig('"none"', $geotracking_stats, $host); } $result = $this->writeGeoPluginConfig('GeoIP', $geotracking_stats, $host); return $result && $this->writeGeoSpecificConfig('GeoIP', $databaseSetting, $host); } return false; }
function getCacheId() { // Cache the graphs for each locale. return array(OX_getHostName(), get_class($this), $GLOBALS['_MAX']['PREF']['language']); }
/** * Check if application is running from appropriate dir * * @static * * @param string $location * @return boolean True if a redirect is needed */ function checkRedirect($location = 'admin') { $aConf = $GLOBALS['_MAX']['CONF']; $redirect = false; // Is it possible to detect that we are NOT in the admin directory // via the URL the user is accessing OpenXwith? if (!preg_match('#/' . $location . '/?$#', $_SERVER['REQUEST_URI'])) { $dirName = dirname($_SERVER['REQUEST_URI']); // This check now allows for files in plugin folders $pluginDirName = basename($aConf['pluginPaths'][$location]); if (!preg_match("#/{$location}(/{$pluginDirName}/.*?)?/?\$#", $dirName)) { // The user is not in the "admin" folder directly. Are they // in the admin folder as a result of a "full" virtual host // configuration? if ($aConf['webpath']['admin'] != OX_getHostName()) { // Not a "full" virtual host setup, so re-direct $redirect = true; } } } return $redirect; }
<?php /* +---------------------------------------------------------------------------+ | Revive Adserver | | http://www.revive-adserver.com | | | | Copyright: See the COPYRIGHT.txt file. | | License: GPLv2 or later, see the LICENSE.txt file. | +---------------------------------------------------------------------------+ */ /** * @package Max * @subpackage SimulationSuite * @author */ if (!defined('SIM_PATH')) { define('SIM_PATH', MAX_PATH . '/www/devel/simulation/'); } define('SIM_TMP', SIM_PATH . '/tmp'); define('SIM_TEMPLATES', SIM_PATH . '/templates'); define('SCENARIOS', 'scenarios'); define('SCENARIOS_DATASETS', SIM_PATH . SCENARIOS . '/datasets/'); define('SCENARIOS_REQUESTSETS', SIM_PATH . SCENARIOS . '/requestsets/'); error_reporting(E_ALL ^ E_NOTICE); define('TEST_ENVIRONMENT_RUNNING', true); require_once 'lib.inc.php'; $conf['simdb'] = $conf['database']; $conf['realConfig'] = OX_getHostName(); global $is_simulation; $is_simulation = true;
/** * Checks if $testArray exists in $section in global config file * * @param string $testSection * @param array $testArray */ function checkGlobalConfigConsists($testSection, $testArray) { $host = OX_getHostName(); $configPath = MAX_PATH . "/var/{$host}.conf.php"; if ($this->assertTrue(file_exists($configPath), "File: '{$configPath}' should exist!")) { $aContents = parse_ini_file($configPath, true); foreach ($testArray as $key => $val) { $this->assertEqual($aContents[$testSection][$key], $val); } } }
| | | Copyright: See the COPYRIGHT.txt file. | | License: GPLv2 or later, see the LICENSE.txt file. | +---------------------------------------------------------------------------+ */ // Require the initialisation file // Note that MAX_PATH will have been defined by the invocated code require_once MAX_PATH . '/init-delivery.php'; // Include required files require_once MAX_PATH . '/lib/max/Delivery/adSelect.php'; require_once MAX_PATH . '/lib/max/Delivery/flash.php'; // init-variables will have set "loc" to $_SERVER['HTTP_REFERER'] // however - in local mode (only), this is not the case global $referer, $loc; $referer = !empty($loc) ? $loc : ''; $loc = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http') . '://' . OX_getHostName() . $_SERVER['REQUEST_URI']; // init-delivery.php is not setting invocationType properly for local invocation type // we should set it here $GLOBALS['_OA']['invocationType'] = 'local'; // This function is a wrapper to view raw, this allows for future migration function view_local($what, $zoneid = 0, $campaignid = 0, $bannerid = 0, $target = '', $source = '', $withtext = '', $context = '', $charset = '') { // start stacked output buffering ob_start(); if (empty($what) && !(strstr($what, 'zone') or strstr($what, 'campaign') or strstr($what, 'banner'))) { if ($zoneid) { $what = "zone:" . $zoneid; } if ($campaignid) { $what = "campaignid:" . $campaignid; }
/** * delete the existing conf file * copy the backup conf file to it's old name * delete the backup conf file and audit * * @param string $confBackup * @param integer $auditId */ function _restoreConfigBackup($confBackup, $auditId) { if ($confBackup) { $host = OX_getHostName(); $confFile = $host . '.conf.php'; if (file_exists(MAX_PATH . '/var/' . $confFile)) { if (!@unlink(MAX_PATH . '/var/' . $confFile)) { $this->oLogger->logError('failed to remove current configuration file'); return false; } } if (!file_exists(MAX_PATH . '/var/' . $confBackup)) { $this->oLogger->logError('failed to find backup configuration file'); return false; } $confOldName = substr($confBackup, strpos($confBackup, 'old.') + 4); if (substr($confOldName, -8, 4) == '.ini') { $confOldName = str_replace('.php', '', $confOldName); } if (!copy(MAX_PATH . '/var/' . $confBackup, MAX_PATH . '/var/' . $confOldName)) { return false; } $this->oLogger->log('restored config file ' . $confOldName); if (!@unlink(MAX_PATH . '/var/' . $confBackup)) { $this->oLogger->log('failed to remove backup configuration file'); return false; } $this->oLogger->log('removed backup config file ' . $confBackup); $this->oAuditor->updateAuditBackupConfDroppedById($auditId, 'dropped during recovery'); } return true; }
/** * rollback the upgrade executed during the previous test * copy the *fake* RECOVER file to the var folder * check the audit trail * delete the RECOVER file after * */ function test_recoverUpgrade() { $host = OX_getHostName(); $confFile = $host . '.conf.php'; if (file_exists(MAX_PATH . '/var/test_' . $confFile)) { if (!@unlink(MAX_PATH . '/var/test_' . $confFile)) { $this->oLogger->logError('failed to remove the backup configuration file'); return false; } } if (file_exists(MAX_PATH . '/var/' . $confFile)) { if (!copy(MAX_PATH . '/var/' . $confFile, MAX_PATH . '/var/test_' . $confFile)) { $this->assertTrue(false, 'test failed to backup conf file before upgrade recovery'); return false; } } $oUpgrade = new OA_Upgrade(); $oUpgrade->_pickupRecoveryFile(); $this->_writeTestRecoveryFile(); $oUpgrade->recoverUpgrade(); if (file_exists(MAX_PATH . '/var/' . $confFile)) { if (!@unlink(MAX_PATH . '/var/' . $confFile)) { $this->oLogger->logError('failed to remove the backup configuration file'); return false; } } if (file_exists(MAX_PATH . '/var/test_' . $confFile)) { if (!copy(MAX_PATH . '/var/test_' . $confFile, MAX_PATH . '/var/' . $confFile)) { $this->assertTrue(false, 'test failed to restore the test conf file after upgrade recovery'); return false; } @unlink(MAX_PATH . '/var/test_' . $confFile); } $aAudit = $oUpgrade->oAuditor->queryAuditAllDescending(); // we should have another 13 records in the upgrade_action audit table // we should have another 13 logfiles in the var folder // we should have 13 backup conf files in the var folder // one for each of the 12 packages plus a version stamp *package* $this->assertEqual(count($aAudit), 26, 'wrong number of audit records'); foreach ($aAudit as $k => $aRec) { $idx = 25 - $k; if ($idx > 12) { $this->assertEqual($aRec['upgrade_action_id'], $idx + 1, ''); $this->assertEqual($aRec['action'], UPGRADE_ACTION_ROLLBACK_SUCCEEDED, 'wrong action definition'); $result = $oUpgrade->oAuditor->queryAuditByUpgradeId($k + 1); $this->assertIsA($result, 'array', 'failed to retrieve the original audit record array'); $this->assertTrue(isset($result[0]), 'failed to retrieve the original audit record'); $aOriginalAuditRec = $result[0]; $this->assertEqual($aOriginalAuditRec['confbackup'], 'dropped during recovery', 'failure to audit that conf was dropped'); //$aOriginalAuditRec['confbackup']); // recovery should restore then drop the backup tables if (file_exists(MAX_PATH . '/var/' . ($k + 11) . '_old.www.mysite.net.conf.php')) { $this->assertFalse(true, 'conf backup was not deleted'); @unlink(MAX_PATH . '/var/' . ($k + 11) . '_old.www.mysite.net.conf.php'); } $this->assertTrue(file_exists(MAX_PATH . '/var/' . $aRec['logfile']), 'logfile does not exist'); $this->assertEqual($aRec['logfile'], $aOriginalAuditRec['logfile'] . '.rollback', 'wrong log file'); @unlink(MAX_PATH . '/var/' . $aRec['logfile']); $this->assertEqual($aRec['upgrade_name'], $aOriginalAuditRec['upgrade_name'], 'package mismatch: ' . $aRec['upgrade_name'] . ' and ' . $aOriginalAuditRec['upgrade_name']); } } // the application variable should match the initial version given in the previous test $this->assertEqual($oUpgrade->oVersioner->getApplicationVersion(), '2.3.32-beta-rc1', 'wrong initial application version: ' . $oUpgrade->versionInitialApplication); $this->assertFalse(file_exists($oUpgrade->recoveryFile), 'recovery file was not deleted after recovery'); // just in case of error, lose the recovery file so we can continue afresh // and not screw up someone's installation next time they run $oUpgrade->_pickupRecoveryFile(); // delete the *restored* dummy conf file @unlink(MAX_PATH . '/var/www.mysite.net.conf.php'); }
function OA_Delivery_XmlRpc_SPC($params) { global $XML_RPC_erruser; global $XML_RPC_String, $XML_RPC_Struct, $XML_RPC_Array; $numParams = $params->getNumParams(); if ($numParams != 7) { $errorCode = $XML_RPC_erruser + 21; $errorMsg = 'Incorrect number of parameters'; return new XML_RPC_Response(0, $errorCode, $errorMsg); } $vars = array(1 => 'what', 2 => 'target', 3 => 'source', 4 => 'withtext', 5 => 'block', 6 => 'blockcampaign'); for ($i = 0; $i < $numParams; $i++) { $p = $params->getParam($i); if ($i) { ${$vars}[$i] = XML_RPC_decode($p); } else { $p = XML_RPC_decode($p); if (!isset($p['remote_addr'])) { $errorCode = $XML_RPC_erruser + 22; $errorMsg = "Missing 'remote_addr' member"; return new XML_RPC_Response(0, $errorCode, $errorMsg); } if (!isset($p['cookies']) || !is_array($p['cookies'])) { $errorCode = $XML_RPC_erruser + 23; $errorMsg = "Missing 'cookies' member"; return new XML_RPC_Response(0, $errorCode, $errorMsg); } $aServerVars = array('remote_addr' => 'REMOTE_ADDR', 'remote_host' => 'REMOTE_HOST', 'request_uri' => 'REQUEST_URI', 'https' => 'HTTPS', 'server_name' => 'SERVER_NAME', 'http_host' => 'HTTP_HOST', 'accept_language' => 'HTTP_ACCEPT_LANGUAGE', 'referer' => 'HTTP_REFERER', 'user_agent' => 'HTTP_USER_AGENT', 'via' => 'HTTP_VIA', 'forwarded' => 'HTTP_FORWARDED', 'forwarded_for' => 'HTTP_FORWARDED_FOR', 'x_forwarded' => 'HTTP_X_FORWARDED', 'x_forwarded_for' => 'HTTP_X_FORWARDED_FOR', 'client_ip' => 'HTTP_CLIENT_IP'); foreach ($aServerVars as $xmlName => $varName) { if (isset($p[$xmlName])) { $_SERVER[$varName] = $p[$xmlName]; } } foreach ($p['cookies'] as $key => $value) { $_COOKIE[$key] = MAX_commonAddslashesRecursive($value); } MAX_remotehostSetInfo(true); OX_Delivery_Common_hook('postInit'); MAX_cookieUnpackCapping(); } } $richmedia = true; $ct0 = ''; $context = array(); global $loc, $referer; $loc = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http') . '://' . OX_getHostName() . $_SERVER['REQUEST_URI']; $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; if (is_numeric($what)) { $zones = OA_cacheGetPublisherZones($what); $nz = false; } else { $zones = unserialize($what); $nz = true; } $spc_output = array(); foreach ($zones as $zone => $data) { if (empty($zone)) { continue; } if ($nz) { $varname = $zone; $zoneid = $data; } else { $varname = $zoneid = $zone; } unset($GLOBALS['_MAX']['deliveryData']); $output = MAX_adSelect('zone:' . $zoneid, '', $target, $source, $withtext, '', $context, $richmedia, $ct0, $GLOBALS['loc'], $GLOBALS['referer']); $spc_output[$varname] = $output; if (!empty($block) && !empty($output['bannerid'])) { $output['context'][] = array('!=' => 'bannerid:' . $output['bannerid']); } if (!empty($blockcampaign) && !empty($output['campaignid'])) { $output['context'][] = array('!=' => 'campaignid:' . $output['campaignid']); } if (!empty($output['context'])) { foreach ($output['context'] as $id => $contextArray) { if (!in_array($contextArray, $context)) { $context[] = $contextArray; } } } } return new XML_RPC_Response(XML_RPC_encode($spc_output)); $output = call_user_func_array('MAX_adSelect', $view_params); if (!is_array($output)) { $output = array(); } elseif (isset($output['contenttype']) && $output['contenttype'] == 'swf') { $output['html'] = MAX_flashGetFlashObjectExternal() . $output['html']; } MAX_cookieFlush(); $output['cookies'] = $GLOBALS['_OA']['COOKIE']['XMLRPC_CACHE']; return new XML_RPC_Response(XML_RPC_encode($output)); }
/** * The general (non-delivery engine) function to parse the configuration .ini file * * @param string $configPath The directory to load the config file from. * Default is Max's /var directory. * @param string $configFile The configuration file name (eg. "geotargeting"). * Default is no name (ie. the main Max * configuration file). * @param boolean $sections Process sections, as per parse_ini_file(). * @param string $type The config file type value (eg. ".php"). Allows BC * support for old ".ini" files. * * @return mixed The array resulting from the call to parse_ini_file(), with * the appropriate .php file for the installation. */ function parseIniFile($configPath = null, $configFile = null, $sections = true, $type = '.php') { // Set up the configuration .ini file path location if (is_null($configPath)) { $configPath = MAX_PATH . '/var'; } // Set up the configuration .ini file type name if (!is_null($configFile)) { $configFile = '.' . $configFile; } // Is this a web, or a cli call? if (is_null($configFile) && !isset($_SERVER['SERVER_NAME'])) { if (!isset($GLOBALS['argv'][1]) && !file_exists($configPath . '/default' . $configFile . '.conf' . $type)) { echo MAX_PRODUCT_NAME . " was called via the command line, but had no host as a parameter.\n"; exit(1); } $host = trim($GLOBALS['argv'][1]); } else { $host = OX_getHostName(); } // Is the system running the test environment? if (is_null($configFile) && defined('TEST_ENVIRONMENT_RUNNING')) { // Does the test environment config exist? $testFilePath = $configPath . '/test.conf' . $type; if (file_exists($testFilePath)) { return @parse_ini_file($testFilePath, $sections); } else { // Define a value so that we know the testing environment is not // configured, so that the TestRenner class knows not to run any // tests, and return an empty config define('TEST_ENVIRONMENT_NO_CONFIG', true); return array(); } } // Is the .ini file for the hostname being used directly accessible? if (file_exists($configPath . '/' . $host . $configFile . '.conf' . $type)) { // Parse the configuration file $conf = @parse_ini_file($configPath . '/' . $host . $configFile . '.conf' . $type, $sections); // Is this a real config file? if (!isset($conf['realConfig'])) { // Yes, return the parsed configuration file return $conf; } // Parse and return the real configuration .ini file if (file_exists($configPath . '/' . $conf['realConfig'] . $configFile . '.conf' . $type)) { $realConfig = @parse_ini_file(MAX_PATH . '/var/' . $conf['realConfig'] . '.conf' . $type, true); $mergedConf = mergeConfigFiles($realConfig, $conf); // if not multiple levels of configs if (!isset($mergedConf['realConfig'])) { return $mergedConf; } } } elseif ($configFile === '.plugin') { // For plugins, if no configuration file is found, return the sane default values $pluginType = basename($configPath); $defaultConfig = MAX_PATH . '/plugins/' . $pluginType . '/default.plugin.conf' . $type; if (file_exists($defaultConfig)) { return parse_ini_file($defaultConfig, $sections); } else { echo MAX_PRODUCT_NAME . " could not read the default configuration file for the {$pluginType} plugin"; exit(1); } } // Check for a default.conf.php file... if (file_exists($configPath . '/default' . $configFile . '.conf' . $type)) { // Parse the configuration file $conf = @parse_ini_file($configPath . '/default' . $configFile . '.conf' . $type, $sections); // Is this a real config file? if (!isset($conf['realConfig'])) { // Yes, return the parsed configuration file return $conf; } // Parse and return the real configuration .ini file if (file_exists($configPath . '/' . $conf['realConfig'] . $configFile . '.conf' . $type)) { $realConfig = @parse_ini_file(MAX_PATH . '/var/' . $conf['realConfig'] . '.conf' . $type, true); $mergedConf = mergeConfigFiles($realConfig, $conf); // if not multiple levels of configs if (!isset($mergedConf['realConfig'])) { return $mergedConf; } } } // Got all this way, and no configuration file yet found - maybe // the user is upgrading from an old version where the config // files have a .ini prefix instead of .php... global $installing; if ($installing) { // ah but MMM might be installed, check for the ini file if (file_exists($configPath . '/' . $host . $configFile . '.conf.ini')) { return parseIniFile($configPath, $configFile, $sections, '.ini'); } if (!$configFile) { // OpenX hasn't been installed, so use the distribution .ini file // this deals with letting a PAN install get into the ugprader return @parse_ini_file(MAX_PATH . '/etc/dist.conf.php', $sections); } //return parseIniFile($configPath, $configFile, $sections, '.ini'); } // Check to ensure OpenX hasn't been installed if (file_exists(MAX_PATH . '/var/INSTALLED')) { // ah but MMM might be installed, check for the ini file if (file_exists($configPath . '/' . $host . $configFile . '.conf.ini')) { return parseIniFile($configPath, $configFile, $sections, '.ini'); } echo MAX_PRODUCT_NAME . " has been installed, but no configuration file " . $configPath . '/' . $host . $configFile . '.conf.php' . " was found.\n"; exit(1); } // OpenX hasn't been installed, so use the distribution .ini file return @parse_ini_file(MAX_PATH . '/etc/dist.conf.php', $sections); }
private function _batchInsertMySQL($qTableName, $fieldList, $aValues, $replace) { $oDbh = OA_DB::singleton(); // File path defaults to var/cache if (!isset(self::$batchInsertPath)) { self::$batchInsertPath = MAX_PATH . '/var/cache'; } // Create file path using hostname and table name $filePath = self::$batchInsertPath . '/' . OX_getHostName() . '-batch-' . $qTableName . '.csv'; if (DIRECTORY_SEPARATOR == '\\') { // On windows, MySQL expects slashes as directory separators $filePath = str_replace('\\', '/', $filePath); } if ($replace) { $replace = ' REPLACE '; } else { $replace = ''; } // Set up CSV delimiters, quotes, etc $delim = "\t"; $quote = '"'; $eol = "\n"; $null = 'NULL'; // Disable error handler RV::disableErrorHandling(); $fp = fopen($filePath, 'wb'); if (!$fp) { return MAX::raiseError('Error creating the tmp file ' . $filePath . ' containing the batch INSERTs.', PEAR_ERROR_RETURN); } // ensure that when maintenance is run in crontab, as root eg. // the file can still be overwritten by maintenance ran from the UI @chmod($filePath, 0777); foreach ($aValues as $aRow) { // Stringify row $row = ''; foreach ($aRow as $value) { if (!isset($value) || is_null($value) || $value === false) { $row .= $null . $delim; } else { $row .= $quote . $value . $quote . $delim; } } // Replace delim with eol $row[strlen($row) - 1] = $eol; // Append $ret = fwrite($fp, $row); if (!$ret) { fclose($fp); unlink($filePath); return MAX::raiseError('Error writing to the tmp file ' . $filePath . ' containing the batch INSERTs.', PEAR_ERROR_RETURN); } } fclose($fp); $query = "\n LOAD DATA LOCAL INFILE\n '{$filePath}'\n {$replace}\n INTO TABLE\n {$qTableName}\n FIELDS TERMINATED BY\n " . $oDbh->quote($delim) . "\n ENCLOSED BY\n " . $oDbh->quote($quote) . "\n ESCAPED BY\n ''\n LINES TERMINATED BY\n " . $oDbh->quote($eol) . "\n \t{$fieldList}\n "; $result = $oDbh->exec($query); @unlink($filePath); // Enable error handler again RV::enableErrorHandling(); return $result; }
| Revive Adserver | | http://www.revive-adserver.com | | | | Copyright: See the COPYRIGHT.txt file. | | License: GPLv2 or later, see the LICENSE.txt file. | +---------------------------------------------------------------------------+ */ require_once LIB_PATH . '/Plugin/Component.php'; require_once LIB_PATH . '/Plugin/ComponentGroupManager.php'; require_once LIB_PATH . '/Util/CodeMunger.php'; require_once MAX_PATH . '/lib/OA/Algorithm/Dependency/Ordered.php'; require_once MAX_PATH . '/lib/OA/Algorithm/Dependency/Source/HoA.php'; /** * Global location for storing merged plugins files code */ define('OX_BUCKETS_COMPILED_FILE', MAX_PATH . '/var/cache/' . OX_getHostName() . '_mergedDeliveryFunctions.php'); /** * Generates delivery log plugins cache and order the dependencies * between components per each delivery log hook. * * @package OpenXExtension * @subpackage DeliveryLog */ class OX_Extension_DeliveryLog_Setup extends OX_Component { const DATA_EXTENSION = 'deliveryDataPrepare'; const LOG_EXTENSION = 'deliveryLog'; public $aDeliveryLogHooks = array('preLog', 'logRequest', 'logImpression', 'logClick', 'logConversion', 'logConversionVariable'); /** * Delivery logging related extension types *