2022-10-04 23:10:31 +02:00
|
|
|
#!/bin/bash
|
|
|
|
################################################################################
|
|
|
|
# Author: Fred (support@qo-op.com)
|
|
|
|
# Version: 0.1
|
|
|
|
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
|
|
|
################################################################################
|
|
|
|
################################################################################
|
2022-11-26 19:36:54 +01:00
|
|
|
## ASTROPORT API SERVER http://${myHOST}:1234
|
2022-10-30 19:32:56 +01:00
|
|
|
## ATOMIC GET REDIRECT TO ONE SHOT WEB SERVICE THROUGH PORTS
|
|
|
|
## ASYNCHRONOUS IPFS API
|
2022-10-22 13:01:46 +02:00
|
|
|
################################################################################
|
2022-10-04 23:10:31 +02:00
|
|
|
MY_PATH="`dirname \"$0\"`" # relative
|
|
|
|
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
2022-12-26 21:43:33 +01:00
|
|
|
. "${MY_PATH}/tools/my.sh"
|
2022-11-21 21:30:58 +01:00
|
|
|
|
2022-10-22 12:20:29 +02:00
|
|
|
PORT=12345
|
2022-10-04 23:10:31 +02:00
|
|
|
|
2022-12-27 19:35:43 +01:00
|
|
|
YOU=$(myIpfsApi); ## API of $USER running ipfs
|
2022-12-28 14:27:01 +01:00
|
|
|
echo "YOU=$YOU"
|
2022-12-29 15:44:36 +01:00
|
|
|
LIBRA=$(myIpfsGw) ## SWARM#0 ENTRANCE URL
|
|
|
|
echo "LIBRA=$LIBRA"
|
|
|
|
TUBE=$(myTube)
|
|
|
|
echo "TUBE=$TUBE"
|
2022-10-27 15:48:35 +02:00
|
|
|
|
2022-12-25 18:43:27 +01:00
|
|
|
mkdir -p ~/.zen/tmp/coucou/ ~/.zen/game/players/localhost
|
2022-10-22 17:08:20 +02:00
|
|
|
|
2022-10-04 23:10:31 +02:00
|
|
|
## CHECK FOR ANY ALREADY RUNNING nc
|
2023-01-05 16:28:10 +01:00
|
|
|
ncrunning=$(ps axf --sort=+utime | grep -w 'nc -l -p 1234' | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1)
|
|
|
|
[[ $ncrunning ]] && echo "RESTARTING" && kill -9 $ncrunning
|
2022-10-30 19:32:56 +01:00
|
|
|
## NOT RUNNING TWICE
|
|
|
|
|
2022-10-31 19:56:24 +01:00
|
|
|
# Some client needs to respect that
|
2022-10-31 19:30:23 +01:00
|
|
|
HTTPCORS="HTTP/1.1 200 OK
|
2022-12-15 22:53:18 +01:00
|
|
|
Access-Control-Allow-Origin: ${myASTROPORT}
|
2022-10-31 19:30:23 +01:00
|
|
|
Access-Control-Allow-Credentials: true
|
|
|
|
Access-Control-Allow-Methods: GET
|
|
|
|
Server: Astroport.ONE
|
|
|
|
Content-Type: text/html; charset=UTF-8
|
|
|
|
"
|
2022-12-04 23:02:09 +01:00
|
|
|
echo "_________________________________________________________ $(date)"
|
|
|
|
echo "LAUNCHING Astroport API Server - TUBE : $LIBRA - "
|
2022-10-30 15:44:49 +01:00
|
|
|
echo
|
2022-12-09 01:21:21 +01:00
|
|
|
echo "GCHANGE ${myASTROPORT}/?salt=totodu56&pepper=totodu56&g1pub"
|
|
|
|
echo "OPEN TW ${myASTROPORT}/?salt=totodu56&pepper=totodu56&g1pub=astro"
|
|
|
|
echo "GCHANGE MESSAGING ${myASTROPORT}/?salt=totodu56&pepper=totodu56&messaging"
|
|
|
|
echo "CREATE SAME PLAYER : ${myASTROPORT}/?salt=totodu56&pepper=totodu56&g1pub=on&email=totodu56@yopmail.com"
|
2022-12-08 20:31:04 +01:00
|
|
|
echo
|
2022-12-09 01:21:21 +01:00
|
|
|
echo "NEW PLAYER : ${myASTROPORT}/?salt=${RANDOM}&pepper=${RANDOM}&g1pub=on&email=astro${RANDOM}@yopmail.com"
|
2022-12-01 18:26:21 +01:00
|
|
|
echo
|
2022-12-09 01:21:21 +01:00
|
|
|
echo "BunkerBOX : ${myASTROPORT}/?salt=totodu56&pepper=totodu56&g1pub=_URL_&email=totodu56@yopmail.com"
|
2022-10-30 18:36:16 +01:00
|
|
|
echo
|
2023-01-02 20:39:23 +01:00
|
|
|
echo "TESTCRAFT ${myASTROPORT}/?salt=totodu56&pepper=totodu56&testcraft=on&dataid=QmPXhrqQrS1bePKJUPH9cJ2qe4RrNjaJdRXaJzSjxWuvDi"
|
2022-10-27 16:28:44 +02:00
|
|
|
echo "_________________________________________________________"
|
2022-10-04 23:10:31 +02:00
|
|
|
|
|
|
|
function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
|
|
|
|
|
2022-11-24 19:39:09 +01:00
|
|
|
#############################
|
|
|
|
########## MAIN ###############
|
|
|
|
#############################
|
2022-10-04 23:10:31 +02:00
|
|
|
while true; do
|
2022-10-30 19:44:25 +01:00
|
|
|
|
2022-11-24 19:39:09 +01:00
|
|
|
start=`date +%s`
|
2022-10-21 20:11:47 +02:00
|
|
|
MOATS=$(date -u +"%Y%m%d%H%M%S%4N")
|
2022-11-24 19:39:09 +01:00
|
|
|
|
|
|
|
# EACH VISITOR RECEIVE COMMAND RESPONSE ON
|
|
|
|
## RANDOM PORT = RESPONSE SOCKET & IPNS SESSION TOKEN
|
|
|
|
|
2022-11-16 06:11:07 +01:00
|
|
|
[ ${PORT} -le 12345 ] && PORT=$((PORT+${RANDOM:0:2})) || PORT=$((PORT-${RANDOM:0:2}))
|
2022-11-24 19:39:09 +01:00
|
|
|
## RANDOM PORT SWAPPINESS AVOIDING COLLISION
|
2022-11-21 18:58:03 +01:00
|
|
|
|
2022-11-24 19:39:09 +01:00
|
|
|
## CHECK PORT IS FREE & KILL OLD ONE
|
2022-12-06 23:45:15 +01:00
|
|
|
pidportinuse=$(ps axf --sort=+utime | grep -w "nc -l -p ${PORT}" | grep -v -E 'color=auto|grep' | awk '{gsub(/^ +| +$/,"")} {print $0}' | tail -n 1 | cut -d " " -f 1)
|
2022-12-06 23:27:27 +01:00
|
|
|
[[ $pidportinuse ]] && kill -9 $pidportinuse && echo "KILLING $pidportinuse" && continue
|
2022-10-21 22:09:13 +02:00
|
|
|
|
2022-11-24 19:39:09 +01:00
|
|
|
## CHECK 12345 PORT RUNNING (STATION FoF MAP)
|
2022-11-03 20:11:17 +01:00
|
|
|
maprunning=$(ps auxf --sort=+utime | grep -w '_12345.sh' | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1)
|
2022-12-12 15:10:02 +01:00
|
|
|
[[ ! $maprunning ]] \
|
2022-12-15 22:53:18 +01:00
|
|
|
&& echo '(ᵔ◡◡ᵔ) LAUNCHING '${myASTROPORT}:'12345 (ᵔ◡◡ᵔ)' \
|
2022-12-12 15:10:02 +01:00
|
|
|
&& exec $MY_PATH/_12345.sh &
|
2022-11-02 15:00:01 +01:00
|
|
|
|
2022-11-24 19:39:09 +01:00
|
|
|
############### ACTIVATE USE ON QUICK IPFS DRIVE
|
2022-10-30 19:32:56 +01:00
|
|
|
### CREATE IPNS KEY - ACTIVATE WHITH ENOUGH BOOTSTRAP
|
2022-11-25 14:48:37 +01:00
|
|
|
#~ echo
|
|
|
|
#~ ipfs key rm ${PORT} > /dev/null 2>&1
|
|
|
|
#~ SESSIONNS=$(ipfs key gen ${PORT})
|
2022-12-15 22:53:18 +01:00
|
|
|
#~ echo "IPNS SESSION ${myIPFS}/ipns/$SESSIONNS CREATED"
|
2022-11-24 19:39:09 +01:00
|
|
|
|
|
|
|
### # USE IT #
|
2022-10-30 19:52:17 +01:00
|
|
|
### MIAM=$(echo ${PORT} | ipfs add -q)
|
2022-11-24 19:39:09 +01:00
|
|
|
### ipfs name publish --allow-offline -t 180s --key=${PORT} /ipfs/$MIAM &
|
|
|
|
|
2022-10-30 16:07:26 +01:00
|
|
|
###############
|
2022-10-30 19:32:56 +01:00
|
|
|
###############
|
2022-10-30 16:07:26 +01:00
|
|
|
|
2022-10-30 19:32:56 +01:00
|
|
|
# RESET VARIABLES
|
2023-01-02 20:39:23 +01:00
|
|
|
CMD="" THAT="" AND="" THIS="" APPNAME="" WHAT="" OBJ="" VAL=""
|
2022-10-21 18:18:16 +02:00
|
|
|
|
2022-10-30 19:32:56 +01:00
|
|
|
############### ############### ############### ############### templates/index.http
|
2022-11-25 15:29:20 +01:00
|
|
|
# REPLACE myHOST in http response template (fixing next API meeting point)
|
2022-12-25 15:12:32 +01:00
|
|
|
echo "$HTTPCORS" > ~/.zen/tmp/coucou/${MOATS}.myHOST.http
|
2022-12-29 14:51:05 +01:00
|
|
|
myHtml >> ~/.zen/tmp/coucou/${MOATS}.myHOST.http
|
2023-01-15 17:40:52 +01:00
|
|
|
sed -i -e "s~\"http://127.0.0.1:1234/\"~\"$(myIpfs)\"~g" \
|
|
|
|
-e "s~http://${myHOST}:12345~http://${myIP}:${PORT}~g" \
|
2022-12-25 23:46:35 +01:00
|
|
|
~/.zen/tmp/coucou/${MOATS}.myHOST.http
|
2022-11-22 23:49:46 +01:00
|
|
|
|
2022-10-24 02:45:49 +02:00
|
|
|
############################################################################
|
2022-11-25 15:29:20 +01:00
|
|
|
## SERVE LANDING REDIRECT PAGE ~/.zen/tmp/coucou/${MOATS}.myHOST.http on PORT 1234 (LOOP BLOCKING POINT)
|
2022-10-24 02:45:49 +02:00
|
|
|
############################################################################
|
2022-11-25 15:29:20 +01:00
|
|
|
REQ=$(cat $HOME/.zen/tmp/coucou/${MOATS}.myHOST.http | nc -l -p 1234 -q 1) ## # WAIT FOR 1234 PORT CONTACT
|
2022-11-24 19:39:09 +01:00
|
|
|
|
2022-11-21 18:58:03 +01:00
|
|
|
URL=$(echo "$REQ" | grep '^GET' | cut -d ' ' -f2 | cut -d '?' -f2)
|
|
|
|
HOSTP=$(echo "$REQ" | grep '^Host:' | cut -d ' ' -f2 | cut -d '?' -f2)
|
|
|
|
HOST=$(echo "$HOSTP" | cut -d ':' -f 1)
|
2022-12-15 17:06:29 +01:00
|
|
|
|
2022-12-25 22:20:50 +01:00
|
|
|
############### ############### ############### ###############
|
2023-01-12 16:20:47 +01:00
|
|
|
[[ $XDG_SESSION_TYPE == 'x11' ]] && espeak "Ding" >/dev/null 1>&2 &
|
2022-10-22 13:01:46 +02:00
|
|
|
############################################################################
|
2022-12-10 03:26:20 +01:00
|
|
|
[[ $URL == "/test" || $URL == "" ]] && continue
|
2022-11-21 18:58:03 +01:00
|
|
|
|
2023-01-02 20:39:23 +01:00
|
|
|
echo "************************************************************************* $(date)"
|
2023-01-12 16:20:47 +01:00
|
|
|
echo "ASTROPORT 1234 UP & RUNNING.......................... $myASTROPORT"
|
|
|
|
echo "${MOATS} NEXT COMMAND DELIVERY PAGE http://$myHOST:${PORT}"
|
2022-11-15 17:24:07 +01:00
|
|
|
|
2022-10-31 02:52:43 +01:00
|
|
|
echo "URL" > ~/.zen/tmp/coucou/${MOATS}.url ## LOGGING URL
|
2022-11-21 18:58:03 +01:00
|
|
|
|
2022-10-24 02:45:49 +02:00
|
|
|
############################################################################
|
2022-10-21 20:11:47 +02:00
|
|
|
start=`date +%s`
|
|
|
|
|
2022-10-26 18:38:37 +02:00
|
|
|
############################################################################
|
2022-11-24 19:39:09 +01:00
|
|
|
## / CONTACT
|
2022-10-21 21:50:40 +02:00
|
|
|
if [[ $URL == "/" ]]; then
|
2022-12-15 22:53:18 +01:00
|
|
|
echo "/ CONTACT : $HOSTP"
|
2022-12-30 23:46:13 +01:00
|
|
|
echo "$HTTPCORS
|
2023-01-02 20:39:23 +01:00
|
|
|
DING : ${MOATS} : $(date)" | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &
|
2022-10-22 13:01:46 +02:00
|
|
|
end=`date +%s`
|
2022-12-25 22:20:50 +01:00
|
|
|
echo " (‿/‿) $myHOST:$PORT / Execution time was "`expr $end - $start` seconds.
|
2022-10-21 22:00:29 +02:00
|
|
|
continue
|
2022-10-21 21:50:40 +02:00
|
|
|
fi
|
2022-11-24 19:39:09 +01:00
|
|
|
|
|
|
|
|
2022-10-26 18:38:37 +02:00
|
|
|
############################################################################
|
2022-11-24 19:39:09 +01:00
|
|
|
# URL DECODING
|
2022-10-26 18:38:37 +02:00
|
|
|
############################################################################
|
|
|
|
|
2022-10-04 23:10:31 +02:00
|
|
|
echo "=================================================="
|
|
|
|
echo "GET RECEPTION : $URL"
|
|
|
|
arr=(${URL//[=&]/ })
|
2022-10-27 16:28:44 +02:00
|
|
|
|
2022-12-30 22:55:10 +01:00
|
|
|
#####################################################################
|
2023-01-02 20:39:23 +01:00
|
|
|
### /?poule
|
2022-12-30 22:55:10 +01:00
|
|
|
#####################################################################
|
|
|
|
if [[ ${arr[0]} == "poule" ]]; then
|
|
|
|
echo "UPDATING CODE git pull > ~/.zen/tmp/.lastpull"
|
|
|
|
echo "$HTTPCORS" > ~/.zen/tmp/.lastpull
|
|
|
|
git pull >> ~/.zen/tmp/.lastpull
|
2022-12-31 20:17:06 +01:00
|
|
|
rm ~/.zen/game/players/localhost/latest
|
2022-12-30 22:55:10 +01:00
|
|
|
(cat ~/.zen/tmp/.lastpull | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &) && continue
|
|
|
|
fi
|
|
|
|
|
2022-10-30 19:32:56 +01:00
|
|
|
########## CHECK GET PARAM NAMES
|
2022-10-21 13:45:53 +02:00
|
|
|
###################################################################################################
|
2022-11-24 19:39:09 +01:00
|
|
|
[[ ${arr[0]} == "" || ${arr[1]} == "" ]] && (echo "$HTTPCORS ERROR - MISSING DATA" | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &) && continue
|
|
|
|
|
2023-01-02 20:39:23 +01:00
|
|
|
CMD=$(urldecode ${arr[0]} | xargs)
|
|
|
|
THAT=$(urldecode ${arr[1]} | xargs)
|
|
|
|
# SPLIT URL INTO
|
2022-12-28 17:21:50 +01:00
|
|
|
|
2023-01-02 20:39:23 +01:00
|
|
|
AND=$(urldecode ${arr[2]} | xargs)
|
|
|
|
THIS=$(urldecode ${arr[3]} | xargs)
|
2022-12-28 17:21:50 +01:00
|
|
|
|
2023-01-02 20:39:23 +01:00
|
|
|
APPNAME=$(urldecode ${arr[4]} | xargs)
|
|
|
|
WHAT=$(urldecode ${arr[5]} | xargs)
|
2022-12-28 17:21:50 +01:00
|
|
|
|
2023-01-02 20:39:23 +01:00
|
|
|
OBJ=$(urldecode ${arr[6]} | xargs)
|
|
|
|
VAL=$(urldecode ${arr[7]} | xargs)
|
2022-12-28 23:11:16 +01:00
|
|
|
|
2023-01-02 20:39:23 +01:00
|
|
|
echo "===== COMMAND = $CMD ====="
|
|
|
|
echo "CMD=THAT&AND=THIS&APPNAME=WHAT&OBJ=VAL"
|
|
|
|
echo "$CMD=$THAT&$AND=$THIS&$APPNAME=$WHAT&$OBJ=$VAL"
|
2022-12-28 23:11:16 +01:00
|
|
|
|
2023-01-02 20:39:23 +01:00
|
|
|
case $CMD in
|
|
|
|
"salt")
|
2023-01-11 01:25:02 +01:00
|
|
|
exec ${MY_PATH}/API/SALT.sh "$PORT" "$THAT" "$AND" "$THIS" "$APPNAME" "$WHAT" "$OBJ" "$VAL" "${MOATS}" &
|
2023-01-02 20:39:23 +01:00
|
|
|
;;
|
2022-12-28 23:11:16 +01:00
|
|
|
|
2023-01-02 20:39:23 +01:00
|
|
|
"player")
|
2023-01-11 01:25:02 +01:00
|
|
|
exec ${MY_PATH}/API/PLAYER.sh "$PORT" "$THAT" "$AND" "$THIS" "$APPNAME" "$WHAT" "$OBJ" "$VAL" "${MOATS}" &
|
2023-01-02 20:39:23 +01:00
|
|
|
;;
|
2022-12-27 15:12:32 +01:00
|
|
|
|
2023-01-02 20:39:23 +01:00
|
|
|
"qrcode")
|
2023-01-11 01:25:02 +01:00
|
|
|
exec ${MY_PATH}/API/QRCODE.sh "$PORT" "$THAT" "$AND" "$THIS" "$APPNAME" "$WHAT" "$OBJ" "$VAL" "${MOATS}" &
|
2023-01-02 20:39:23 +01:00
|
|
|
;;
|
2022-12-28 14:27:01 +01:00
|
|
|
|
2023-01-03 18:42:41 +01:00
|
|
|
"")
|
|
|
|
echo "$HTTPCORS
|
|
|
|
ERROR UNKNOWN $CMD : ${MOATS} : $(date)" | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &
|
|
|
|
|
2023-01-02 20:39:23 +01:00
|
|
|
;;
|
2022-10-04 23:10:31 +02:00
|
|
|
|
2023-01-03 18:42:41 +01:00
|
|
|
### ADD API SCRIPT INTO /API
|
|
|
|
*)
|
|
|
|
|
|
|
|
[[ ! -s ${MY_PATH}/API/${CMD^^}.sh ]] \
|
|
|
|
&& ( echo "$HTTPCORS
|
|
|
|
ERROR UNKNOWN $CMD : ${MOATS} : $(date)" | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 & ) \
|
|
|
|
|| exec ${MY_PATH}/API/${CMD^^}.sh "$PORT" "$THAT" "$AND" "$THIS" "$APPNAME" "$WHAT" "$OBJ" "$VAL" &
|
|
|
|
|
2023-01-02 20:39:23 +01:00
|
|
|
;;
|
2022-10-21 14:38:25 +02:00
|
|
|
|
2023-01-02 20:39:23 +01:00
|
|
|
esac
|
2022-12-30 22:55:10 +01:00
|
|
|
|
2023-01-03 18:42:41 +01:00
|
|
|
end=`date +%s`
|
|
|
|
echo " ($CMD) $myHOST:$PORT / Launching time was "`expr $end - $start` seconds.
|
|
|
|
|
2022-10-04 23:10:31 +02:00
|
|
|
done
|
|
|
|
exit 0
|