public function addAction() { $this->view->pageTitle = $this->lmsg('addPageTitle'); $this->view->uplevelLink = pm_Context::getBaseUrl(); $form = new Modules_SlaveDnsManager_Form_Add(); if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) { $form->process(); $this->_status->addMessage('info', $this->lmsg('slaveSaved')); $this->_helper->json(array('redirect' => pm_Context::getBaseUrl())); } $this->view->form = $form; $rndc = new Modules_SlaveDnsManager_Rndc(); $this->view->pleskIp = $this->view->escape($rndc->getServerIP()); }
public function save(array $data) { $keyAlgorithm = array_key_exists('algorithm', $data) ? $data['algorithm'] : 'hmac-md5'; $keySecret = $data['secret']; $slaveIp = $data['ip']; $slavePort = array_key_exists('port', $data) ? $data['port'] : 953; $view = new Zend_View(); $view->setScriptPath(pm_Context::getPlibDir() . 'views/scripts'); $rndc = new Modules_SlaveDnsManager_Rndc(); $pleskIp = $view->escape($rndc->getServerIP()); $slaveConfiguration = $view->partial('index/slave-config.phtml', array('pleskIp' => $pleskIp, 'secret' => $keySecret)); $slaveConfiguration = trim(html_entity_decode(strip_tags($slaveConfiguration))); $slaveConfiguration = preg_replace('/^/m', ' ', $slaveConfiguration); $configuration = <<<CONF /* {$slaveConfiguration} */ key "rndc-key" { algorithm {$keyAlgorithm}; secret "{$keySecret}"; }; options { default-key "rndc-key"; default-server {$slaveIp}; default-port {$slavePort}; }; CONF; if (null === $this->_config) { $this->_config = "slave_{$slaveIp}.conf"; } $result = file_put_contents($this->getConfigPath(), $configuration); if (false === $result) { throw new pm_Exception("Failed to save configuration {$this->_config}"); } $acl = new Modules_SlaveDnsManager_Acl(); $acl->add($slaveIp); }