tuxis-ie / nsedit

DNS Editor working with PowerDNS's new API
GNU General Public License v2.0
197 stars 56 forks source link

nsedit get api error after pdns upgrade 4.1 #162

Closed p2107 closed 6 years ago

p2107 commented 6 years ago

nsedit does not work after upgrade from pdns 4.0 to 4.1 I get API error 404 not found when edit or create zone/record. Is there some fix?

margau commented 6 years ago

Hallo, same problem here.

@tuxis-ie Is there any kind of debug output so i may can look into the issue?

Best regards margau

lvo12 commented 6 years ago

Same problem here.

skfigved commented 6 years ago

Same here as well

tuxis-ie commented 6 years ago

https://github.com/tuxis-ie/nsedit/blob/master/includes/class/ApiHandler.php#L71 is where the magic happens. So you can debug some stuff there.

Calling zones.php directly (use inspector in your browser to see which calls are made) might give some useful output then.

paulgiordanozethcon commented 6 years ago

Try this:

--- ApiHandler.php      2018-03-28 07:36:21.833684298 -0500
+++ ApiHandler-fixed.php        2018-03-28 07:37:07.093835996 -0500
@@ -29,15 +29,19 @@
     private function apiurl() {
         $tmp = new ApiHandler();

-        $tmp->url = '/api';
+        $tmp->url = '/api/v1/servers/localhost';
         $tmp->go();
-
-        if ($tmp->json[0]['version'] <= 1) {
-            $this->apiurl = $tmp->json[0]['url'];
+               $v = intval(substr($tmp->json["version"],0,1));
+        if ($v == 4) {
+            $this->apiurl = $tmp->json["url"];
         } else {
             throw new Exception("Unsupported API version");
         }
-
     }

     private function curlopts() {

--- PdnsApi.php 2018-03-28 07:36:21.833684298 -0500
+++ PdnsApi-fixed.php   2018-03-28 07:40:13.762461478 -0500
@@ -11,7 +11,7 @@
         $api = clone $this->http;
         $api->method = 'GET';
         if ($q) {
-            $api->url = "/servers/localhost/search-data?q=*".$q."*&max=25";
+            $api->url = "/search-data?q=*".$q."*&max=25";
             $api->call();
             $ret = Array();
             $seen = Array();
@@ -28,7 +28,7 @@

             return $ret;
         }
-        $api->url = "/servers/localhost/zones";
+        $api->url = "/zones";
         $api->call();

         return $api->json;
@@ -37,7 +37,7 @@
     public function loadzone($zoneid) {
         $api = clone $this->http;
         $api->method = 'GET';
-        $api->url = "/servers/localhost/zones/$zoneid";
+        $api->url = "/zones/$zoneid";
         $api->call();

         return $api->json;
@@ -46,7 +46,7 @@
     public function exportzone($zoneid) {
         $api = clone $this->http;
         $api->method = 'GET';
-        $api->url = "/servers/localhost/zones/$zoneid/export";
+        $api->url = "/zones/$zoneid/export";
         $api->call();

         return $api->json;
@@ -64,7 +64,7 @@

         if (!isset($zone['serial']) or gettype($zone['serial']) != 'integer') {
             $api->method = 'POST';
-            $api->url = '/servers/localhost/zones';
+            $api->url = '/localhost/zones';
             $api->content = json_encode($zonedata);
             $api->call();

@@ -88,7 +88,7 @@
     public function deletezone($zoneid) {
         $api = clone $this->http;
         $api->method = 'DELETE';
-        $api->url = "/servers/localhost/zones/$zoneid";
+        $api->url = "/zones/$zoneid";
         $api->call();

         return $api->json;
@@ -98,7 +98,7 @@
         $ret = array();
         $api = clone $this->http;
         $api->method = 'GET';
-        $api->url = "/servers/localhost/zones/$zoneid/cryptokeys";
+        $api->url = "/zones/$zoneid/cryptokeys";

         $api->call();
skfigved commented 6 years ago

Did anyone get it working?

tuxis-ie commented 6 years ago

On Thu, 2018-04-12 at 07:20 +0000, skf82 wrote:

Did anyone get it working?

Didn't Pauls suggestion help you?

-- Kerio Operator in de Cloud? https://www.kerioindecloud.nl/ Mark Schouten | Tuxis Internet Engineering KvK: 61527076 | http://www.tuxis.nl/ T: 0318 200208 | info@tuxis.nl

lvo12 commented 6 years ago

Could someone post how to patch these files? I tried this: patch foo.c < patch.diff

But that fails on line 23 for the ApiHandler.php file. It runs fine on the PdnsApi.php file.

skfigved commented 6 years ago

I fixed this issue by redownloading from master and reusing the config.inc.php