コード例 #1
0
ファイル: Settings.php プロジェクト: villos/tree_admin
 /**
  * A method for writing out the OpenX configuration .conf.php file(s),
  * including any changes that have been made to the configuration in the
  * current object.
  *
  * Configuration files are prefixed with the host name being used to access
  * Openads, so that multiple OpenX installations can be run from a single
  * code base, if the correct virtual hosts are configured.
  *
  * @param string $configPath The directory to save the config file(s) in.
  *                           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 $reParse   If the config file should be parsed again
  *                           after writing (default is true).
  *
  * @return boolean True when the configuration file(s) was (were)
  *                 correctly written out, false otherwise.
  */
 function writeConfigChange($configPath = null, $configFile = null, $reParse = true)
 {
     if (is_null($configPath)) {
         $configPath = MAX_PATH . '/var';
     }
     if (!is_null($configFile)) {
         $configFile = '.' . $configFile;
     }
     if (defined('TEST_ENVIRONMENT_RUNNING') && !$GLOBALS['override_TEST_ENVIRONMENT_RUNNING']) {
         // Special case! The test environment is running, so just write the
         // configuration to the test configuration file...
         $testConfigFile = $configPath . '/test.conf.php';
         if (!OA_Admin_Settings::isConfigWritable($testConfigFile)) {
             return false;
         }
         $oConfig = new Config();
         $oConfigContainer =& $oConfig->parseConfig($this->aConf, 'phpArray');
         $oConfigContainer->createComment('*** DO NOT REMOVE THE LINE ABOVE ***', 'top');
         $oConfigContainer->createComment('<' . '?php exit; ?>', 'top');
         if (!$oConfig->writeConfig($testConfigFile, 'IniCommented')) {
             return false;
         }
         // Re-parse the config file?
         if ($reParse) {
             $GLOBALS['_MAX']['CONF'] = @parse_ini_file($testConfigFile, true);
             $this->aConf = $GLOBALS['_MAX']['CONF'];
             // Set the global $conf value -- normally set by the init
             // script -- to be the same as $GLOBALS['_MAX']['CONF']
             global $conf;
             $conf = $GLOBALS['_MAX']['CONF'];
         }
         return true;
     }
     // What were the old host names used for the installation?
     $aConf = $GLOBALS['_MAX']['CONF'];
     $url = @parse_url('http://' . $aConf['webpath']['admin']);
     $oldAdminHost = $url['host'];
     $url = @parse_url('http://' . $aConf['webpath']['delivery']);
     $oldDeliveryHost = $url['host'];
     $url = @parse_url('http://' . $aConf['webpath']['deliverySSL']);
     $oldDeliverySslHost = $url['host'];
     // What are the new host names used for the installation?
     $url = @parse_url('http://' . $this->aConf['webpath']['admin']);
     $newAdminHost = $url['host'];
     $url = @parse_url('http://' . $this->aConf['webpath']['delivery']);
     $newDeliveryHost = $url['host'];
     $url = @parse_url('http://' . $this->aConf['webpath']['deliverySSL']);
     $newDeliverySslHost = $url['host'];
     // Write out the new main configuration file
     $mainConfigFile = $configPath . '/' . $newDeliveryHost . $configFile . '.conf.php';
     if (!OA_Admin_Settings::isConfigWritable($mainConfigFile)) {
         return false;
     }
     $oConfig = new Config();
     $oConfigContainer =& $oConfig->parseConfig($this->aConf, 'phpArray');
     $oConfigContainer->createComment('*** DO NOT REMOVE THE LINE ABOVE ***', 'top');
     $oConfigContainer->createComment('<' . '?php exit; ?>', 'top');
     if (!$oConfig->writeConfig($mainConfigFile, 'IniCommented')) {
         return false;
     }
     // Check if a different host name is used for the admin
     if ($newAdminHost != $newDeliveryHost) {
         // Write out the new "fake" configuration file
         $file = $configPath . '/' . $newAdminHost . $configFile . '.conf.php';
         if (!OA_Admin_Settings::isConfigWritable($file)) {
             return false;
         }
         $aConfig = array('realConfig' => $newDeliveryHost);
         $oConfig = new Config();
         $oConfigContainer =& $oConfig->parseConfig($aConfig, 'phpArray');
         $oConfigContainer->createComment('*** DO NOT REMOVE THE LINE ABOVE ***', 'top');
         $oConfigContainer->createComment('<' . '?php exit; ?>', 'top');
         if (!$oConfig->writeConfig($file, 'IniCommented')) {
             return false;
         }
     }
     // Check if a different host name is used for the delivery SSL
     if ($newDeliverySslHost != $newDeliveryHost) {
         // Write out the new "fake" configuration file
         $file = $configPath . '/' . $newDeliverySslHost . $configFile . '.conf.php';
         if (!OA_Admin_Settings::isConfigWritable($file)) {
             return false;
         }
         $aConfig = array('realConfig' => $newDeliveryHost);
         $oConfig = new Config();
         $oConfigContainer =& $oConfig->parseConfig($aConfig, 'phpArray');
         $oConfigContainer->createComment('*** DO NOT REMOVE THE LINE ABOVE ***', 'top');
         $oConfigContainer->createComment('<' . '?php exit; ?>', 'top');
         if (!$oConfig->writeConfig($file, 'IniCommented')) {
             return false;
         }
     }
     // Always touch the INSTALLED file
     if (!file_exists(MAX_PATH . '/var/INSTALLED') && !touch(MAX_PATH . '/var/INSTALLED')) {
         return false;
     }
     // Do any old configuration files need to be deleted?
     if (!is_null($oldAdminHost) && $newAdminHost != $oldAdminHost) {
         $file = $configPath . '/' . $oldAdminHost . $configFile . '.conf.php';
         if ($file != $mainConfigFile) {
             @unlink($file);
         }
     }
     if (!is_null($oldDeliveryHost) && $newDeliveryHost != $oldDeliveryHost && $oldDeliveryHost != $newAdminHost) {
         $file = $configPath . '/' . $oldDeliveryHost . $configFile . '.conf.php';
         if ($file != $mainConfigFile) {
             @unlink($file);
         }
     }
     if (!is_null($oldDeliverySslHost) && $newDeliverySslHost != $oldDeliverySslHost && $oldDeliverySslHost != $newAdminHost) {
         $file = $configPath . '/' . $oldDeliverySslHost . $configFile . '.conf.php';
         if ($file != $mainConfigFile) {
             @unlink($file);
         }
     }
     // If the main (delivery) conf file changed or if there are any un-accounted for
     // config files in the var directory, don't write a default.conf.php file
     $aOtherConfigFiles = $this->findOtherConfigFiles($configPath, $configFile);
     if ($oldDeliveryHost != $newDeliveryHost || empty($aOtherConfigFiles)) {
         if (!OA_Admin_Settings::writeDefaultConfigFile($configPath, $configFile, $newDeliveryHost)) {
             return false;
         }
     } else {
         OA::debug('Did not create a default.conf.php file due to the presence of:' . implode(', ', $aOtherConfigFiles), PEAR_LOG_INFO);
     }
     // Re-parse the config file?
     if ($reParse) {
         $file = $configPath . '/' . $newDeliveryHost . $configFile . '.conf.php';
         $GLOBALS['_MAX']['CONF'] = @parse_ini_file($file, true);
         $this->aConf = $GLOBALS['_MAX']['CONF'];
         // Set the global $conf value -- normally set by the init
         // script -- to be the same as $GLOBALS['_MAX']['CONF']
         global $conf;
         $conf = $GLOBALS['_MAX']['CONF'];
     }
     return true;
 }