Skip to content

Commit

Permalink
Merge pull request willswire#11 from dhutchison/feat/ddclient-support
Browse files Browse the repository at this point in the history
feat: added support for ddclient based devices willswire#8
  • Loading branch information
willswire authored May 26, 2022
2 parents 56141b0 + 415d7e5 commit b70c6b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ You must have a Cloudflare account and your domain must be configured to point t
- `Hostname`: the full subdomain and hostname of the record you want to update (e.g. `subdomain.mydomain.com`, `mydomain.com` for root domain)
- `Username`: the domain name containing the record (e.g. `mydomain.com`)
- `Password`: the Cloudflare API Token you created earlier
- `Server`: the Cloudflare Worker route `<worker-name>.<worker-subdomain>.workers.dev/update?ip=%i&hostname=`
- `Server`: the Cloudflare Worker route `<worker-name>.<worker-subdomain>.workers.dev/update?ip=%i&hostname=`. Note on devices older than the UDM the value should be configured as `<worker-name>.<worker-subdomain>.workers.dev` only, with no path suffix.

## Solution 2 - Free Hosted Configuration (BETA)

Expand All @@ -43,6 +43,7 @@ Because the Worker code makes requests to Cloudflare's API on your behalf using
- `Server`: the free, hosted Cloudflare Worker at `unificloudflareddns.com/update?ip=%i&hostname=`

## Acknowledgements
- [inadyn](https://github.com/troglobit/inadyn) is an open-source application that supports different dynamic DNS providers. It's used by UniFi OS under-the-hood to update your public IP address.
- [inadyn](https://github.com/troglobit/inadyn) is an open-source application that supports different dynamic DNS providers. It's used by UniFi OS on newer devices under-the-hood to update your public IP address. (UDM onwards)
- [ddclient](https://github.com/ddclient/ddclient) is an open-source application that supports different dynamic DNS providers. It's used by UniFi OS on older devices under-the-hood to update your public IP address. (such as the USG-3P)
- [inadyn-cloudflare](https://github.com/blackjid/inadyn-cloudflare) much of the code for this project is taken from [blackjid](https://github.com/blackjid)'s project.
- [Cloudflare Workers Basic Auth Example](https://developers.cloudflare.com/workers/examples/basic-auth)
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
}

switch (pathname) {
case "/update": {

case "/nic/update":
case "/update":
if (request.headers.has("Authorization")) {
const { username, password } = basicAuthentication(request);

Expand All @@ -29,7 +31,6 @@
}

throw new BadRequestException("Please provide valid credentials.");
}

case "/favicon.ico":
case "/robots.txt":
Expand All @@ -49,7 +50,9 @@
async function informAPI(url, name, token) {
// Parse Url
const hostname = url.searchParams.get("hostname");
const ip = url.searchParams.get("ip");
// Get the IP address. This can accept two query parameters, this will
// use the "ip" query parameter if it is set, otherwise falling back to "myip".
const ip = url.searchParams.get("ip") || url.searchParams.get("myip");

// Initialize API Handler
const cloudflare = new Cloudflare({
Expand Down Expand Up @@ -84,7 +87,7 @@ function verifyParameters(url) {
throw new BadRequestException("You must specify a hostname");
}

if (!url.searchParams.get("ip")) {
if (!(url.searchParams.get("ip") || url.searchParams.get("myip"))) {
throw new BadRequestException("You must specify an ip address");
}
}
Expand Down

0 comments on commit b70c6b9

Please sign in to comment.