From ffc82958ede264aa62d8122f8a0722d0da648ea5 Mon Sep 17 00:00:00 2001 From: jbergner Date: Fri, 17 Jan 2025 06:40:41 +0100 Subject: [PATCH] init --- .gitea/workflows/registry.yml | 51 ++++++++++++++++++ Dockerfile | 10 ++++ go.mod | 3 ++ main.go | 97 +++++++++++++++++++++++++++++++++++ 4 files changed, 161 insertions(+) create mode 100644 .gitea/workflows/registry.yml create mode 100644 Dockerfile create mode 100644 go.mod create mode 100644 main.go diff --git a/.gitea/workflows/registry.yml b/.gitea/workflows/registry.yml new file mode 100644 index 0000000..d609b9f --- /dev/null +++ b/.gitea/workflows/registry.yml @@ -0,0 +1,51 @@ +name: release-tag +on: + push: + branches: + - 'main' +jobs: + release-image: + runs-on: ubuntu-latest + env: + DOCKER_ORG: sendnrw + DOCKER_LATEST: latest + RUNNER_TOOL_CACHE: /toolcache + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker BuildX + uses: docker/setup-buildx-action@v2 + with: # replace it with your local IP + config-inline: | + [registry."git.send.nrw"] + http = true + insecure = true + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + registry: git.send.nrw # replace it with your local IP + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Get Meta + id: meta + run: | + echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}') >> $GITHUB_OUTPUT + echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + platforms: | + linux/amd64 + push: true + tags: | # replace it with your local IP and tags + git.send.nrw/${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }} + git.send.nrw/${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ env.DOCKER_LATEST }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..21b3940 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM golang:1.23.3 +RUN mkdir /data +COPY data/* /data +WORKDIR /app +COPY go.mod go.sum ./ +RUN go mod download +COPY *.go ./ +RUN CGO_ENABLED=0 GOOS=linux go build -o /go-ddns +EXPOSE 8080 +CMD ["/go-ddns"] \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..41acdc3 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.send.nrw/sendnrw/dyndns_container + +go 1.23.1 diff --git a/main.go b/main.go new file mode 100644 index 0000000..e9c7bf9 --- /dev/null +++ b/main.go @@ -0,0 +1,97 @@ +package main + +import ( + "fmt" + "io" + "net/http" + "os" + "time" +) + +func main() { + + DEV_TESTING := os.Getenv("DYNDNS_URL") + + DYNDNS_URL := os.Getenv("DYNDNS_URL") + DYNDNS_ADDRESS := os.Getenv("DYNDNS_ADDRESS") + DYNDNS_IPv4 := os.Getenv("DYNDNS_IPv4") + DYNDNS_IPv6 := os.Getenv("DYNDNS_IPv6") + DYNDNS_USERNAME := os.Getenv("DYNDNS_USERNAME") + DYNDNS_PASSWORD := os.Getenv("DYNDNS_PASSWORD") + + DYNDNS_IPv4_ADDR_RESOLVER := os.Getenv("DYNDNS_IPv4_ADDR_RESOLVER") + DYNDNS_IPv6_ADDR_RESOLVER := os.Getenv("DYNDNS_IPv6_ADDR_RESOLVER") + + if DYNDNS_IPv4_ADDR_RESOLVER == "" { + DYNDNS_IPv4_ADDR_RESOLVER = "https://dns.hilden.info/ip" + } + + if DYNDNS_IPv6_ADDR_RESOLVER == "" { + DYNDNS_IPv6_ADDR_RESOLVER = "https://dns.hilden.info/ip" + } + + if DEV_TESTING == "" { + DYNDNS_URL = "https://dns.hilden.info" + DYNDNS_ADDRESS = "devtest.dns.hilden.info" + DYNDNS_IPv4 = "9.8.7.6" + DYNDNS_IPv6 = "2001:db8::1" + DYNDNS_USERNAME = "admin" + DYNDNS_PASSWORD = "password" + DYNDNS_IPv4_ADDR_RESOLVER = "https://dns.hilden.info/ip" + DYNDNS_IPv6_ADDR_RESOLVER = "https://dns.hilden.info/ip" + } + + for { + /*GetIPv4*/ + respipv4, err := http.Get(DYNDNS_IPv4_ADDR_RESOLVER) + if err != nil { + fmt.Println("Fehler beim Abrufen der URL:", DYNDNS_IPv4_ADDR_RESOLVER, err) + } else { + body, err := io.ReadAll(respipv4.Body) + if err != nil { + fmt.Println("Fehler beim Lesen des Antwort-Bodys:", err) + } else { + // Antwort-Inhalt ausgeben + DYNDNS_IPv4 = string(body) + fmt.Println("Statuscode:", respipv4.StatusCode) + fmt.Println("Antwort-Inhalt:", string(body)) + } + respipv4.Body.Close() + } + + /*GetIPv6*/ + respipv6, err := http.Get(DYNDNS_IPv6_ADDR_RESOLVER) + if err != nil { + fmt.Println("Fehler beim Abrufen der URL:", DYNDNS_IPv6_ADDR_RESOLVER, err) + } else { + body, err := io.ReadAll(respipv6.Body) + if err != nil { + fmt.Println("Fehler beim Lesen des Antwort-Bodys:", err) + } else { + // Antwort-Inhalt ausgeben + DYNDNS_IPv6 = string(body) + fmt.Println("Statuscode:", respipv6.StatusCode) + fmt.Println("Antwort-Inhalt:", string(body)) + } + respipv6.Body.Close() + } + + /**/ + url := DYNDNS_URL + "/?DDNS=" + DYNDNS_ADDRESS + "&IP=" + DYNDNS_IPv4 + "&IPv6=" + DYNDNS_IPv6 + "&USER=" + DYNDNS_USERNAME + "&TOKEN=" + DYNDNS_PASSWORD + resp, err := http.Get(url) + if err != nil { + fmt.Println("Fehler beim Abrufen der URL:", DYNDNS_IPv6_ADDR_RESOLVER, err) + } else { + body, err := io.ReadAll(resp.Body) + if err != nil { + fmt.Println("Fehler beim Lesen des Antwort-Bodys:", err) + } else { + // Antwort-Inhalt ausgeben + fmt.Println("Statuscode:", resp.StatusCode) + fmt.Println("Antwort-Inhalt:", string(body)) + } + resp.Body.Close() + } + time.Sleep(5 * time.Minute) + } +}