From 59f4f1e70fcc147e45f35a2c220756e36e0592f9 Mon Sep 17 00:00:00 2001 From: Mark Schouten Date: Thu, 17 Dec 2015 10:04:54 +0100 Subject: [PATCH] Allow pdns 4.0 users to use nsedit as well, by allowing to set the API version --- doc/apiconf.txt | 8 ++++++++ includes/config.inc.php-dist | 1 + includes/misc.inc.php | 15 +++++++++++++-- zones.php | 4 ++-- 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 doc/apiconf.txt diff --git a/doc/apiconf.txt b/doc/apiconf.txt new file mode 100644 index 0000000..0d80ead --- /dev/null +++ b/doc/apiconf.txt @@ -0,0 +1,8 @@ +There are several values in config.inc.php that you MUST set for the API to work. + +$apipass : The API password or API Authentication Key +$apiip : The IP on which the API is reachable +$apiport : The port on which the API is reachable. Default port is 8081 +$apivers : The version of the API to use. In pre-PDNS 4.0, the API was + reachable via /. In 4.0, the path was changed to /api/v1. You do NOT set the path of the API, you set the version of the API. 0 is for pre 4.0, 1 is currently only used in 4.0. + diff --git a/includes/config.inc.php-dist b/includes/config.inc.php-dist index 428a390..d09b843 100644 --- a/includes/config.inc.php-dist +++ b/includes/config.inc.php-dist @@ -4,6 +4,7 @@ $apiuser = ''; # The PowerDNS API username. Leave empty for authmethod $apipass = ''; # The PowerDNS API-user password or the PowerDNS-API key (see AUTHENTICATION) $apiip = ''; # The IP of the PowerDNS API $apiport = '8081'; # The port of the PowerDNS API +$apivers = 0; # The version of the PowerDNS API. 0 == experimental, 1 = v1 (pdns 4.0) $apisid = 'localhost'; # PowerDNS's :server_id $apiproto = 'http'; # http | https $apisslverify = FALSE; # Verify SSL Certificate if using https for apiproto diff --git a/includes/misc.inc.php b/includes/misc.inc.php index 88fe31d..2248cf5 100644 --- a/includes/misc.inc.php +++ b/includes/misc.inc.php @@ -4,8 +4,13 @@ include('config.inc.php'); $blocklogin = FALSE; -if ((!isset($apipass) or empty($apipass)) or (!isset($apiip) or empty($apiip)) or (!isset($apiport) or empty($apiport))) { - $errormsg = "You need to configure your settings for the PowerDNS API"; +if ((!isset($apipass) or empty($apipass)) or (!isset($apiip) or empty($apiip)) or (!isset($apiport) or empty($apiport)) or (!isset($apivers) or empty($apivers)) { + $errormsg = 'You need to configure your settings for the PowerDNS API. See doc/apiconf.txt'; + $blocklogin = TRUE; +} + +if (!preg_match('/^[01]$/', $apivers)) { + $errormsg = "The value for \$apivers is incorrect your config"; $blocklogin = TRUE; } @@ -41,6 +46,12 @@ if (isset($defaults['primaryns'])) { /* No need to change stuf below */ +if ($apivers == 0) { + $apipath = ""; +} elseif ($apivers == 1) { + $apipath = "/api/v1"; +} + if (function_exists('curl_init') === FALSE) { $errormsg = "You need PHP Curl to run nsedit"; $blocklogin = TRUE; diff --git a/zones.php b/zones.php index d567e60..61d7b80 100644 --- a/zones.php +++ b/zones.php @@ -11,9 +11,9 @@ if (!is_csrf_safe()) { } function api_request($path, $opts = null, $type = null) { - global $apiproto, $apisslverify, $apisid, $apiuser, $apipass, $apiip, $apiport, $authmethod; + global $apiproto, $apisslverify, $apisid, $apiuser, $apipass, $apiip, $apiport, $authmethod, $apipath; - $url = "$apiproto://$apiip:$apiport${path}"; + $url = "$apiproto://$apiip:$apiport${apipath}${path}"; if ($authmethod == "auto") { $ad = curl_init();