diff --git a/data/bremen.freifunk.net.zone b/bremen.freifunk.net.zone similarity index 100% rename from data/bremen.freifunk.net.zone rename to bremen.freifunk.net.zone diff --git a/data/ffhb.de.zone b/ffhb.de.zone similarity index 100% rename from data/ffhb.de.zone rename to ffhb.de.zone diff --git a/rzonegen.py b/rzonegen.py deleted file mode 100755 index 547903f..0000000 --- a/rzonegen.py +++ /dev/null @@ -1,59 +0,0 @@ -#! /usr/bin/env python3 - -import sys -import json -import re -import ipaddress -from datetime import datetime - -def str_to_domainlabel(s): - label = re.sub("[^0-9a-zA-Z-]", "-", s) - label = re.sub("-+", "-", label) - label = re.sub("^-*", "", label) - label = re.sub("-*$", "", label) - - if not re.match("^[a-zA-Z][a-zA-Z0-9-]{,61}[a-zA-Z0-9]$", label): - raise RuntimeError("Not convertable to a domain label: %s" % s) - return label - -def ipv6_addr_to_rdns(addr): - return ".".join(reversed(addr.exploded.replace(':', ''))) + ".ip6.arpa." - -data = json.load(sys.stdin) -domain = sys.argv[1] -if not domain.startswith("."): - domain = "." + domain - -if not domain.endswith("."): - domain = domain + "." - -print("""$TTL 1h -@ IN SOA vpn03.bremen.freifunk.net. noc.bremen.freifunk.net. ( - %s ; serial - 1h ; refresh - 30m ; retry - 2d ; expiration - 1h ; caching - ) - - NS vpn02.bremen.freifunk.net. - NS vpn03.bremen.freifunk.net. -""" % datetime.now().strftime("%Y%m%d%H%M")) - -for node in data.values(): - try: - for address in node['network']['addresses']: - try: - address = ipaddress.IPv6Address(address) - except ValueError: - continue - - if address.is_link_local or address.is_private: - continue - - rdns = ipv6_addr_to_rdns(address) - - if rdns.endswith(domain): - print("%s PTR %s.nodes.ffhb.de." % (rdns[0:-len(domain)], str_to_domainlabel(node['hostname']))) - except (KeyError, RuntimeError): - pass diff --git a/update-dns-nodes.sh b/update-dns-nodes.sh deleted file mode 100755 index 4f8b6e1..0000000 --- a/update-dns-nodes.sh +++ /dev/null @@ -1,118 +0,0 @@ -#! /usr/bin/env bash -# 2014, Moritz Kaspar Rudert (mortzu) . -# All rights reserved. - -# Redistribution and use in source and binary forms, with or without modification, are -# permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# * The names of its contributors may not be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# * Feel free to send Club Mate to support the work. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS -# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS -# AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. - -# PID file -RUN_FILE='/run/update-dns-nodes.run' - -# getting workingdir of scripts -WORK_DIR="$(dirname $(readlink -nf $0))" - -# set safe path -PATH="${WORK_DIR}:/sbin:/usr/sbin:/bin:/usr/bin" - -# alfred data file -ALFRED_DATA_FILE='/var/cache/ffhb/alfred.json' - -# create alfred data directory -mkdir -p "$(dirname $ALFRED_DATA_FILE)" - -# define variable to count loops -declare -i NUM=0 - -# tmp file -TMP_FILE="$(mktemp)" - -# if creation of tmp file failed -# exit -if [ -z "$TMP_FILE" ]; then - exit 1 -fi - -# names of zones -ZONEFILE=/var/lib/nsd/net.freifunk.bremen.nodes.zone -RZONEFILE=/var/lib/nsd/arpa.ip6.f.d.2.f.5.1.1.9.0.f.2.c.zone - -function on_exit() { - # remove tmp files - for FILE in "$TMP_FILE" "$RUN_FILE"; do - if [ -n "$FILE" ]; then - rm -f "$FILE" - fi - done -} - -trap on_exit EXIT SIGTERM SIGINT - -# write run file -if [ -f "$RUN_FILE" ]; then - echo 'Script already running!' >&2 - exit 1 -else - touch "$RUN_FILE" -fi - -# loop until data received -while true; do - # increment counter - NUM=$(($NUM+1)) - - # get data from alfred - # but limit the time - timeout -s KILL 30s alfred-json -z -r 158 >"$TMP_FILE" 2>/dev/null - - # on success leave loop - if [ $? -eq 0 ]; then - break - fi - - # if the 240th run has reached kill script - if [ $NUM -gt 240 ]; then - # exit with error code - exit 1 - fi - - # sleep to be safe CPU load don't getting higher - sleep 1 -done - -# generate forward zone -if zonegen.py <"$TMP_FILE" >"${ZONEFILE}.new"; then - mv "${ZONEFILE}.new" "${ZONEFILE}" -fi - -# generate reverse zone -if rzonegen.py 0.0.0.0.c.2.f.0.9.1.1.5.f.2.d.f.ip6.arpa <"$TMP_FILE" >"${RZONEFILE}.new"; then - mv "${RZONEFILE}.new" "${RZONEFILE}" -fi - -# reload nameserver -nsd-control reload > /dev/null - -# copy alfred file -cp "$TMP_FILE" "$ALFRED_DATA_FILE" diff --git a/update-dns.sh b/update-dns.sh deleted file mode 100755 index 17840fb..0000000 --- a/update-dns.sh +++ /dev/null @@ -1,128 +0,0 @@ -#! /usr/bin/env bash -# 2014, Moritz Kaspar Rudert (mortzu) . -# All rights reserved. - -# Redistribution and use in source and binary forms, with or without modification, are -# permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# * The names of its contributors may not be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# * Feel free to send Club Mate to support the work. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS -# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS -# AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. - -# variable to check changes -declare -i CHANGED=0 - -# PID file -RUN_FILE="$HOME/.var/run/ffhb-dns" - -# destination zonefile directory -DEST_DIR="$HOME/zones" - -# getting workingdir of scripts -WORK_DIR="$(dirname $(readlink -nf $0))" - -# set safe path -PATH=/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin - -function on_exit() { - # remove tmp files - if [ -n "$RUN_FILE" ]; then - rm -f "$RUN_FILE" - fi -} - -trap on_exit EXIT SIGTERM SIGINT - -# write run file -if [ -f "$RUN_FILE" ]; then - echo 'Script already running!' >&2 - exit 1 -else - mkdir -p "$(dirname $RUN_FILE)" - touch "$RUN_FILE" -fi - -# refresh git repository -git --work-tree="${WORK_DIR}" --git-dir="${WORK_DIR}/.git" pull -q --rebase=false origin master - -# loop over zones -for FILE in ${WORK_DIR}/data/*; do - # tmp file - TMP_FILE="$(mktemp)" - - # reset some variables - OLD_SERIAL='' - NEW_SERIAL='' - - # construct realname - FILE_NAME="$(basename $FILE)" - - # construct origin - ORIGIN="$(basename "${FILE/.zone/}")" - - cp "$FILE" "$TMP_FILE" - - # if zone already exists - if [ -f "${DEST_DIR}/${FILE_NAME}" ]; then - # save old serial number - OLD_SERIAL="$(grep -Eho "20[0-1][0-9]{7}" "${DEST_DIR}/${FILE_NAME}")" - - # strip serial from old and new files - # diff is easier without different serial numbers - TMP_FILE_OLD="$(mktemp)" - TMP_FILE_NEW="$(mktemp)" - sed -e '/20[0-1][0-9]\{7\}/d' "${DEST_DIR}/${FILE_NAME}" >"$TMP_FILE_OLD" - sed -e '/20[0-1][0-9]\{7\}/d' "$TMP_FILE" >"$TMP_FILE_NEW" - - # check if update is necessary - if diff -q "$TMP_FILE_OLD" "$TMP_FILE_NEW" >/dev/null 2>&1; then - # if zones are identically - # remove tmp files - for FILE in "$TMP_FILE" "$TMP_FILE_OLD" "$TMP_FILE_NEW"; do - if [ -n "$FILE" ]; then - rm -f "$FILE" - fi - done - continue - fi - fi - - # changed variable - CHANGED=1 - - # update serial - if [ -n "$OLD_SERIAL" ]; then - NEW_SERIAL=$(($OLD_SERIAL + 1)) - else - NEW_SERIAL=$(date +'%Y%m%d%H') - fi - sed -e 's/20[0-1][0-9]\{7\}/'${NEW_SERIAL}'/g' -i "$TMP_FILE" - - # move the file to real place - mv "$TMP_FILE" "${DEST_DIR}/${FILE_NAME}" - - # fix permissions - chmod 0644 "${DEST_DIR}/${FILE_NAME}" -done - -if [ $CHANGED -ne 0 ]; then - planetcyborg-dns-reload -fi diff --git a/zonegen.py b/zonegen.py deleted file mode 100755 index 2ab4edb..0000000 --- a/zonegen.py +++ /dev/null @@ -1,49 +0,0 @@ -#! /usr/bin/env python3 - -import sys -import json -import re -import ipaddress -from datetime import datetime - -def str_to_domainlabel(s): - label = re.sub("[^0-9a-zA-Z-]", "-", s) - label = re.sub("-+", "-", label) - label = re.sub("^-*", "", label) - label = re.sub("-*$", "", label) - - if not re.match("^[a-zA-Z][a-zA-Z0-9-]{,61}[a-zA-Z0-9]$", label): - raise RuntimeError("Not convertable to a domain label: %s" % s) - - return label - -data = json.load(sys.stdin) - -print("""$TTL 1h -@ IN SOA vpn03.bremen.freifunk.net. noc.bremen.freifunk.net. ( - %s ; serial - 1h ; refresh - 30m ; retry - 2d ; expiration - 1h ; caching - ) - - NS vpn02.bremen.freifunk.net. - NS vpn03.bremen.freifunk.net. - -""" % datetime.now().strftime("%Y%m%d%H%M")) - -for node in data.values(): - try: - for address in node['network']['addresses']: - try: - address = ipaddress.IPv6Address(address) - except ValueError: - continue - - if address.is_link_local or address.is_private: - continue - - print("%-15s AAAA %s" % (str_to_domainlabel(node['hostname']), address)) - except: - pass