From 3fb23f8c611187c8b215a6204505b7fd860548fa Mon Sep 17 00:00:00 2001 From: fred Date: Sat, 5 Nov 2022 12:32:16 +0100 Subject: [PATCH] isLAN or WAN => ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin --- 12345.sh | 7 +++++-- ASTROBOT/G1Voeu.sh | 5 ----- install.sh | 4 +++- tools/ipfs_setup.sh | 5 ++++- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/12345.sh b/12345.sh index b127e915..94751bfd 100755 --- a/12345.sh +++ b/12345.sh @@ -16,7 +16,9 @@ ME="${0##*/}" MOATS=$(date -u +"%Y%m%d%H%M%S%4N") IPFSNODEID=$(cat ~/.ipfs/config | jq -r .Identity.PeerID) myIP=$(hostname -I | awk '{print $1}' | head -n 1) -[[ ! $myIP ]] && myIP="127.0.1.1" +isLAN=$(echo $myIP | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") +[[ ! $myIP || $isLAN ]] && myIP="127.0.1.1" + PORT=12345 YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1); ## $USER running ipfs @@ -355,7 +357,8 @@ echo "" > ~/.zen/tmp/.ipfsgw.bad.twt # TODO move in 20h12.sh [[ ! $OLDIP ]] && (echo "$HTTPCORS 501 ERROR - SORRY - YOUR TW IS OUT OF SWARM#0 - CONTINUE " | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &) && echo "(☓‿‿☓) Execution time was "`expr $end - $start` seconds. && continue echo "TW is on $OLDIP" wasLAN=$(echo $OLDIP | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") - [[ ! $wasLAN ]] && TWIP=$OLDIP || TWIP=$myIP + [[ ! $wasLAN ]] && TWIP=$OLDIP \ + || TWIP=$myIP # LOCKED TW BECOMING ACTIVE GATEWAY if [[ $OLDIP == "_SECRET_" || "$TWIP" == "$myIP" ]]; then echo "_SECRET_ TW PUSHING TW" ## BECOMING OFFICIAL BECOME R/W TW diff --git a/ASTROBOT/G1Voeu.sh b/ASTROBOT/G1Voeu.sh index b0d2ac6a..b18be5f5 100755 --- a/ASTROBOT/G1Voeu.sh +++ b/ASTROBOT/G1Voeu.sh @@ -118,11 +118,6 @@ echo [[ -s ~/.zen/tmp/newindex.html ]] && cp ~/.zen/tmp/newindex.html ~/.zen/game/world/$WISHKEY/index.html [[ ! -s ~/.zen/tmp/newindex.html ]] && echo "ERROR ~/.zen/tmp/newindex.html MISSING" && exit 1 -## EXTEND ipfs daemon accreditation -ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://'$myIP':8080", "http://127.0.0.1:8080", "http://astroport:8080", "http://'$(hostname)'.home:8080" ]' -ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin ## CORS -echo "RESTART IPFS !?" - echo "# CREATION QR CODE" LIBRA=$(head -n 2 ~/.zen/Astroport.ONE/A_boostrap_nodes.txt | tail -n 1 | cut -d ' ' -f 2) diff --git a/install.sh b/install.sh index 935bafba..b59f450a 100755 --- a/install.sh +++ b/install.sh @@ -214,7 +214,9 @@ ipfs config --json Addresses.Swarm | jq '. += ["/ip4/0.0.0.0/tcp/30215/ws"]' > / ipfs config --json Addresses.Swarm "$(cat /tmp/30215.ws)" myIP=$(hostname -I | awk '{print $1}' | head -n 1) -ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://'$myIP':8080", "http://127.0.0.1:8080", "http://astroport", "https://astroport.com", "https://qo-op.com", "https://tube.copylaradio.com", "http://libra.copylaradio.com:8080" ]' +isLAN=$(echo $myIP | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") +[[ ! $isLAN ]] && ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://'$myIP':8080", "http://127.0.0.1:8080", "http://127.0.1.1:8080" ]' \ + || ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://127.0.0.1:8080", "http://127.0.1.1:8080" ]' ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]' ipfs config --json API.HTTPHeaders.Access-Control-Allow-Credentials '["true"]' diff --git a/tools/ipfs_setup.sh b/tools/ipfs_setup.sh index c4a26c5f..a168a6c3 100755 --- a/tools/ipfs_setup.sh +++ b/tools/ipfs_setup.sh @@ -90,7 +90,10 @@ ipfs config --json Experimental.Libp2pStreamMounting true ipfs config --json Experimental.P2pHttpProxy true ipfs config --json Swarm.ConnMgr.LowWater 0 ipfs config --json Swarm.ConnMgr.HighWater 0 -ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://127.0.0.1:8080", "http://astroport", "https://astroport.com", "https://qo-op.com", "https://tube.copylaradio.com" ]' +myIP=$(hostname -I | awk '{print $1}' | head -n 1) +isLAN=$(echo $myIP | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") +[[ ! $isLAN ]] && ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://'$myIP':8080", "http://127.0.0.1:8080", "http://127.0.1.1:8080" ]' \ + || ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["http://127.0.0.1:8080", "http://127.0.1.1:8080" ]' ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]' ipfs config --json API.HTTPHeaders.Access-Control-Allow-Credentials '["true"]'