Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple Views #33

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions plib/library/Form/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function init()
'value' => '',
'required' => false,
'validators' => array(
array('Callback', true, array(array($this, 'isValidAlnumDashUnderscore'))),
array('Callback', true, array(array($this, 'isValidAlnumDashUnderscoreSemicol'))),
),
));

Expand Down Expand Up @@ -89,9 +89,9 @@ public function isValidSecret($data)
throw new pm_Exception($this->lmsg('invalidSecret'));
}

public function isValidAlnumDashUnderscore($data)
public function isValidAlnumDashUnderscoreSemicol($data)
{
if (preg_match('/^[a-zA-Z0-9_-]+$/', $data)) {
if (preg_match('/^[;a-zA-Z0-9_-]+$/', $data)) {
return true;
}
throw new pm_Exception($this->lmsg('invalidAlnumDashUnderscore'));
Expand Down
39 changes: 22 additions & 17 deletions plib/library/Rndc.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,71 @@ private function _call(Modules_SlaveDnsManager_Slave $slave, $arguments, $verbos
"-y \"{$slave->getRndcKeyId()}\"",
"-c \"{$slave->getConfigPath()}\"",
$arguments,
]);

]);
if (pm_ProductInfo::isWindows()) {
$command = '"' . PRODUCT_ROOT . '\dns\bin\rndc.exe"';
} else {
$command = '/usr/sbin/rndc';
}
exec("{$command} {$arguments} 2>&1", $out, $code);
$output = implode("\n", $out);

if ($verbose) {
if ($code != 0) {
throw new pm_Exception("$command $arguments\n$output\n\nError code: $code");
}
return $output;
}

if ($code != 0) {
// Cannot send output header due to possible API-RPC calls
error_log("Error code $code: $output");
}

return $code == 0;
}

public function addZone($domain, Modules_SlaveDnsManager_Slave $slave = null)
{
$slaves = null === $slave ? Modules_SlaveDnsManager_Slave::getList() : [$slave];
foreach ($slaves as $slave) {
$this->_call($slave, "addzone \"{$domain}\" \"{$slave->getRndcClass()}\" \"{$slave->getRndcView()}\"" .
foreach (explode(';', $slave->getRndcViews()) as $view) {
$this->_call($slave, "addzone \"{$domain}\" \"{$slave->getRndcClass()}\" \"{$view}\"" .
" \"{ type slave; file \\\"{$domain}\\\"; masters { {$slave->getMasterPublicIp()}; }; };\"");
}
}
}

public function updateZone($domain, Modules_SlaveDnsManager_Slave $slave = null)
{
$slaves = null === $slave ? Modules_SlaveDnsManager_Slave::getList() : [$slave];
foreach ($slaves as $slave) {
$result = $this->_call($slave, "refresh \"{$domain}\" \"{$slave->getRndcClass()}\" \"{$slave->getRndcView()}\"");
if (false === $result) {
$this->addZone($domain, $slave);
foreach (explode(';', $slave->getRndcViews()) as $view) {
$result = $this->_call($slave, "refresh \"{$domain}\" \"{$slave->getRndcClass()}\" \"{$view}\"");
if (false === $result) {
$this->addZone($domain, $slave);
}
}
}
}

public function deleteZone($domain, Modules_SlaveDnsManager_Slave $slave = null)
{
$slaves = null === $slave ? Modules_SlaveDnsManager_Slave::getList() : [$slave];
foreach ($slaves as $slave) {
$slaveStatus = $this->checkStatus($slave);
// version: 9.9.4-RedHat-9.9.4-51.el7_4.2 (none) <id:8f9657aa>
// version: BIND 9.10.3-P4-Ubuntu <id:ebd72b3> (none)
$cleanFlag = (preg_match("/version: (BIND )?(9\.10\.\d+|9\.11\.\d+|9\.12\.\d+)/", $slaveStatus)) ? "-clean" : "";

$this->_call($slave, "delzone $cleanFlag \"{$domain}\" \"{$slave->getRndcClass()}\" \"{$slave->getRndcView()}\"");
$cleanFlag = (preg_match("/version: (BIND )?(9\.10\.\d+|9\.11\.\d+|9\.12\.\d+)/", $slaveStatus)) ? "-clean" : "";

foreach (explode(';', $slave->getRndcViews()) as $view) {
$this->_call($slave, "delzone $cleanFlag \"{$domain}\" \"{$slave->getRndcClass()}\" \"{$view}\"");
}
}
}

public function checkStatus(Modules_SlaveDnsManager_Slave $slave)
{
return $this->_call($slave, "status", true);
}
}