diff --git a/src/freedombone-freedns b/src/freedombone-freedns deleted file mode 100755 index 7daab578a36bc0bb781ff93918828e9b684b0211..0000000000000000000000000000000000000000 --- a/src/freedombone-freedns +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash -# _____ _ _ -# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___ -# | __| _| -_| -_| . | . | | . | . | | -_| -# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___| -# -# Freedom in the Cloud -# -# freedns update command for use in cron or a daemon -# -# License -# ======= -# -# Copyright (C) 2016-2018 Bob Mottram <bob@freedombone.net> -# -# 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 <http://www.gnu.org/licenses/>. - -PROJECT_NAME='freedombone' - -export TEXTDOMAIN=${PROJECT_NAME}-freedns -export TEXTDOMAINDIR="/usr/share/locale" - -VERBOSE= -CONFIGURATION_FILE=/root/${PROJECT_NAME}.cfg - -if [[ "$1" == "--verbose" || "$1" == "-v" ]]; then - VERBOSE=1 -fi - -if [ ! -f "$CONFIGURATION_FILE" ]; then - exit 0 -fi - -if ! grep -q 'DEFAULT_DOMAIN_CODE=' "$CONFIGURATION_FILE"; then - exit 0 -fi - -code=$(grep 'DEFAULT_DOMAIN_CODE=' "$CONFIGURATION_FILE" | awk -F '=' '{print $2}') - -if [ ${#code} -lt 30 ]; then - exit 0 -fi - -if [ $VERBOSE ]; then - echo $"wget --no-check-certificate -O - https://freedns.afraid.org/dynamic/update.php?${code}= >> /tmp/freedns 2>&1 &" -fi - -if [ -f /tmp/freedns ]; then - rm /tmp/freedns -fi - -# shellcheck disable=SC2086 -wget --no-check-certificate -O - https://freedns.afraid.org/dynamic/update.php?${code}= >> /tmp/freedns 2>&1 & - -exit 0 diff --git a/src/freedombone-utils-dns b/src/freedombone-utils-dns index e8bcb9cc309fa349df514c178036107de94b9f3c..e87cdb781f0d0dcd525404288f1fdbef1c80a228 100755 --- a/src/freedombone-utils-dns +++ b/src/freedombone-utils-dns @@ -120,14 +120,37 @@ function enable_mdns { sed -i "s|hosts:.*|hosts: files mdns4_minimal mdns4 mdns dns|g" /etc/nsswitch.conf } +function freedns_update_cron { + if grep -q "${PROJECT_NAME}-freedns" /etc/crontab; then + sed -i "/${PROJECT_NAME}-freedns/d" /etc/crontab + fi + if ! grep -q "freedns" /etc/crontab; then + if grep -q "DEFAULT_DOMAIN_CODE=" "$CONFIGURATION_FILE"; then + ddns_code=$(grep 'DEFAULT_DOMAIN_CODE=' "$CONFIGURATION_FILE" | awk -F '=' '{print $2}') + if [ "$ddns_code" ]; then + if [ ${#ddns_code} -gt 10 ]; then + # TODO randomise these timings + echo "3,8,13,18,23,28,33,38,43,48,53,58 * * * * root sleep 46 ; wget --no-check-certificate -O - https://freedns.afraid.org/dynamic/update.php?${ddns_code}= >> /var/log/freedns_@_update.log 2>&1 &" >> /etc/crontab + fi + fi + fi + else + ddns_code=$(grep 'DEFAULT_DOMAIN_CODE=' "$CONFIGURATION_FILE" | awk -F '=' '{print $2}') + if [ "$ddns_code" ]; then + if [ ${#ddns_code} -gt 10 ]; then + sed -i "s|dynamic/update.php.*|dynamic/update.php?${ddns_code}= >> /var/log/freedns_@_update.log 2>&1 &|g" /etc/crontab + fi + fi + fi +} + function update_inadyn_config { if [[ "$DDNS_PROVIDER" == *'freedns'* ]]; then - if ! grep -q "/usr/local/bin/${PROJECT_NAME}-freedns" /etc/crontab; then - echo "*/1 * * * * root /usr/local/bin/${PROJECT_NAME}-freedns" >> /etc/crontab - fi + freedns_update_cron return fi + # remove any freedns entries from crontab if grep -q 'freedns' /etc/crontab; then sed -i '/freedns/d' /etc/crontab fi @@ -221,11 +244,7 @@ function create_freedns_updater { fi # add the update command to cron - if ! grep -q "/usr/local/bin/${PROJECT_NAME}-freedns" /etc/crontab; then - function_check cron_add_mins - cron_add_mins 1 "/usr/local/bin/${PROJECT_NAME}-freedns" - systemctl restart cron - fi + freedns_update_cron mark_completed "${FUNCNAME[0]}" }