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);
    }
 public function __construct(Zend_View $view, Zend_Controller_Request_Abstract $request)
 {
     parent::__construct($view, $request);
     $data = array();
     foreach (Modules_SlaveDnsManager_Slave::getList() as $slave) {
         try {
             $rndc = new Modules_SlaveDnsManager_Rndc();
             $details = $rndc->checkStatus($slave);
             $icon = 'ok';
         } catch (Exception $e) {
             $details = $e->getMessage();
             $icon = 'warning';
         }
         $ip = $view->escape((string) $slave->getIp());
         $config = $view->escape((string) $slave->getConfig());
         $data[] = array('select' => '<input type="checkbox" class="checkbox" name="listCheckbox[]" value="' . $config . '"/>', 'status' => '<img class="slave-status" src="/theme/icons/16/plesk/' . $icon . '.png" title="' . $view->escape($details) . '"/>', 'config' => '<a href="' . $view->getHelper('baseUrl')->moduleUrl(array('action' => 'view')) . '?config=' . $config . '">' . $ip . '</a>');
     }
     $this->setData($data);
     $this->setColumns(array('select' => array('title' => '<input type="checkbox" class="checkbox" name="listGlobalCheckbox"/>', 'sortable' => false, 'noEscape' => true), 'status' => array('title' => $this->lmsg('statusColumnTitle'), 'noEscape' => true), 'config' => array('title' => $this->lmsg('configColumnTitle'), 'noEscape' => true)));
     $this->setTools(array(array('title' => $this->lmsg('addToolTitle'), 'description' => $this->lmsg('addToolDescription'), 'class' => 'sb-add-new', 'link' => $view->getHelper('baseUrl')->moduleUrl(array('action' => 'add'))), array('title' => $this->lmsg('refreshToolTitle'), 'description' => $this->lmsg('refreshToolDescription'), 'class' => 'sb-refresh', 'link' => pm_Context::getBaseUrl()), array('title' => $this->lmsg('removeToolTitle'), 'description' => $this->lmsg('removeToolDescription'), 'class' => 'sb-remove-selected', 'link' => 'javascript:removeSlaves()')));
     $this->setDataUrl(array('action' => 'list-data'));
 }
Esempio n. 4
0
 public function getServerIP()
 {
     if (self::$_serverIp) {
         return self::$_serverIp;
     }
     $request = "<ip><get/></ip>";
     $response = pm_ApiRpc::getService('1.6.5.0')->call($request);
     if ('ok' != $response->ip->get->result->status) {
         throw new pm_Exception("Unable to get server IP. Error: {$response->ip->get->result->errtext}");
     }
     // Get default IP
     foreach ($response->ip->get->result->addresses->ip_info as $address) {
         if (!isset($address->default)) {
             continue;
         }
         return self::$_serverIp = (string) $address->public_ip_address ?: (string) $address->ip_address;
     }
     // Get first IP
     foreach ($response->ip->get->result->addresses->ip_info as $address) {
         return self::$_serverIp = (string) $address->public_ip_address ?: (string) $address->ip_address;
     }
     throw new pm_Exception("Unable to get server IP: empty result.");
 }
pm_Loader::registerAutoload();
pm_Context::init('slave-dns-manager');
$jsonInput = file_get_contents('php://stdin');
$data = json_decode($jsonInput);
if (!is_array($data)) {
    echo "Invalid json data input: {$jsonInput}\n";
    exit(1);
}
foreach ($data as $task) {
    $command = (string) $task->command;
    if (!in_array($command, ['create', 'update', 'delete'])) {
        continue;
    }
    $domain = substr((string) $task->zone->name, 0, -1);
    if (!$domain) {
        echo "Invalid zone name: {$task->zone->name}\n";
        continue;
    }
    $rndc = new Modules_SlaveDnsManager_Rndc();
    switch ($command) {
        case 'create':
            $rndc->addZone($domain);
            break;
        case 'update':
            $rndc->updateZone($domain);
            break;
        case 'delete':
            $rndc->deleteZone($domain);
            break;
    }
}