This commit is contained in:
Bob Mottram 2018-05-12 13:25:22 +01:00
commit ac0b5304e4
4 changed files with 288 additions and 163 deletions

View File

@ -38,7 +38,7 @@ export TEXTDOMAIN=${PROJECT_NAME}-config
export TEXTDOMAINDIR="/usr/share/locale" export TEXTDOMAINDIR="/usr/share/locale"
# Web site # Web site
FREEDOMBONE_WEBSITE="https://freedombone.net or http://4fvfozz6g3zmvf76.onion" FREEDOMBONE_WEBSITE="https://freedombone.net or http://yjxlc3imv7obva4grjae6u3qw527koaytrgjgdp364hmthrst3jodiid.onion"
# Minimum number of characters in a password # Minimum number of characters in a password
MINIMUM_PASSWORD_LENGTH=$(grep 'MINIMUM_PASSWORD_LENGTH=' "/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-passwords" | head -n 1 | awk -F '=' '{print $2}') MINIMUM_PASSWORD_LENGTH=$(grep 'MINIMUM_PASSWORD_LENGTH=' "/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-passwords" | head -n 1 | awk -F '=' '{print $2}')
@ -184,7 +184,7 @@ function choose_social_instance_domain_name {
while [ ! $DEFAULT_DOMAIN_DETAILS_COMPLETE ] while [ ! $DEFAULT_DOMAIN_DETAILS_COMPLETE ]
do do
data=$(mktemp 2>/dev/null) data=$(mktemp 2>/dev/null)
if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then if [[ "$DDNS_PROVIDER" == "default@freedns.afraid.org" ]]; then
dialog --backtitle $"Freedombone Configuration" \ dialog --backtitle $"Freedombone Configuration" \
--title $"Instance domain" \ --title $"Instance domain" \
--form $"\\nEnter your instance domain name and its FreeDNS code:" 11 55 3 \ --form $"\\nEnter your instance domain name and its FreeDNS code:" 11 55 3 \
@ -247,9 +247,9 @@ function choose_default_domain_name {
while [ ! $DEFAULT_DOMAIN_DETAILS_COMPLETE ] while [ ! $DEFAULT_DOMAIN_DETAILS_COMPLETE ]
do do
data=$(mktemp 2>/dev/null) data=$(mktemp 2>/dev/null)
if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then if [[ "$DDNS_PROVIDER" == "default@freedns.afraid.org" ]]; then
dialog --backtitle $"Freedombone Configuration" \ dialog --backtitle $"Freedombone Configuration" \
--title $"Your main domain name" \ --title $"Your main domain name on FreeDNS" \
--form $"\nWhich domain name should your email/XMPP/IRC/Mumble be associated with?" 13 55 5 \ --form $"\nWhich domain name should your email/XMPP/IRC/Mumble be associated with?" 13 55 5 \
$"Domain:" 1 1 "$(grep 'DEFAULT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 24 33 40 \ $"Domain:" 1 1 "$(grep 'DEFAULT_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 24 33 40 \
$"Code:" 2 1 "$(grep 'DEFAULT_DOMAIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 24 33 255 \ $"Code:" 2 1 "$(grep 'DEFAULT_DOMAIN_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 24 33 255 \
@ -320,159 +320,6 @@ function choose_default_domain_name {
save_configuration_values save_configuration_values
} }
function dynamic_dns_setup {
W=(1 freedns.afraid.org
2 dyn.com
3 zoneedit.com
4 no-ip.com
5 easydns.com
6 dnsomatic.com
7 dns.he.net
8 tunnelbroker.net
9 sitelutions.com
10 dnsexit.com
11 changeip.com
12 zerigo.com
13 dhis.org
14 nsupdate.info
15 loopia.com
16 namecheap.com
17 ovh.com
18 dtdns.com
19 giradns.com
20 duiadns.net
21 ddnss.de
22 dynv6.com
23 ipv4.dynv6.com
24 spdyn.de
25 freemyip.com
26 cloudxns.net)
# shellcheck disable=SC2068
selection=$(dialog --backtitle $"Freedombone Configuration" --title $"Dynamic DNS" --menu $"Choose Dynamic DNS provider, or ESC for none:" 24 60 32 "${W[@]}" 3>&2 2>&1 1>&3)
if [ ! "$selection" ]; then
if [ -f /etc/systemd/system/inadyn.service ]; then
systemctl stop inadyn
systemctl disable inadyn
fi
return
fi
case $selection in
1) DDNS_PROVIDER="default@freedns.afraid.org";;
2) DDNS_PROVIDER="default@www.dyn.com";;
3) DDNS_PROVIDER="default@www.zoneedit.com";;
4) DDNS_PROVIDER="default@www.no-ip.com";;
5) DDNS_PROVIDER="default@www.easydns.com";;
6) DDNS_PROVIDER="default@www.dnsomatic.com";;
7) DDNS_PROVIDER="default@dns.he.net";;
8) DDNS_PROVIDER="default@www.tunnelbroker.net";;
9) DDNS_PROVIDER="default@www.sitelutions.com";;
10) DDNS_PROVIDER="default@www.dnsexit.com";;
11) DDNS_PROVIDER="default@www.changeip.com";;
12) DDNS_PROVIDER="default@www.zerigo.com";;
13) DDNS_PROVIDER="default@www.dhis.org";;
14) DDNS_PROVIDER="default@nsupdate.info";;
15) DDNS_PROVIDER="default@www.loopia.com";;
16) DDNS_PROVIDER="default@www.namecheap.com";;
17) DDNS_PROVIDER="default@www.ovh.com";;
18) DDNS_PROVIDER="default@www.dtdns.com";;
19) DDNS_PROVIDER="default@giradns.com";;
20) DDNS_PROVIDER="default@www.duiadns.net";;
21) DDNS_PROVIDER="default@ddnss.de";;
22) DDNS_PROVIDER="default@dynv6.com";;
23) DDNS_PROVIDER="default@ipv4.dynv6.com";;
24) DDNS_PROVIDER="default@spdyn.de";;
25) DDNS_PROVIDER="default@freemyip.com";;
26) DDNS_PROVIDER="default@www.cloudxns.net";;
esac
save_configuration_values
valid_ddns_username=
valid_ddns_password=
if [[ "$DDNS_PROVIDER" == "none" ]]; then
if [ -f /etc/systemd/system/inadyn.service ]; then
systemctl stop inadyn
systemctl disable inadyn
fi
else
while [ ! $valid_ddns_username ]
do
data=$(mktemp 2>/dev/null)
dialog --backtitle $"Freedombone Configuration" \
--inputbox $"Dynamic DNS provider username" 10 30 "$(grep 'DDNS_USERNAME' temp.cfg | awk -F '=' '{print $2}')" 2> "$data"
sel=$?
case $sel in
0) possible_username=$(cat "$data")
if [ "$possible_username" ]; then
if [ ${#possible_username} -gt 1 ]; then
valid_ddns_username=$(cat "$data")
# shellcheck disable=SC2034
DDNS_USERNAME="$valid_ddns_username"
rm -f "$data"
break;
fi
fi
;;
1) rm -f "$data"
exit 1;;
255) rm -f "$data"
exit 1;;
esac
rm -f "$data"
done
save_configuration_values
while [ ! $valid_ddns_password ]
do
data=$(mktemp 2>/dev/null)
dialog --backtitle $"Freedombone Configuration" \
--clear \
--insecure \
--passwordbox $"Dynamic DNS provider password" 10 30 "$(grep 'DDNS_PASSWORD' temp.cfg | awk -F '=' '{print $2}')" 2> "$data"
sel=$?
case $sel in
0) possible_password=$(cat "$data")
if [ "$possible_password" ]; then
if [ ${#possible_password} -gt 1 ]; then
valid_ddns_password=$(cat "$data")
DDNS_PASSWORD=$valid_ddns_password
break;
fi
fi
;;
1) rm -f "$data"
exit 1;;
255) rm -f "$data"
exit 1;;
esac
rm -f "$data"
if [ ${#DDNS_PASSWORD} -lt "$MINIMUM_PASSWORD_LENGTH" ]; then
dialog --title $"Password quality check" --msgbox $"The password given was too short. It must be at least $MINIMUM_PASSWORD_LENGTH characters. You may need to change your password on the dynamic DNS provider's web site." 10 40
DDNS_PASSWORD=""
fi
done
save_configuration_values
fi
}
function choose_dynamic_dns {
DDNS_PROVIDER="none"
if [[ "$SYSTEM_TYPE" != "mesh"* && "$ONION_ONLY" == "no" ]]; then
dialog --title $"Dynamic DNS" \
--backtitle $"Freedombone Configuration" \
--yesno $"\\nConfigure a dynamic DNS service?\\n\\nIf it is already handled by your internet router then select 'no'." 10 50
sel=$?
case $sel in
0) dynamic_dns_setup;;
255) exit 1;;
esac
fi
save_configuration_values
}
function choose_debian_repo { function choose_debian_repo {
if [[ "$MINIMAL_INSTALL" == "no" ]]; then if [[ "$MINIMAL_INSTALL" == "no" ]]; then
@ -1100,7 +947,12 @@ function interactive_config {
choose_rng choose_rng
choose_debian_repo choose_debian_repo
"${PROJECT_NAME}-wifi" --networksinteractive "$WIFI_NETWORKS_FILE" "${PROJECT_NAME}-wifi" --networksinteractive "$WIFI_NETWORKS_FILE"
choose_dynamic_dns
"${PROJECT_NAME}-ddns"
read_config_param DDNS_PROVIDER
read_config_param DDNS_USERNAME
read_config_param DDNS_PASSWORD
choose_default_domain_name choose_default_domain_name
choose_email_address choose_email_address
interactive_key_recovery interactive_key_recovery

View File

@ -1981,11 +1981,12 @@ function menu_top_level {
13 $"Add Clacks" 13 $"Add Clacks"
14 $"Check for updates" 14 $"Check for updates"
15 $"Performance Benchmarks" 15 $"Performance Benchmarks"
16 $"Power off the system" 16 $"Change Dynamic DNS settings"
17 $"Restart the system") 17 $"Power off the system"
18 $"Restart the system")
# shellcheck disable=SC2068 # shellcheck disable=SC2068
selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"Administrator Control Panel" --menu $"Choose an operation, or ESC to exit:" 24 60 24 "${W[@]}" 3>&2 2>&1 1>&3) selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"Administrator Control Panel" --menu $"Choose an operation, or ESC to exit:" 25 60 25 "${W[@]}" 3>&2 2>&1 1>&3)
if [ ! "$selection" ]; then if [ ! "$selection" ]; then
break break
@ -2012,8 +2013,9 @@ function menu_top_level {
13) add_clacks;; 13) add_clacks;;
14) check_for_updates;; 14) check_for_updates;;
15) performance_benchmarks;; 15) performance_benchmarks;;
16) shut_down_system;; 16) "${PROJECT_NAME}-ddns";;
17) restart_system;; 17) shut_down_system;;
18) restart_system;;
esac esac
done done
} }

