From 22fc220f1d215be8acd0526348ad21e67b83523a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 16 Oct 2016 12:38:08 +0100 Subject: [PATCH] Change freedns update so that it can handle arbitrary domains --- src/freedombone-freedns | 69 +++++++++++++++++++++++++++++++++++++++ src/freedombone-utils-dns | 54 ++---------------------------- 2 files changed, 72 insertions(+), 51 deletions(-) create mode 100755 src/freedombone-freedns diff --git a/src/freedombone-freedns b/src/freedombone-freedns new file mode 100755 index 00000000..26265638 --- /dev/null +++ b/src/freedombone-freedns @@ -0,0 +1,69 @@ +#!/bin/bash +# +# .---. . . +# | | | +# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-. +# | | (.-' (.-' ( | ( )| | | | )( )| | (.-' +# ' ' --' --' -' - -' ' ' -' -' -' ' - --' +# +# Freedom in the Cloud +# +# freedns update command for use in cron or a daemon + +# License +# ======= +# +# Copyright (C) 2016 Bob Mottram +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +PROJECT_NAME='freedombone' + +export TEXTDOMAIN=${PROJECT_NAME}-freedns +export TEXTDOMAINDIR="/usr/share/locale" + +CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg +FREEDNS_WGET='wget -q --read-timeout=0.0 --waitretry=5 --tries=4 https://freedns.afraid.org/dynamic/update.php?' + +if [ ! -f $CONFIGURATION_FILE ]; then + exit 0 +fi + +function item_in_array { + local e + for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done + return 1 +} + +detected_codes=() +codelines=$(grep "_CODE=" $CONFIGURATION_FILE | uniq) +for line in "${codelines[@]}" +do + code=$(echo "$line" | awk -F '=' '{print $2}') + item_in_array "$code" "${detected_codes[@]}" + if [[ $? != 0 ]]; then + detected_codes+=("$code") + fi +done + +if [ ! -d $HOME/.freedns-update ]; then + mkdir $HOME/.freedns-update +fi +cd $HOME/.freedns-update +for code in "${detected_codes[@]}" +do + $FREEDNS_WGET${code} +done + +exit 0 diff --git a/src/freedombone-utils-dns b/src/freedombone-utils-dns index 93308d0a..a021f20c 100755 --- a/src/freedombone-utils-dns +++ b/src/freedombone-utils-dns @@ -101,64 +101,16 @@ function create_freedns_updater { if grep -Fxq "create_freedns_updater" $COMPLETION_FILE; then return fi - if [[ $DDNS_PROVIDER != "default@freedns.afraid.org" ]]; then + if [[ $DDNS_PROVIDER != *"freedns"* ]]; then return fi if [[ $SYSTEM_TYPE == "mesh"* ]]; then return fi - FREEDNS_WGET='wget -q --read-timeout=0.0 --waitretry=5 --tries=4 https://freedns.afraid.org/dynamic/update.php?' - - echo '#!/bin/bash' > /usr/bin/dynamicdns - echo 'cd /tmp' >> /usr/bin/dynamicdns - if [ $DEFAULT_DOMAIN_CODE ]; then - echo "# $DEFAULT_DOMAIN_NAME" >> /usr/bin/dynamicdns - echo "$FREEDNS_WGET$DEFAULT_DOMAIN_CODE=" >> /usr/bin/dynamicdns - fi - if [ $DOKUWIKI_CODE ]; then - if [[ $DOKUWIKI_CODE != "$DEFAULT_DOMAIN_CODE" ]]; then - echo "# $DOKUWIKI_DOMAIN_NAME" >> /usr/bin/dynamicdns - echo "$FREEDNS_WGET$DOKUWIKI_CODE=" >> /usr/bin/dynamicdns - fi - fi - if [ $FULLBLOG_CODE ]; then - if [[ $FULLBLOG_CODE != "$DEFAULT_DOMAIN_CODE" ]]; then - echo "# $FULLBLOG_DOMAIN_NAME" >> /usr/bin/dynamicdns - echo "$FREEDNS_WGET$FULLBLOG_CODE=" >> /usr/bin/dynamicdns - fi - fi - if [ $HUBZILLA_CODE ]; then - if [[ $HUBZILLA_CODE != "$DEFAULT_DOMAIN_CODE" ]]; then - echo "# $HUBZILLA_DOMAIN_NAME" >> /usr/bin/dynamicdns - echo "$FREEDNS_WGET$HUBZILLA_CODE=" >> /usr/bin/dynamicdns - fi - fi - if [ $MICROBLOG_CODE ]; then - if [[ $MICROBLOG_CODE != "$DEFAULT_DOMAIN_CODE" ]]; then - echo "# $MICROBLOG_DOMAIN_NAME" >> /usr/bin/dynamicdns - echo "$FREEDNS_WGET$MICROBLOG_CODE=" >> /usr/bin/dynamicdns - fi - fi - if [ $GIT_CODE ]; then - if [[ $GIT_CODE != "$DEFAULT_DOMAIN_CODE" ]]; then - echo "# $GIT_DOMAIN_NAME" >> /usr/bin/dynamicdns - echo "$FREEDNS_WGET$GIT_CODE=" >> /usr/bin/dynamicdns - fi - fi - if [ $MEDIAGOBLIN_CODE ]; then - if [[ $MEDIAGOBLIN_CODE != "$DEFAULT_DOMAIN_CODE" ]]; then - echo "# $MEDIAGOBLIN_DOMAIN_NAME" >> /usr/bin/dynamicdns - echo "$FREEDNS_WGET$MEDIAGOBLIN_CODE=" >> /usr/bin/dynamicdns - fi - fi - echo 'exit 0' >> /usr/bin/dynamicdns - chmod 600 /usr/bin/dynamicdns - chmod +x /usr/bin/dynamicdns - - if ! grep -q "/usr/bin/dynamicdns" /etc/crontab; then + if ! grep -q "/usr/local/bin/freedombone-freedns" /etc/crontab; then function_check cron_add_mins - cron_add_mins 3 '/usr/bin/dynamicdns' + cron_add_mins 3 '/usr/local/bin/freedombone-freedns' systemctl restart cron fi