/** * Handle all necessary operations when a new account is created * * @see DB_DataObject::insert() */ function insert() { $result = parent::insert(); if ($this->account_type == OA_ACCOUNT_ADMIN && $result) { OA_Dal_ApplicationVariables::set('admin_account_id', $result); } return $result; }
/** * A helper method to set applicationvariables * * @param Date $oScheduledDate * @param Date $oDate */ function setVariables($oScheduledDate, $oDate) { if (isset($oScheduledDate)) { OA_Dal_ApplicationVariables::set('maintenance_cron_timestamp', $oScheduledDate->getDate(DATE_FORMAT_UNIXTIME)); } else { OA_Dal_ApplicationVariables::delete('maintenance_cron_timestamp'); } if (isset($oDate)) { OA_Dal_ApplicationVariables::set('maintenance_timestamp', $oDate->getDate(DATE_FORMAT_UNIXTIME)); } else { OA_Dal_ApplicationVariables::delete('maintenance_timestamp'); } }
/** * Test set, get and delete * */ function testSetGetDelete() { // Force cache clean-up OA_Dal_ApplicationVariables::cleanCache(); $result = OA_Dal_ApplicationVariables::get('foo'); $this->assertNull($result); $result = OA_Dal_ApplicationVariables::set('foo', 'bar'); $this->assertTrue($result); // Check cached values $result = OA_Dal_ApplicationVariables::get('foo'); $this->assertEqual($result, 'bar'); // Force cache clean-up OA_Dal_ApplicationVariables::cleanCache(); // Check DB-stored values $result = OA_Dal_ApplicationVariables::get('foo'); $this->assertEqual($result, 'bar'); $result = OA_Dal_ApplicationVariables::set('foo', 'foobar'); $this->assertTrue($result); // Check cached values $result = OA_Dal_ApplicationVariables::get('foo'); $this->assertEqual($result, 'foobar'); // Force cache clean-up OA_Dal_ApplicationVariables::cleanCache(); // Check DB-stored values $result = OA_Dal_ApplicationVariables::get('foo'); $this->assertEqual($result, 'foobar'); $result = OA_Dal_ApplicationVariables::delete('foo'); $this->assertTrue($result); // Check cached values $result = OA_Dal_ApplicationVariables::get('foo'); $this->assertNull($result); // Force cache clean-up OA_Dal_ApplicationVariables::cleanCache(); // Check DB-stored values $result = OA_Dal_ApplicationVariables::get('foo'); $this->assertNull($result); }
/** * Connect to OpenX Sync to check for updates * * @param float $already_seen Only check for updates newer than this value. * @return array An array of two items: * * Item 0 is the XML-RPC error code. Meanings: * -2 => The admin user has disabled update checking * -1 => No response from the server * 0 - 799 => XML-RPC library error codes * 0 => No error * 800 => No updates * 801+ => Error codes from the remote XML-RPC server * * Item 1 is either the error message (item 1 != 0), or an array containing update info */ function checkForUpdates($already_seen = 0) { global $XML_RPC_erruser; if (!$this->aConf['sync']['checkForUpdates']) { // Checking for updates has been disabled by the admin user, // so do not communicate with the server that provides the // details of what upgrades are available - just return an // 800 "error" $aReturn = array(-2, 'Check for updates has been disabled by the administrator.'); return $aReturn; } // Create the XML-RPC client object $client = OA_Central::getXmlRpcClient($this->_conf); // Prepare the installation's platform hash $platform_hash = OA_Dal_ApplicationVariables::get('platform_hash'); if (!$platform_hash) { // The installation does not have a platform hash; generate one, // and save it to the database for later use OA::debug("Generating a new platform_hash for the installation", PEAR_LOG_INFO); $platform_hash = OA_Dal_ApplicationVariables::generatePlatformHash(); if (!OA_Dal_ApplicationVariables::set('platform_hash', $platform_hash)) { OA::debug("Could not save the new platform_hash to the database", PEAR_LOG_ERR); unset($platform_hash); OA::debug("Sync process proceeding without a platform_hash", PEAR_LOG_INFO); } } // Prepare the parameters required for the XML-RPC call to // obtain if an update is available for this installation $params = array(new XML_RPC_Value(PRODUCT_NAME, 'string'), new XML_RPC_Value($this->getConfigVersion(OA_Dal_ApplicationVariables::get('oa_version')), 'string'), new XML_RPC_Value($already_seen, 'string'), new XML_RPC_Value($platform_hash, 'string')); // Has the Revive Adserver admin user kindly agreed to share the // technology stack that it is running on, to help the community? $aTechStack = array('data' => false); if ($this->aConf['sync']['shareStack']) { // Thanks, admin user! You're a star! Prepare the technology stack // data and add it to the XML-RPC call if ($this->oDbh->dbsyntax == 'mysql') { $dbms = 'MySQL'; } else { if ($this->oDbh->dbsyntax == 'pgsql') { $dbms = 'PostgreSQL'; } else { $dbms = 'UnknownSQL'; } } $aTechStack = array('os_type' => php_uname('s'), 'os_version' => php_uname('r'), 'webserver_type' => isset($_SERVER['SERVER_SOFTWARE']) ? preg_replace('#^(.*?)/.*$#', '$1', $_SERVER['SERVER_SOFTWARE']) : '', 'webserver_version' => isset($_SERVER['SERVER_SOFTWARE']) ? preg_replace('#^.*?/(.*?)(?: .*)?$#', '$1', $_SERVER['SERVER_SOFTWARE']) : '', 'db_type' => $dbms, 'db_version' => $this->oDbh->queryOne("SELECT VERSION()"), 'php_version' => phpversion(), 'php_sapi' => ucfirst(php_sapi_name()), 'php_extensions' => get_loaded_extensions(), 'php_register_globals' => (bool) ini_get('register_globals'), 'php_magic_quotes_gpc' => (bool) ini_get('magic_quotes_gpc'), 'php_safe_mode' => (bool) ini_get('safe_mode'), 'php_open_basedir' => (bool) strlen(ini_get('open_basedir')), 'php_upload_tmp_readable' => (bool) is_readable(ini_get('upload_tmp_dir') . DIRECTORY_SEPARATOR)); } $params[] = XML_RPC_Encode($aTechStack); // Add the registered email address $params[] = new XML_RPC_Value(OA_Dal_ApplicationVariables::get('sync_registered_email'), 'string'); // Create the XML-RPC request message $msg = new XML_RPC_Message("Revive.Sync", $params); // Send the XML-RPC request message if ($response = $client->send($msg, 10)) { // XML-RPC server found, now checking for errors if (!$response->faultCode()) { // No fault! Woo! Get the response and return it! $aReturn = array(0, XML_RPC_Decode($response->value())); // Prepare cache $cache = $aReturn[1]; // Update last run OA_Dal_ApplicationVariables::set('sync_last_run', date('Y-m-d H:i:s')); // Also write to the debug log OA::debug("Sync: updates found!", PEAR_LOG_INFO); } else { // Boo! An error! (Well, maybe - if it's 800, yay!) $aReturn = array($response->faultCode(), $response->faultString()); // Prepare cache $cache = false; // Update last run if ($response->faultCode() == 800) { // Update last run OA_Dal_ApplicationVariables::set('sync_last_run', date('Y-m-d H:i:s')); // Also write to the debug log OA::debug("Sync: {$aReturn[1]}", PEAR_LOG_INFO); } else { // Write to the debug log OA::debug("Sync: {$aReturn[1]} (code: {$aReturn[0]}", PEAR_LOG_ERR); // Return immediately without writing to cache return $aReturn; } } OA_Dal_ApplicationVariables::set('sync_cache', serialize($cache)); OA_Dal_ApplicationVariables::set('sync_timestamp', time()); return $aReturn; } $aReturn = array(-1, 'No response from the remote XML-RPC server.'); // Also write to the debug log OA::debug("Sync: {$aReturn[1]}", PEAR_LOG_ERR); return $aReturn; }
/** * Update checkForUpdates value into Settings * * @param boolean $syncEnabled * @return boolean */ function putSyncSettings($syncEnabled) { require_once MAX_PATH . '/lib/OA/Admin/Settings.php'; require_once MAX_PATH . '/lib/OA/Sync.php'; $oSettings = new OA_Admin_Settings(); $oSettings->settingChange('sync', 'checkForUpdates', $syncEnabled); // Reset Sync cache OA_Dal_ApplicationVariables::delete('sync_cache'); OA_Dal_ApplicationVariables::delete('sync_timestamp'); OA_Dal_ApplicationVariables::delete('sync_last_seen'); if (!$oSettings->writeConfigChange()) { $this->oLogger->logError('Error saving Sync settings to the config file'); return false; } // Generate a new Platform Hash if empty $platformHash = OA_Dal_ApplicationVariables::get('platform_hash'); if (empty($platformHash) && !OA_Dal_ApplicationVariables::set('platform_hash', OA_Dal_ApplicationVariables::generatePlatformHash())) { $this->oLogger->logError('Error inserting Platform Hash into database'); return false; } $oSync = new OA_Sync(); OA::disableErrorHandling(); $oSync->checkForUpdates(); OA::enableErrorHandling(); return true; }
/** * A method to update maintenance last run information for * old maintenance code. */ function updateLastRun($bScheduled = false) { $sField = $bScheduled ? 'maintenance_cron_timestamp' : 'maintenance_timestamp'; OA_Dal_ApplicationVariables::set($sField, OA::getNow('U')); // Make sure that the maintenance delivery cache is regenerated MAX_cacheCheckIfMaintenanceShouldRun(false); }
/** * Process input from user and creates/upgrades DB etc.... * * @param OA_Admin_UI_Component_Form $oForm * @param OX_Admin_UI_Install_Wizard $oWizard */ protected function processDatabaseAction($oForm, $oWizard) { $oUpgrader = $this->getUpgrader(); $upgraderSuccess = false; $aDbConfig = $oForm->populateDbConfig(); if ($oUpgrader->canUpgradeOrInstall()) { $installStatus = $oUpgrader->existing_installation_status; define('DISABLE_ALL_EMAILS', 1); OA_Permission::switchToSystemProcessUser('Installer'); if ($installStatus == OA_STATUS_NOT_INSTALLED) { if ($oUpgrader->install($aDbConfig)) { $message = $GLOBALS['strDBInstallSuccess']; $upgraderSuccess = true; } } else { if ($oUpgrader->upgrade($oUpgrader->package_file)) { // Timezone support - hack if ($oUpgrader->versionInitialSchema['tables_core'] < 538 && empty($aDbConfig['noTzAlert'])) { OA_Dal_ApplicationVariables::set('utc_update', OA::getNowUTC()); } // Clear the menu cache to built a new one with the new settings OA_Admin_Menu::_clearCache(OA_ACCOUNT_ADMIN); OA_Admin_Menu::_clearCache(OA_ACCOUNT_MANAGER); OA_Admin_Menu::_clearCache(OA_ACCOUNT_ADVERTISER); OA_Admin_Menu::_clearCache(OA_ACCOUNT_TRAFFICKER); OA_Admin_Menu::singleton(); $message = $GLOBALS['strDBUpgradeSuccess']; $upgraderSuccess = true; } } OA_Permission::switchToSystemProcessUser(); //get back to normal user previously logged in } else { if ($oUpgrader->existing_installation_status == OA_STATUS_CURRENT_VERSION) { $upgraderSuccess = true; //rare but can occur if DB has been installed and user revisits the screen } } $dbSuccess = $upgraderSuccess && !$oUpgrader->oLogger->errorExists; if ($dbSuccess) { //show success status OA_Admin_UI::getInstance()->queueMessage($message, 'global', 'info'); } else { //sth went wrong, display messages from upgrader $aMessages = OX_Admin_UI_Install_InstallUtils::getMessagesWithType($oUpgrader->getMessages()); $this->setModelProperty('aMessages', $aMessages); } return $dbSuccess; }
require_once MAX_PATH . '/www/admin/config.php'; require_once MAX_PATH . '/lib/OA/Dal/ApplicationVariables.php'; require_once MAX_PATH . '/lib/OA/Sync.php'; require_once MAX_PATH . '/lib/max/language/Loader.php'; Language_Loader::load('settings'); // Security check OA_Permission::enforceAccount(OA_ACCOUNT_ADMIN); /*-------------------------------------------------------*/ /* HTML framework */ /*-------------------------------------------------------*/ $title = $GLOBALS['strPlatformHashRegenerate']; $oHeaderModel = new OA_Admin_UI_Model_PageHeaderModel($title); phpAds_PageHeader('account-settings-index', $oHeaderModel); /*-------------------------------------------------------*/ /* Main code */ /*-------------------------------------------------------*/ $platformHash = OA_Dal_ApplicationVariables::generatePlatformHash(); if (OA_Dal_ApplicationVariables::set('platform_hash', $platformHash)) { echo $GLOBALS['strNewPlatformHash'] . " " . $platformHash; $oSync = new OA_Sync(); OA::disableErrorHandling(); $oSync->checkForUpdates(); OA::enableErrorHandling(); } else { $this->oLogger->logError('Error inserting Platform Hash into database'); echo $GLOBALS['strPlatformHashInsertingError']; } /*-------------------------------------------------------*/ /* HTML framework */ /*-------------------------------------------------------*/ phpAds_PageFooter();
/** * A static method to update the last run * */ function updateLastRun() { OA_Dal_ApplicationVariables::set('maintenance_timestamp', time()); }
function testGetLastRun() { $oMaintenance = new OX_Maintenance(); $this->assertNull($oMaintenance->getLastRun()); $iLastRun = strtotime('2002-01-01'); OA_Dal_ApplicationVariables::set('maintenance_timestamp', $iLastRun); $oDate = new Date((int) $iLastRun); $this->assertTrue($oDate->equals($oMaintenance->getLastRun())); OA_Dal_ApplicationVariables::delete('maintenance_timestamp'); }
if ($aVars['sync_cache']) { $update_check = unserialize($aVars['sync_cache']); } // If cache timestamp not set or older than 24hrs, re-sync if (isset($aVars['sync_timestamp']) && $aVars['sync_timestamp'] + 86400 < time()) { $oSync = new OA_Sync(); $res = $oSync->checkForUpdates(); if ($res[0] == 0) { $update_check = $res[1]; } } if (!is_array($update_check) || $update_check['config_version'] <= $aVars['sync_last_seen']) { $update_check = false; } else { // Make sure that the alert doesn't display everytime OA_Dal_ApplicationVariables::set('sync_last_seen', $update_check['config_version']); // Format like the XML-RPC response $update_check = array(0, $update_check); } } phpAds_SessionDataRegister('maint_update_js', true); phpAds_SessionDataStore(); // Add Product Update redirector if (isset($update_check[0]) && $update_check[0] == 0) { header("Content-Type: application/x-javascript"); if ($update_check[1]['security_fix']) { echo "alert('" . $strUpdateAlertSecurity . "');\n"; } else { echo "if (confirm('" . $strUpdateAlert . "'))\n\t"; } echo "document.location.replace('updates-product.php');\n";
/** * A method to retrieve the revenue information until last GMT midnight * * @see R-AN-7: Synchronizing the revenue information * * @todo Implement rollback * * @return boolean True on success */ function getRevenue() { $batchSequence = OA_Dal_ApplicationVariables::get('batch_sequence'); $batchSequence = is_null($batchSequence) ? 1 : $batchSequence + 1; $aRevenues = $this->oMapper->getRevenue($batchSequence); if (PEAR::isError($aRevenues)) { return false; } if (!$this->oDal->beginTransaction()) { return false; } $aBannerIds = $this->oDal->getBannerIdsFromOacIds(array_keys($aRevenues)); foreach ($aRevenues as $bannerId => $aData) { foreach ($aData as $aRevenue) { if (!isset($aBannerIds[$bannerId])) { continue; } if (!$this->oDal->revenueClearStats($aBannerIds[$bannerId], $aRevenue)) { return $this->oDal->rollbackAndReturnFalse(); } if (!$this->oDal->revenuePerformUpdate($aBannerIds[$bannerId], $aRevenue)) { return $this->oDal->rollbackAndReturnFalse(); } } } if (!OA_Dal_ApplicationVariables::set('batch_sequence', $batchSequence)) { return $this->oDal->rollbackAndReturnFalse(); } return $this->oDal->commit(); }
/** * Connect to OpenX Sync to check for updates * * @param float $already_seen Only check for updates newer than this value. * @return array An array of two items: * * Item 0 is the XML-RPC error code. Meanings: * -2 => The admin user has disabled update checking * -1 => No response from the server * 0 - 799 => XML-RPC library error codes * 0 => No error * 800 => No updates * 801+ => Error codes from the remote XML-RPC server * * Item 1 is either the error message (item 1 != 0), or an array containing update info */ function checkForUpdates($already_seen = 0) { global $XML_RPC_erruser; if (!$this->aConf['sync']['checkForUpdates']) { // Checking for updates has been disabled by the admin user, // so do not communicate with the OpenX server that provides // the details of what upgrades are available - just return // an 800 "error" $aReturn = array(-2, 'Check for updates has been disabled by the OpenX administrator.'); return $aReturn; } // Should this server's technology stack be shared with OpenX? $shareTechStack = false; if ($this->aConf['sync']['shareStack']) { $shareTechStack = true; } // Should this server's aggregate impression and click statistcs // be shared with OpenX? $shareStats = false; if ($this->aConf['sync']['shareData']) { $shareStats = true; } // Create the XML-RPC client object $client = OA_Central::getXmlRpcClient($this->_conf); // Prepare the parameters required for the XML-RPC call to // obtain if an update is available for this OpenX installation $params = array(new XML_RPC_Value(MAX_PRODUCT_NAME, 'string'), new XML_RPC_Value($this->getConfigVersion(OA_Dal_ApplicationVariables::get('oa_version')), 'string'), new XML_RPC_Value($already_seen, 'string'), new XML_RPC_Value('', 'string'), new XML_RPC_Value(OA_Dal_ApplicationVariables::get('platform_hash'), 'string')); // Has the OpenX admin user kindly agreed to share the technology // stack that OpenX is running on, so that OpenX can monitor what // technology stacks the community users, to help with supporting // OpenX? $aTechStack = array('data' => false); if ($shareTechStack) { // Thanks, OpenX admin user! You're a star! Prepare the // technology stack data and add it to the XML-RPC call if ($this->oDbh->dbsyntax == 'mysql') { $dbms = 'MySQL'; } else { if ($this->oDbh->dbsyntax == 'pgsql') { $dbms = 'PostgreSQL'; } else { $dbms = 'UnknownSQL'; } } $aTechStack = array('os_type' => php_uname('s'), 'os_version' => php_uname('r'), 'webserver_type' => isset($_SERVER['SERVER_SOFTWARE']) ? preg_replace('#^(.*?)/.*$#', '$1', $_SERVER['SERVER_SOFTWARE']) : '', 'webserver_version' => isset($_SERVER['SERVER_SOFTWARE']) ? preg_replace('#^.*?/(.*?)(?: .*)?$#', '$1', $_SERVER['SERVER_SOFTWARE']) : '', 'db_type' => $dbms, 'db_version' => $this->oDbh->queryOne("SELECT VERSION()"), 'php_version' => phpversion(), 'php_sapi' => ucfirst(php_sapi_name()), 'php_extensions' => get_loaded_extensions(), 'php_register_globals' => (bool) ini_get('register_globals'), 'php_magic_quotes_gpc' => (bool) ini_get('magic_quotes_gpc'), 'php_safe_mode' => (bool) ini_get('safe_mode'), 'php_open_basedir' => (bool) strlen(ini_get('open_basedir')), 'php_upload_tmp_readable' => (bool) is_readable(ini_get('upload_tmp_dir') . DIRECTORY_SEPARATOR)); } $params[] = XML_RPC_Encode($aTechStack); // Has the OpenX admin user kindly agreed to share their // aggregate impression and click statistics to help // OpenX monitor what sizes of OpenX installations exist // (to ensure OpenX scales to appropriate sizes), and also // so that the total community size can be shown in the // Dashboard? $aStats = array(); if ($shareStats) { // Thanks, OpenX admin user! You're a star! Prepare the // aggregate impression and click statistics data and // add it to the XML-RPC call foreach ($this->buildStats() as $k => $v) { $aStats[$k] = XML_RPC_encode($v); } } $params[] = new XML_RPC_Value($aStats, 'struct'); // Add the OpenX package Origin ID, if appropriate $originID = ''; $originFile = MAX_PATH . '/etc/origin.txt'; if (file_exists($originFile) && is_readable($originFile)) { $rOriginFile = @fopen($originFile, 'r'); if ($rOriginFile !== false) { $originID = fread($rOriginFile, 32); fclose($rOriginFile); } if ($originID === false) { $originID = ''; } } $params[] = new XML_RPC_Value($originID, 'string'); // Add the registered email address $params[] = new XML_RPC_Value(OA_Dal_ApplicationVariables::get('sync_registered_email'), 'string'); // Create the XML-RPC request message $msg = new XML_RPC_Message("OpenX.Sync", $params); // Send the XML-RPC request message if ($response = $client->send($msg, 10)) { // XML-RPC server found, now checking for errors if (!$response->faultCode()) { // No fault! Woo! Get the response and return it! $aReturn = array(0, XML_RPC_Decode($response->value())); // Prepare cache $cache = $aReturn[1]; // Update last run OA_Dal_ApplicationVariables::set('sync_last_run', date('Y-m-d H:i:s')); } else { // Boo! An error! (Well, maybe - it it's 800, yay!) $aReturn = array($response->faultCode(), $response->faultString()); // Prepare cache $cache = false; // Update last run if ($response->faultCode() == 800) { OA_Dal_ApplicationVariables::set('sync_last_run', date('Y-m-d H:i:s')); } } OA_Dal_ApplicationVariables::set('sync_cache', serialize($cache)); OA_Dal_ApplicationVariables::set('sync_timestamp', time()); return $aReturn; } $aReturn = array(-1, 'No response from the remote XML-RPC server.'); return $aReturn; }
OA_Permission::switchToSystemProcessUser('Installer'); if ($installStatus == OA_STATUS_NOT_INSTALLED) { if ($oUpgrader->install($_POST['aConfig'])) { $message = $strDBCreatedSuccesful . ' ' . OA_VERSION; $action = OA_UPGRADE_INSTALL; } } else { if (empty($_COOKIE['oat']) || $_COOKIE['oat'] != OA_UPGRADE_UPGRADE) { // Hey, what's going on, we shouldn't be here, go back to login! $action = OA_UPGRADE_LOGIN; } elseif ($oUpgrader->upgrade($oUpgrader->package_file)) { $message = $strUpgradeComplete; $action = OA_UPGRADE_UPGRADE; // Timezone support - hack if ($oUpgrader->versionInitialSchema['tables_core'] < 538 && empty($_POST['noTzAlert'])) { OA_Dal_ApplicationVariables::set('utc_update', OA::getNowUTC()); } // Clear the menu cache to built a new one with the new settings OA_Admin_Menu::_clearCache(OA_ACCOUNT_ADMIN); OA_Admin_Menu::_clearCache(OA_ACCOUNT_MANAGER); OA_Admin_Menu::_clearCache(OA_ACCOUNT_ADVERTISER); OA_Admin_Menu::_clearCache(OA_ACCOUNT_TRAFFICKER); OA_Admin_Menu::singleton(); } } } if ($action != OA_UPGRADE_UPGRADE && $action != OA_UPGRADE_INSTALL && $action != OA_UPGRADE_LOGIN || $oUpgrader->oLogger->errorExists) { // if they're being redirected from an install, they will have DB info in POST, otherwise they will have DBinfo in CONF if ($_POST['aConfig']) { $aDatabase = $_POST['aConfig']; } else {