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-10-22 13:01:46 +02:00
## ASTROPORT API SERVER http://$myIP: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
ME = " ${ 0 ##*/ } "
MOATS = $( date -u +"%Y%m%d%H%M%S%4N" )
IPFSNODEID = $( cat ~/.ipfs/config | jq -r .Identity.PeerID)
2022-10-22 12:20:29 +02:00
myIP = $( hostname -I | awk '{print $1}' | head -n 1)
2022-11-05 12:32:16 +01:00
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"
2022-10-22 12:20:29 +02:00
PORT = 12345
2022-10-04 23:10:31 +02:00
2022-11-16 06:11:07 +01:00
YOU = $( ipfs swarm peers >/dev/null 2>& 1 && echo " $USER " || ps auxf --sort= +utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) ; ## $USER running ipfs
2022-10-30 19:32:56 +01:00
LIBRA = $( head -n 2 ~/.zen/Astroport.ONE/A_boostrap_nodes.txt | tail -n 1 | cut -d ' ' -f 2) ## SWARM#0 ENTRANCE URL
2022-10-27 15:48:35 +02:00
2022-10-31 02:52:43 +01:00
mkdir -p ~/.zen/tmp/coucou/
2022-10-22 17:08:20 +02:00
2022-10-04 23:10:31 +02:00
## CHECK FOR ANY ALREADY RUNNING nc
2022-10-07 02:16:53 +02:00
ncrunning = $( ps auxf --sort= +utime | grep -w 'nc -l -p 1234' | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1)
2022-10-30 18:36:16 +01:00
[ [ $ncrunning ] ] && echo " ERROR - API Server Already Running - http:// $myIP :1234/?salt=totodu56&pepper=totodu56 " && exit 1
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-11-02 15:12:13 +01:00
Access-Control-Allow-Origin: \*
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-10-31 19:42:10 +01:00
2022-10-31 19:30:23 +01:00
"
2022-10-27 16:28:44 +02:00
echo "_________________________________________________________"
2022-10-30 15:44:49 +01:00
echo "LAUNCHING Astroport API Server - TEST - "
echo
2022-10-30 18:36:16 +01:00
echo " CREATE GCHANGE + TW http:// $myIP :1234/?salt=totodu56&pepper=totodu56&g1pub=on&email=fred@astroport.com "
2022-10-30 15:44:49 +01:00
echo
2022-10-30 18:36:16 +01:00
echo " OPEN TW R/W http:// $myIP :1234/?salt=totodu56&pepper=totodu56&official "
2022-10-30 15:44:49 +01:00
echo
2022-10-30 18:36:16 +01:00
echo " GCHANGE MESSAGING http:// $myIP :1234/?salt=totodu56&pepper=totodu56&messaging "
echo " GCHANGE PLAYER URL http:// $myIP :1234/?salt=totodu56&pepper=totodu56&g1pub "
echo
2022-11-02 17:43:55 +01:00
echo " TESTCRAFT http:// $myIP :1234/?salt=totodu56&pepper=totodu56&testcraft=on&nodeid=12D3KooWK1ACupF7RD3MNvkBFU9Z6fX11pKRAR99WDzEUiYp5t8j&dataid=QmPXhrqQrS1bePKJUPH9cJ2qe4RrNjaJdRXaJzSjxWuvDi "
2022-10-27 16:28:44 +02:00
echo "_________________________________________________________"
2022-10-04 23:10:31 +02:00
function urldecode( ) { : " ${ *//+/ } " ; echo -e " ${ _ //%/ \\ x } " ; }
while true; do
2022-10-30 19:44:25 +01:00
start = ` date +%s`
2022-10-21 20:11:47 +02:00
MOATS = $( date -u +"%Y%m%d%H%M%S%4N" )
2022-10-21 22:09:13 +02:00
## CHANGE NEXT PORT (HERE YOU CREATE A SOCKET QUEUE)
2022-11-16 06:11:07 +01:00
[ ${ PORT } -le 12345 ] && PORT = $(( PORT+${ RANDOM : 0 : 2 } )) || PORT = $(( PORT-${ RANDOM : 0 : 2 } ))
2022-11-16 07:11:44 +01:00
pidportinuse = $( ps axf --sort= +utime | grep -w " nc -l -p ${ PORT } " | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 2)
[ [ $pidportinuse ] ] && kill -9 $pidportinuse && echo " KILLING $portinuse " && continue
2022-11-02 18:01:10 +01:00
## RANDOM PORT SWAPPINESS AVOIDING COLLISION
2022-10-21 22:09:13 +02:00
2022-11-02 15:00:01 +01:00
## CHECK 12345 PORT RUNNING (PUBLISHING IPNS SWARM 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)
#maprunning=$(ps auxf --sort=+utime | grep -w 'nc -l -p 12345' | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1)
2022-11-02 15:00:01 +01:00
[ [ ! $maprunning ] ] && ( $MY_PATH /_12345.sh & ) && echo '(ᵔ◡◡ᵔ) LAUNCHING http://' $myIP :'12345 (ᵔ◡◡ᵔ)'
2022-11-02 18:01:10 +01:00
############### IPNS SESSION KEY TRY LATER
2022-10-30 19:32:56 +01:00
### CREATE IPNS KEY - ACTIVATE WHITH ENOUGH BOOTSTRAP
2022-10-30 19:52:17 +01:00
### echo
### ipfs key rm ${PORT} > /dev/null 2>&1
### SESSIONNS=$(ipfs key gen ${PORT})
### echo "IPNS SESSION http://$myIP:8080/ipns/$SESSIONNS CREATED"
### MIAM=$(echo ${PORT} | ipfs add -q)
### ipfs name publish --allow-offline --key=${PORT} /ipfs/$MIAM
### end=`date +%s`
### echo ${PORT} initialisation time was `expr $end - $start` seconds.
### echo
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
2022-11-11 18:22:35 +01:00
SALT = "" ; PEPPER = "" ; APPNAME = ""
2022-10-21 20:22:28 +02:00
echo "************************************************************************* "
2022-10-31 17:22:40 +01:00
echo " ASTROPORT 1234 UP & RUNNING.......................... http:// $myIP :1234 PORT "
2022-11-05 20:15:02 +01:00
echo " ${ MOATS } NEXT COMMAND DELIVERY PAGE http:// $myIP : ${ PORT } "
2022-10-21 18:18:16 +02:00
2022-10-30 19:32:56 +01:00
############### ############### ############### ############### templates/index.http
# REPLACE myIP in http response template (fixing next API meeting point)
2022-10-31 02:52:43 +01:00
sed " s~127.0.0.1:12345~ $myIP : ${ PORT } ~g " $HOME /.zen/Astroport.ONE/templates/index.http > ~/.zen/tmp/coucou/${ MOATS } .myIP.http
sed -i " s~127.0.0.1~ $myIP ~g " ~/.zen/tmp/coucou/${ MOATS } .myIP.http
sed -i " s~:12345~: ${ PORT } ~g " ~/.zen/tmp/coucou/${ MOATS } .myIP.http
2022-11-05 20:15:02 +01:00
sed -i " s~_IPFSNODEID_~ ${ IPFSNODEID } ~g " ~/.zen/tmp/coucou/${ MOATS } .myIP.http ## NODE PUBLISH HOSTED ${WHAT}'S JSON
2022-10-31 02:52:43 +01:00
sed -i " s~_HOSTNAME_~ $( hostname) ~g " ~/.zen/tmp/coucou/${ MOATS } .myIP.http ## HOSTNAME
2022-10-30 19:32:56 +01:00
############### ############### ############### ###############
2022-10-24 02:45:49 +02:00
############################################################################
2022-10-31 02:52:43 +01:00
## SERVE LANDING REDIRECT PAGE ~/.zen/tmp/coucou/${MOATS}.myIP.http on PORT 1234 (LOOP BLOCKING POINT)
2022-10-24 02:45:49 +02:00
############################################################################
2022-10-31 02:52:43 +01:00
URL = $( cat $HOME /.zen/tmp/coucou/${ MOATS } .myIP.http | nc -l -p 1234 -q 1 | grep '^GET' | cut -d ' ' -f2 | cut -d '?' -f2)
2022-10-22 13:01:46 +02:00
############################################################################
2022-11-15 19:58:35 +01:00
espeak "Ding" > /dev/null 2>& 1
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-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-10-30 19:32:56 +01:00
## / CONTACT - PUBLISH HTML HOMEPAGE (ADD HTTP HEADER)
2022-10-21 21:50:40 +02:00
if [ [ $URL = = "/" ] ] ; then
2022-10-30 19:32:56 +01:00
echo " / CONTACT : http:// $myIP :1234 "
2022-10-30 03:02:59 +01:00
echo "___________________________ Preparing register.html"
2022-10-31 19:30:23 +01:00
echo " $HTTPCORS " > ~/.zen/tmp/coucou/${ MOATS } .index.redirect ## HTTP 1.1 HEADER + HTML BODY
2022-10-31 02:52:43 +01:00
sed " s~127.0.0.1~ $myIP ~g " $HOME /.zen/Astroport.ONE/templates/register.html >> ~/.zen/tmp/coucou/${ MOATS } .index.redirect
sed -i " s~_IPFSNODEID_~ ${ IPFSNODEID } ~g " ~/.zen/tmp/coucou/${ MOATS } .index.redirect
sed -i " s~_HOSTNAME_~ $( hostname) ~g " ~/.zen/tmp/coucou/${ MOATS } .index.redirect
2022-10-21 22:00:29 +02:00
2022-11-06 12:13:19 +01:00
## Random Background image ;)
2022-11-06 13:03:23 +01:00
sed -i " s~.000.~. $( printf '%03d' $( echo ${ RANDOM } % 18 | bc) ) .~g " ~/.zen/tmp/coucou/${ MOATS } .index.redirect
2022-11-06 12:13:19 +01:00
2022-10-31 02:52:43 +01:00
cat ~/.zen/tmp/coucou/${ MOATS } .index.redirect | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 &
2022-10-22 13:01:46 +02:00
end = ` date +%s`
2022-11-02 17:23:12 +01:00
echo " (☓‿‿☓) 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-10-26 18:38:37 +02:00
############################################################################
############################################################################
2022-10-30 19:32:56 +01: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-11-11 18:22:35 +01:00
# CHECK APPNAME
APPNAME = $( urldecode ${ arr [4] } )
2022-10-27 15:48:35 +02:00
WHAT = $( urldecode ${ arr [5] } )
2022-10-04 23:10:31 +02:00
2022-10-31 19:30:23 +01:00
[ [ ${ arr [0] } = = "" || ${ arr [1] } = = "" ] ] && ( echo " $HTTPCORS ERROR - MISSING DATA " | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 & ) && continue
2022-10-07 03:25:10 +02:00
2022-10-30 19:32:56 +01:00
########## CHECK GET PARAM NAMES
2022-10-21 13:45:53 +02:00
###################################################################################################
###################################################################################################
2022-10-22 17:08:20 +02:00
# API ZERO ## Made In Zion & La Bureautique
2022-10-21 13:45:53 +02:00
if [ [ ${ arr [0] } = = "salt" ] ] ; then
2022-10-30 19:32:56 +01:00
################### KEY GEN ###################################
2022-11-11 18:22:35 +01:00
echo " >>>>>>>>>>>>>> Application LaBureautique >><< APPNAME = $APPNAME <<<<<<<<<<<<<<<<<<<< "
2022-10-30 19:32:56 +01:00
2022-10-26 17:53:37 +02:00
SALT = $( urldecode ${ arr [1] } | xargs) ;
2022-10-31 19:30:23 +01:00
[ [ ! $SALT ] ] && ( echo " $HTTPCORS ERROR - SALT MISSING " | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 & ) && continue
2022-10-26 17:53:37 +02:00
PEPPER = $( urldecode ${ arr [3] } | xargs)
2022-10-31 19:30:23 +01:00
[ [ ! $PEPPER ] ] && ( echo " $HTTPCORS ERROR - PEPPER MISSING " | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 & ) && continue
2022-10-22 17:08:20 +02:00
2022-11-11 18:22:35 +01:00
APPNAME = $( urldecode ${ arr [4] } | xargs)
2022-10-27 15:48:35 +02:00
WHAT = $( urldecode ${ arr [5] } | xargs)
2022-10-21 13:45:53 +02:00
2022-10-30 19:32:56 +01:00
## SAVE "salt" "pepper" DEBUG REMOVE OR PASS ENCRYPT FOR SECURITY REASON
echo " PLAYER CREDENTIALS : \" $SALT \" \" $PEPPER \" "
2022-10-31 02:52:43 +01:00
echo " \" $SALT \" \" $PEPPER \" " > ~/.zen/tmp/coucou/${ MOATS } .secret.june
2022-10-22 15:47:54 +02:00
2022-10-30 19:32:56 +01:00
# CALCULATING ${MOATS}.secret.key + G1PUB
2022-10-31 02:52:43 +01:00
${ MY_PATH } /tools/keygen -t duniter -o ~/.zen/tmp/coucou/${ MOATS } .secret.key " $SALT " " $PEPPER "
G1PUB = $( cat ~/.zen/tmp/coucou/${ MOATS } .secret.key | grep 'pub:' | cut -d ' ' -f 2)
2022-10-31 19:30:23 +01:00
[ [ ! ${ G1PUB } ] ] && ( echo " $HTTPCORS ERROR - KEYGEN COMPUTATION DISFUNCTON " | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 & ) && continue
2022-10-30 19:32:56 +01:00
echo " G1PUB : ${ G1PUB } "
2022-10-21 13:45:53 +02:00
## CALCULATING IPNS ADDRESS
2022-10-30 19:32:56 +01:00
ipfs key rm ${ G1PUB } > /dev/null 2>& 1
2022-10-31 02:52:43 +01:00
rm -f ~/.zen/tmp/coucou/${ MOATS } .${ G1PUB } .ipns.key
${ MY_PATH } /tools/keygen -t ipfs -o ~/.zen/tmp/coucou/${ MOATS } .${ G1PUB } .ipns.key " $SALT " " $PEPPER "
ASTRONAUTENS = $( ipfs key import ${ G1PUB } -f pem-pkcs8-cleartext ~/.zen/tmp/coucou/${ MOATS } .${ G1PUB } .ipns.key )
2022-10-28 13:13:20 +02:00
echo " ASTRONAUTE TW : http:// $myIP :8080/ipns/ ${ ASTRONAUTENS } "
2022-10-27 18:01:04 +02:00
echo
2022-10-30 19:32:56 +01:00
################### KEY GEN ###################################
2022-10-31 18:38:20 +01:00
# Get PLAYER wallet amount
( ## SUB PROCESS
COINS = $( $MY_PATH /tools/jaklis/jaklis.py -k ~/.zen/tmp/coucou/${ MOATS } .secret.key balance)
echo " +++ WALLET BALANCE _ $COINS (G1) _ "
end = ` date +%s`
2022-11-02 17:23:12 +01:00
echo "G1WALLET (☓‿‿☓) Execution time was " ` expr $end - $start ` seconds.
2022-10-31 18:38:20 +01:00
) &
2022-10-28 13:13:20 +02:00
########################################
2022-11-05 20:15:02 +01:00
## ARCHIVE TOCTOC ${WHAT}S & KEEPS LOGS CLEAN
2022-10-31 17:22:40 +01:00
mkdir -p ~/.zen/game/players/.toctoc/
ISTHERE = $( ls -t ~/.zen/game/players/.toctoc/*.${ G1PUB } .ipns.key 2>/dev/null | tail -n 1)
2022-10-22 18:42:58 +02:00
TTIME = $( echo $ISTHERE | rev | cut -d '.' -f 4 | cut -d '/' -f 1 | rev)
if [ [ ! $ISTHERE ] ] ; then
2022-11-05 20:15:02 +01:00
echo " ${ WHAT } 1ST TOCTOC : ${ MOATS } "
2022-10-31 17:22:40 +01:00
cp ~/.zen/tmp/coucou/${ MOATS } .* ~/.zen/game/players/.toctoc/
2022-10-27 18:01:04 +02:00
else ## KEEP 1ST CONTACT ONLY
2022-10-31 02:52:43 +01:00
OLDONE = $( ls -t ~/.zen/tmp/coucou/*.${ G1PUB } .ipns.key | tail -n 1)
2022-10-22 18:42:58 +02:00
DTIME = $( echo $OLDONE | rev | cut -d '.' -f 4 | cut -d '/' -f 1 | rev)
2022-11-05 20:15:02 +01:00
[ [ $DTIME != ${ MOATS } ] ] && rm ~/.zen/tmp/coucou/$DTIME .*
2022-10-22 18:42:58 +02:00
fi
2022-10-27 18:01:04 +02:00
2022-11-11 18:22:35 +01:00
## APPNAME SLECTION ########################
2022-10-25 14:33:15 +02:00
# MESSAGING
2022-11-11 18:22:35 +01:00
if [ [ $APPNAME = = "messaging" ] ] ; then
2022-10-31 18:38:20 +01:00
( ## SUB PROCESS
2022-10-30 19:32:56 +01:00
echo " Extracting ${ G1PUB } messages... "
2022-10-31 17:22:40 +01:00
~/.zen/Astroport.ONE/tools/timeout.sh -t 12 \
2022-10-31 02:52:43 +01:00
${ MY_PATH } /tools/jaklis/jaklis.py -k ~/.zen/tmp/coucou/${ MOATS } .secret.key read -n 10 -j > ~/.zen/tmp/coucou/messin.${ G1PUB } .json
[ [ ! -s ~/.zen/tmp/coucou/messin.${ G1PUB } .json || $( grep -v -E 'Aucun message à afficher' ~/.zen/tmp/coucou/messin.${ G1PUB } .json) = = "True" ] ] && echo "[]" > ~/.zen/tmp/coucou/messin.${ G1PUB } .json
2022-10-26 20:38:01 +02:00
2022-10-31 17:22:40 +01:00
~/.zen/Astroport.ONE/tools/timeout.sh -t 12 \
2022-10-31 02:52:43 +01:00
${ MY_PATH } /tools/jaklis/jaklis.py -k ~/.zen/tmp/coucou/${ MOATS } .secret.key read -n 10 -j -o > ~/.zen/tmp/coucou/messout.${ G1PUB } .json
[ [ ! -s ~/.zen/tmp/coucou/messout.${ G1PUB } .json || $( grep -v -E 'Aucun message à afficher' ~/.zen/tmp/coucou/messout.${ G1PUB } .json) = = "True" ] ] && echo "[]" > ~/.zen/tmp/coucou/messout.${ G1PUB } .json
2022-10-22 17:08:20 +02:00
2022-10-31 02:52:43 +01:00
echo " Creating messages In/Out JSON ~/.zen/tmp/coucou/ ${ MOATS } .messaging.json "
echo '[' > ~/.zen/tmp/coucou/${ MOATS } .messaging.json
cat ~/.zen/tmp/coucou/messin.${ G1PUB } .json >> ~/.zen/tmp/coucou/${ MOATS } .messaging.json
echo "," >> ~/.zen/tmp/coucou/${ MOATS } .messaging.json
cat ~/.zen/tmp/coucou/messout.${ G1PUB } .json >> ~/.zen/tmp/coucou/${ MOATS } .messaging.json
echo ']' >> ~/.zen/tmp/coucou/${ MOATS } .messaging.json
2022-10-21 20:11:47 +02:00
2022-10-25 14:50:15 +02:00
## ADDING HTTP/1.1 PROTOCOL HEADER
2022-10-31 19:30:23 +01:00
echo " $HTTPCORS " > ~/.zen/tmp/coucou/${ MOATS } .index.redirect
sed -i "s~text/html~application/json~g" ~/.zen/tmp/coucou/${ MOATS } .index.redirect
cat ~/.zen/tmp/coucou/${ MOATS } .messaging.json >> ~/.zen/tmp/coucou/${ MOATS } .index.redirect
2022-10-21 20:11:47 +02:00
2022-10-31 02:52:43 +01:00
### REPONSE=$(cat ~/.zen/tmp/coucou/${MOATS}.messaging.json | ipfs add -q)
2022-10-30 19:52:17 +01:00
### ipfs name publish --allow-offline --key=${PORT} /ipfs/$REPONSE
### echo "SESSION http://$myIP:8080/ipns/$SESSIONNS "
2022-10-30 16:07:26 +01:00
2022-10-31 02:52:43 +01:00
cat ~/.zen/tmp/coucou/${ MOATS } .index.redirect | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 &
2022-10-31 17:22:40 +01:00
end = ` date +%s`
2022-11-11 18:22:35 +01:00
echo " $APPNAME (☓‿‿☓) Execution time was " ` expr $end - $start ` seconds.
2022-10-31 17:22:40 +01:00
) &
2022-10-30 03:02:59 +01:00
end = ` date +%s`
2022-11-16 22:06:57 +01:00
echo " Messaging launch (☓‿‿☓) Execution time was " ` expr $end - $start ` seconds.
2022-10-30 03:02:59 +01:00
continue
2022-10-21 20:11:47 +02:00
fi
2022-10-27 18:01:04 +02:00
######################## MESSAGING END
2022-10-25 14:50:15 +02:00
2022-10-27 18:01:04 +02:00
########################################
# G1PUB -> Open Gchange Profile
########################################
2022-11-11 18:22:35 +01:00
if [ [ " $APPNAME " = = "g1pub" && ${ arr [7] } = = "" ] ] ; then
2022-10-28 13:13:20 +02:00
## NO EMAIL = REDIRECT TO GCHANGE PROFILE
2022-10-31 20:07:29 +01:00
sed " s~_TWLINK_~https://www.gchange.fr/#/app/user/ ${ G1PUB } /~g " ~/.zen/Astroport.ONE/templates/index.302 > ~/.zen/tmp/coucou/${ MOATS } .index.redirect
2022-11-05 16:43:13 +01:00
## https://git.p2p.legal/La_Bureautique/zeg1jeux/src/branch/main/lib/Fred.class.php#L81
echo "url='https://www.gchange.fr/#/app/user/" ${ G1PUB } "/'" >> ~/.zen/tmp/coucou/${ MOATS } .index.redirect
2022-11-05 17:51:10 +01:00
echo "GCHANGE REDIRECTING https://www.gchange.fr/#/app/user/" ${ G1PUB } "/"
2022-10-30 19:52:17 +01:00
### REPONSE=$(echo https://www.gchange.fr/#/app/user/${G1PUB}/ | ipfs add -q)
### ipfs name publish --allow-offline --key=${PORT} /ipfs/$REPONSE
### echo "SESSION http://$myIP:8080/ipns/$SESSIONNS "
2022-10-30 16:07:26 +01:00
2022-10-31 02:52:43 +01:00
cat ~/.zen/tmp/coucou/${ MOATS } .index.redirect | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 &
2022-10-30 03:02:59 +01:00
end = ` date +%s`
2022-11-11 18:22:35 +01:00
echo $APPNAME " (☓‿‿☓) Execution time was " ` expr $end - $start ` seconds.
2022-10-30 03:02:59 +01:00
continue
2022-10-27 18:01:04 +02:00
fi
2022-10-27 16:13:15 +02:00
########################################
2022-10-30 17:40:51 +01:00
########################################
########################################
2022-10-27 16:13:15 +02:00
#TESTCRAFT=ON nodeid dataid
2022-10-30 17:40:51 +01:00
########################################
2022-10-27 16:13:15 +02:00
########################################
2022-11-11 18:22:35 +01:00
if [ [ " $APPNAME " = = "testcraft" ] ] ; then
2022-11-16 22:06:57 +01:00
( # testcraft SUB PROCESS
start = ` date +%s`
2022-10-28 13:13:20 +02:00
## RECORD DATA MADE IN BROWSER (JSON)
2022-10-27 13:27:17 +02:00
SALT = $( urldecode ${ arr [1] } | xargs)
PEPPER = $( urldecode ${ arr [3] } | xargs)
NODEID = $( urldecode ${ arr [7] } | xargs)
DATAID = $( urldecode ${ arr [9] } | xargs)
2022-11-05 13:33:49 +01:00
## IS IT INDEX JSON
2022-11-11 18:22:35 +01:00
echo " $APPNAME IS ${ WHAT } "
mkdir -p ~/.zen/tmp/${ IPFSNODEID } /${ ASTRONAUTENS } /${ APPNAME }
2022-10-28 15:32:44 +02:00
2022-11-11 18:22:35 +01:00
[ [ $WHAT = = "on" ] ] && WHAT = "json" # data mimetype (default "on" = json)
2022-10-30 20:04:32 +01:00
2022-11-05 13:33:49 +01:00
## TODO : modify timeout if isLAN or NOT
[ [ $isLAN ] ] && WAIT = 3 || WAIT = 6
2022-11-11 18:22:35 +01:00
echo " 1ST TRY : ipfs --timeout ${ WAIT } s cat /ipfs/ $DATAID > ~/.zen/tmp/ ${ IPFSNODEID } / ${ ASTRONAUTENS } / ${ APPNAME } / ${ MOATS } .data. ${ WHAT } "
ipfs --timeout ${ WAIT } s cat /ipfs/$DATAID > ~/.zen/tmp/${ IPFSNODEID } /${ ASTRONAUTENS } /${ APPNAME } /${ MOATS } .data.${ WHAT }
2022-11-14 20:45:06 +01:00
2022-11-02 17:43:55 +01:00
echo "" > ~/.zen/tmp/.ipfsgw.bad.twt # TODO move in 20h12.sh
2022-11-05 13:33:49 +01:00
2022-11-11 18:22:35 +01:00
if [ [ ! -s ~/.zen/tmp/${ IPFSNODEID } /${ ASTRONAUTENS } /${ APPNAME } /${ MOATS } .data.${ WHAT } ] ] ; then
2022-11-02 17:23:12 +01:00
2022-11-11 18:22:35 +01:00
echo " IPFS TIMEOUT >>> (°▃▃°) $DATAID STILL MISSING GATEWAY BANGING FOR IT (°▃▃°) "
2022-11-14 20:45:06 +01:00
array = ( https://tube.copylaradio.com/ipfs/:hash https://ipns.co/:hash https://dweb.link/ipfs/:hash https://ipfs.io/ipfs/:hash https://ipfs.fleek.co/ipfs/:hash https://ipfs.best-practice.se/ipfs/:hash https://gateway.pinata.cloud/ipfs/:hash https://gateway.ipfs.io/ipfs/:hash https://cf-ipfs.com/ipfs/:hash https://cloudflare-ipfs.com/ipfs/:hash)
2022-11-11 18:22:35 +01:00
# size=${#array[@]}; index=$(($RANDOM % $size)); echo ${array[$index]} ## TODO CHOOSE RANDOM
2022-11-02 17:23:12 +01:00
# official ipfs best gateway from https://luke.lol/ipfs.php
2022-11-11 18:22:35 +01:00
for nicegw in ${ array [@] } ; do
2022-11-14 20:45:06 +01:00
2022-11-02 17:43:55 +01:00
[ [ $( cat ~/.zen/tmp/.ipfsgw.bad.twt | grep -w $nicegw ) ] ] && echo " <<< BAD GATEWAY >>> $nicegw " && continue
2022-11-02 17:23:12 +01:00
gum = $( echo " $nicegw " | sed " s~:hash~ $DATAID ~g " )
echo " LOADING $gum "
2022-11-11 18:22:35 +01:00
curl -m 3 -so ~/.zen/tmp/${ IPFSNODEID } /${ ASTRONAUTENS } /${ APPNAME } /${ MOATS } .data.${ WHAT } " $gum "
2022-11-02 17:43:55 +01:00
[ [ $? != 0 ] ] && echo " (✜‿‿✜) $nicegw BYPASSING " ; echo
2022-11-02 17:23:12 +01:00
2022-11-11 18:22:35 +01:00
if [ [ -s ~/.zen/tmp/${ IPFSNODEID } /${ ASTRONAUTENS } /${ APPNAME } /${ MOATS } .data.${ WHAT } ] ] ; then
2022-11-14 20:45:06 +01:00
MIME = $( mimetype -b ~/.zen/tmp/${ IPFSNODEID } /${ ASTRONAUTENS } /${ APPNAME } /${ MOATS } .data.${ WHAT } )
GOAL = $( ipfs add -q ~/.zen/tmp/${ IPFSNODEID } /${ ASTRONAUTENS } /${ APPNAME } /${ MOATS } .data.${ WHAT } )
if [ [ ${ GOAL } != ${ DATAID } ] ] ; then
echo " (╥☁╥ ) - $nicegw ${ WHAT } FORMAT ERROR - (╥☁╥ ) "
ipfs pin rm /ipfs/${ GOAL }
# NOT A JSON AVOID BANISHMENT
echo $nicegw >> ~/.zen/tmp/.ipfsgw.bad.twt
continue
else
## GOT IT !! IPFS ADD
ipfs pin add /ipfs/${ GOAL }
## + TW ADD (new_file_in_astroport.sh)
echo " (♥‿‿♥) $nicegw OK " ; echo
break
fi
echo " (⇀‿‿↼) - $nicegw TIMEOUT - (⇀‿‿↼) "
2022-11-02 17:23:12 +01:00
continue
2022-11-14 20:45:06 +01:00
2022-11-02 17:43:55 +01:00
fi
2022-11-11 18:22:35 +01:00
2022-11-02 17:23:12 +01:00
done
2022-11-14 20:45:06 +01:00
2022-11-02 17:23:12 +01:00
fi ## NO DIRECT IPFS - GATEWAY TRY
## REALLY NO FILE FOUND !!!
2022-11-11 18:22:35 +01:00
[ [ ! -s ~/.zen/tmp/${ IPFSNODEID } /${ ASTRONAUTENS } /${ APPNAME } /${ MOATS } .data.${ WHAT } ] ] && \
2022-11-02 17:23:12 +01:00
echo " $HTTPCORS ERROR (╥☁╥ ) - $DATAID TIMEOUT - (╥☁╥ ) " | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 &
2022-11-11 18:22:35 +01:00
## SPECIAL index.[json/html/...] MODE.
[ [ ${ WHAT } = = "index" ] ] && cp ~/.zen/tmp/${ IPFSNODEID } /${ ASTRONAUTENS } /${ APPNAME } /${ MOATS } .data.${ WHAT } ~/.zen/tmp/${ IPFSNODEID } /${ APPNAME } .json
## TODO MAKE MULTIFORMAT DATA & INDEX
# RWHAT=$(echo "$WHAT" | cut -d '.' -f 1)
# TWHAT=$(echo "$WHAT" | cut -d '.' -f 2)
# cp ~/.zen/tmp/${IPFSNODEID}/${ASTRONAUTENS}/${APPNAME}/${MOATS}.data.${WHAT} ~/.zen/tmp/${IPFSNODEID}/${APPNAME}/${RWHAT}.${TWHAT}
2022-10-30 20:04:32 +01:00
## REPONSE ON PORT
2022-10-31 19:30:23 +01:00
echo " $HTTPCORS " > ~/.zen/tmp/coucou/${ MOATS } .index.redirect
sed -i "s~text/html~application/json~g" ~/.zen/tmp/coucou/${ MOATS } .index.redirect
2022-11-11 18:22:35 +01:00
cat ~/.zen/tmp/${ IPFSNODEID } /${ ASTRONAUTENS } /${ APPNAME } /${ MOATS } .data.${ WHAT } >> ~/.zen/tmp/coucou/${ MOATS } .index.redirect
2022-10-31 19:30:23 +01:00
cat ~/.zen/tmp/coucou/${ MOATS } .index.redirect | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 &
2022-10-30 20:04:32 +01:00
2022-11-01 14:41:30 +01:00
## REPONSE ON IPFSNODEID
(
2022-11-16 22:06:57 +01:00
start = ` date +%s`
2022-11-01 14:41:30 +01:00
echo " ¯\_༼<O͡〰o>༽_/¯ $IPFSNODEID $PLAYER SIGNALING "
ROUTING = $( ipfs add -rwq ~/.zen/tmp/${ IPFSNODEID } /* | tail -n 1 )
ipfs name publish --allow-offline /ipfs/$ROUTING
echo "DONE"
end = ` date +%s`
2022-11-02 18:01:10 +01:00
echo "MAP PUBLISHING (o‿‿o) Execution time was " ` expr $end - $start ` seconds.
2022-11-01 14:41:30 +01:00
) &
2022-10-31 18:38:20 +01:00
end = ` date +%s`
2022-11-11 18:22:35 +01:00
echo " (| $APPNAME |) Execution time was " ` expr $end - $start ` seconds.
2022-11-16 22:06:57 +01:00
) & # testcraft SUB PROCESS
2022-10-31 18:38:20 +01:00
2022-10-30 03:02:59 +01:00
end = ` date +%s`
2022-11-02 18:01:10 +01:00
echo "(☓‿‿☓) Execution time was " ` expr $end - $start ` seconds.
2022-10-30 03:02:59 +01:00
continue
2022-10-27 13:27:17 +02:00
fi
2022-10-28 13:13:20 +02:00
##############################################
# DEFAULT (NO REDIRECT DONE YET) CHECK OFFICIAL GATEWAY
##############################################
2022-10-31 20:07:29 +01:00
TWIP = $( hostname)
2022-10-30 18:27:08 +01:00
# OFFICIAL Gateway ( increase waiting time ) - MORE SECURE
2022-11-11 18:22:35 +01:00
if [ [ $APPNAME = = "official" ] ] ; then
2022-10-30 18:27:08 +01:00
2022-11-01 00:27:26 +01:00
echo " SEARCHING FOR OFFICIAL TW GW... $LIBRA /ipns/ ${ ASTRONAUTENS } ( $YOU ) "
2022-10-30 18:27:08 +01:00
2022-11-01 00:27:26 +01:00
## GETTING LAST TW via IPFS or HTTP GW
2022-10-31 02:52:43 +01:00
[ [ $YOU ] ] && echo " http:// $myIP :8080/ipns/ ${ ASTRONAUTENS } ( $YOU ) " && ipfs --timeout 12s cat /ipns/${ ASTRONAUTENS } > ~/.zen/tmp/coucou/${ MOATS } .astroindex.html
[ [ ! -s ~/.zen/tmp/coucou/${ MOATS } .astroindex.html ] ] && echo " $LIBRA /ipns/ ${ ASTRONAUTENS } " && curl -m 12 -so ~/.zen/tmp/coucou/${ MOATS } .astroindex.html " $LIBRA /ipns/ ${ ASTRONAUTENS } "
2022-10-30 18:27:08 +01:00
# DEBUG
2022-10-31 02:52:43 +01:00
# echo "tiddlywiki --load ~/.zen/tmp/coucou/${MOATS}.astroindex.html --output ~/.zen/tmp --render '.' 'miz.json' 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' 'MadeInZion'"
2022-10-30 18:27:08 +01:00
# echo "cat ~/.zen/tmp/miz.json | jq -r .[].secret"
2022-10-31 02:52:43 +01:00
if [ [ -s ~/.zen/tmp/coucou/${ MOATS } .astroindex.html ] ] ; then
2022-11-04 20:08:33 +01:00
echo "GOT TW CACHE !!"
2022-10-31 02:52:43 +01:00
tiddlywiki --load ~/.zen/tmp/coucou/${ MOATS } .astroindex.html --output ~/.zen/tmp --render '.' 'miz.json' 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' 'MadeInZion'
2022-11-17 15:24:32 +01:00
CRYPTIP = $( cat ~/.zen/tmp/miz.json | jq -r .[ ] .secret | base16 -d)
2022-11-17 15:53:40 +01:00
[ [ ! $CRYPTIP ] ] && ( echo " $HTTPCORS CRYPTIP ERROR - SORRY - CANNOT CONTINUE " | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 & ) && echo "BAD CRYPTIP (☓‿‿☓) Execution time was " ` expr $( date +%s) - $start ` seconds. && continue
2022-11-16 04:42:27 +01:00
#
# CRYPTO DECODING CRYPTIP -> myIP
rm -f ~/.zen/tmp/myIP.2
2022-11-16 22:06:57 +01:00
echo " $CRYPTIP " > ~/.zen/tmp/myIP.$G1PUB .enc.2
2022-11-16 05:08:45 +01:00
$MY_PATH /tools/natools.py decrypt -f pubsec -k ~/.zen/tmp/coucou/${ MOATS } .secret.key -i ~/.zen/tmp/myIP.$G1PUB .enc.2 -o ~/.zen/tmp/myIP.2 > /dev/null 2>& 1
OLDIP = $( cat ~/.zen/tmp/myIP.2 > /dev/null 2>& 1)
2022-11-16 04:42:27 +01:00
[ [ ! $OLDIP ] ] && OLDIP = $CRYPTIP ## STILL CLEAR IP TW
2022-11-17 15:53:40 +01:00
echo " TW is on $OLDIP ( $CRYPTIP ) "
2022-11-06 10:41:55 +01:00
2022-11-16 05:08:45 +01:00
echo " WAS $OLDIP ( $TUBE ) BECOMING TW GATEWAY : $myIP " ## BECOMING OFFICIAL BECOME R/W TW
2022-11-16 04:42:27 +01:00
###########################
# Modification Tiddlers de contrôle de GW & API
echo '[{"title":"$:/ipfs/saver/api/http/localhost/5001","tags":"$:/ipfs/core $:/ipfs/saver/api","text":"http://' $myIP ':5001"}]' > ~/.zen/tmp/5001.json
echo '[{"title":"$:/ipfs/saver/gateway/http/localhost","tags":"$:/ipfs/core $:/ipfs/saver/gateway","text":"http://' $myIP ':8080"}]' > ~/.zen/tmp/8080.json
tiddlywiki --load ~/.zen/tmp/coucou/${ MOATS } .astroindex.html \
--import " $HOME /.zen/tmp/5001.json " "application/json" \
--import " $HOME /.zen/tmp/8080.json " "application/json" \
--output ~/.zen/tmp/coucou --render " $:/core/save/all " " ${ MOATS } .newindex.html " "text/plain"
[ [ -s ~/.zen/tmp/coucou/${ MOATS } .newindex.html ] ] \
&& cp ~/.zen/tmp/coucou/${ MOATS } .newindex.html ~/.zen/tmp/coucou/${ MOATS } .astroindex.html \
&& rm ~/.zen/tmp/coucou/${ MOATS } .newindex.html
###########################
# GET PLAYER FROM Dessin de $PLAYER (LE NOM DE LA CLEF IPNS EST DANS LE TITRE DE "Dessin de Moa" forgé à la création du TW)
2022-10-31 02:52:43 +01:00
tiddlywiki --load ~/.zen/tmp/coucou/${ MOATS } .astroindex.html --output ~/.zen/tmp --render '.' 'MOA.json' 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' '[tag[moa]]'
2022-11-16 04:42:27 +01:00
PLAYER = $( cat ~/.zen/tmp/MOA.json | jq -r .[ ] .president)
2022-10-31 02:42:18 +01:00
2022-11-17 15:53:40 +01:00
[ [ ! $PLAYER ] ] && ( echo " $HTTPCORS ERROR - BAD [tag[moa]] president field /ipns/ ${ ASTRONAUTENS } - CONTINUE " | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 & ) && echo "BAD MOA (☓‿‿☓) Execution time was " ` expr $( date +%s) - $start ` seconds. && continue
2022-10-31 02:15:06 +01:00
## CREATE $PLAYER IPNS KEY (for next 20h12)
2022-10-31 02:52:43 +01:00
ipfs key import ${ PLAYER } -f pem-pkcs8-cleartext ~/.zen/tmp/coucou/${ MOATS } .${ G1PUB } .ipns.key
2022-10-31 02:42:18 +01:00
[ [ ! -d ~/.zen/game/players/$PLAYER /ipfs/moa ] ] && mkdir -p ~/.zen/game/players/$PLAYER /ipfs/moa/
2022-11-04 20:30:23 +01:00
cp ~/.zen/tmp/coucou/${ MOATS } .astroindex.html ~/.zen/game/players/$PLAYER /ipfs/moa/index.html
2022-10-31 02:15:06 +01:00
2022-11-15 15:31:39 +01:00
echo " ## PUBLISHING ${ PLAYER } /ipns/ $ASTRONAUTENS / & "
(
2022-10-31 02:52:43 +01:00
IPUSH = $( ipfs add -Hq ~/.zen/tmp/coucou/${ MOATS } .astroindex.html | tail -n 1)
2022-10-31 02:42:18 +01:00
[ [ $IPUSH ] ] && ipfs name publish --key= ${ PLAYER } /ipfs/$IPUSH 2>/dev/null
2022-11-15 15:31:39 +01:00
echo " ## PUBLISHING ${ PLAYER } /ipns/ $ASTRONAUTENS / END "
) &
2022-10-31 02:17:27 +01:00
## MEMORISE PLAYER Ŋ1 ZONE (TODO compare with VISA.new.sh)
2022-10-31 02:15:06 +01:00
echo " $PLAYER " > ~/.zen/game/players/$PLAYER /.player
echo " $G1PUB " > ~/.zen/game/players/$PLAYER /.g1pub
2022-11-16 04:42:27 +01:00
echo " ${ ASTRONAUTENS } " > ~/.zen/game/players/$PLAYER /.playerns
2022-11-01 00:27:26 +01:00
OLDIP = ${ myIP }
2022-11-14 15:24:20 +01:00
TWIP = ${ myIP }
2022-10-30 18:27:08 +01:00
echo " *********** OFFICIAL LOGIN GOES TO $TWIP "
2022-11-16 05:08:45 +01:00
2022-10-25 14:33:15 +02:00
else
2022-11-04 20:30:23 +01:00
echo "NO TW FOUND - LAUNCHING CENTRAL"
## 302 REDIRECT CENTRAL GW
cat ~/.zen/Astroport.ONE/templates/index.302 >> ~/.zen/tmp/coucou/${ MOATS } .index.redirect
sed -i " s~_TWLINK_~ $LIBRA /ipns/ ${ ASTRONAUTENS } ~g " ~/.zen/tmp/coucou/${ MOATS } .index.redirect
2022-11-15 15:31:39 +01:00
( cat ~/.zen/tmp/coucou/${ MOATS } .index.redirect | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 & ) && echo "(0‿‿0) Execution time was " ` expr $( date +%s) - $start ` seconds. && continue
2022-10-25 14:33:15 +02:00
fi
2022-10-31 19:06:22 +01:00
2022-11-14 16:46:45 +01:00
## 302 REDIRECT $TWIP
cat ~/.zen/Astroport.ONE/templates/index.302 >> ~/.zen/tmp/coucou/${ MOATS } .index.redirect
sed -i " s~_TWLINK_~http:// $TWIP :8080/ipns/ ${ ASTRONAUTENS } ~g " ~/.zen/tmp/coucou/${ MOATS } .index.redirect
2022-11-15 17:23:23 +01:00
2022-11-15 15:31:39 +01:00
( cat ~/.zen/tmp/coucou/${ MOATS } .index.redirect | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 & ) && echo "(0‿‿0) Execution time was " ` expr $( date +%s) - $start ` seconds. && continue
2022-10-21 13:45:53 +02:00
2022-11-07 01:52:53 +01:00
fi ## official
2022-10-21 13:45:53 +02:00
2022-10-27 13:27:17 +02:00
2022-11-07 01:52:53 +01:00
###################################################################################################
###################################################################################################
# API ONE : ?salt=PHRASE%20UNE&pepper=PHRASE%20DEUX&g1pub=on&email/elastic=ELASTICID&pseudo=PROFILENAME
2022-10-27 20:36:25 +02:00
if [ [ ( ${ arr [6] } = = "email" || ${ arr [6] } = = "elastic" ) && ${ arr [7] } != "" ] ] ; then
2022-10-27 13:27:17 +02:00
2022-11-15 15:31:39 +01:00
[ [ $APPNAME != "g1pub" ] ] && ( echo " $HTTPCORS ERROR - BAD COMMAND $APPNAME " | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 & ) && echo "(☓‿‿☓) Execution time was " ` expr $( date +%s) - $start ` seconds. && continue
2022-10-26 18:38:37 +02:00
2022-11-07 01:52:53 +01:00
start = ` date +%s`
2022-10-22 13:01:46 +02:00
2022-11-07 01:52:53 +01:00
SALT = $( urldecode ${ arr [1] } | xargs)
PEPPER = $( urldecode ${ arr [3] } | xargs)
2022-11-16 06:17:54 +01:00
WHAT = $( urldecode ${ arr [7] } | xargs)
2022-11-07 01:52:53 +01:00
PSEUDO = $( urldecode ${ arr [9] } | xargs)
2022-10-24 02:45:49 +02:00
2022-11-15 15:31:39 +01:00
[ [ ! ${ WHAT } ] ] && ( echo " $HTTPCORS ERROR - MISSING ${ WHAT } FOR ${ WHAT } CONTACT " | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 & ) && echo "(☓‿‿☓) Execution time was " ` expr $( date +%s) - $start ` seconds. && continue
2022-11-05 20:15:02 +01:00
2022-11-07 01:52:53 +01:00
regex = " ^[a-z0-9!#\$%&'*+/=?^_\`{|}~-]+(\.[a-z0-9!# $%&'*+/=?^_\`{|}~-]+)*@([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?\$ "
if [ [ ${ WHAT } = ~ $regex ] ] ; then
echo "VALID EMAIL OK"
else
echo "BAD EMAIL"
( echo " $HTTPCORS KO ${ WHAT } : bad ' " | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 & ) && continue
fi
2022-10-04 23:10:31 +02:00
2022-10-21 13:45:53 +02:00
if [ [ ! $PSEUDO ] ] ; then
2022-11-05 20:15:02 +01:00
PSEUDO = $( echo ${ WHAT } | cut -d '@' -f 1)
2022-10-24 02:45:49 +02:00
PSEUDO = ${ PSEUDO ,, } ; PSEUDO = ${ PSEUDO %%[0-9]* } ${ RANDOM : 0 : 3 }
2022-10-21 13:45:53 +02:00
fi
2022-10-06 15:57:22 +02:00
# PASS CRYPTING KEY
PASS = $( echo " ${ RANDOM } ${ RANDOM } ${ RANDOM } ${ RANDOM } " | tail -c-7)
2022-11-16 06:17:54 +01:00
echo " $SALT / $PEPPER ( $PASS ) "
2022-10-04 23:10:31 +02:00
2022-11-05 20:15:02 +01:00
if [ [ ! -d ~/.zen/game/players/${ WHAT } ] ] ; then
2022-11-17 15:24:32 +01:00
echo " # ASTRONAUT NEW VISA Create VISA.new.sh in background (~/.zen/tmp/email. ${ WHAT } . ${ MOATS } .txt) "
2022-11-05 20:15:02 +01:00
(
$MY_PATH /tools/VISA.new.sh " $SALT " " $PEPPER " " ${ WHAT } " " $PSEUDO " > ~/.zen/tmp/email.${ WHAT } .${ MOATS } .txt
$MY_PATH /tools/mailjet.sh " ${ WHAT } " ~/.zen/tmp/email.${ WHAT } .${ MOATS } .txt
) &
2022-11-17 15:24:32 +01:00
echo " $HTTPCORS - BOOTING - ASTRONAUT $PSEUDO - IPFS FORMATING - [ $SALT + $PEPPER ] ( ${ WHAT } )
<br>- TW - http://$myIP :8080/ipns/$ASTRONAUTENS <br> - GW - /ipns/$IPFSNODEID " | nc -l -p ${ PORT } -q 1 > /dev/null 2>&1 &
2022-11-02 18:01:10 +01:00
echo "(☓‿‿☓) Execution time was " ` expr $end - $start ` seconds.
2022-10-26 18:26:50 +02:00
continue
2022-10-21 13:45:53 +02:00
else
2022-11-05 20:15:02 +01:00
# ASTRONAUT EXISTING ${WHAT}
CHECK = $( cat ~/.zen/game/players/${ WHAT } /secret.june | grep -w " $SALT " )
[ [ $CHECK ] ] && CHECK = $( cat ~/.zen/game/players/${ WHAT } /secret.june | grep -w " $PEPPER " )
2022-11-15 15:31:39 +01:00
[ [ ! $CHECK ] ] && ( echo " $HTTPCORS ERROR - ${ WHAT } ${ WHAT } ALREADY EXISTS " | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 & ) && echo "(☓‿‿☓) Execution time was " ` expr $( date +%s) - $start ` seconds. && continue
2022-10-24 03:00:50 +02:00
fi
2022-10-22 13:01:46 +02:00
2022-10-26 18:26:50 +02:00
###################################################################################################
2022-10-06 15:57:22 +02:00
end = ` date +%s`
2022-11-02 17:23:12 +01:00
echo " (☓‿‿☓) Execution time was " ` expr $end - $start ` seconds.
2022-10-04 23:10:31 +02:00
fi
2022-11-07 01:52:53 +01:00
## RESPONDING
cat ~/.zen/tmp/coucou/${ MOATS } .index.redirect | nc -l -p ${ PORT } -q 1 > ~/.zen/tmp/coucou/${ MOATS } .official.swallow &
echo "HTTP 1.1 PROTOCOL DOCUMENT READY"
cat ~/.zen/tmp/coucou/${ MOATS } .index.redirect
echo " ${ MOATS } -----> PAGE AVAILABLE -----> http:// $myIP : ${ PORT } "
#echo "${ASTRONAUTENS}" | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &
## CHECK IF ALREADY EXISTING ${WHAT}
# IF NOT = BATCH CREATE TW
end = ` date +%s`
echo $type " (☓‿‿☓) Execution time was " ` expr $end - $start ` seconds.
fi ## END IF SALT
2022-10-06 15:57:22 +02:00
###################################################################################################
###################################################################################################
2022-10-21 13:45:53 +02:00
# API TWO : ?qrcode=G1PUB
2022-10-04 23:10:31 +02:00
if [ [ ${ arr [0] } = = "qrcode" ] ] ; then
2022-11-05 20:15:02 +01:00
## Astroport.ONE local use QRCODE Contains ${WHAT} G1PUB
2022-10-26 18:26:50 +02:00
QRCODE = $( echo $URL | cut -d ' ' -f2 | cut -d '=' -f 2 | cut -d '&' -f 1) && echo " QRCODE : $QRCODE "
2022-10-04 23:10:31 +02:00
g1pubpath = $( grep $QRCODE ~/.zen/game/players/*/.g1pub | cut -d ':' -f 1 2>/dev/null)
2022-11-16 06:17:54 +01:00
WHAT = $( echo " $g1pubpath " | rev | cut -d '/' -f 2 | rev 2>/dev/null)
2022-10-04 23:10:31 +02:00
## FORCE LOCAL USE ONLY. Remove to open 1234 API
2022-11-05 20:15:02 +01:00
[ [ ! -d ~/.zen/game/players/${ WHAT } || ${ WHAT } = = "" ] ] && ( echo " $HTTPCORS ERROR - QRCODE - NO ${ WHAT } ON BOARD !! " | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 & ) && continue
2022-10-04 23:10:31 +02:00
2022-10-28 20:47:47 +02:00
## USE SECOND HTTP SERVER TO RECEIVE PASS
2022-10-04 23:10:31 +02:00
2022-10-31 19:30:23 +01:00
[ [ ${ arr [2] } = = "" ] ] && ( echo " $HTTPCORS ERROR - QRCODE - MISSING ACTION " | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 & ) && continue
2022-10-26 18:26:50 +02:00
## Demande de copie d'une URL reçue.
if [ [ ${ arr [2] } = = "url" ] ] ; then
wsource = " ${ arr [3] } "
[ [ ${ arr [4] } = = "type" ] ] && wtype = " ${ arr [5] } " || wtype = "Youtube"
2022-10-07 02:16:53 +02:00
2022-10-28 20:47:47 +02:00
## CREATION TIDDLER "G1Voeu" G1CopierYoutube
2022-10-30 02:29:45 +01:00
# /.zen/Astropor.ONE/ajouter_media.sh "$(urldecode $wsource)" "$wtype" "$QRCODE" &
2022-10-28 20:47:47 +02:00
echo "## Insertion tiddler : G1CopierYoutube"
echo ' [
{
"title" : " ' ${ MOATS } ' " ,
"type" : "'text/vnd.tiddlywiki'" ,
"text" : " ' $( urldecode $wsource ) ' " ,
2022-11-05 20:15:02 +01:00
"tags" : " 'CopierYoutube ${ ${ WHAT } } ' "
2022-10-28 20:47:47 +02:00
}
]
2022-11-05 20:15:02 +01:00
' > ~/.zen/tmp/${ ${ WHAT } } .${ MOATS } .import.json
2022-10-28 20:47:47 +02:00
2022-11-05 20:15:02 +01:00
## TODO ASTROBOT "G1AstroAPI" READS ~/.zen/tmp/${${WHAT}}.${MOATS}.import.json
2022-10-28 20:47:47 +02:00
2022-11-05 20:15:02 +01:00
( echo " $HTTPCORS OK - ~/.zen/tmp/ ${ ${ WHAT } } . ${ MOATS } .import.json WORKS IF YOU MAKE THE WISH voeu 'AstroAPI' " | nc -l -p ${ PORT } -q 1 > /dev/null 2>& 1 & ) && continue
2022-10-26 18:26:50 +02:00
fi
2022-10-04 23:10:31 +02:00
fi
2022-10-21 14:38:25 +02:00
2022-10-04 23:10:31 +02:00
done
exit 0