2023-12-02 22:27:45 +01:00
|
|
|
################################################################################
|
|
|
|
# Author: Fred (support@qo-op.com)
|
|
|
|
# Version: 0.1
|
|
|
|
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
|
|
|
################################################################################
|
|
|
|
################################################################################
|
|
|
|
## API: ZONE
|
|
|
|
## Used by OSM2IPFS map_render.html & other UPlanet Client App
|
|
|
|
# ?zone=DEG&ulat=LAT&ulon=LON
|
2024-02-15 14:53:26 +01:00
|
|
|
## Search for TW numbers in received zone # >> return json
|
2023-12-02 22:27:45 +01:00
|
|
|
################################################################################
|
|
|
|
MY_PATH="`dirname \"$0\"`" # relative
|
|
|
|
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
|
|
|
. "${MY_PATH}/../tools/my.sh"
|
|
|
|
|
|
|
|
start=`date +%s`
|
|
|
|
|
|
|
|
echo "PORT=$1
|
|
|
|
THAT=$2
|
|
|
|
AND=$3
|
|
|
|
THIS=$4
|
|
|
|
APPNAME=$5
|
|
|
|
WHAT=$6
|
|
|
|
OBJ=$7
|
|
|
|
VAL=$8
|
|
|
|
MOATS=$9
|
|
|
|
COOKIE=$10"
|
|
|
|
PORT="$1" THAT="$2" AND="$3" THIS="$4" APPNAME="$5" WHAT="$6" OBJ="$7" VAL="$8" MOATS="$9" COOKIE="$10"
|
|
|
|
### transfer variables according to script
|
|
|
|
|
|
|
|
HTTPCORS="HTTP/1.1 200 OK
|
2023-12-03 22:15:46 +01:00
|
|
|
Access-Control-Allow-Origin: *
|
2023-12-02 22:27:45 +01:00
|
|
|
Access-Control-Allow-Credentials: true
|
|
|
|
Access-Control-Allow-Methods: GET
|
|
|
|
Server: Astroport.ONE
|
|
|
|
Content-Type: text/html; charset=UTF-8
|
|
|
|
|
|
|
|
"
|
2023-12-03 22:15:46 +01:00
|
|
|
|
2023-12-02 22:27:45 +01:00
|
|
|
function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
|
|
|
|
|
2023-12-30 03:30:43 +01:00
|
|
|
## RUNNING UPLANET LAT/LON TW DETECTION
|
2023-12-02 22:27:45 +01:00
|
|
|
mkdir -p ~/.zen/tmp/${MOATS}/
|
2024-02-15 15:20:27 +01:00
|
|
|
# PREPARE HTTP RESPONSE (application/json)
|
|
|
|
echo "${HTTPCORS}" > ~/.zen/tmp/${MOATS}.http
|
|
|
|
sed -i "s~text/html~application/json~g" ~/.zen/tmp/${MOATS}.http
|
|
|
|
|
2024-02-15 14:53:26 +01:00
|
|
|
# ------------------------------------------------------------------- #
|
|
|
|
# GET/?zone=0.001&ulat=0.02&ulon=0.01
|
|
|
|
# ------------------------------------------------------------------- #
|
|
|
|
|
2024-02-15 15:20:27 +01:00
|
|
|
DEG="${THAT}"
|
|
|
|
[[ -z ${DEG} ]] && DEG=1
|
|
|
|
# DEG=$(echo "${DEG} * 10" | bc -l )
|
|
|
|
|
|
|
|
LAT="${THIS}"
|
2023-12-03 22:15:46 +01:00
|
|
|
[[ -z $LAT ]] && LAT=0.00
|
|
|
|
|
2024-02-15 15:20:27 +01:00
|
|
|
LON="${WHAT}"
|
|
|
|
[[ -z $LON ]] && LON=0.00
|
2023-12-04 12:58:28 +01:00
|
|
|
|
2024-02-15 15:20:27 +01:00
|
|
|
LAT=$(makecoord ${LAT})
|
|
|
|
LON=$(makecoord ${LON})
|
|
|
|
JSON="ZONE_${LAT}_${LON}_${DEG}.json"
|
2023-12-04 14:05:43 +01:00
|
|
|
|
2024-02-15 15:20:27 +01:00
|
|
|
## SECTOR LEVEL
|
|
|
|
if [[ ${DEG} == "0.01" ]]; then
|
2024-03-12 00:40:23 +01:00
|
|
|
SECLAT="${LAT::-1}"
|
|
|
|
SECLON="${LON::-1}"
|
2024-02-15 15:20:27 +01:00
|
|
|
SECTOR="_${SECLAT}_${SECLON}"
|
|
|
|
echo "SECTOR = ${SECTOR}"
|
2024-03-26 01:19:52 +01:00
|
|
|
ZONEINDEX="/ipns/"$(cat ~/.zen/tmp/swarm/*/UPLANET/__/_*_*/_*.?_*.?/_${SECLAT}*_${SECLON}*/SECTORNS | tail -n 1)
|
|
|
|
[[ ! $ZONEINDEX ]] && ZONEINDEX="/ipns/"$(cat ~/.zen/tmp/${IPFSNODEID}/UPLANET/__/_*_*/_*.?_*.?/_${SECLAT}*_${SECLON}*/SECTORNS | tail -n 1)
|
|
|
|
ZONEG1PUB=$(cat ~/.zen/tmp/swarm/*/UPLANET/__/_*_*/_*.?_*.?/_${SECLAT}*_${SECLON}*/SECTORG1PUB | tail -n 1)
|
|
|
|
[[ ! $ZONEG1PUB ]] && ZONEG1PUB=$(cat ~/.zen/tmp/${IPFSNODEID}/UPLANET/__/_*_*/_*.?_*.?/_${SECLAT}*_${SECLON}*/SECTORG1PUB | tail -n 1)
|
2024-02-15 15:20:27 +01:00
|
|
|
JSON="ZONE${SECTOR}_${DEG}.json"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
## REGION & ABOVE LEVEL
|
|
|
|
if [[ ${DEG} == "0.1" || ${DEG} == "1" ]]; then
|
|
|
|
LAT=$(echo ${LAT} | cut -d '.' -f 1)
|
|
|
|
LON=$(echo ${LON} | cut -d '.' -f 1)
|
|
|
|
ZONE="_${LAT}_${LON}"
|
|
|
|
echo "ZONE = ${ZONE}"
|
2024-03-26 01:19:52 +01:00
|
|
|
ZONEINDEX="/ipns/"$(cat ~/.zen/tmp/swarm/*/UPLANET/__/_*_*/_*.?_*.?/_${LAT}*_${LON}*/REGIONNS | tail -n 1)
|
|
|
|
[[ ! $ZONEINDEX ]] && ZONEINDEX="/ipns/"$(cat ~/.zen/tmp/${IPFSNODEID}/UPLANET/__/_*_*/_*.?_*.?/_${LAT}*_${LON}*/REGIONNS | tail -n 1)
|
2024-03-26 00:38:42 +01:00
|
|
|
ZONEG1PUB=$(cat ~/.zen/tmp/swarm/*/UPLANET/__/_*_*/_*.?_*.?/_${LAT}*_${LON}*/REGIONG1PUB | tail -n 1)
|
|
|
|
[[ ! $ZONEG1PUB ]] && ZONEG1PUB=$(cat ~/.zen/tmp/${IPFSNODEID}/UPLANET/__/_*_*/_*.?_*.?/_${LAT}*_${LON}*/REGIONG1PUB | tail -n 1)
|
2024-02-15 15:20:27 +01:00
|
|
|
JSON="ZONE${ZONE}_${DEG}.json"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo " JSON = ${JSON}"
|
|
|
|
|
|
|
|
if [[ ! -s ~/.zen/tmp/${JSON} ]]; then
|
2023-12-30 20:16:39 +01:00
|
|
|
|
2024-02-14 15:38:40 +01:00
|
|
|
## UMAP LEVEL
|
2024-02-15 15:20:27 +01:00
|
|
|
if [[ ${DEG} == "0.001" ]]; then
|
2023-12-31 18:46:23 +01:00
|
|
|
|
2024-02-14 15:38:40 +01:00
|
|
|
swarmnum=$(ls -d ~/.zen/tmp/swarm/*/UPLANET/__/_*_*/_*.?_*.?/_${LAT}*_${LON}*/TW/* 2>/dev/null | wc -l )
|
|
|
|
nodenum=$(ls -d ~/.zen/tmp/${IPFSNODEID}/UPLANET/__/_*_*/_*.?_*.?/_${LAT}*_${LON}*/TW/* 2>/dev/null | wc -l )
|
|
|
|
totnum=$(( swarmnum + nodenum ))
|
|
|
|
echo " ## UMAP _${LAT}*_${LON}* = ${totnum} PLAYERs"
|
2023-12-05 16:33:32 +01:00
|
|
|
|
2024-03-26 00:38:42 +01:00
|
|
|
UMAPNS=$(cat ~/.zen/tmp/swarm/*/UPLANET/__/_*_*/_*.?_*.?/_${LAT}*_${LON}*/TODATENS)
|
|
|
|
[[ ! $UMAPNS ]] && UMAPNS=$(cat ~/.zen/tmp/${IPFSNODEID}/UPLANET/__/_*_*/_*.?_*.?/_${LAT}*_${LON}*/TODATENS)
|
|
|
|
G1PUB=$(cat ~/.zen/tmp/swarm/*/UPLANET/__/_*_*/_*.?_*.?/_${LAT}*_${LON}*/G1PUB)
|
|
|
|
[[ ! $G1PUB ]] && G1PUB=$(cat ~/.zen/tmp/${IPFSNODEID}/UPLANET/__/_*_*/_*.?_*.?/_${LAT}*_${LON}*/G1PUB)
|
2023-12-30 03:30:43 +01:00
|
|
|
|
2024-02-15 15:20:27 +01:00
|
|
|
echo '{ "gridNumbers": [ {"lat": '${LAT}', "lon": '${LON}', "number": "(_'${LAT}'_'${LON}') = '${totnum}'", "ipns": "'${myIPFS}/ipns/${UMAPNS}/_index.html'" } ] }' \
|
2024-02-27 02:03:29 +01:00
|
|
|
> ~/.zen/tmp/${MOATS}/http.grid
|
2024-02-15 15:20:27 +01:00
|
|
|
|
2024-02-27 02:03:29 +01:00
|
|
|
cp ~/.zen/tmp/${MOATS}/http.grid ~/.zen/tmp/${JSON}
|
2024-02-15 14:53:26 +01:00
|
|
|
cat ~/.zen/tmp/${JSON} >> ~/.zen/tmp/${MOATS}.http
|
2024-02-14 15:38:40 +01:00
|
|
|
|
|
|
|
cat ~/.zen/tmp/${MOATS}.http | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &
|
|
|
|
|
|
|
|
rm -Rf ~/.zen/tmp/${MOATS}/
|
|
|
|
end=`date +%s`
|
2024-03-26 01:19:52 +01:00
|
|
|
echo "(UMAP)_${LAT}_${LON} $UMAPNS Operation time was "`expr $end - $start` seconds.
|
2024-02-14 15:38:40 +01:00
|
|
|
exit 0
|
2023-12-04 12:58:28 +01:00
|
|
|
|
2024-02-14 15:38:40 +01:00
|
|
|
fi
|
2023-12-04 12:58:28 +01:00
|
|
|
|
2024-02-15 15:20:27 +01:00
|
|
|
##############################################
|
|
|
|
## SEARCH FOR UPLANET TW NUMBERS IN THAT ZONE
|
2024-02-27 02:03:29 +01:00
|
|
|
echo '{ "gridNumbers": [' >> ~/.zen/tmp/${MOATS}/http.grid
|
2023-12-04 12:58:28 +01:00
|
|
|
|
2024-02-14 15:38:40 +01:00
|
|
|
for i in $(seq 0 9);
|
|
|
|
do
|
2024-02-27 02:03:29 +01:00
|
|
|
|
|
|
|
ZLAT=$(echo "$LAT + ${DEG} * $i" | bc -l)
|
2024-02-14 15:38:40 +01:00
|
|
|
[[ -z ${ZLAT} ]] && ZLAT=0
|
2024-02-27 02:03:29 +01:00
|
|
|
|
|
|
|
for j in $(seq 0 9); do
|
|
|
|
|
|
|
|
ZLON=$(echo "$LON + ${DEG} * $j" | bc -l)
|
|
|
|
[[ -z ${ZLON} ]] && ZLON=0
|
|
|
|
|
|
|
|
echo " ## SEARCH UPLANET/__/_*_*/_*.?_*.?/_${ZLAT}*_${ZLON}*"
|
|
|
|
swarmnum=$(ls -d ~/.zen/tmp/swarm/*/UPLANET/__/_*_*/_*.?_*.?/_${ZLAT}*_${ZLON}*/TW/* 2>/dev/null | wc -l )
|
|
|
|
nodenum=$(ls -d ~/.zen/tmp/${IPFSNODEID}/UPLANET/__/_*_*/_*.?_*.?/_${ZLAT}*_${ZLON}*/TW/* 2>/dev/null | wc -l )
|
|
|
|
totnum=$(( swarmnum + nodenum ))
|
|
|
|
|
|
|
|
[[ $totnum -gt 9 ]] && displaynum="X" || displaynum=$totnum
|
|
|
|
|
|
|
|
[[ $displaynum != "0" ]] && echo '{"lat": '${ZLAT}', "lon": '${ZLON}', "number": "'${displaynum}'", "ipns": "'${ZONEINDEX}'" }
|
|
|
|
,' >> ~/.zen/tmp/${MOATS}/http.grid \
|
|
|
|
&& echo "${DEG} :" '{"lat": '${ZLAT}', "lon": '${ZLON}', "number": "'${totnum}'", "ipns": "'${ZONEINDEX}'" }'
|
|
|
|
|
|
|
|
done
|
|
|
|
|
2024-02-14 15:38:40 +01:00
|
|
|
done
|
|
|
|
|
2024-02-27 02:03:29 +01:00
|
|
|
[[ ! $(cat ~/.zen/tmp/${MOATS}/http.grid | tail -n 1 | grep 'gridNumbers' ) ]] \
|
|
|
|
&& sed -i '$ d' ~/.zen/tmp/${MOATS}/http.grid ## REMOVE LAST ','
|
|
|
|
|
|
|
|
echo ']}' >> ~/.zen/tmp/${MOATS}/http.grid
|
2024-02-14 15:38:40 +01:00
|
|
|
|
2024-02-15 15:20:27 +01:00
|
|
|
echo "## ADD TO CACHE ~/.zen/tmp/${JSON}"
|
2024-02-27 02:03:29 +01:00
|
|
|
cp ~/.zen/tmp/${MOATS}/http.grid ~/.zen/tmp/${JSON}
|
2024-02-14 15:38:40 +01:00
|
|
|
|
|
|
|
fi
|
2023-12-03 22:15:46 +01:00
|
|
|
|
2024-02-27 02:03:29 +01:00
|
|
|
cat ~/.zen/tmp/${JSON} | jq -c
|
|
|
|
|
2023-12-31 18:46:23 +01:00
|
|
|
### SEND RESPONSE ON PORT
|
2024-02-15 14:53:26 +01:00
|
|
|
cat ~/.zen/tmp/${JSON} >> ~/.zen/tmp/${MOATS}.http
|
|
|
|
(
|
|
|
|
cat ~/.zen/tmp/${MOATS}.http | nc -l -p ${PORT} -q 1 > /dev/null 2>&1
|
2024-02-27 02:03:29 +01:00
|
|
|
rm ~/.zen/tmp/${MOATS}/http.grid 2>/dev/null
|
2024-02-15 14:53:26 +01:00
|
|
|
rm ~/.zen/tmp/${MOATS}.http && echo "BLURP ${JSON}"
|
|
|
|
) &
|
2023-12-31 18:46:23 +01:00
|
|
|
## CLEANING
|
2023-12-02 22:27:45 +01:00
|
|
|
rm -Rf ~/.zen/tmp/${MOATS}/
|
2023-12-31 18:46:23 +01:00
|
|
|
## TIMING
|
2023-12-03 22:15:46 +01:00
|
|
|
end=`date +%s`
|
|
|
|
echo "(ZONE) Operation time was "`expr $end - $start` seconds.
|
2023-12-02 22:27:45 +01:00
|
|
|
exit 0
|