From 19d63548267e783e767f8fef769dd5290d37c8f9 Mon Sep 17 00:00:00 2001 From: webhainaut Date: Fri, 10 Jul 2020 15:15:48 +0200 Subject: [PATCH] init commit --- .gitignore | 1 + .travis.yml | 16 +++++++++++++++ Dockerfile | 37 +++++++++++++++++++++++++++++++++++ LICENSE | 21 ++++++++++++++++++++ README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++ config/cmd.sh | 4 ++++ config/cronjob.txt | 2 ++ config/dynhost.sh | 42 ++++++++++++++++++++++++++++++++++++++++ config/entrypoint.sh | 7 +++++++ 9 files changed, 176 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 config/cmd.sh create mode 100644 config/cronjob.txt create mode 100644 config/dynhost.sh create mode 100644 config/entrypoint.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e73b261 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +language: bash +os: linux +arch: + - amd64 + - arm64 + - ppc64le + - s390x + +services: docker +sudo: required + +script: + - docker build . + +after_script: + - docker images \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a87e19d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +ARG ARCH=amd64/ +FROM ${ARCH}alpine:latest +MAINTAINER webhainaut + +ENV HOST="" +ENV LOGIN="" +ENV PASSWORD="" +ENV ENTRYPOINT="https://www.ovh.com/nic/update" +ENV NSSERVER="8.8.8.8" + +RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \ + && apk --no-cache update \ + && apk --no-cache upgrade \ + && apk add --no-cache \ + curl \ + wget \ + curl \ + bash \ + zip \ + dcron \ + bind-tools \ + ca-certificates \ + && mkdir -p /srv/dyndns + +COPY config /srv/dyndns/cmd.sh +COPY config /srv/dyndns/entrypoint.sh +COPY config /srv/dyndns/dynhost +COPY config /etc/cron.d/dynhost + +RUN chmod +x /srv/dyndns/dynhost \ + && chmod +x /srv/dyndns/entrypoint.sh \ + && chmod +x /srv/dyndns/cmd.sh + +HEALTHCHECK --interval=5s --timeout=3s CMD ps aux | grep '[c]rond' || exit 1 + +ENTRYPOINT ["/srv/dyndns/entrypoint.sh"] +CMD ["/srv/dyndns/cmd.sh"] \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..25c00b7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 webhainaut + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..dda2cfc --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ +# DynDNS update script for OVH domains + +[![Build Status](https://travis-ci.org/webhainaut/docker.svg?branch=master)](https://travis-ci.org/webhainaut/docker) + +this is based on *ovh-dyndns* from [Ambroisemaupate work](https://github.com/ambroisemaupate/Docker). + +https://docs.ovh.com/fr/domains/utilisation-dynhost/ + +Check every 5 minutes you WAN IP and if changed call OVH entry-point to update +your DynDNS domain. + +``` +docker run -d --name="ovh-dyndns" \ + -e "HOST=mydynamicdomain.domain.com" \ + -e "LOGIN=mylogin" \ + -e "PASSWORD=mypassword" \ + ambroisemaupate/ovh-dyndns +``` + +## Docker-compose + +``` +version: "3" +services: + crond: + image: ambroisemaupate/ovh-dyndns + environment: + HOST: mydynamicdomain.domain.com + LOGIN: mylogin + PASSWORD: mypassword + restart: always +``` + +## Customize external NS server + +By default, we use Google DNS to check your current DynDNS IP, but you can choose an +other DNS overriding `NSSERVER` env var: + +``` +docker run -d --name="ovh-dyndns" \ + -e "HOST=mydynamicdomain.domain.com" \ + -e "LOGIN=mylogin" \ + -e "PASSWORD=mypassword" \ + -e "NSSERVER=192.168.1.1" \ + ambroisemaupate/ovh-dyndns +``` \ No newline at end of file diff --git a/config/cmd.sh b/config/cmd.sh new file mode 100644 index 0000000..33f729f --- /dev/null +++ b/config/cmd.sh @@ -0,0 +1,4 @@ +#!/bin/sh +set -e + +crond -s /etc/cron.d -f -L /proc/self/fd/1 "$@" \ No newline at end of file diff --git a/config/cronjob.txt b/config/cronjob.txt new file mode 100644 index 0000000..3ca929c --- /dev/null +++ b/config/cronjob.txt @@ -0,0 +1,2 @@ +# Exec dynhost every 5 minutes +*/5 * * * * /bin/sh /srv/dyndns/dynhost \ No newline at end of file diff --git a/config/dynhost.sh b/config/dynhost.sh new file mode 100644 index 0000000..0dbcff5 --- /dev/null +++ b/config/dynhost.sh @@ -0,0 +1,42 @@ +#! /bin/sh +# Mainly inspired by DynHost script given by OVH +# New version by zwindler (zwindler.fr/wordpress) +# +# Initial version was doing nasty grep/cut on local ppp0 interface +# +# This coulnd't work in a NATed environnement like on ISP boxes +# on private networks. +# +# Also got rid of ipcheck.py thanks to mafiaman42 +# +# This script uses curl to get the public IP, and then uses wget +# to update DynHost entry in OVH DNS +# +# Logfile: dynhost.log +# +# CHANGE: "HOST", "LOGIN" and "PASSWORD" to reflect YOUR account variables +SCRIPT_PATH='/srv/dyndns' + +getip() { + IP=`curl http://ifconfig.me/ip` + OLDIP=`dig +short $HOST @$NSSERVER` +} + +echo "[`date '+%Y-%m-%d %H:%M:%S'`] =============================================================" +echo "[`date '+%Y-%m-%d %H:%M:%S'`] Begining new dyndns check" +getip + +if [ "$IP" ]; then + echo "[`date '+%Y-%m-%d %H:%M:%S'`] Old IP is ${OLDIP}" + echo "[`date '+%Y-%m-%d %H:%M:%S'`] New IP is ${IP}" + + if [ "$OLDIP" != "$IP" ]; then + echo "[`date '+%Y-%m-%d %H:%M:%S'`] Update is needed…" + wget "${ENTRYPOINT}?system=dyndns&hostname=${HOST}&myip=${IP}" --user="${LOGIN}" --password="${PASSWORD}" + echo -n "$IP" > $SCRIPT_PATH/old.ip + else + echo "[`date '+%Y-%m-%d %H:%M:%S'`] No update required." + fi + else + echo "[`date '+%Y-%m-%d %H:%M:%S'`] WAN IP not found. Exiting!" + fi \ No newline at end of file diff --git a/config/entrypoint.sh b/config/entrypoint.sh new file mode 100644 index 0000000..c9d0fc4 --- /dev/null +++ b/config/entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/sh +set -e + +# see: https://github.com/dubiousjim/dcron/issues/13 +# ignore using `exec` for `dcron` to get another pid instead of `1` +# exec "$@" +exec "$@" \ No newline at end of file