214
src/freedombone-ddns Executable file
View File

@ -0,0 +1,214 @@
#!/bin/bash
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
#
# Freedom in the Cloud
#
# Change dynamic dns settings
#
# License
# =======
#
# Copyright (C) 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}-ddns
export TEXTDOMAINDIR="/usr/share/locale"
source "/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-config"
source "/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-dns"
DDNS_PROVIDER="none"
DDNS_USERNAME=
DDNS_PASSWORD=
function dynamic_dns_setup {
DDNS_PROVIDER='none'
W=(1 freedns.afraid.org
2 dyn.com
3 zoneedit.com
4 no-ip.com
5 easydns.com
6 dnsomatic.com
7 dns.he.net
8 tunnelbroker.net
9 sitelutions.com
10 dnsexit.com
11 changeip.com
12 zerigo.com
13 dhis.org
14 nsupdate.info
15 loopia.com
16 namecheap.com
17 ovh.com
18 dtdns.com
19 giradns.com
20 duiadns.net
21 ddnss.de
22 dynv6.com
23 ipv4.dynv6.com
24 spdyn.de
25 freemyip.com
26 cloudxns.net)
# shellcheck disable=SC2068
selection=$(dialog --backtitle $"Freedombone Configuration" --title $"Dynamic DNS" --menu $"Choose Dynamic DNS provider, or ESC for none:" 24 60 32 "${W[@]}" 3>&2 2>&1 1>&3)
if [ ! "$selection" ]; then
if [ -f /etc/systemd/system/inadyn.service ]; then
systemctl stop inadyn
systemctl disable inadyn
fi
return
fi
case $selection in
1) DDNS_PROVIDER="default@freedns.afraid.org";;
2) DDNS_PROVIDER="default@www.dyn.com";;
3) DDNS_PROVIDER="default@www.zoneedit.com";;
4) DDNS_PROVIDER="default@www.no-ip.com";;
5) DDNS_PROVIDER="default@www.easydns.com";;
6) DDNS_PROVIDER="default@www.dnsomatic.com";;
7) DDNS_PROVIDER="default@dns.he.net";;
8) DDNS_PROVIDER="default@www.tunnelbroker.net";;
9) DDNS_PROVIDER="default@www.sitelutions.com";;
10) DDNS_PROVIDER="default@www.dnsexit.com";;
11) DDNS_PROVIDER="default@www.changeip.com";;
12) DDNS_PROVIDER="default@www.zerigo.com";;
13) DDNS_PROVIDER="default@www.dhis.org";;
14) DDNS_PROVIDER="default@nsupdate.info";;
15) DDNS_PROVIDER="default@www.loopia.com";;
16) DDNS_PROVIDER="default@www.namecheap.com";;
17) DDNS_PROVIDER="default@www.ovh.com";;
18) DDNS_PROVIDER="default@www.dtdns.com";;
19) DDNS_PROVIDER="default@giradns.com";;
20) DDNS_PROVIDER="default@www.duiadns.net";;
21) DDNS_PROVIDER="default@ddnss.de";;
22) DDNS_PROVIDER="default@dynv6.com";;
23) DDNS_PROVIDER="default@ipv4.dynv6.com";;
24) DDNS_PROVIDER="default@spdyn.de";;
25) DDNS_PROVIDER="default@freemyip.com";;
26) DDNS_PROVIDER="default@www.cloudxns.net";;
esac
save_configuration_values
valid_ddns_username=
valid_ddns_password=
if [[ "$DDNS_PROVIDER" == "none" ]]; then
if [ -f /etc/systemd/system/inadyn.service ]; then
systemctl stop inadyn
systemctl disable inadyn
fi
else
while [ ! $valid_ddns_username ]
do
data=$(mktemp 2>/dev/null)
dialog --backtitle $"Freedombone Configuration" \
--inputbox $"Dynamic DNS provider username" 10 30 "$(grep 'DDNS_USERNAME' temp.cfg | awk -F '=' '{print $2}')" 2> "$data"
sel=$?
case $sel in
0) possible_username=$(cat "$data")
if [ "$possible_username" ]; then
if [ ${#possible_username} -gt 1 ]; then
valid_ddns_username=$(cat "$data")
# shellcheck disable=SC2034
DDNS_USERNAME="$valid_ddns_username"
rm -f "$data"
break;
fi
fi
;;
1) rm -f "$data"
clear
exit 1;;
255) rm -f "$data"
clear
exit 1;;
esac
rm -f "$data"
done
save_configuration_values
while [ ! $valid_ddns_password ]
do
data=$(mktemp 2>/dev/null)
dialog --backtitle $"Freedombone Configuration" \
--clear \
--insecure \
--passwordbox $"Dynamic DNS provider password" 10 30 "$(grep 'DDNS_PASSWORD' temp.cfg | awk -F '=' '{print $2}')" 2> "$data"
sel=$?
case $sel in
0) possible_password=$(cat "$data")
if [ "$possible_password" ]; then
if [ ${#possible_password} -gt 1 ]; then
valid_ddns_password=$(cat "$data")
DDNS_PASSWORD=$valid_ddns_password
break;
fi
fi
;;
1) rm -f "$data"
clear
exit 1;;
255) rm -f "$data"
clear
exit 1;;
esac
rm -f "$data"
if [ ${#DDNS_PASSWORD} -lt "$MINIMUM_PASSWORD_LENGTH" ]; then
dialog --title $"Password quality check" --msgbox $"The password given was too short. It must be at least $MINIMUM_PASSWORD_LENGTH characters. You may need to change your password on the dynamic DNS provider's web site." 10 40
DDNS_PASSWORD=""
fi
done
save_configuration_values
update_inadyn_config
fi
}
function choose_dynamic_dns {
if [[ "$SYSTEM_TYPE" != "mesh"* && "$ONION_ONLY" == "no" ]]; then
dialog --title $"Dynamic DNS" \
--backtitle $"Freedombone Configuration" \
--yesno $"\\nConfigure a dynamic DNS service?\\n\\nIf it is already handled by your internet router then select 'no'." 10 50
sel=$?
case $sel in
0) dynamic_dns_setup
;;
255) clear
exit 1
;;
esac
fi
}
if [ ! "$CONFIGURATION_FILE" ]; then
CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
fi
read_configuration_values
if [[ "$ONION_ONLY" != 'no' ]]; then
exit 0
fi
choose_dynamic_dns
clear
exit 0

