WillyXJ / facileManager

A modular suite of web apps built with the sysadmin in mind.
www.facilemanager.com
GNU General Public License v2.0
87 stars 37 forks source link

[HELP] Howto use API? #510

Closed internethering closed 1 year ago

internethering commented 3 years ago

Hey, I'm confused of using the API. For example I want to set a new IP for all A-Records:

php /usr/local/facileManager/fmDNS/client.php -d -n -z id=39 action=update type=A newvalue=10.0.0.2

I get a config with the old 10.0.0.1 ip:

Dryrun mode (nothing will be written to disk)

==================================================
/var/bind/master/db.example.hosts:
==================================================
; This file was built using fmDNS 4.0.2 on Mon, 28 Dec 2020 11:44:12 CET Europe/Berlin

$TTL 5m
le-h. IN SOA ns1.example.org. info.example.org. (
                2015061300      ; Serial
                5m              ; Refresh
                5m              ; Retry
                6w              ; Expire
                5m )            ; Negative caching of TTL

; Name servers
example.org.                      300   IN   NS   ns1.example.org.
example.org.                       300   IN   NS   ns2.example.org.

; Host addresses
example.org.                       300   IN   A   10.0.0.1

I tried several other commands like delete or add. Nothing worked.

WillyXJ commented 3 years ago

You need to specify the setHost parameter to invoke the API. Here is an example:

php /usr/local/facileManager/fmDNS/client.php setHost id=36 action=add name=www value=1.2.3.4 type=A ttl=500 createPTR=yes comment="some comment" status=active

You would have to update each A record individually and given your example RR is at the root, it should look something like this:

php /usr/local/facileManager/fmDNS/client.php setHost id=36 action=update domain=example.org name="@" newvalue=10.0.0.2 type=A

Then a dry-run build should reflect the change:

php /usr/local/facileManager/fmDNS/client.php -d -n -z id=39
internethering commented 3 years ago

Thanks, nice to see this working. But it's difficult to handle. I want to use the api with let's encrypt, there I have to set every renew two TXT records:

_acme-challenge.example.org.  300   IN   TXT     ("F_huPhIxHEwrGAJ_V2-Vsohzzpwp5LZpKkPWE98H2Sg")
_acme-challenge.example.org.   300   IN   TXT     ("5eaqdCurfBqU94VM837tdM1GBRzbSgVKPJ-ke0rE6QY")

I want to delete the old ones, but:

php /usr/local/facileManager/fmDNS/client.php setHost id=39 action=delete type=TXT name=_acme-challenge
value is a required parameter.

Can you please enable delete without value parameter?

Then I've to have to access the database to get the IDs, it would be easyier for scripting, if I could access the api by setHost host=, may you add this?

WillyXJ commented 3 years ago

Thanks for the feedback.

Without specifying the record value, how will fmDNS know which record (when there are multiple of the same name) to delete or update? This is why value is required. Perhaps an additional flag could be used to delete/update all records of the same name.

Specifying the domain ID is required because a lot of users have multiple views with the same domain names so the ID is what separates them.

internethering commented 3 years ago

Without specifying the record value, how will fmDNS know which record (when there are multiple of the same name) to delete or update? This is why value is required. Perhaps an additional flag could be used to delete/update all records of the same name.

'action=delete type=TXT name=_acme-challenge' should simply delete all _acme-challenge records.

Specifying the domain ID is required because a lot of users have multiple views with the same domain names so the ID is what separates them.

ok, thats an argument.

pedro6161 commented 3 years ago

the API should run from client ? can we run from server ?

WillyXJ commented 3 years ago

Correct, the API calls are currently only supported from client.php.

pedro6161 commented 3 years ago

Correct, the API calls are currently only supported from client.php.

are there is a way to add,update and delete record from server over bash cli to trigger php or maybe using curl with payload to trigger the php ?

to run API using client.php, do i need run install first or i can initiate from any without run php74 client.php install ?

internethering commented 3 years ago

@WillyXJ thx for removing the parameter, it works fine. When I do:

