mirror of
https://github.com/RustyRaptor/namecheap-ddns-docker.git
synced 2026-12-03 22:25:15 -07:00
v1.1.0
This commit is contained in:
1 parent
9030f36cfe
commit
6a2cd45c1f
8 files changed
+40
-43
No files matched your search
+3
-3
@@ -1,11 +1,11 @@
|
||||
FROM golang:1.17.7-alpine3.15 as build
|
||||
FROM golang:1.19.0-alpine3.16 as build
|
||||
ARG OS
|
||||
ARG ARCH
|
||||
COPY . /build/
|
||||
WORKDIR /build
|
||||
RUN go mod download && GOOS=${OS} GOARCH=${ARCH} go build -o ncddns
|
||||
RUN go mod download && go build -o ncddns
|
||||
|
||||
FROM alpine:3.15
|
||||
FROM alpine:3.16
|
||||
ARG VERSION
|
||||
ARG user=ncddns
|
||||
ARG group=ncddns
|
||||
|
||||
@@ -33,11 +33,7 @@ If your server do not have static IP, i.e. When Public IP of your server / route
|
||||
Suppose, You need DDNS for `server.example.com`
|
||||
|
||||
```
|
||||
# For Linux running on amd64 arch
|
||||
docker run --name server.example.com -d --restart unless-stopped -e NC_HOST='server' -e NC_DOMAIN='example.com' -e NC_PASS='DynamicDDNSPa2w0rd' linuxshots/namecheap-ddns:1.0.0
|
||||
|
||||
# For linux running on arm64 arch
|
||||
docker run --name server.example.com -d --restart unless-stopped -e NC_HOST='server' -e NC_DOMAIN='example.com' -e NC_PASS='DynamicDDNSPa2w0rd' linuxshots/namecheap-ddns:arm64v8-linux-1.0.0
|
||||
docker run --name server.example.com -d --restart unless-stopped -e NC_HOST='server' -e NC_DOMAIN='example.com' -e NC_PASS='DynamicDDNSPa2w0rd' linuxshots/namecheap-ddns
|
||||
```
|
||||
|
||||
Here,
|
||||
@@ -71,7 +67,7 @@ To build your own image
|
||||
|
||||
```
|
||||
# Replace OS and ARCH values with valid values of GOlang environment variables GOOS and GOARCH.
|
||||
docker build --build-arg OS=linux --build-arg ARCH=amd64 --build-arg VERSION=1.0.0 -t linuxshots/namecheap-ddns:1.0.0 .
|
||||
docker build --build-arg VERSION=1.0.0 -t linuxshots/namecheap-ddns .
|
||||
```
|
||||
|
||||
NOTE: This sets the TTL to Automatic i.e. 30 minutes. Currently, There is no way provided by Namecheap to set custom TTL in Dynamic DDNS.
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/ussr/bin/env bash
|
||||
|
||||
docker buildx create --use
|
||||
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t linuxshots/namecheap-ddns:1.1.0 --push --pull .
|
||||
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t linuxshots/namecheap-ddns:latest --push --pull .
|
||||
@@ -1,4 +1,3 @@
|
||||
module github.com/navilg/namecheap-ddns-docker
|
||||
|
||||
go 1.17
|
||||
|
||||
go 1.19
|
||||
@@ -1,20 +0,0 @@
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/jedib0t/go-pretty/v6 v6.3.0 h1:QQ5yZPDUMEjbZRXDJtZlvwfDQqCYFaxV3yEzTkogUgk=
|
||||
github.com/jedib0t/go-pretty/v6 v6.3.0/go.mod h1:FMkOpgGD3EZ91cW8g/96RfxoV7bdeJyzXPYgz1L1ln0=
|
||||
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
|
||||
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
golang.org/x/sys v0.0.0-20180816055513-1c9583448a9c h1:uHnKXcvx6SNkuwC+nrzxkJ+TpPwZOtumbhWrrOYN5YA=
|
||||
golang.org/x/sys v0.0.0-20180816055513-1c9583448a9c/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
@@ -24,10 +24,10 @@ func main() {
|
||||
|
||||
pubIp, err := getPubIP()
|
||||
if err != nil {
|
||||
DDNSLogger(ErrorLog, *host, *domain, "Failed to get public Ip of your machine. "+err.Error())
|
||||
DDNSLogger(ErrorLog, *host, *domain, err.Error())
|
||||
} else {
|
||||
setDNSRecord(*host, *domain, *password, pubIp)
|
||||
DDNSLogger(InformationLog, *host, *domain, "Record updated.")
|
||||
DDNSLogger(InformationLog, *host, *domain, "Record updated. "+pubIp)
|
||||
}
|
||||
|
||||
updateRecord(*domain, *host, *password)
|
||||
|
||||
@@ -15,7 +15,8 @@ func (err *CustomError) Error() string {
|
||||
}
|
||||
|
||||
var (
|
||||
version string = "1.0.0-go1.17"
|
||||
version string = "1.1.0-go1.19"
|
||||
daemon_poll_time time.Duration = 1 * time.Minute // Time in minute
|
||||
gitrepo string = "https://github.com/navilg/namecheap-ddns-docker"
|
||||
httpTimeout time.Duration = 30 * time.Second
|
||||
)
|
||||
+25
-9
@@ -29,12 +29,19 @@ func updateRecord(domain, host, password string) {
|
||||
DDNSLogger(ErrorLog, host, domain, err.Error())
|
||||
}
|
||||
|
||||
err = setDNSRecord(host, domain, password, pubIp)
|
||||
if err != nil {
|
||||
DDNSLogger(ErrorLog, host, domain, err.Error())
|
||||
currentIp := os.Getenv("NC_PUB_IP")
|
||||
|
||||
if currentIp == pubIp {
|
||||
DDNSLogger(InformationLog, host, domain, "DNS record is same as current IP. "+pubIp)
|
||||
} else {
|
||||
err = setDNSRecord(host, domain, password, pubIp)
|
||||
if err != nil {
|
||||
DDNSLogger(ErrorLog, host, domain, err.Error())
|
||||
} else {
|
||||
DDNSLogger(InformationLog, host, domain, "Record updated (ip: "+currentIp+"->"+pubIp+")")
|
||||
}
|
||||
}
|
||||
|
||||
DDNSLogger(InformationLog, host, domain, "Record updated (ip: "+os.Getenv("NC_PUB_IP")+"->"+pubIp+")")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,22 +73,31 @@ func getPubIP() (string, error) {
|
||||
|
||||
var ipbody GetIPBody
|
||||
|
||||
response, err := http.Get("https://ipinfo.io/json")
|
||||
apiclient := &http.Client{Timeout: httpTimeout}
|
||||
|
||||
response, err := apiclient.Get("https://api.ipify.org?format=json")
|
||||
if err != nil {
|
||||
return "", nil
|
||||
response, err = apiclient.Get("https://ipinfo.io/json")
|
||||
if err != nil {
|
||||
return "", nil
|
||||
}
|
||||
}
|
||||
|
||||
defer response.Body.Close()
|
||||
bodyBytes, err := ioutil.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
// fmt.Println(err.Error())
|
||||
return "", err
|
||||
return "", &CustomError{ErrorCode: response.StatusCode, Err: errors.New("IP could not be fetched." + err.Error())}
|
||||
}
|
||||
|
||||
err = json.Unmarshal(bodyBytes, &ipbody)
|
||||
if err != nil {
|
||||
// fmt.Println(err.Error())
|
||||
return "", err
|
||||
return "", &CustomError{ErrorCode: response.StatusCode, Err: errors.New("IP could not be fetched." + err.Error())}
|
||||
}
|
||||
|
||||
if ipbody.IP == "" {
|
||||
return "", &CustomError{ErrorCode: response.StatusCode, Err: errors.New("IP could not be fetched. Empty IP value detected.")}
|
||||
}
|
||||
|
||||
return ipbody.IP, nil
|
||||
@@ -95,7 +111,7 @@ func setDNSRecord(host, domain, password, pubIp string) error {
|
||||
|
||||
ncURL := "https://dynamicdns.park-your-domain.com/update?host=" + host + "&domain=" + domain + "&password=" + password + "&ip=" + pubIp
|
||||
|
||||
apiclient := &http.Client{}
|
||||
apiclient := &http.Client{Timeout: httpTimeout}
|
||||
|
||||
req, err := http.NewRequest("GET", ncURL, nil)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user