Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
David Prandzioch committed Mar 18, 2019
2 parents 7688001 + c9956b7 commit d05a661
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 12 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: go
go:
- 1.7.x

services:
- docker

script: make unit_tests && make image

notifications:
email:
on_success: change
on_failure: always
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[1.3.0]
* Add basic CI integration
* Add usage example for docker-compose
* Use request IP address when no `addr` is provided for better compatibility with DD-WRT (by vdweegen)
* Allow IPv4 and IPv6 addresses to co-exist for the same domain

[1.2.1]
* Fix permissions of /var/cache/bind on container startup
* Create zone options if not done, fixing support for persistent volumes
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ api_test:
curl "http://localhost:8080/update?secret=changeme&domain=foo&addr=1.2.3.4"
dig @localhost foo.example.org

api_test_46:
curl "http://localhost:8080/update?secret=changeme&domain=foo&addr=1.2.3.4"
curl "http://localhost:8080/update?secret=changeme&domain=foo&addr=2001:0db8:85a3:0000:0000:8a2e:0370:7334"
dig @localhost foo.example.org
dig @localhost AAAA foo.example.org

api_test_multiple_domains:
curl "http://localhost:8080/update?secret=changeme&domain=foo,bar,baz&addr=1.2.3.4"
dig @localhost foo.example.org
Expand Down
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Dynamic DNS with Docker, Go and Bind9

![DockerHub build status](https://dockerbuildbadges.quelltext.eu/status.svg?organization=davd&repository=docker-ddns)
![Travis build status](https://travis-ci.com/dprandzioch/docker-ddns.svg?branch=master)

This package allows you to set up a server for dynamic DNS using docker with a
few simple commands. You don't have to worry about nameserver setup, REST API
and all that stuff.
This package allows you to set up a dynamic DNS server that allows you to connect to
devices at home from anywhere in the world. All you need is a cheap VPS, a domain and access to it's nameserver.

![Connect to your NAS from work](https://raw.githubusercontent.com/dprandzioch/docker-ddns/develop/connect-to-your-nas-from-work.png)

## Installation

Expand All @@ -26,19 +28,25 @@ docker run -it -d \
davd/docker-ddns:latest
```

If you want to persist DNS configuration across container recreation, add `-v /somefolder:/var/cache/bind`. If you are experiencing any issues updating DNS configuration using the API
(`NOTAUTH` and `SERVFAIL`), make sure to add writing permissions for root (UID=0) to your persistent storage (e.g. `chmod -R a+w /somefolder`).
If you want to persist DNS configuration across container recreation, add `-v /somefolder:/var/cache/bind`. If you are experiencing any
issues updating DNS configuration using the API (`NOTAUTH` and `SERVFAIL`), make sure to add writing permissions for root (UID=0) to your
persistent storage (e.g. `chmod -R a+w /somefolder`).

You can also use Compose / Swarm to set up this project. For more information and an example `docker-compose.yml` with persistent data
storage, please refer to this file: https://github.com/dprandzioch/docker-ddns/blob/master/docker-compose.yml

### Build from source / GitHub

```
git clone https://github.com/dprandzioch/docker-ddns
git checkout master # Make sure to build the latest stable release
cd docker-ddns
$EDITOR envfile
make deploy
```

Make sure to change all environment variables in `envfile` to match your needs. Some more information can be found here: https://www.davd.eu/build-your-own-dynamic-dns-in-5-minutes/
Make sure to change all environment variables in `envfile` to match your needs. Some more information can be found here:
https://www.davd.eu/build-your-own-dynamic-dns-in-5-minutes/

## Exposed ports

Expand Down
Binary file added connect-to-your-nas-from-work.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions rest-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ func UpdateRecord(domain string, ipaddr string, addrType string) string {

w.WriteString(fmt.Sprintf("server %s\n", appConfig.Server))
w.WriteString(fmt.Sprintf("zone %s\n", appConfig.Zone))
w.WriteString(fmt.Sprintf("update delete %s.%s A\n", domain, appConfig.Domain))
w.WriteString(fmt.Sprintf("update delete %s.%s AAAA\n", domain, appConfig.Domain))
w.WriteString(fmt.Sprintf("update delete %s.%s %s\n", domain, appConfig.Domain, addrType))
w.WriteString(fmt.Sprintf("update add %s.%s %v %s %s\n", domain, appConfig.Domain, appConfig.RecordTTL, addrType, ipaddr))
w.WriteString("send\n")

Expand Down
27 changes: 23 additions & 4 deletions rest-api/request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"log"
"fmt"
"net"
"net/http"
"strings"

Expand Down Expand Up @@ -52,10 +53,28 @@ func BuildWebserviceResponseFromRequest(r *http.Request, appConfig *Config) Webs
} else if ipparser.ValidIP6(response.Address) {
response.AddrType = "AAAA"
} else {
response.Success = false
response.Message = fmt.Sprintf("%s is neither a valid IPv4 nor IPv6 address", response.Address)
log.Println(fmt.Sprintf("Invalid address: %s", response.Address))
return response
ip, _, err := net.SplitHostPort(r.RemoteAddr)

if err != nil {
response.Success = false
response.Message = fmt.Sprintf("%q is neither a valid IPv4 nor IPv6 address", r.RemoteAddr)
log.Println(fmt.Sprintf("Invalid address: %q", r.RemoteAddr))
return response
}

// @todo refactor this code to remove duplication
if ipparser.ValidIP4(ip) {
response.AddrType = "A"
response.Address = ip
} else if ipparser.ValidIP6(ip) {
response.AddrType = "AAAA"
response.Address = ip
} else {
response.Success = false
response.Message = fmt.Sprintf("%s is neither a valid IPv4 nor IPv6 address", response.Address)
log.Println(fmt.Sprintf("Invalid address: %s", response.Address))
return response
}
}

response.Success = true
Expand Down

0 comments on commit d05a661

Please sign in to comment.