View File

@ -94,6 +94,60 @@ EXTERNAL_IP_SERVICES=( \
'http://ipinfo.io/' \ 'http://ipinfo.io/' \
'http://httpbin.org/ip') 'http://httpbin.org/ip')
function update_inadyn_config {
if [ ! -f /etc/inadyn.conf ]; then
return
fi
if [[ "$DDNS_PROVIDER" == *'freedns'* ]]; then
return
fi
if ! grep -q "$DDNS_PROVIDER" /etc/inadyn.conf; then
# store any previous aliases
grep 'alias ' /etc/inadyn.conf > /tmp/inadyn_aliases
# remove entry for any previous ddns
sed -i '/system /,$d' /etc/inadyn.conf
# add the new provider
{ echo '';
echo "system $DDNS_PROVIDER";
echo ' ssl';
echo " checkip-url $GET_IP_ADDRESS_URL /"; } >> /etc/inadyn.conf
if [ "$DDNS_USERNAME" ]; then
echo " username $DDNS_USERNAME" >> /etc/inadyn.conf
fi
if [ "$DDNS_PASSWORD" ]; then
echo " password $DDNS_PASSWORD" >> /etc/inadyn.conf
fi
if [ -f /tmp/inadyn_aliases ]; then
cat /tmp/inadyn_aliases >> /etc/inadyn.conf
rm /tmp/inadyn_aliases
fi
else
# change username/password for an existing provider
if [ "$DDNS_USERNAME" ]; then
if grep -q " username " /etc/inadyn.conf; then
sed -i "s| username .*| username $DDNS_USERNAME|g" /etc/inadyn.conf
else
echo " username $DDNS_USERNAME" >> /etc/inadyn.conf
fi
fi
if [ "$DDNS_PASSWORD" ]; then
if grep -q " password " /etc/inadyn.conf; then
sed -i "s| password .*| password $DDNS_PASSWORD|g" /etc/inadyn.conf
else
echo " password $DDNS_PASSWORD" >> /etc/inadyn.conf
fi
fi
fi
systemctl enable inadyn
systemctl restart inadyn
}
function create_freedns_updater { function create_freedns_updater {
if [[ $ONION_ONLY != "no" ]]; then if [[ $ONION_ONLY != "no" ]]; then
return return
@ -137,6 +191,9 @@ function add_ddns_domain {
if [[ $ONION_ONLY != "no" ]]; then if [[ $ONION_ONLY != "no" ]]; then
return return
fi fi
if [ ! "$DDNS_PROVIDER" ]; then
return
fi
if [[ "$DDNS_PROVIDER" == 'none' ]]; then if [[ "$DDNS_PROVIDER" == 'none' ]]; then
return return
fi fi