First goal of this project is to learn go. Side effect is a tool that applies phpIPAM changelog to DNS via dynamic updates.
-once: run only once and exits, by default it loops forever with a one second sleep in-between-skip-state: start to handle the changelogs from the first entry, and reconcile every address again
phpIPAM writes no changelog row for changes made through its API (no logged-in user), so the changelog alone misses them.
Every 15 seconds (and on the first loop), phpipam2dns also reads every address that has a hostname from ipaddresses and diffs it against the previous read:
- new or changed address: A and PTR ensured (the stale A/PTR of a renamed or readdressed one is deleted first)
- removed address, or hostname cleared: A and PTR deleted
- rows sharing a deleted hostname or IP are ensured again, since a delete clears every A of the name and every PTR of the IP
- a failed DNS update is retried on the next pass
- an empty read while the previous one was not is refused, so an emptied table cannot wipe the zones
The last read is kept in state.json (addresses), so deletions made while phpipam2dns is stopped are still applied. Without it (first run, -skip-state), every address is ensured once.
A hostname has a single A and an IP a single PTR: two addresses sharing either one overwrite each other.
LOG_LEVEL(optional): one ofpanic,fatal,error,warn,warning,info,debugortrace. Default:info(see logrus ParseLevel)
Main config file is named config.yml and is expected to be in the current working directory. It contains dsn, zones and key definitions for forward and reverse updates as follow:
dsn: usingusername:password@tcp(ip-or-hostname)/databaseformat. For more information refer to mysql go driver data source nameforward zonesandreverse zones: configuration for straight and reverse zones. Each of those entries are dictionaries where keys are zone name and values are server definitions, like so:server: ip of the serveralgo: key's algorithm (see: https://github.com/miekg/dns/blob/master/tsig.go)keyname: the key namesecret: the shared secret as generated. See bellow Bind configuration example
dsn: username:password@tcp(127.0.0.3)/phpipam
forward zones:
example.com: &server-127-0-0-2-keyname
server: 127.0.0.2
algo: hmac-sha256
keyname: keyname
secret: wL8Yu+QOrf1+oijvVYgafKIyRYMvXTs6gEMd7yw5wZo=
example.org: *server-127-0-0-2-keyname
reverse zones:
0.16.172.in-addr.arpa: *server-127-0-0-2-keyname
0.168.192.in-addr.arpa: *server-127-0-0-2-keyname
1.168.192.in-addr.arpa: *server-127-0-0-2-keyname
First, generate a key using ddns-confgen -k keyname or tsig-keygen keyname and include the key "xxx" {[...]}; in your bind configuration.
Then configure the zones you want to update with the allow-update stanza.
example:
zone "example.com" in {
type master;
file "/etc/bind/masters/example.com";
allow-update { key "keyname"; };
};
Make sure bind has write permission on the folder to write journal files and write permission on zone files for bind to rewrite it on rndc sync calls.
Reload bind and once configured accordingly, run phpipam2dns
- Unit:
go test ./... - End to end: phpIPAM (web + API), MariaDB and BIND in
e2e/compose.yml, BIND published on127.0.0.2:53. The suite builds the binary, makes changes through the phpIPAM API (static app code: reconcile path; user login: changelog path) and reads the result back from BIND.Withdocker compose -f e2e/compose.yml up -d --wait go test -tags e2e -count=1 ./e2e/ docker compose -f e2e/compose.yml down -vGOCOVERDIRset, the binary is built with-coverand writes its coverage there (go tool covdata textfmtturns it into a profile). - CI: unit, E2E and combined coverage in the job summary; the HTML report is the
coverageartifact.