php /usr/local/facileManager/fmDNS/client.php setHost id=39 action=add type=TXT name=_acme-challenge value=test php /usr/local/facileManager/fmDNS/client.php -z id=39

Only the first Nameserver is resolving, the second not:

$ host -t txt _acme-challenge.example.org. ns1.example.com

_acme-challenge.example.org descriptive text "test"

$ host -t txt _acme-challenge.example.org. ns2.example.com

Host _acme-challenge.example.org. not found: 3(NXDOMAIN)

The Webinterface shows me one avaiable update and after processing the second nameserver shows the correct value. Is it possible to run this update with client.php?

beza2000 commented 3 years ago

I found a bug/a feature in php /usr/local/facileManager/fmDNS/client.php -z id=39 The server is being updated, but facileManager reports that the zone needs to be updated. In this case, repeated changes via the API and server updates lead to the preservation of the old SOA serial - if there are slave DNSs, they will not be updated - SOA serial is not updated due to the fact that the facileManager believes that there were no updates.

WillyXJ commented 3 years ago

fM was originally designed with GUI interaction in mind so the API is lacking (and likely not fully thought out). As such, the API is not able to issue zone updates on other clients nor does it reset zone reload flags in the database as those get updates through the GUI when all associated servers get successfully updated.

The API will likely need to be rewritten to handle these use cases.

Until then, it can be used to add, updated, delete records, but the reloads should be issued from the GUI.

beza2000 commented 3 years ago

Calling php /usr/local/facileManager/fmDNS/client.php -z id=39

WillyXJ commented 3 years ago

Technically that client gets called from the fM server so it’s not an API call per se and it’s the server side that will update the SOA when all associated clients successfully reload the zone from the server. fmDNS was originally designed around users interacting with the server and not the client.

lravelo commented 1 year ago

Calling php /usr/local/facileManager/fmDNS/client.php -z id=39

* is this an API call or not?
  P.S.: To solve my problem, I made an additional call to reloadZoneSQL($domain_id, "none", "one");
  in function buildZoneConfig  in facileManager/server/fm-modules/fmDNS/classes/class_buildconf.php

@beza2000 would it be possible for you to show me how you made this call (I'm assuming you did this via CLI)? I'm looking for a way to add records programmatically and reload the zones afterwards and this part is the last step I'm missing. Thanks in advance!

beza2000 commented 1 year ago

Calling php /usr/local/facileManager/fmDNS/client.php -z id=39

* is this an API call or not?
  P.S.: To solve my problem, I made an additional call to reloadZoneSQL($domain_id, "none", "one");
  in function buildZoneConfig  in facileManager/server/fm-modules/fmDNS/classes/class_buildconf.php

@beza2000 would it be possible for you to show me how you made this call (I'm assuming you did this via CLI)? I'm looking for a way to add records programmatically and reload the zones afterwards and this part is the last step I'm missing. Thanks in advance!

I am using the facilitemanager v4.1.1 & fmDNS v5.1.0. Patch file: patch.txt

lravelo commented 1 year ago

Calling php /usr/local/facileManager/fmDNS/client.php -z id=39

* is this an API call or not?
  P.S.: To solve my problem, I made an additional call to reloadZoneSQL($domain_id, "none", "one");
  in function buildZoneConfig  in facileManager/server/fm-modules/fmDNS/classes/class_buildconf.php

@beza2000 would it be possible for you to show me how you made this call (I'm assuming you did this via CLI)? I'm looking for a way to add records programmatically and reload the zones afterwards and this part is the last step I'm missing. Thanks in advance!

I am using the facilitemanager v4.1.1 & fmDNS v5.1.0. Patch file: patch.txt

forgive my ignorance but I'm not seeing how to perform this via CLI (I know next to nothing about php. Just trying to automate creating records and reloading zones using ansible).

beza2000 commented 1 year ago

I am using the facilitemanager v4.1.1 & fmDNS v5.1.0. Patch file: patch.txt

forgive my ignorance but I'm not seeing how to perform this via CLI (I know next to nothing about php. Just trying to automate creating records and reloading zones using ansible).

My solution in the current code will not work without making changes. Then look for another solution.