use more variables instead of hard-coding (fixes #3)

This commit is contained in:
Jannik Beyerstedt 2019-11-12 21:06:04 +01:00
parent d48064a7e3
commit 04686de59c
15 changed files with 101 additions and 70 deletions

View file

@ -1,44 +0,0 @@
[Unit]
Description=Caddy HTTP/2 web server
Documentation=https://caddyserver.com/docs
After=network-online.target
Wants=network-online.target
[Service]
Restart=on-abnormal
User=www-data
Group=www-data
Environment=CADDYPATH=/etc/ssl/caddy
PIDFile=/run/caddy.pid
ExecStart=/usr/local/bin/caddy -log stdout -agree -email=code@jannikbeyerstedt.de -conf=/etc/caddy/Caddyfile -root=/var/tmp
ExecReload=/bin/kill -USR1 $MAINPID
KillMode=mixed
KillSignal=SIGQUIT
TimeoutStopSec=5s
LimitNOFILE=8192
LimitNPROC=64
StartLimitInterval=600
;StartLimitBurst=5
RestartSec=60
PermissionsStartOnly=true
PrivateTmp=true
;PrivateDevices=true
;ProtectHome=true
;ProtectSystem=full
ReadWriteDirectories=/etc/ssl/caddy
; The following additional security directives only work with systemd v229 or later.
; They further restrict privileges that can be gained by caddy.
; Note that you may have to add capabilities required by any plugins in use.
;CapabilityBoundingSet=CAP_NET_BIND_SERVICE
;AmbientCapabilities=CAP_NET_BIND_SERVICE
;NoNewPrivileges=true
[Install]
WantedBy=multi-user.target

View file

@ -1,54 +0,0 @@
#!/bin/sh
passwd='dyndnshosts'
hostname=$(hostname | tr '[:upper:]' '[:lower:]')
platform='unknown'
unamestr=$(uname)
if [ "$unamestr" = 'Linux' ]; then
platform='linux'
elif [ "$unamestr" = 'FreeBSD' ]; then
platform='freebsd'
fi
ip6addr=''
ip4addr=''
if [ $platform = 'linux' ]; then
ip6addr=$(ip -6 addr show scope global | grep inet6 | tail -1 | egrep -o '([0-9abcdef]{4}[0-9:abcdef]*)')
# filter local IPv4 address ranges (172.16.0.0/12, 10.0.0.0/8, 192.168.0.0/16)
ip4addr=$(ip -4 addr show scope global | grep inet | egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}' | grep -Ev '172.(1[6-9]|2[0-9]|3[0-1])' | grep -Ev '10.' | grep -Ev '192.168.' | head -n 1)
elif [ $platform = 'freebsd' ]; then
ip6addr=$(ifconfig em0 | grep inet6 | tail -1 | egrep -o '([0-9abcdef]{4}[0-9:abcdef]*)')
ip4addr=$(ifconfig em0 inet | grep inet | egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}' | head -n 1)
fi
echo "Current IP addresses of $hostname are: $ip4addr, $ip6addr"
if [ $ip4addr ]; then
echo "Updating IPv4 DNS entry..."
else
echo "No public IPv4 address, updating DNS entry anyway..."
fi
# API always returns 200, so check for response payload to begin with {"Success":true,
url="https://dyndns.jtbx.de/update?secret=$passwd&domain=$hostname&addr=$ip4addr"
statuscode=$(curl -s $url)
case "$statuscode" in
{\"Success\":true*) echo "IPv4 Success" ;;
*) (>&2 echo "IPv4 DynDNS update failed: API response:\n$statuscode") ;;
esac
if [ $ip6addr ]; then
echo "Updating IPv6 DNS entry..."
# API always returns 200, so check for response payload to begin with {"Success":true,
url="https://dyndns.jtbx.de/update?secret=$passwd&domain=$hostname&addr=$ip6addr"
statuscode=$(curl -s $url)
case "$statuscode" in
{\"Success\":true*) echo "IPv6 Success" ;;
*) (>&2 echo "IPv6 DynDNS update failed: API response:\n$statuscode") ;;
esac
else
echo "No public IPv6 Address, skipping DNS update."
fi

View file

@ -1,6 +0,0 @@
#!/bin/bash
passwd='dyndnshosts'
hostname=$(hostname | tr '[:upper:]' '[:lower:]')
domain=jtbx.space
/usr/bin/curl -4 -s "http://dynamicdns.park-your-domain.com/update?host=$hostname&domain=$domain&password=$passwd" > /dev/null