################################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
################################################################################
################################################################################
## API: UPLANET
## Dedicated to OSM2IPFS & UPlanet Client App
# ?uplanet=EMAIL&salt=LAT&pepper=LON
## https://git.p2p.legal/qo-op/OSM2IPFS
################################################################################
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
QRCODE=$(echo "$THAT" | cut -d ':' -f 1) # G1nkgo compatible
HTTPCORS="HTTP/1.1 200 OK
Access-Control-Allow-Origin: ${myASTROPORT}
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET
Server: Astroport.ONE
Content-Type: text/html; charset=UTF-8
"
function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
## GET TW
mkdir -p ~/.zen/tmp/${MOATS}/
## GET PARAM, with case uplanet="" decalage !
PLAYER=${THAT}
[[ ${PLAYER} == "salt" ]] && PLAYER="@"
[[ ${AND} == "salt" ]] && SALT=${THIS} || SALT=${AND}
[[ ${SALT} == "0" ]] && SALT="0.00"
input_number=${SALT}
if [[ ! $input_number =~ ^-?[0-9]{1,3}(\.[0-9]{1,2})?$ ]]; then
(echo "$HTTPCORS ERROR - BAD LAT $LAT" | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &) && echo "(☓‿‿☓) Execution time was "`expr $(date +%s) - $start` seconds. && exit 0
else
# If input_number has one decimal digit, add a trailing zero
if [[ ${input_number} =~ ^-?[0-9]+\.[0-9]$ ]]; then
input_number="${input_number}0"
elif [[ ${input_number} =~ ^-?[0-9]+$ ]]; then
# If input_number is an integer, add ".00"
input_number="${input_number}.00"
fi
# Convert input_number to LAT with two decimal digits
LAT="${input_number}"
fi
[[ ${APPNAME} == "pepper" ]] && PEPPER=${WHAT} || PEPPER=${APPNAME}
[[ ${PEPPER} == "0" ]] && PEPPER="0.00"
input_number=${PEPPER}
if [[ ! $input_number =~ ^-?[0-9]{1,3}(\.[0-9]{1,2})?$ ]]; then
(echo "$HTTPCORS ERROR - BAD LON $LON" | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &) && echo "(☓‿‿☓) Execution time was "`expr $(date +%s) - $start` seconds. && exit 0
else
# If input_number has one decimal digit, add a trailing zero
if [[ ${input_number} =~ ^-?[0-9]+\.[0-9]$ ]]; then
input_number="${input_number}0"
elif [[ ${input_number} =~ ^-?[0-9]+$ ]]; then
# If input_number is an integer, add ".00"
input_number="${input_number}.00"
fi
# Convert input_number to LAT with two decimal digits
LON="${input_number}"
fi
PASS=$(echo "${RANDOM}${RANDOM}${RANDOM}${RANDOM}" | tail -c-7)
## RECEIVED PASS
[[ ${OBJ} == "g1pub" && ${VAL} != "" ]] && PASS=${VAL}
### CHECK PLAYER EMAIL
EMAIL="${PLAYER,,}" # lowercase
[[ ! ${EMAIL} ]] && (echo "$HTTPCORS ERROR - MISSING ${EMAIL} FOR UPLANET LANDING" | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &) && echo "(☓‿‿☓) Execution time was "`expr $(date +%s) - $start` seconds. && exit 0
## CHECK WHAT IS EMAIL
if [[ "${EMAIL}" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$ ]]; then
echo "VALID ${EMAIL} EMAIL OK"
else
echo "BAD EMAIL"
(echo "$HTTPCORS PLEASE PROVIDE A VALID EMAIL ${EMAIL} '" | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &) && exit 0
fi
### CREATE G1VISA & G1Card
echo "${MY_PATH}/../tools/VISA.print.sh" "${EMAIL}" "'"$LAT"'" "'"$LON"'" "'"$PASS"'" "'"$PASS"'"
${MY_PATH}/../tools/VISA.print.sh "${EMAIL}" "$LAT" "$LON" "$PASS" "${PASS}"##
[[ ${EMAIL} != "" && ${EMAIL} != $(cat ~/.zen/game/players/.current/.player 2>/dev/null) ]] && rm -Rf ~/.zen/game/players/${EMAIL}/
# UPLANET #############################################
## OCCUPY COMMON CRYPTO KEY CYBERSPACE
## SALT="$LAT" PEPPER="$LON"
######################################################
echo "UMAP = $LAT:$LON"
echo "# CALCULATING MAP G1PUB WALLET"
${MY_PATH}/../tools/keygen -t duniter -o ~/.zen/tmp/${MOATS}/${G1PUB}/_cesium.key "$LAT" "$LON"
G1PUB=$(cat ~/.zen/tmp/${MOATS}/${G1PUB}/_cesium.key | grep 'pub:' | cut -d ' ' -f 2)
[[ ! ${G1PUB} ]] && (echo "$HTTPCORS ERROR - (╥☁╥ ) - KEYGEN COMPUTATION DISFUNCTON" | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &) && exit 1
echo "MAPG1PUB : ${G1PUB}"
echo "# CALCULATING UMAP IPNS ADDRESS"
mkdir -p ~/.zen/tmp/${MOATS}/${G1PUB}
mkdir -p ~/.zen/tmp/${MOATS}/${LAT}_${LON}
ipfs key rm ${G1PUB} > /dev/null 2>&1
rm ~/.zen/tmp/${MOATS}/_ipns.priv 2>/dev/null
${MY_PATH}/../tools/keygen -t ipfs -o ~/.zen/tmp/${MOATS}/_ipns.priv "$LAT" "$LON"
UMAPNS=$(ipfs key import ${G1PUB} -f pem-pkcs8-cleartext ~/.zen/tmp/${MOATS}/_ipns.priv )
[[ ! ${UMAPNS} ]] && (echo "$HTTPCORS ERROR - (╥☁╥ ) - UMAPNS COMPUTATION DISFUNCTON" | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &) && exit 1
echo "UMAPNS : http://ipfs.localhost:8080/ipns/${UMAPNS}"
###################################################
## GET NETWORK CACHE
echo "ipfs --timeout 22s get -o ~/.zen/tmp/${MOATS}/ /ipns/${UMAPNS}/"
ipfs --timeout 22s get -o ~/.zen/tmp/${MOATS}/ /ipns/${UMAPNS}/
####################################### Umap.png
## CREATING Umap_${LAT}_${LON}.png
echo "# OSM2IPFS ~/.zen/tmp/${MOATS}/Umap_${LAT}_${LON}.png"
UMAPGEN="/ipfs/QmSaFpSM6ps2pBqYxxLjKJfuigpEo98GNCPdK4PkMXnDaY/Umap.html?southWestLat=$LAT&southWestLon=$LON°=0.01"
echo ${UMAPGEN}
echo "" > ~/.zen/tmp/${MOATS}/Umap.html
## TODO find a better crawling method (pb tiles are not fully loaded before screenshot)
echo "chromium --headless --disable-gpu --screenshot=/tmp/Umap_${LAT}_${LON}.jpg --window-size=1200x1200 \"https://ipfs.copylaradio.com${UMAPGEN}\""
chromium --headless --disable-gpu --screenshot=/tmp/Umap.jpg --window-size=1200x1200 "https://ipfs.copylaradio.com${UMAPGEN}"
chromium --headless --disable-gpu --screenshot=/tmp/Umap.png --window-size=1200x1200 "https://ipfs.copylaradio.com${UMAPGEN}"
echo "" > ~/.zen/tmp/${MOATS}/G1Card.html
echo "
" > ~/.zen/tmp/${MOATS}/G1Visa.html
## ADD TO FRIENDS
echo "${EMAIL}" >> ~/.zen/tmp/${MOATS}/UFriends.txt
## COPYING FILES FROM ABROAD
cp /tmp/Umap.jpg ~/.zen/tmp/${MOATS}/
cp /tmp/Umap.png ~/.zen/tmp/${MOATS}/
rm -f ~/.zen/tmp/${MOATS}/G1*.jpg ## DELETE VISA FROM PREVIOUS VISITOR
cp ~/.zen/tmp/${PASS}##/G1Visa.${PASS}.jpg ~/.zen/tmp/${MOATS}/G1Visa.${EMAIL}.jpg
cp -f ~/.zen/tmp/${PASS}##/${PASS}.jpg ~/.zen/tmp/${MOATS}/G1Card.${EMAIL}.jpg
ls ~/.zen/tmp/${MOATS}/
### CREATE A G1VISA FOR PLAYER (IF PASS WAS GIVEN AND NO TW EXISTS YET)
if [[ ! -f ~/.zen/tmp/${MOATS}/TW/${EMAIL}/index.html ]]; then
## Create a redirection to PLAYER (EMAIL/PASS) TW
if [[ ${PASS} == ${VAL} ]]; then
mkdir -p ~/.zen/tmp/${MOATS}/TW/${EMAIL}
## CREATE TW LINK
TWADD=$(${MY_PATH}/../tools/keygen -t ipfs "$EMAIL" "$PASS")
echo "" > ~/.zen/tmp/${MOATS}/TW/${EMAIL}/index.html
## CREATE OR TRANSFER TW ON CURRENT ASTROPORT
(
${MY_PATH}/../tools/VISA.new.sh "${EMAIL}" "${PASS}" "${EMAIL}" "UPlanet" "ADD YOUTUBE VIDEO CHANNEL URL" "${LAT}" "${LON}" >> ~/.zen/tmp/email.${EMAIL}.${MOATS}.txt
${MY_PATH}/../tools/mailjet.sh "${EMAIL}" ~/.zen/tmp/email.${EMAIL}.${MOATS}.txt ## Send VISA.new log to EMAIL
) &
fi
fi
## MAKE A MESSAGE
echo "