From 947f9fdce947e79a498094f756e9d334aa8f1aa5 Mon Sep 17 00:00:00 2001 From: Nicolas Dorier Date: Tue, 11 Jun 2019 18:13:37 +0900 Subject: [PATCH] Make sure we do not announce domains ending in .lan and .local (#149) * Do not announce internal hostname * update environment on btcpay-update.sh * Rename to btcpay_update_docker_env * Properly quote enclose some env variables --- btcpay-setup.sh | 42 +++++-------------- btcpay-update.sh | 1 + changedomain.sh | 9 ++-- .../docker-fragments/bitcoin-clightning.yml | 2 +- .../docker-fragments/bitcoin-lnd.yml | 2 +- .../docker-fragments/litecoin-clightning.yml | 2 +- .../docker-fragments/litecoin-lnd.yml | 2 +- helpers.sh | 38 +++++++++++++++++ 8 files changed, 59 insertions(+), 39 deletions(-) diff --git a/btcpay-setup.sh b/btcpay-setup.sh index b2540e0..0b89469 100755 --- a/btcpay-setup.sh +++ b/btcpay-setup.sh @@ -109,9 +109,9 @@ fi : "${ACME_CA_URI:=https://acme-v01.api.letsencrypt.org/directory}" : "${BTCPAY_PROTOCOL:=https}" -OLD_BTCPAY_DOCKER_COMPOSE=$BTCPAY_DOCKER_COMPOSE -ORIGINAL_DIRECTORY=$(pwd) -BTCPAY_BASE_DIRECTORY="$(dirname $(pwd))" +OLD_BTCPAY_DOCKER_COMPOSE="$BTCPAY_DOCKER_COMPOSE" +ORIGINAL_DIRECTORY="$(pwd)" +BTCPAY_BASE_DIRECTORY="$(dirname "$(pwd)")" if [ "$BTCPAYGEN_OLD_PREGEN" == "true" ]; then if [[ $(dirname $BTCPAY_DOCKER_COMPOSE) == *Production ]]; then @@ -146,16 +146,11 @@ if [[ "$BTCPAYGEN_REVERSEPROXY" == "nginx" ]] && [[ "$BTCPAY_HOST" ]]; then BTCPAY_HOST="$DOMAIN_NAME" fi -BTCPAY_CRYPTOS="" -for i in "$BTCPAYGEN_CRYPTO1" "$BTCPAYGEN_CRYPTO2" "$BTCPAYGEN_CRYPTO3" "$BTCPAYGEN_CRYPTO4" "$BTCPAYGEN_CRYPTO5" "$BTCPAYGEN_CRYPTO5" "$BTCPAYGEN_CRYPTO6" "$BTCPAYGEN_CRYPTO7" "$BTCPAYGEN_CRYPTO8" -do - if [ ! -z "$i" ]; then - if [ ! -z "$BTCPAY_CRYPTOS" ]; then - BTCPAY_CRYPTOS="$BTCPAY_CRYPTOS;" - fi - BTCPAY_CRYPTOS="$BTCPAY_CRYPTOS$i" - fi -done +cd "$BTCPAY_BASE_DIRECTORY/btcpayserver-docker" +. helpers.sh +btcpay_expand_variables + +cd "$ORIGINAL_DIRECTORY" echo " -------SETUP----------- @@ -193,6 +188,7 @@ BTCPAYGEN_OLD_PREGEN=$BTCPAYGEN_OLD_PREGEN BTCPAY_SSHKEYFILE=$BTCPAY_SSHKEYFILE BTCPAY_SSHTRUSTEDFINGERPRINTS:$BTCPAY_SSHTRUSTEDFINGERPRINTS BTCPAY_CRYPTOS:$BTCPAY_CRYPTOS +BTCPAY_ANNOUNCEABLE_HOST:$BTCPAY_ANNOUNCEABLE_HOST ---------------------- " @@ -235,22 +231,7 @@ chmod +x /etc/profile.d/btcpay-env.sh echo -e "BTCPay Server environment variables successfully saved in /etc/profile.d/btcpay-env.sh\n" -# Set .env file -touch $BTCPAY_ENV_FILE -echo " -BTCPAY_PROTOCOL=$BTCPAY_PROTOCOL -BTCPAY_HOST=$BTCPAY_HOST -BTCPAY_IMAGE=$BTCPAY_IMAGE -ACME_CA_URI=$ACME_CA_URI -NBITCOIN_NETWORK=$NBITCOIN_NETWORK -LETSENCRYPT_EMAIL=$LETSENCRYPT_EMAIL -LIGHTNING_ALIAS=$LIGHTNING_ALIAS -BTCPAY_SSHTRUSTEDFINGERPRINTS=$BTCPAY_SSHTRUSTEDFINGERPRINTS -BTCPAY_SSHKEYFILE=$BTCPAY_SSHKEYFILE -LIBREPATRON_HOST=$LIBREPATRON_HOST -BTCTRANSMUTER_HOST=$BTCTRANSMUTER_HOST -BTCPAY_CRYPTOS=$BTCPAY_CRYPTOS -WOOCOMMERCE_HOST=$WOOCOMMERCE_HOST" > $BTCPAY_ENV_FILE +btcpay_update_docker_env echo -e "BTCPay Server docker-compose parameters saved in $BTCPAY_ENV_FILE\n" . /etc/profile.d/btcpay-env.sh @@ -406,8 +387,7 @@ if [[ -f "$BTCPAY_HOST_SSHKEYFILE" ]]; then docker cp "$BTCPAY_HOST_SSHKEYFILE" $(docker ps --filter "name=_btcpayserver_" -q):$BTCPAY_SSHKEYFILE fi -cd "$BTCPAY_BASE_DIRECTORY/btcpayserver-docker" -. helpers.sh +cd "$BTCPAY_BASE_DIRECTORY/btcpayserver-docker" install_tooling cd $ORIGINAL_DIRECTORY diff --git a/btcpay-update.sh b/btcpay-update.sh index 0f0b2fe..fb3c8d0 100755 --- a/btcpay-update.sh +++ b/btcpay-update.sh @@ -43,6 +43,7 @@ fi . helpers.sh install_tooling +btcpay_update_docker_env cd "`dirname $BTCPAY_ENV_FILE`" docker-compose -f $BTCPAY_DOCKER_COMPOSE up -d --remove-orphans -t "${COMPOSE_HTTP_TIMEOUT:-180}" diff --git a/changedomain.sh b/changedomain.sh index d4cdb83..c3ca9d4 100755 --- a/changedomain.sh +++ b/changedomain.sh @@ -13,11 +13,12 @@ echo "Changing domain from \"$OLD_HOST\" to \"$NEW_HOST\"" export BTCPAY_HOST="$NEW_HOST" export ACME_CA_URI="https://acme-v01.api.letsencrypt.org/directory" +ORIGINAL_DIRECTORY="$(pwd)" # Modify environment file -sed -i '/^BTCPAY_HOST/d' "$BTCPAY_ENV_FILE" -sed -i '/^ACME_CA_URI/d' "$BTCPAY_ENV_FILE" -echo "BTCPAY_HOST=$BTCPAY_HOST" >> "$BTCPAY_ENV_FILE" -echo "ACME_CA_URI=$ACME_CA_URI" >> "$BTCPAY_ENV_FILE" +cd "$BTCPAY_BASE_DIRECTORY/btcpayserver-docker" +. helpers.sh +btcpay_update_docker_env +cd "$ORIGINAL_DIRECTORY" cd "`dirname $BTCPAY_ENV_FILE`" docker-compose -f "$BTCPAY_DOCKER_COMPOSE" up -d -t "${COMPOSE_HTTP_TIMEOUT:-180}" diff --git a/docker-compose-generator/docker-fragments/bitcoin-clightning.yml b/docker-compose-generator/docker-fragments/bitcoin-clightning.yml index 8a90963..a30cc60 100644 --- a/docker-compose-generator/docker-fragments/bitcoin-clightning.yml +++ b/docker-compose-generator/docker-fragments/bitcoin-clightning.yml @@ -9,7 +9,7 @@ services: LIGHTNINGD_NETWORK: ${NBITCOIN_NETWORK:-regtest} LIGHTNINGD_CHAIN: btc LIGHTNINGD_ALIAS: ${LIGHTNING_ALIAS} - LIGHTNINGD_ANNOUNCEADDR: ${BTCPAY_HOST} + LIGHTNINGD_ANNOUNCEADDR: ${BTCPAY_ANNOUNCEABLE_HOST} LIGHTNINGD_PORT: 9735 LIGHTNINGD_READY_FILE: /root/.nbxplorer/btc_fully_synched LIGHTNINGD_OPT: | diff --git a/docker-compose-generator/docker-fragments/bitcoin-lnd.yml b/docker-compose-generator/docker-fragments/bitcoin-lnd.yml index ff7a3e9..9626707 100644 --- a/docker-compose-generator/docker-fragments/bitcoin-lnd.yml +++ b/docker-compose-generator/docker-fragments/bitcoin-lnd.yml @@ -7,7 +7,7 @@ services: restart: unless-stopped environment: LND_CHAIN: "btc" - LND_EXTERNALIP: ${BTCPAY_HOST} + LND_EXTERNALIP: ${BTCPAY_ANNOUNCEABLE_HOST} LND_PORT: 9735 LND_ALIAS: ${LIGHTNING_ALIAS} LND_ENVIRONMENT: "${NBITCOIN_NETWORK:-regtest}" diff --git a/docker-compose-generator/docker-fragments/litecoin-clightning.yml b/docker-compose-generator/docker-fragments/litecoin-clightning.yml index 678e990..dc9deb1 100644 --- a/docker-compose-generator/docker-fragments/litecoin-clightning.yml +++ b/docker-compose-generator/docker-fragments/litecoin-clightning.yml @@ -9,7 +9,7 @@ services: LIGHTNINGD_NETWORK: ${NBITCOIN_NETWORK:-regtest} LIGHTNINGD_CHAIN: ltc LIGHTNINGD_ALIAS: ${LIGHTNING_ALIAS} - LIGHTNINGD_ANNOUNCEADDR: ${BTCPAY_HOST} + LIGHTNINGD_ANNOUNCEADDR: ${BTCPAY_ANNOUNCEABLE_HOST} LIGHTNINGD_PORT: 9735 LIGHTNINGD_READY_FILE: /root/.nbxplorer/ltc_fully_synched LIGHTNINGD_OPT: | diff --git a/docker-compose-generator/docker-fragments/litecoin-lnd.yml b/docker-compose-generator/docker-fragments/litecoin-lnd.yml index a437479..73f46d6 100644 --- a/docker-compose-generator/docker-fragments/litecoin-lnd.yml +++ b/docker-compose-generator/docker-fragments/litecoin-lnd.yml @@ -7,7 +7,7 @@ services: restart: unless-stopped environment: LND_CHAIN: "ltc" - LND_EXTERNALIP: ${BTCPAY_HOST} + LND_EXTERNALIP: ${BTCPAY_ANNOUNCEABLE_HOST} LND_PORT: 9736 LND_ALIAS: ${LIGHTNING_ALIAS} LND_ENVIRONMENT: "${NBITCOIN_NETWORK:-regtest}" diff --git a/helpers.sh b/helpers.sh index 75521d0..ad4cd1b 100755 --- a/helpers.sh +++ b/helpers.sh @@ -44,4 +44,42 @@ install_tooling() { fi i=`expr $i + 3` done +} + +btcpay_expand_variables() { + BTCPAY_CRYPTOS="" + for i in "$BTCPAYGEN_CRYPTO1" "$BTCPAYGEN_CRYPTO2" "$BTCPAYGEN_CRYPTO3" "$BTCPAYGEN_CRYPTO4" "$BTCPAYGEN_CRYPTO5" "$BTCPAYGEN_CRYPTO5" "$BTCPAYGEN_CRYPTO6" "$BTCPAYGEN_CRYPTO7" "$BTCPAYGEN_CRYPTO8" + do + if [ ! -z "$i" ]; then + if [ ! -z "$BTCPAY_CRYPTOS" ]; then + BTCPAY_CRYPTOS="$BTCPAY_CRYPTOS;" + fi + BTCPAY_CRYPTOS="$BTCPAY_CRYPTOS$i" + fi + done + BTCPAY_ANNOUNCEABLE_HOST="" + if [[ "$BTCPAY_HOST" != *.local ]] && [[ "$BTCPAY_HOST" != *.lan ]]; then + BTCPAY_ANNOUNCEABLE_HOST="$BTCPAY_HOST" + fi +} + +# Set .env file +btcpay_update_docker_env() { +btcpay_expand_variables +touch $BTCPAY_ENV_FILE +echo " +BTCPAY_PROTOCOL=$BTCPAY_PROTOCOL +BTCPAY_HOST=$BTCPAY_HOST +BTCPAY_ANNOUNCEABLE_HOST=$BTCPAY_ANNOUNCEABLE_HOST +BTCPAY_IMAGE=$BTCPAY_IMAGE +ACME_CA_URI=$ACME_CA_URI +NBITCOIN_NETWORK=$NBITCOIN_NETWORK +LETSENCRYPT_EMAIL=$LETSENCRYPT_EMAIL +LIGHTNING_ALIAS=$LIGHTNING_ALIAS +BTCPAY_SSHTRUSTEDFINGERPRINTS=$BTCPAY_SSHTRUSTEDFINGERPRINTS +BTCPAY_SSHKEYFILE=$BTCPAY_SSHKEYFILE +LIBREPATRON_HOST=$LIBREPATRON_HOST +BTCTRANSMUTER_HOST=$BTCTRANSMUTER_HOST +BTCPAY_CRYPTOS=$BTCPAY_CRYPTOS +WOOCOMMERCE_HOST=$WOOCOMMERCE_HOST" > $BTCPAY_ENV_FILE } \ No newline at end of file