freedombone-ddns 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # Change dynamic dns settings
  10. #
  11. # License
  12. # =======
  13. #
  14. # Copyright (C) 2018 Bob Mottram <bob@freedombone.net>
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU Affero General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU Affero General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU Affero General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. PROJECT_NAME='freedombone'
  29. export TEXTDOMAIN=${PROJECT_NAME}-ddns
  30. export TEXTDOMAINDIR="/usr/share/locale"
  31. source "/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-config"
  32. DDNS_PROVIDER="none"
  33. DDNS_USERNAME=
  34. DDNS_PASSWORD=
  35. function update_inadyn_config {
  36. if [ ! -f /etc/inadyn.conf ]; then
  37. return
  38. fi
  39. if [[ "$DDNS_PROVIDER" == *'freedns'* ]]; then
  40. return
  41. fi
  42. if ! grep -q "$DDNS_PROVIDER" /etc/inadyn.conf; then
  43. # remove entry for any previous ddns
  44. sed -i '/system /,$d' /etc/inadyn.conf
  45. # add the new provider
  46. { echo '';
  47. echo "system $DDNS_PROVIDER";
  48. echo ' ssl';
  49. echo " checkip-url $GET_IP_ADDRESS_URL /"; } >> /etc/inadyn.conf
  50. if [ "$DDNS_USERNAME" ]; then
  51. echo " username $DDNS_USERNAME" >> /etc/inadyn.conf
  52. fi
  53. if [ "$DDNS_PASSWORD" ]; then
  54. echo " password $DDNS_PASSWORD" >> /etc/inadyn.conf
  55. fi
  56. else
  57. # change username/password for an existing provider
  58. if [ "$DDNS_USERNAME" ]; then
  59. sed -i "s| username .*| username $DDNS_USERNAME|g" /etc/inadyn.conf
  60. fi
  61. if [ "$DDNS_PASSWORD" ]; then
  62. sed -i "s| password .*| password $DDNS_PASSWORD|g" /etc/inadyn.conf
  63. fi
  64. fi
  65. systemctl enable inadyn
  66. systemctl restart inadyn
  67. }
  68. function dynamic_dns_setup {
  69. DDNS_PROVIDER='none'
  70. W=(1 freedns.afraid.org
  71. 2 dyn.com
  72. 3 zoneedit.com
  73. 4 no-ip.com
  74. 5 easydns.com
  75. 6 dnsomatic.com
  76. 7 dns.he.net
  77. 8 tunnelbroker.net
  78. 9 sitelutions.com
  79. 10 dnsexit.com
  80. 11 changeip.com
  81. 12 zerigo.com
  82. 13 dhis.org
  83. 14 nsupdate.info
  84. 15 loopia.com
  85. 16 namecheap.com
  86. 17 ovh.com
  87. 18 dtdns.com
  88. 19 giradns.com
  89. 20 duiadns.net
  90. 21 ddnss.de
  91. 22 dynv6.com
  92. 23 ipv4.dynv6.com
  93. 24 spdyn.de
  94. 25 freemyip.com
  95. 26 cloudxns.net)
  96. # shellcheck disable=SC2068
  97. 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)
  98. if [ ! "$selection" ]; then
  99. if [ -f /etc/systemd/system/inadyn.service ]; then
  100. systemctl stop inadyn
  101. systemctl disable inadyn
  102. fi
  103. return
  104. fi
  105. case $selection in
  106. 1) DDNS_PROVIDER="default@freedns.afraid.org";;
  107. 2) DDNS_PROVIDER="default@www.dyn.com";;
  108. 3) DDNS_PROVIDER="default@www.zoneedit.com";;
  109. 4) DDNS_PROVIDER="default@www.no-ip.com";;
  110. 5) DDNS_PROVIDER="default@www.easydns.com";;
  111. 6) DDNS_PROVIDER="default@www.dnsomatic.com";;
  112. 7) DDNS_PROVIDER="default@dns.he.net";;
  113. 8) DDNS_PROVIDER="default@www.tunnelbroker.net";;
  114. 9) DDNS_PROVIDER="default@www.sitelutions.com";;
  115. 10) DDNS_PROVIDER="default@www.dnsexit.com";;
  116. 11) DDNS_PROVIDER="default@www.changeip.com";;
  117. 12) DDNS_PROVIDER="default@www.zerigo.com";;
  118. 13) DDNS_PROVIDER="default@www.dhis.org";;
  119. 14) DDNS_PROVIDER="default@nsupdate.info";;
  120. 15) DDNS_PROVIDER="default@www.loopia.com";;
  121. 16) DDNS_PROVIDER="default@www.namecheap.com";;
  122. 17) DDNS_PROVIDER="default@www.ovh.com";;
  123. 18) DDNS_PROVIDER="default@www.dtdns.com";;
  124. 19) DDNS_PROVIDER="default@giradns.com";;
  125. 20) DDNS_PROVIDER="default@www.duiadns.net";;
  126. 21) DDNS_PROVIDER="default@ddnss.de";;
  127. 22) DDNS_PROVIDER="default@dynv6.com";;
  128. 23) DDNS_PROVIDER="default@ipv4.dynv6.com";;
  129. 24) DDNS_PROVIDER="default@spdyn.de";;
  130. 25) DDNS_PROVIDER="default@freemyip.com";;
  131. 26) DDNS_PROVIDER="default@www.cloudxns.net";;
  132. esac
  133. save_configuration_values
  134. valid_ddns_username=
  135. valid_ddns_password=
  136. if [[ "$DDNS_PROVIDER" == "none" ]]; then
  137. if [ -f /etc/systemd/system/inadyn.service ]; then
  138. systemctl stop inadyn
  139. systemctl disable inadyn
  140. fi
  141. else
  142. while [ ! $valid_ddns_username ]
  143. do
  144. data=$(mktemp 2>/dev/null)
  145. dialog --backtitle $"Freedombone Configuration" \
  146. --inputbox $"Dynamic DNS provider username" 10 30 "$(grep 'DDNS_USERNAME' temp.cfg | awk -F '=' '{print $2}')" 2> "$data"
  147. sel=$?
  148. case $sel in
  149. 0) possible_username=$(cat "$data")
  150. if [ "$possible_username" ]; then
  151. if [ ${#possible_username} -gt 1 ]; then
  152. valid_ddns_username=$(cat "$data")
  153. # shellcheck disable=SC2034
  154. DDNS_USERNAME="$valid_ddns_username"
  155. rm -f "$data"
  156. break;
  157. fi
  158. fi
  159. ;;
  160. 1) rm -f "$data"
  161. clear
  162. exit 1;;
  163. 255) rm -f "$data"
  164. clear
  165. exit 1;;
  166. esac
  167. rm -f "$data"
  168. done
  169. save_configuration_values
  170. while [ ! $valid_ddns_password ]
  171. do
  172. data=$(mktemp 2>/dev/null)
  173. dialog --backtitle $"Freedombone Configuration" \
  174. --clear \
  175. --insecure \
  176. --passwordbox $"Dynamic DNS provider password" 10 30 "$(grep 'DDNS_PASSWORD' temp.cfg | awk -F '=' '{print $2}')" 2> "$data"
  177. sel=$?
  178. case $sel in
  179. 0) possible_password=$(cat "$data")
  180. if [ "$possible_password" ]; then
  181. if [ ${#possible_password} -gt 1 ]; then
  182. valid_ddns_password=$(cat "$data")
  183. DDNS_PASSWORD=$valid_ddns_password
  184. break;
  185. fi
  186. fi
  187. ;;
  188. 1) rm -f "$data"
  189. clear
  190. exit 1;;
  191. 255) rm -f "$data"
  192. clear
  193. exit 1;;
  194. esac
  195. rm -f "$data"
  196. if [ ${#DDNS_PASSWORD} -lt "$MINIMUM_PASSWORD_LENGTH" ]; then
  197. 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
  198. DDNS_PASSWORD=""
  199. fi
  200. done
  201. save_configuration_values
  202. update_inadyn_config
  203. fi
  204. }
  205. function choose_dynamic_dns {
  206. if [[ "$SYSTEM_TYPE" != "mesh"* && "$ONION_ONLY" == "no" ]]; then
  207. dialog --title $"Dynamic DNS" \
  208. --backtitle $"Freedombone Configuration" \
  209. --yesno $"\\nConfigure a dynamic DNS service?\\n\\nIf it is already handled by your internet router then select 'no'." 10 50
  210. sel=$?
  211. case $sel in
  212. 0) dynamic_dns_setup
  213. ;;
  214. 255) clear
  215. exit 1
  216. ;;
  217. esac
  218. fi
  219. }
  220. if [ ! "$CONFIGURATION_FILE" ]; then
  221. CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
  222. fi
  223. read_configuration_values
  224. if [[ "$ONION_ONLY" != 'no' ]]; then
  225. exit 0
  226. fi
  227. choose_dynamic_dns
  228. clear
  229. exit 0