From 03d9d8802628859ba7fd5d0ab33244d27867d704 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 2 Feb 2018 14:58:10 +0100 Subject: [PATCH 1/4] add "notifyafterupdate" flag --- includes/class/PdnsApi.php | 8 ++++++++ includes/config.inc.php-dist | 3 ++- zones.php | 11 ++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/includes/class/PdnsApi.php b/includes/class/PdnsApi.php index 25a1581..901c4d7 100644 --- a/includes/class/PdnsApi.php +++ b/includes/class/PdnsApi.php @@ -84,6 +84,14 @@ class PdnsAPI { return $this->loadzone($zone['id']); } + public function notifyzone($zoneid) { + $api = clone $this->http; + $api->method = 'PUT'; + $api->url = "/servers/localhost/zones/$zoneid/notify"; + $api->call(); + + return $api->json; + } public function deletezone($zoneid) { $api = clone $this->http; diff --git a/includes/config.inc.php-dist b/includes/config.inc.php-dist index 8991b81..c6fb8f9 100644 --- a/includes/config.inc.php-dist +++ b/includes/config.inc.php-dist @@ -8,7 +8,8 @@ $apisslverify = FALSE; # Verify SSL Certificate if using https for apiproto $allowzoneadd = FALSE; # Allow normal users to add zones $logging = TRUE; $allowclearlogs = TRUE; # Allow clearing of log entries -$allowrotatelogs = FALSE;# Allow rotation to text file on server +$allowrotatelogs = FALSE;# Allow rotation to text file on serveri +$notifyafterupdate = TRUE;# send notify to slaves after zone update # Log directory - if allowrotatelogs is set, this is where the logs will # be written. It must be writeable by the web server user. diff --git a/zones.php b/zones.php index a784673..456e229 100644 --- a/zones.php +++ b/zones.php @@ -304,6 +304,7 @@ case "create": } $api->savezone($zone->export()); + $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; $zone = new Zone(); $zone->parse($api->loadzone($zonename)); @@ -327,7 +328,8 @@ case "create": $rrset->delete(); } } - $api->savezone($zone->export()); + $api->savezone($zone->export()); + $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; foreach ($template['records'] as $record) { $name = $record['name'] != '' ? join(Array($record['name'],'.',$zonename)) : $zonename; @@ -340,6 +342,7 @@ case "create": } $zone = $api->savezone($zone->export()); + $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; writelog("Created zone ".$zone['name']); jtable_respond($zone, 'single'); break; @@ -370,6 +373,7 @@ case "update": writelog("Updated zone ".$zone->name); jtable_respond($api->savezone($zone->export()), 'single'); + $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; break; case "createrecord": @@ -411,6 +415,7 @@ case "createrecord": $record = $zone->addRecord($name, $type, $content, $_POST['disabled'], $_POST['ttl'], $_POST['setptr']); $api->savezone($zone->export()); + $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; writelog("Created record: ".$record['id']); jtable_respond($record, 'single'); @@ -436,6 +441,7 @@ case "editrecord": $zone->addRecord($_POST['name'], $_POST['type'], $content, $_POST['disabled'], $_POST['ttl'], $_POST['setptr']); $api->savezone($zone->export()); + $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; $record = $zone->getRecord($_POST['name'], $_POST['type'], $content); writelog("Updated record ".$_POST['id']." to ".$record['id']); @@ -453,6 +459,7 @@ case "deleterecord": $rrset->deleteRecord($old_record['content']); $api->savezone($zone->export()); + $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; writelog("Deleted record ".$_POST['id']); jtable_respond(null, 'delete'); @@ -486,6 +493,7 @@ case "clone": $srczone->setKind($_POST['kind']); $zone = $api->savezone($srczone->export()); + $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; $srczone->parse($zone); @@ -504,6 +512,7 @@ case "clone": } $zone = $api->savezone($srczone->export()); + $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; writelog("Cloned zone $src into $name"); jtable_respond($zone, 'single'); From cb234599b7b7bc0b43344e3cedcae9f49ae448fc Mon Sep 17 00:00:00 2001 From: root Date: Fri, 2 Feb 2018 15:10:54 +0100 Subject: [PATCH 2/4] typo correction --- includes/config.inc.php-dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/config.inc.php-dist b/includes/config.inc.php-dist index c6fb8f9..38fb67a 100644 --- a/includes/config.inc.php-dist +++ b/includes/config.inc.php-dist @@ -8,7 +8,7 @@ $apisslverify = FALSE; # Verify SSL Certificate if using https for apiproto $allowzoneadd = FALSE; # Allow normal users to add zones $logging = TRUE; $allowclearlogs = TRUE; # Allow clearing of log entries -$allowrotatelogs = FALSE;# Allow rotation to text file on serveri +$allowrotatelogs = FALSE;# Allow rotation to text file on server $notifyafterupdate = TRUE;# send notify to slaves after zone update # Log directory - if allowrotatelogs is set, this is where the logs will From 6dc6df497e805dacb496a2d0cbb86a5d87640976 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 2 Feb 2018 15:12:11 +0100 Subject: [PATCH 3/4] typo correction --- zones.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zones.php b/zones.php index 456e229..50662a6 100644 --- a/zones.php +++ b/zones.php @@ -328,7 +328,7 @@ case "create": $rrset->delete(); } } - $api->savezone($zone->export()); + $api->savezone($zone->export()); $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; foreach ($template['records'] as $record) { From d44b1a011f9c2767e41dedae4746390b317b4359 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 5 Feb 2018 09:58:06 +0100 Subject: [PATCH 4/4] wrong syntax correction --- zones.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/zones.php b/zones.php index 50662a6..27da9ef 100644 --- a/zones.php +++ b/zones.php @@ -304,7 +304,7 @@ case "create": } $api->savezone($zone->export()); - $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; + if ($notifyafterupdate) $api->notifyzone($_GET['zoneid']); $zone = new Zone(); $zone->parse($api->loadzone($zonename)); @@ -328,8 +328,8 @@ case "create": $rrset->delete(); } } - $api->savezone($zone->export()); - $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; + $api->savezone($zone->export()); + if ($notifyafterupdate) $api->notifyzone($_GET['zoneid']); foreach ($template['records'] as $record) { $name = $record['name'] != '' ? join(Array($record['name'],'.',$zonename)) : $zonename; @@ -342,7 +342,7 @@ case "create": } $zone = $api->savezone($zone->export()); - $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; + if ($notifyafterupdate) $api->notifyzone($_GET['zoneid']); writelog("Created zone ".$zone['name']); jtable_respond($zone, 'single'); break; @@ -373,7 +373,7 @@ case "update": writelog("Updated zone ".$zone->name); jtable_respond($api->savezone($zone->export()), 'single'); - $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; + if ($notifyafterupdate) $api->notifyzone($_GET['zoneid']); break; case "createrecord": @@ -415,7 +415,7 @@ case "createrecord": $record = $zone->addRecord($name, $type, $content, $_POST['disabled'], $_POST['ttl'], $_POST['setptr']); $api->savezone($zone->export()); - $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; + if ($notifyafterupdate) $api->notifyzone($_GET['zoneid']); writelog("Created record: ".$record['id']); jtable_respond($record, 'single'); @@ -441,7 +441,7 @@ case "editrecord": $zone->addRecord($_POST['name'], $_POST['type'], $content, $_POST['disabled'], $_POST['ttl'], $_POST['setptr']); $api->savezone($zone->export()); - $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; + if ($notifyafterupdate) $api->notifyzone($_GET['zoneid']); $record = $zone->getRecord($_POST['name'], $_POST['type'], $content); writelog("Updated record ".$_POST['id']." to ".$record['id']); @@ -459,7 +459,7 @@ case "deleterecord": $rrset->deleteRecord($old_record['content']); $api->savezone($zone->export()); - $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; + if ($notifyafterupdate) $api->notifyzone($_GET['zoneid']); writelog("Deleted record ".$_POST['id']); jtable_respond(null, 'delete'); @@ -493,7 +493,7 @@ case "clone": $srczone->setKind($_POST['kind']); $zone = $api->savezone($srczone->export()); - $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; + if ($notifyafterupdate) $api->notifyzone($_GET['zoneid']); $srczone->parse($zone); @@ -512,7 +512,7 @@ case "clone": } $zone = $api->savezone($srczone->export()); - $api->notifyzone($_GET['zoneid']) if $notifyafterupdate; + if ($notifyafterupdate) $api->notifyzone($_GET['zoneid']); writelog("Cloned zone $src into $name"); jtable_respond($zone, 'single');