[GH-ISSUE #73] some more changes appear to be necessary for api v1 compatibility #42

Closed
opened 2026-02-28 01:20:42 +03:00 by kerem · 14 comments
Owner

Originally created by @ZaphodB on GitHub (Jan 8, 2016).
Original GitHub issue: https://github.com/tuxis-ie/nsedit/issues/73

Originally assigned to: @tuxis-ie on GitHub.

I was only able to restore function with api v1 doing the following but i'm sure there is a cleaner way to get there, so this is more a note that there seem to be some issues and not a suggestion to make use of the changes below. ;-)

--- a/zones.php
+++ b/zones.php
@@ -13,7 +13,15 @@ if (!is_csrf_safe()) {
 function api_request($path, $opts = null, $type = null) {
     global $apiproto, $apisslverify, $apisid, $apiuser, $apipass, $apiip, $apiport, $authmethod, $apipath;

-    $url = "$apiproto://$apiip:$apiport${apipath}${path}";
+    syslog(LOG_INFO, "path: " . $path);
+
+    if(preg_match("/^api\/v1/", $path)) {
+       $url = "$apiproto://$apiip:$apiport/${path}";
+       syslog(LOG_INFO, "preg url: " . $url);
+    } else {
+       $url = "$apiproto://$apiip:$apiport${apipath}${path}";
+       syslog(LOG_INFO, "url: " . $url);
+    }

     if ($authmethod == "auto") {
         $ad = curl_init();
@@ -140,12 +148,12 @@ function make_record($zone, $input) {

     if ('' == $name) {
         $name = $zone['name'];
-    } elseif (string_ends_with($name, '.')) {
-        # "absolute" name, shouldn't append zone[name] - but check.
-        $name = substr($name, 0, -1);
-        if (!string_ends_with($name, $zone['name'])) {
-            jtable_respond(null, 'error', "Name $name not in zone ".$zone['name']);
-        }
+    #} elseif (string_ends_with($name, '.')) {
+    #    # "absolute" name, shouldn't append zone[name] - but check.
+    #    $name = substr($name, 0, -1);
+    #    if (!string_ends_with($name, $zone['name'])) {
+    #        jtable_respond(null, 'error', "Name $name not in zone ".$zone['name']);
+    #    }
     } else if (!string_ends_with($name, $zone['name'])) {
         $name = $name . '.' . $zone['name'];
     }
Originally created by @ZaphodB on GitHub (Jan 8, 2016). Original GitHub issue: https://github.com/tuxis-ie/nsedit/issues/73 Originally assigned to: @tuxis-ie on GitHub. I was only able to restore function with api v1 doing the following but i'm sure there is a cleaner way to get there, so this is more a note that there seem to be some issues and not a suggestion to make use of the changes below. ;-) ``` php --- a/zones.php +++ b/zones.php @@ -13,7 +13,15 @@ if (!is_csrf_safe()) { function api_request($path, $opts = null, $type = null) { global $apiproto, $apisslverify, $apisid, $apiuser, $apipass, $apiip, $apiport, $authmethod, $apipath; - $url = "$apiproto://$apiip:$apiport${apipath}${path}"; + syslog(LOG_INFO, "path: " . $path); + + if(preg_match("/^api\/v1/", $path)) { + $url = "$apiproto://$apiip:$apiport/${path}"; + syslog(LOG_INFO, "preg url: " . $url); + } else { + $url = "$apiproto://$apiip:$apiport${apipath}${path}"; + syslog(LOG_INFO, "url: " . $url); + } if ($authmethod == "auto") { $ad = curl_init(); @@ -140,12 +148,12 @@ function make_record($zone, $input) { if ('' == $name) { $name = $zone['name']; - } elseif (string_ends_with($name, '.')) { - # "absolute" name, shouldn't append zone[name] - but check. - $name = substr($name, 0, -1); - if (!string_ends_with($name, $zone['name'])) { - jtable_respond(null, 'error', "Name $name not in zone ".$zone['name']); - } + #} elseif (string_ends_with($name, '.')) { + # # "absolute" name, shouldn't append zone[name] - but check. + # $name = substr($name, 0, -1); + # if (!string_ends_with($name, $zone['name'])) { + # jtable_respond(null, 'error', "Name $name not in zone ".$zone['name']); + # } } else if (!string_ends_with($name, $zone['name'])) { $name = $name . '.' . $zone['name']; } ```
kerem 2026-02-28 01:20:42 +03:00
Author
Owner

@tuxis-ie commented on GitHub (Jan 13, 2016):

I don't get the $url part. https://github.com/tuxis-ie/nsedit/blob/master/includes/misc.inc.php#L54 should set $apipath if needed.

<!-- gh-comment-id:171275584 --> @tuxis-ie commented on GitHub (Jan 13, 2016): I don't get the $url part. https://github.com/tuxis-ie/nsedit/blob/master/includes/misc.inc.php#L54 should set $apipath if needed.
Author
Owner

@Stary2001 commented on GitHub (Jan 28, 2016):

with APIv1, the zoneurl returned by powerdns looks like "api/v1/zone/path", this patch fixes it by not including $apipath if the path already starts with "api/v1", the problem before was the API path was being added twice: once by powerdns, once by us. Possibly a cleaner fix would be to fix zoneurl when we get it either in the list action or in get_all_zones.

<!-- gh-comment-id:176038271 --> @Stary2001 commented on GitHub (Jan 28, 2016): with APIv1, the zoneurl returned by powerdns looks like "api/v1/zone/path", this patch fixes it by not including $apipath if the path already starts with "api/v1", the problem before was the API path was being added twice: once by powerdns, once by us. Possibly a cleaner fix would be to fix zoneurl when we get it either in the list action or in get_all_zones.
Author
Owner

@celevra commented on GitHub (Feb 16, 2016):

the patch worked for me until there is a real fix, thank you!

<!-- gh-comment-id:184822489 --> @celevra commented on GitHub (Feb 16, 2016): the patch worked for me until there is a real fix, thank you!
Author
Owner

@thekoma commented on GitHub (Feb 26, 2016):

More and more changes are coming on the 4.0 (alpha 2 has added new features)

<!-- gh-comment-id:189209389 --> @thekoma commented on GitHub (Feb 26, 2016): More and more changes are coming on the 4.0 (alpha 2 has added new features)
Author
Owner

@celevra commented on GitHub (Mar 2, 2016):

jep, i've updated today and now nsedit can't fetch my records anymore

<!-- gh-comment-id:191125441 --> @celevra commented on GitHub (Mar 2, 2016): jep, i've updated today and now nsedit can't fetch my records anymore
Author
Owner

@tuxis-ie commented on GitHub (Mar 2, 2016):

You've updated what?

<!-- gh-comment-id:191126392 --> @tuxis-ie commented on GitHub (Mar 2, 2016): You've updated what?
Author
Owner

@celevra commented on GitHub (Mar 2, 2016):

pdns
ns html # dpkg -l | grep pdns
ii pdns-backend-mysql 0.0.781gfbb356b-1pdns.trusty amd64 generic MySQL backend for PowerDNS
ii pdns-server 0.0.781gfbb356b-1pdns.trusty amd64 extremely powerful and versatile nameserver

<!-- gh-comment-id:191130452 --> @celevra commented on GitHub (Mar 2, 2016): pdns ns html # dpkg -l | grep pdns ii pdns-backend-mysql 0.0.781gfbb356b-1pdns.trusty amd64 generic MySQL backend for PowerDNS ii pdns-server 0.0.781gfbb356b-1pdns.trusty amd64 extremely powerful and versatile nameserver
Author
Owner

@tuxis-ie commented on GitHub (Mar 2, 2016):

Yes. Well, as long as pdns has not completely finished their API, I'm not in the mood to adjust nsedit for it. e.g., https://github.com/PowerDNS/pdns/issues/3253 is open and that's something I would really like to see. If anyone is willing to fix this, please send a PR. But keep in mind that stable pdns should still work..

<!-- gh-comment-id:191132096 --> @tuxis-ie commented on GitHub (Mar 2, 2016): Yes. Well, as long as pdns has not completely finished their API, I'm not in the mood to adjust nsedit for it. e.g., https://github.com/PowerDNS/pdns/issues/3253 is open and that's something I would really like to see. If anyone is willing to fix this, please send a PR. But keep in mind that stable pdns should still work..
Author
Owner

@HLFH commented on GitHub (Mar 2, 2016):

In the meantime before the final release of PowerDNS 4.0, we could use pdnsutil in CLI.

<!-- gh-comment-id:191202714 --> @HLFH commented on GitHub (Mar 2, 2016): In the meantime before the final release of PowerDNS 4.0, we could use [pdnsutil in CLI](http://blog.powerdns.com/2016/02/02/powerdns-authoritative-the-new-old-way-to-manage-domains/).
Author
Owner

@tuxis-ie commented on GitHub (Mar 2, 2016):

@zeha has just created https://github.com/PowerDNS/pdns/pull/3495 which should make this pretty easy. I'll track that PR and make sure nsedit supports it ASAP. (Feel free to write a PR to implement this).

<!-- gh-comment-id:191227441 --> @tuxis-ie commented on GitHub (Mar 2, 2016): @zeha has just created https://github.com/PowerDNS/pdns/pull/3495 which should make this pretty easy. I'll track that PR and make sure nsedit supports it ASAP. (Feel free to write a PR to implement this).
Author
Owner

@petzsch commented on GitHub (Apr 27, 2016):

just wanted to note that alpha2 is included in ubuntu 16.04. The patch above got rid of some 404 api errors when editing zones. But trying to add an A Record, I still get:
API Error 422: Key 'ttl' not an Integer or not present

Any help with this would be appreciated.

<!-- gh-comment-id:215204009 --> @petzsch commented on GitHub (Apr 27, 2016): just wanted to note that alpha2 is included in ubuntu 16.04. The patch above got rid of some 404 api errors when editing zones. But trying to add an A Record, I still get: API Error 422: Key 'ttl' not an Integer or not present Any help with this would be appreciated.
Author
Owner

@julian7 commented on GitHub (Jun 10, 2016):

It looks like there are a lot of API changes.

  • listrecord: the JSON response have "rrsets" instead of "records". However, now we have multiple contents for the same record, in an array in "records".
  • createrecord: "ttl" also has to be put to the response.

Certainly all of the methods might require some changes.

<!-- gh-comment-id:225131238 --> @julian7 commented on GitHub (Jun 10, 2016): It looks like there are a lot of API changes. - [listrecord](https://github.com/tuxis-ie/nsedit/blob/8f2290019e1210b25805aa759e26778b58d55574/zones.php#L584): the JSON response have "rrsets" instead of "records". However, now we have multiple contents for the same record, in an array in "records". - [createrecord](https://github.com/tuxis-ie/nsedit/blob/8f2290019e1210b25805aa759e26778b58d55574/zones.php#L222): "ttl" also has to be put to the response. Certainly all of the methods might require some changes.
Author
Owner

@tuxis-ie commented on GitHub (Jun 10, 2016):

Yes. I`m planning to create a 2.0 branche to fix compatibility with the new pdns api. Help would be much appreciated

<!-- gh-comment-id:225138774 --> @tuxis-ie commented on GitHub (Jun 10, 2016): Yes. I`m planning to create a 2.0 branche to fix compatibility with the new pdns api. Help would be much appreciated
Author
Owner

@tuxis-ie commented on GitHub (Aug 4, 2016):

Working on this, nearing completion.

I'm expection to release NSEdit 1.0 tomorrow.

<!-- gh-comment-id:237579269 --> @tuxis-ie commented on GitHub (Aug 4, 2016): Working on this, nearing completion. I'm expection to release NSEdit 1.0 tomorrow.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/nsedit#42
No description provided.