What is this?
This is a framework that will allow you to easily create and use a simple DynDNS implementation in PHP while being easily hackable to add new features and processors. This project was born out of my frustration in trying to find a simple PHP DynDNS implementation that would allow me to use Digital Ocean as the backend DNS. This project solved my problem, hopefully it will be useful to someone else.
composer require "michaelesmith/dyndns-kit"
Server: basic unit that will try to execute a request
Handler: operates on a specific type of request. A generic handler for typical dyndns requests is provided but you could create one to handle API request for instance.
Transformer: this transforms a raw request into a
Authenicator: this allows us to authenticate the request based on many factors. The included authenticator will use an http basic username and password and can limit users to specific domains.
Processor: this processes our given query and stores the result.
How do I use it
To see a full example usage please refer to the example project.
$server = new Server([ new GenericHandler( new DynDNSTransformer(), new HttpBasicAuthenticator([new RegexUser('testuser', 's3cret', '.+')]), new JsonProcessor(__DIR__ . '/var/dns.json') ), ]); $server->execute(Request::createFromGlobals());
In this example we use only a single
GenericHandler, the standard
HttpBasicAuthenticator with a single user that will allow any domain and the included
JsonProcessor is probably not very useful in real life but it allows us to easily test this setup without the need for other components. Using the curl example below will create the file dns.json and store the address in it.
More advanced usage
$server = new Server([ new GenericHandler( new DynDNSTransformer(), new HttpBasicAuthenticator([new RegexUser('testuser', 's3cret', '.+')]), new CacheProcessor( new DigitalOceanApiProcessor(['example.com'], new DigitalOceanV2(new GuzzleHttpAdapter('my_api_token'))), new FilesystemCachePool(new Filesystem(new Local(__DIR__ . '/../var/'))) ) ), ]); $server->execute(Request::createFromGlobals());
This example uses the exact same setup as before except for the processor. Here we use a caching processor so only new or updated requests are actually sent to the embedded processor which in this case updates the DNS entry for a domain hosted at Digital Ocean.
Try it out
Example curl command
Example with multiple hosts
Example without IP (if no IP is given the client IP address will be used)
- Cache - allows an embedded processor to only be called with new or updated requests
- DigitalOcean - allows the you to update dns entries via the Digital Ocean API
Have an idea to make something better? Submit a pull request. Need integration of some other backend service? Build it. I would be happy to add a link here. PR's make the open source world turn.