From 0dac87f73d25845e900946ce3bdb6ae3e886165f Mon Sep 17 00:00:00 2001 From: geco91 Date: Thu, 29 Oct 2020 19:58:26 +0100 Subject: [PATCH] #1656 reducing calls on DNS requests (#1728) --- home.admin/00infoBlitz.sh | 5 +++-- home.admin/40addHDD.sh | 27 +++++---------------------- home.admin/config.scripts/internet.sh | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/home.admin/00infoBlitz.sh b/home.admin/00infoBlitz.sh index 902742bf..e323110a 100755 --- a/home.admin/00infoBlitz.sh +++ b/home.admin/00infoBlitz.sh @@ -20,7 +20,8 @@ source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status) hdd="${hddUsedInfo}" ## get internet info -source <(sudo /home/admin/config.scripts/internet.sh status global) +source <(sudo /home/admin/config.scripts/internet.sh status) +cleanip=$(echo "${publicIP}" | tr -d '[]') ## get UPS info source <(/home/admin/config.scripts/blitz.ups.sh status) @@ -180,7 +181,7 @@ else # IP address networkConnectionsInfo="${color_purple}${networkConnections} ${color_gray}connections" - public_addr="${publicip}:${public_port}" + public_addr="${publicIP}:${public_port}" public_check=$(nc -z -w6 ${cleanip} ${public_port} 2>/dev/null; echo $?) if [ $public_check = "0" ] || [ "${ipv6}" == "on" ] ; then public="" diff --git a/home.admin/40addHDD.sh b/home.admin/40addHDD.sh index 84394191..8773c24d 100755 --- a/home.admin/40addHDD.sh +++ b/home.admin/40addHDD.sh @@ -103,32 +103,15 @@ else echo "lcd2hdmi=${lcd2hdmi}" >> /home/admin/raspiblitz.conf echo "lcdrotate=1" >> /home/admin/raspiblitz.conf - # try to determine publicIP and if not possible use localIP as placeholder - # https://github.com/rootzoll/raspiblitz/issues/312#issuecomment-462675101 - freshPublicIP=$(curl -s http://v4.ipv6-test.com/api/myip.php) - - # sanity check on IP data - # see https://github.com/rootzoll/raspiblitz/issues/371#issuecomment-472416349 - echo "# sanity check of IP data:" - if [[ $freshPublicIP =~ ^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$ ]]; then - echo "# OK IPv6" - elif [[ $freshPublicIP =~ ^([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$ ]]; then - echo "# OK IPv4" - else - echo "# FAIL - not an IPv4 or IPv6 address" - freshPublicIP="" - fi - if [ ${#freshPublicIP} -eq 0 ]; then - localIP=$(ip addr | grep 'state UP' -A2 | egrep -v 'docker0|veth' | grep 'eth0\|wlan0\|enp0' | tail -n1 | awk '{print $2}' | cut -f1 -d'/') - echo "# WARNING: No publicIP information at all yet - working with placeholder : ${localIP}" - freshPublicIP="${localIP}" - fi - echo "publicIP='${freshPublicIP}'" >> /home/admin/raspiblitz.conf - sudo mv /home/admin/raspiblitz.conf $configFile sudo chown root:root ${configFile} sudo chmod 777 ${configFile} sleep 3 + + # try to determine publicIP and make sure its in raspiblitz.conf + # https://github.com/rootzoll/raspiblitz/issues/312#issuecomment-462675101 + /home/admin/config.scripts/internet.sh update-publicip + fi # link ssh directory from SD catd to HDD diff --git a/home.admin/config.scripts/internet.sh b/home.admin/config.scripts/internet.sh index 565b9680..b95e2a22 100755 --- a/home.admin/config.scripts/internet.sh +++ b/home.admin/config.scripts/internet.sh @@ -118,11 +118,26 @@ if [ ${runGlobal} -eq 1 ]; then ########################################### # Global IP # the public IP that can be detected from outside + globalIP="" + echo "# getting public IP from third party service" if [ "${ipv6}" == "on" ]; then globalIP=$(curl -s -f -S -m 5 http://v6.ipv6-test.com/api/myip.php 2>/dev/null) else globalIP=$(curl -s -f -S -m 5 http://v4.ipv6-test.com/api/myip.php 2>/dev/null) fi + + # sanity check on IP data + # see https://github.com/rootzoll/raspiblitz/issues/371#issuecomment-472416349 + echo "# sanity check of IP data:" + if [[ $globalIP =~ ^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$ ]]; then + echo "# OK IPv6" + elif [[ $globalIP =~ ^([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$ ]]; then + echo "# OK IPv4" + else + echo "# FAIL - not an IPv4 or IPv6 address" + globalIP="" + fi + # prevent having no publicIP set at all and LND getting stuck # https://github.com/rootzoll/raspiblitz/issues/312#issuecomment-462675101 if [ ${#globalIP} -eq 0 ]; then