mirror of
https://github.com/tuxis-ie/nsedit.git
synced 2025-05-24 00:24:07 +03:00
Add new classes to handle zones and pdns-api v4.0
This commit is contained in:
parent
22502ae521
commit
367dde6f19
3 changed files with 478 additions and 0 deletions
84
includes/class/PdnsApi.php
Normal file
84
includes/class/PdnsApi.php
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
include_once('apihandler.php');
|
||||
|
||||
class PdnsAPI {
|
||||
public function __construct() {
|
||||
$this->http = new ApiHandler();
|
||||
}
|
||||
|
||||
public function listzones($q = FALSE) {
|
||||
$api = clone $this->http;
|
||||
$api->method = 'GET';
|
||||
if ($q) {
|
||||
$api->url = "/servers/localhost/search-data?q=*".$q."*&max=25";
|
||||
$api->call();
|
||||
$ret = Array();
|
||||
$seen = Array();
|
||||
|
||||
foreach ($api->json as $result) {
|
||||
if (isset($seen[$result['zone_id']])) {
|
||||
continue;
|
||||
}
|
||||
$zone = $this->loadzone($result['zone_id']);
|
||||
unset($zone['rrsets']);
|
||||
array_push($ret, $zone);
|
||||
$seen[$result['zone_id']] = 1;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
$api->url = "/servers/localhost/zones";
|
||||
$api->call();
|
||||
|
||||
return $api->json;
|
||||
}
|
||||
|
||||
public function loadzone($zoneid) {
|
||||
$api = clone $this->http;
|
||||
$api->method = 'GET';
|
||||
$api->url = "/servers/localhost/zones/$zoneid";
|
||||
$api->call();
|
||||
|
||||
return $api->json;
|
||||
}
|
||||
|
||||
public function savezone($zone) {
|
||||
$api = clone $this->http;
|
||||
// We have to split up RRSets and Zoneinfo.
|
||||
// First, update the zone
|
||||
$zonedata = $zone;
|
||||
unset($zonedata['id']);
|
||||
unset($zonedata['url']);
|
||||
unset($zonedata['rrsets']);
|
||||
|
||||
if ($zone['serial'] == '') {
|
||||
$api->method = 'POST';
|
||||
$api->url = '/servers/localhost/zones';
|
||||
$api->content = json_encode($zonedata);
|
||||
$api->call();
|
||||
|
||||
return $api->json;
|
||||
}
|
||||
$api->method = 'PUT';
|
||||
$api->url = $zone['url'];
|
||||
$api->content = json_encode($zonedata);
|
||||
$api->call();
|
||||
|
||||
// Then, update the rrsets
|
||||
$api->method = 'PATCH';
|
||||
$api->content = json_encode(Array('rrsets' => $zone['rrsets']));
|
||||
$api->call();
|
||||
}
|
||||
|
||||
public function deletezone($zoneid) {
|
||||
$api = clone $this->http;
|
||||
$api->method = 'DELETE';
|
||||
$api->url = "/servers/localhost/zones/$zoneid";
|
||||
$api->call();
|
||||
|
||||
return $api->json;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue