function testSwitchToSystemProcessUser() { global $session; OA_Permission::switchToSystemProcessUser('installer'); $oUser = $session['user']; $this->assertIsA($oUser, 'OA_Permission_SystemUser'); $this->assertEqual($oUser->aUser['username'], 'installer'); OA_Permission::switchToSystemProcessUser(); $this->assertNull($session['user']); $oUser = new OA_Permission_User(OA_Dal::factoryDO('users')); $oUser->aUser['username'] = '******'; $session['user'] = $oUser; OA_Permission::switchToSystemProcessUser('installer'); $oUser = $session['user']; $this->assertIsA($oUser, 'OA_Permission_SystemUser'); $this->assertEqual($oUser->aUser['username'], 'installer'); OA_Permission::switchToSystemProcessUser('maintenance'); $oUser = $session['user']; $this->assertIsA($oUser, 'OA_Permission_SystemUser'); $this->assertEqual($oUser->aUser['username'], 'maintenance'); OA_Permission::switchToSystemProcessUser(); $oUser = $session['user']; $this->assertIsA($oUser, 'OA_Permission_User'); $this->assertEqual($oUser->aUser['username'], 'testuser'); }
/** * Process input from user and creates admin saves path in config file * * @param OA_Admin_UI_Component_Form $oForm * @param OX_Admin_UI_Install_Wizard $oWizard */ protected function processConfigurationAction($oForm, $oWizard, $isUpgrade) { if ($isUpgrade) { $aConfig['config'] = $this->getUpgrader()->getConfig(); $aUpgradeConfig = $oForm->populateConfig(); //not much here, just previous path $previousInstallationPath = $aUpgradeConfig['config']['previousInstallationPath']; } else { $aConfig = $oForm->populateConfig(); } $oUpgrader = $this->getUpgrader(); $isUpgrade = $this->getInstallStatus()->isUpgrade(); $configStepSuccess = true; $syncEnabled = true; // 1) Import any plugins present from the previous install $path = isset($previousInstallationPath) ? $previousInstallationPath : ''; $path = get_magic_quotes_gpc() ? stripslashes($path) : $path; if ($path && $path != MAX_PATH) { $importOK = OX_Admin_UI_Install_InstallUtils::importPlugins($path); if (!$importOK) { $errMessage = $GLOBALS['strPathToPreviousError']; $configStepSuccess = false; } } // 2) Save config (if previous task was fine) if ($configStepSuccess) { if ($oUpgrader->saveConfig($aConfig['config'])) { $configStepSuccess = true; if (!OX_Admin_UI_Install_InstallUtils::checkFolderPermissions($aConfig['config']['store']['webDir'])) { $errMessage = $GLOBALS['strImageDirLockedDetected']; $configStepSuccess = false; } } else { if ($isUpgrade) { $errMessage = $GLOBALS['strUnableUpdateConfFile']; } else { $errMessage = $GLOBALS['strUnableCreateConfFile']; } } } //3) config saved, go ahead and save admin when new install if ($configStepSuccess && !$isUpgrade) { OA_Permission::switchToSystemProcessUser('Installer'); // we set the default from: in OpenX emails to the administrator's email if (empty($GLOBALS['_MAX']['CONF']['email']['fromAddress'])) { $oUpgrader->oConfiguration->setValue('email', 'fromAddress', $aConfig['admin']['email']); $oUpgrader->oConfiguration->writeConfig(true); } // Save admin credentials $adminSaved = $oUpgrader->putAdmin($aConfig['admin'], $aConfig['prefs']); if (!$adminSaved) { $errMessage = $GLOBALS['strUnableToCreateAdmin']; $configStepSuccess = false; } OA_Permission::switchToSystemProcessUser(); //get back to normal user previously logged in } $configStepSuccess = $configStepSuccess && empty($errMessage); if ($errMessage) { $this->setModelProperty('aMessages', array('error' => array($errMessage))); } return $configStepSuccess; }
/** * The method to run the Maintenance Priority Engine process. * * @static * @param boolean $alwaysRun Default value is false. If true, the Maintenance * Priority Engine process will always run, even if * instant priority updates have been disabled in the * configuration. Used to ensure that the maintenance * script process can always update priorities. * @return boolean True on MPE running correctly, false otherwise. */ function run($alwaysRun = false) { OA::switchLogIdent('maintenance'); // Get the configuration $aConf = $GLOBALS['_MAX']['CONF']; // Should the MPE process run? if (!$alwaysRun) { // Is instant update for priority set? if (!$aConf['priority']['instantUpdate']) { OA::debug('Instant update of priorities disabled, not running MPE', PEAR_LOG_INFO); return false; } OA::debug(); } // Log the start of the process OA::debug('Running Maintenance Priority Engine', PEAR_LOG_INFO); // Set longer time out, and ignore user abort if (!ini_get('safe_mode')) { @set_time_limit($aConf['maintenance']['timeLimitScripts']); @ignore_user_abort(true); } // Attempt to increase PHP memory OX_increaseMemoryLimit(OX_getMinimumRequiredMemory('maintenance')); // Run the following code as the "Maintenance" user OA_Permission::switchToSystemProcessUser('Maintenance'); // Create a Maintenance DAL object $oDal = new OA_Dal_Maintenance_Priority(); // Try to get the MPE database-level lock $lock = $oDal->obtainPriorityLock(); if (!$lock) { OA::debug('Unable to obtain database-level lock, not running MPE', PEAR_LOG_ERR); return false; } // Ensure the the current time is registered with the OA_ServiceLocator $oServiceLocator =& OA_ServiceLocator::instance(); $oDate =& $oServiceLocator->get('now'); if (!$oDate) { // Record the current time, and register with the OA_ServiceLocator $oDate = new Date(); $oServiceLocator->register('now', $oDate); } // Run the MPE process for the AdServer module require_once MAX_PATH . '/lib/OA/Maintenance/Priority/AdServer.php'; $oMaintenancePriority = new OA_Maintenance_Priority_AdServer(); // TODO: OA_Maintenance_Priority_AdServer::updatePriorities // should be refactored to return a boolean we can check here. $oMaintenancePriority->updatePriorities(); // Release the MPE database-level lock $result = $oDal->releasePriorityLock(); if (PEAR::isError($result)) { // Unable to continue! OA::debug('Unable to release database-level lock', PEAR_LOG_ERR); return false; } // Return to the "normal" user OA_Permission::switchToSystemProcessUser(); // Log the end of the process OA::debug('Maintenance Priority Engine Completed (Started at ' . $oDate->format('%Y-%m-%d %H:%M:%S') . ' ' . $oDate->tz->getShortName() . ')', PEAR_LOG_INFO); OA::switchLogIdent(); return true; }
/** * The method to run the Maintenance Statistics Engine process. * * @static */ function run() { OA::switchLogIdent('maintenance'); // Get the configuration $aConf = $GLOBALS['_MAX']['CONF']; // Log the start of the process OA::debug('Running Maintenance Statistics Engine', PEAR_LOG_INFO); // Set longer time out, and ignore user abort if (!ini_get('safe_mode')) { @set_time_limit($aConf['maintenance']['timeLimitScripts']); @ignore_user_abort(true); } // Run the following code as the "Maintenance" user OA_Permission::switchToSystemProcessUser('Maintenance'); // Ensure the the current time is registered with the OA_ServiceLocator $oServiceLocator =& OA_ServiceLocator::instance(); $oDate =& $oServiceLocator->get('now'); if (!$oDate) { // Record the current time, and register with the OA_ServiceLocator $oDate = new Date(); $oServiceLocator->register('now', $oDate); } $this->aComponents = OX_Component::getListOfRegisteredComponentsForHook('addMaintenanceStatisticsTask'); // addMaintenanceStatisticsTask hook if (!empty($this->aComponents) && is_array($this->aComponents)) { foreach ($this->aComponents as $componentId) { if ($obj = OX_Component::factoryByComponentIdentifier($componentId)) { $obj->beforeMse(); } } } // Initialise the task runner object, for storing/running the tasks $this->oTaskRunner = new OA_Task_Runner(); // Register this object as the controlling class for the process, // so that tasks run by the task runner can locate this class to // update the report, etc. $oServiceLocator =& OA_ServiceLocator::instance(); $oServiceLocator->register('Maintenance_Statistics_Controller', $this); // Create and register an instance of the OA_Dal_Maintenance_Statistics DAL // class for the following tasks to use if (!$oServiceLocator->get('OX_Dal_Maintenance_Statistics')) { $oFactory = new OX_Dal_Maintenance_Statistics_Factory(); $oDal = $oFactory->factory(); $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal); } // Add the task to set the update requirements $oSetUpdateRequirements = new OX_Maintenance_Statistics_Task_SetUpdateRequirements(); $this->oTaskRunner->addTask($oSetUpdateRequirements); // Add the task to migrate the bucket data into the statistics tables $oSummariseIntermediate = new OX_Maintenance_Statistics_Task_MigrateBucketData(); $this->oTaskRunner->addTask($oSummariseIntermediate); // Add the task to handle the de-duplication and rejection of empty conversions $oDeDuplicateConversions = new OX_Maintenance_Statistics_Task_DeDuplicateConversions(); $this->oTaskRunner->addTask($oDeDuplicateConversions); // Add the task to handle the updating of "intermediate" statistics with // conversion information, as a legacy issue until all code obtains // conversion data from the standard conversion statistics tables $oManageConversions = new OX_Maintenance_Statistics_Task_ManageConversions(); $this->oTaskRunner->addTask($oManageConversions); // Add the task to summarise the intermediate statistics into final form $oSummariseFinal = new OX_Maintenance_Statistics_Task_SummariseFinal(); $this->oTaskRunner->addTask($oSummariseFinal); // Add the task to log the completion of the task $oLogCompletion = new OX_Maintenance_Statistics_Task_LogCompletion(); $this->oTaskRunner->addTask($oLogCompletion); // Add the task to manage (enable/disable) campaigns $oManageCampaigns = new OX_Maintenance_Statistics_Task_ManageCampaigns(); $this->oTaskRunner->addTask($oManageCampaigns); // addMaintenanceStatisticsTask hook if (!empty($this->aComponents) && is_array($this->aComponents)) { foreach ($this->aComponents as $componentId) { if ($obj = OX_Component::factoryByComponentIdentifier($componentId)) { $this->oTaskRunner->addTask($obj->addMaintenanceStatisticsTask(), $obj->getExistingClassName(), $obj->getOrder()); } } } // Run the MSE process tasks $this->oTaskRunner->runTasks(); // addMaintenanceStatisticsTask hook if (!empty($this->aComponents) && is_array($this->aComponents)) { foreach ($this->aComponents as $componentId) { if ($obj = OX_Component::factoryByComponentIdentifier($componentId)) { $obj->afterMse(); } } } // Return to the "normal" user OA_Permission::switchToSystemProcessUser(); // Log the end of the process OA::debug('Maintenance Statistics Engine Completed (Started at ' . $oDate->format('%Y-%m-%d %H:%M:%S') . ' ' . $oDate->tz->getShortName() . ')', PEAR_LOG_INFO); OA::switchLogIdent(); }
} } else { if (array_key_exists('btn_terms', $_POST)) { setcookie('oat', OA_UPGRADE_SYSCHECK); $action = OA_UPGRADE_TERMS; } else { if (array_key_exists('btn_plugins', $_POST)) { require_once MAX_PATH . '/lib/JSON/JSON.php'; $aUrls = array(); if (!OA_Upgrade_Login::checkLogin()) { $message = $strUsernameOrPasswordWrong; $action = OA_UPGRADE_LOGIN; } else { // deal with data from previous page if ($_COOKIE['oat'] == OA_UPGRADE_INSTALL) { OA_Permission::switchToSystemProcessUser('Installer'); $aAdminInfo = $_POST['aAdmin']; // we set the default from: in OpenX emails to the administrator's email if (empty($GLOBALS['_MAX']['CONF']['email']['fromAddress'])) { $oUpgrader->oConfiguration->setValue('email', 'fromAddress', $aAdminInfo['email']); $oUpgrader->oConfiguration->writeConfig(true); } // Save admin credentials $oUpgrader->putAdmin($aAdminInfo); // Save admim account preference for timezone $oUpgrader->putTimezoneAccountPreference($_POST['aPrefs']); } $importErrors = false; // Import any plugins present from the previous install if (isset($_POST['previousPath']) && $_POST['previousPath'] != MAX_PATH) { // Prevent directory traversal and other nasty tricks: