/** * Initializes the storage provider by loading the configuration values from * the passed module configuration. * * @param \AppserverIo\Server\Interfaces\ModuleConfigurationInterface $moduleConfiguration The module configuration * * @throws \Exception Is thrown if the JSON can not be read */ public function __construct(ModuleConfigurationInterface $moduleConfiguration) { // load the configuration values $recordFile = $moduleConfiguration->getParam(JsonStorageProvider::RECORD_FILE); $defaultTtl = $moduleConfiguration->getParam(AbstractStorageProvider::DEFAULT_TTL); // try to open the file $handle = @fopen($recordFile, "r"); if (!$handle) { throw new \Exception('Unable to open dns record file.'); } // read the file $dnsJson = fread($handle, filesize($recordFile)); fclose($handle); // try to decode the JSON content $dnsRecords = json_decode($dnsJson, true); if (!$dnsRecords) { throw new \Exception('Unable to parse dns record file.'); } // query whether or not the default TTL is an integer if (!is_int($defaultTtl)) { throw new \Exception('Default TTL must be an integer.'); } // set the default TTL and the DNS records $this->dsTtl = $defaultTtl; $this->dnsRecords = $dnsRecords; }
/** * Initializes the storage provider by loading the configuration values from * the passed module configuration. * * @param \AppserverIo\Appserver\Core\Interfaces\SystemConfigurationInterface $systemConfiguration The system configuration * @param \AppserverIo\Server\Interfaces\ModuleConfigurationInterface $moduleConfiguration The module configuration * * @throws \Exception Is thrown if the JSON can not be read */ public function __construct(SystemConfigurationInterface $systemConfiguration, ModuleConfigurationInterface $moduleConfiguration) { // load the configuration values $defaultTtl = $moduleConfiguration->getParam(AbstractStorageProvider::DEFAULT_TTL); // query whether or not the default TTL is an integer if (!is_int($defaultTtl)) { throw new \Exception('Default TTL must be an integer.'); } // declare the array for the DNS records $dnsRecords = array(); // iterate over the system configuration and create DNS A records from the found virtual hosts foreach ($systemConfiguration->getContainers() as $containerNode) { foreach ($containerNode->getServers() as $serverNode) { foreach ($serverNode->getVirtualHosts() as $virtualHost) { if (sizeof($dnsNames = explode(' ', $virtualHost->getName())) > 0) { foreach ($dnsNames as $dnsName) { // add the IPv4 + IPv6 address for localhost $dnsRecords[$dnsName]['A'] = array('127.0.0.1'); $dnsRecords[$dnsName]['AAAA'] = array('::1'); } } } } } // set the default TTL and the DNS records $this->dsTtl = $defaultTtl; $this->dnsRecords = $dnsRecords; }