This commit is contained in:
fred 2022-10-22 17:08:20 +02:00
parent 94d3556042
commit 4409797bf7
2 changed files with 47 additions and 43 deletions

View File

@ -18,6 +18,8 @@ myIP=$(hostname -I | awk '{print $1}' | head -n 1)
[[ ! $myIP ]] && myIP="127.0.1.1"
PORT=12345
mkdir -p ~/.zen/tmp/123
## CHECK FOR ANY ALREADY RUNNING nc
ncrunning=$(ps auxf --sort=+utime | grep -w 'nc -l -p 1234' | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1)
[[ $ncrunning ]] && echo "ERROR - API Server Already Running - http://$myIP:1234/?salt=toto&pepper=toto " && exit 1
@ -39,8 +41,8 @@ while true; do
echo "$MOATS LANDING PAGE http://$myIP:$PORT"
# REPLACE myIP in http response template
sed "s~127.0.0.1:12345~$myIP:$PORT~g" $HOME/.zen/Astroport.ONE/templates/index.http > ~/.zen/tmp/${MOATS}.myIP.http
sed -i "s~127.0.0.1~$myIP~g" ~/.zen/tmp/${MOATS}.myIP.http
sed "s~127.0.0.1:12345~$myIP:$PORT~g" $HOME/.zen/Astroport.ONE/templates/index.http > ~/.zen/tmp/123/${MOATS}.myIP.http
sed -i "s~127.0.0.1~$myIP~g" ~/.zen/tmp/123/${MOATS}.myIP.http
## WAITING TO SERVE LANDING REDIRECT PAGE
URL=$(cat $HOME/.zen/tmp/${MOATS}.myIP.http | nc -l -p 1234 -q 1 | grep '^GET' | cut -d ' ' -f2 | cut -d '?' -f2)
@ -54,10 +56,10 @@ while true; do
echo "HTTP/1.1 200 OK
Server: Astroport
Content-Type: text/html; charset=UTF-8
" > ~/.zen/tmp/${MOATS}.index.redirect
sed "s~127.0.0.1~$myIP~g" $HOME/.zen/Astroport.ONE/templates/homepage.html >> ~/.zen/tmp/${MOATS}.index.redirect
" > ~/.zen/tmp/123/${MOATS}.index.redirect
sed "s~127.0.0.1~$myIP~g" $HOME/.zen/Astroport.ONE/templates/homepage.html >> ~/.zen/tmp/123/${MOATS}.index.redirect
cat ~/.zen/tmp/${MOATS}.index.redirect | nc -l -p ${PORT} -q 1 &
cat ~/.zen/tmp/123/${MOATS}.index.redirect | nc -l -p ${PORT} -q 1 &
end=`date +%s`
echo Execution time was `expr $end - $start` seconds.
@ -70,67 +72,67 @@ sed "s~127.0.0.1~$myIP~g" $HOME/.zen/Astroport.ONE/templates/homepage.html >> ~/
echo "PARAM : ${arr[0]} = ${arr[1]} & ${arr[2]} = ${arr[3]} & ${arr[4]} = ${arr[5]} & ${arr[6]} = ${arr[7]}"
[[ ${arr[0]} == "" && ${arr[1]} == "" ]] && echo "GET NO DATA" && continue
[[ ${arr[1]} == "ph1" ]] && echo "GET NO DATA" && continue
########## CHECK GET PARAM NAMES
###################################################################################################
###################################################################################################
# API ZERO : ?salt=Phrase%20Une&pepper=Phrase%20Deux
# API ZERO ## Made In Zion & La Bureautique
if [[ ${arr[0]} == "salt" ]]; then
echo "Application G1Radar !!"
echo "Application LaBureautique !!"
SALT=$(urldecode ${arr[1]})
[[ ! $SALT ]] && echo "BAD SALT API CALL" && continue
PEPPER=$(urldecode ${arr[3]})
[[ ! $PEPPER ]] && echo "BAD PEPPER API CALL" && continue
TYPE=$(urldecode ${arr[4]})
PLAYER=$(urldecode ${arr[5]})
echo "API ZERO CALL : http://$myIP:1234/?salt=$SALT&pepper=$PEPPER&$TYPE=$PLAYER"
echo "\"$SALT\" \"$PEPPER\"" > ~/.zen/tmp/${MOATS}.secret.june
echo "\"$SALT\" \"$PEPPER\"" > ~/.zen/tmp/123/${MOATS}.secret.june
# CALCULATING G1PUB
${MY_PATH}/tools/keygen -t duniter -o ~/.zen/tmp/${MOATS}.secret.key "$SALT" "$PEPPER"
G1PUB=$(cat ~/.zen/tmp/${MOATS}.secret.key | grep 'pub:' | cut -d ' ' -f 2)
${MY_PATH}/tools/keygen -t duniter -o ~/.zen/tmp/123/${MOATS}.secret.key "$SALT" "$PEPPER"
G1PUB=$(cat ~/.zen/tmp/123/${MOATS}.secret.key | grep 'pub:' | cut -d ' ' -f 2)
[[ ! $G1PUB ]] && echo "ERROR - G1PUB COMPUTATION EMPTY" && continue
## CALCULATING IPNS ADDRESS
ipfs key rm gchange 2>/dev/null
rm -f ~/.zen/tmp/${MOATS}.${G1PUB}.ipns.key
${MY_PATH}/tools/keygen -t ipfs -o ~/.zen/tmp/${MOATS}.${G1PUB}.ipns.key "$SALT" "$PEPPER"
GNS=$(ipfs key import gchange -f pem-pkcs8-cleartext ~/.zen/tmp/${MOATS}.${G1PUB}.ipns.key )
rm -f ~/.zen/tmp/123/${MOATS}.${G1PUB}.ipns.key
${MY_PATH}/tools/keygen -t ipfs -o ~/.zen/tmp/123/${MOATS}.${G1PUB}.ipns.key "$SALT" "$PEPPER"
GNS=$(ipfs key import gchange -f pem-pkcs8-cleartext ~/.zen/tmp/123/${MOATS}.${G1PUB}.ipns.key )
echo "Astronaute TW ? http://$myIP:8080/ipns/$GNS"
if [[ $TYPE == "messaging" ]]; then
echo "Extracting $G1PUB messages..."
${MY_PATH}/tools/jaklis/jaklis.py -k ~/.zen/tmp/${MOATS}.secret.key read -n 10 -j > ~/.zen/tmp/messin.${G1PUB}.json
[[ $(grep -v -E 'Aucun message à afficher' ~/.zen/tmp/messin.${G1PUB}.json) == "True" ]] && echo "[]" > ~/.zen/tmp/messin.${G1PUB}.json
${MY_PATH}/tools/jaklis/jaklis.py -k ~/.zen/tmp/${MOATS}.secret.key read -n 10 -j -o > ~/.zen/tmp/messout.${G1PUB}.json
[[ $(grep -v -E 'Aucun message à afficher' ~/.zen/tmp/messout.${G1PUB}.json) == "True" ]] && echo "[]" > ~/.zen/tmp/messout.${G1PUB}.json
${MY_PATH}/tools/jaklis/jaklis.py -k ~/.zen/tmp/123/${MOATS}.secret.key read -n 10 -j > ~/.zen/tmp/123/messin.${G1PUB}.json
[[ $(grep -v -E 'Aucun message à afficher' ~/.zen/tmp/123/messin.${G1PUB}.json) == "True" ]] && echo "[]" > ~/.zen/tmp/123/messin.${G1PUB}.json
${MY_PATH}/tools/jaklis/jaklis.py -k ~/.zen/tmp/123/${MOATS}.secret.key read -n 10 -j -o > ~/.zen/tmp/123/messout.${G1PUB}.json
[[ $(grep -v -E 'Aucun message à afficher' ~/.zen/tmp/123/messout.${G1PUB}.json) == "True" ]] && echo "[]" > ~/.zen/tmp/123/messout.${G1PUB}.json
echo "Creating messages In/Out JSON ~/.zen/tmp/${MOATS}.messaging.json"
echo '[' > ~/.zen/tmp/${MOATS}.messaging.json
cat ~/.zen/tmp/messin.${G1PUB}.json >> ~/.zen/tmp/${MOATS}.messaging.json
echo "," >> ~/.zen/tmp/${MOATS}.messaging.json
cat ~/.zen/tmp/messout.${G1PUB}.json >> ~/.zen/tmp/${MOATS}.messaging.json
echo ']' >> ~/.zen/tmp/${MOATS}.messaging.json
echo "Creating messages In/Out JSON ~/.zen/tmp/123/${MOATS}.messaging.json"
echo '[' > ~/.zen/tmp/123/${MOATS}.messaging.json
cat ~/.zen/tmp/123/messin.${G1PUB}.json >> ~/.zen/tmp/123/${MOATS}.messaging.json
echo "," >> ~/.zen/tmp/123/${MOATS}.messaging.json
cat ~/.zen/tmp/123/messout.${G1PUB}.json >> ~/.zen/tmp/123/${MOATS}.messaging.json
echo ']' >> ~/.zen/tmp/123/${MOATS}.messaging.json
echo "HTTP/1.1 200 OK
Server: Astroport
Content-Type: text/html; charset=UTF-8
" > ~/.zen/tmp/${MOATS}.index.redirect
cat ~/.zen/tmp/${MOATS}.messaging.json >> ~/.zen/tmp/${MOATS}.index.redirect
" > ~/.zen/tmp/123/${MOATS}.index.redirect
cat ~/.zen/tmp/123/${MOATS}.messaging.json >> ~/.zen/tmp/123/${MOATS}.index.redirect
fi
## IF NO MESSAGING => IPNS TW REDIRECT PAGE
[[ "$TYPE" == "g1pub" ]] && sed "s~_TWLINK_~https://www.gchange.fr/#/app/user/$G1PUB/~g" ~/.zen/Astroport.ONE/templates/index.redirect > ~/.zen/tmp/${MOATS}.index.redirect
[[ ! -f ~/.zen/tmp/${MOATS}.index.redirect ]] && sed "s~_TWLINK_~http://$myIP:8080/ipns/$GNS~g" ~/.zen/Astroport.ONE/templates/index.redirect > ~/.zen/tmp/${MOATS}.index.redirect
[[ "$TYPE" == "g1pub" ]] && sed "s~_TWLINK_~https://www.gchange.fr/#/app/user/$G1PUB/~g" ~/.zen/Astroport.ONE/templates/index.redirect > ~/.zen/tmp/123/${MOATS}.index.redirect
[[ ! -f ~/.zen/tmp/123/${MOATS}.index.redirect ]] && sed "s~_TWLINK_~http://$myIP:8080/ipns/$GNS~g" ~/.zen/Astroport.ONE/templates/index.redirect > ~/.zen/tmp/123/${MOATS}.index.redirect
## RESPONDING
cat ~/.zen/tmp/${MOATS}.index.redirect | nc -l -p ${PORT} -q 1 &
echo "HTTP 1.1 PROTOCOL DOCUMENT READY ~/.zen/tmp/${MOATS}.index.redirect"
cat ~/.zen/tmp/123/${MOATS}.index.redirect | nc -l -p ${PORT} -q 1 &
echo "HTTP 1.1 PROTOCOL DOCUMENT READY ~/.zen/tmp/123/${MOATS}.index.redirect"
echo "$MOATS -----> PAGE AVAILABLE -----> http://$myIP:${PORT}"
#echo "$GNS" | nc -l -p ${PORT} -q 1 &
@ -148,9 +150,9 @@ cat ~/.zen/tmp/${MOATS}.messaging.json >> ~/.zen/tmp/${MOATS}.index.redirect
if [[ ${arr[0]} == "email" || ${arr[0]} == "elastic" ]]; then
#######################################
### RELAUCH myIP.http.${MOATS} SELF REDIRECT $PORT PAGE UNTIL ~/.zen/tmp/${MOATS}.index.redirect IS CREATED &
### RELAUCH myIP.http.${MOATS} SELF REDIRECT $PORT PAGE UNTIL ~/.zen/tmp/123/${MOATS}.index.redirect IS CREATED &
###################################################################################################
while [[ ! -f ~/.zen/tmp/${MOATS}.index.redirect && ! $(ps auxf --sort=+utime | grep -w 'nc -l -p '${PORT} | grep -v -E 'color=auto|grep') ]]; do cat $HOME/.zen/tmp/${MOATS}.myIP.http | nc -l -p ${PORT} -q 1; done &
while [[ ! -f ~/.zen/tmp/123/${MOATS}.index.redirect && ! $(ps auxf --sort=+utime | grep -w 'nc -l -p '${PORT} | grep -v -E 'color=auto|grep') ]]; do cat $HOME/.zen/tmp/${MOATS}.myIP.http | nc -l -p ${PORT} -q 1; done &
###################################################################################################
PLAYER=$(urldecode ${arr[1]})
@ -178,15 +180,15 @@ while [[ ! -f ~/.zen/tmp/${MOATS}.index.redirect && ! $(ps auxf --sort=+utime |
[[ $CHECK ]] && CHECK=$(cat ~/.zen/game/players/$PLAYER/secret.june | grep -w "$PEPPER")
[[ ! $CHECK ]] && echo "ERROR - CREDENTIALS NOT CORRESPONDING WITH PLAYER" && continue
mkdir -p ~/.zen/tmp/TW/
cp ~/.zen/game/players/$PLAYER/ipfs/moa/index.html ~/.zen/tmp/TW/index.html
mkdir -p ~/.zen/tmp/123/TW/
cp ~/.zen/game/players/$PLAYER/ipfs/moa/index.html ~/.zen/tmp/123/TW/index.html
fi
###################################################################################################
# VERIFICATION PAR EXTRACTION MOA
rm -f ~/.zen/tmp/tiddlers.json
tiddlywiki --load ~/.zen/tmp/TW/index.html --output ~/.zen/tmp --render '.' 'tiddlers.json' 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' '[tag[moa]]'
TITLE=$(cat ~/.zen/tmp/tiddlers.json | jq -r '.[].title') # Dessin de PLAYER
rm -f ~/.zen/tmp/123/tiddlers.json
tiddlywiki --load ~/.zen/tmp/123/TW/index.html --output ~/.zen/tmp --render '.' 'tiddlers.json' 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' '[tag[moa]]'
TITLE=$(cat ~/.zen/tmp/123/tiddlers.json | jq -r '.[].title') # Dessin de PLAYER
PLAYER=$(echo $TITLE | rev | cut -f 1 -d ' ' | rev)
[[ ! $PLAYER ]] && echo "ERROR WRONG TW" && continue
@ -197,13 +199,13 @@ while [[ ! -f ~/.zen/tmp/${MOATS}.index.redirect && ! $(ps auxf --sort=+utime |
echo "$TWLINK"
# Injection TWLINK dans template de redirection.
sed "s~_TWLINK_~$TWLINK~g" ~/.zen/Astroport.ONE/templates/index.redirect > ~/.zen/tmp/${MOATS}.index.redirect
sed "s~_TWLINK_~$TWLINK~g" ~/.zen/Astroport.ONE/templates/index.redirect > ~/.zen/tmp/123/${MOATS}.index.redirect
## NOW ~/.zen/tmp/${MOATS}.index.redirect APPEARS. WAITING $PORT AVAILABLE THEN INJECT $TWLINK REDIRECT
## NOW ~/.zen/tmp/123/${MOATS}.index.redirect APPEARS. WAITING $PORT AVAILABLE THEN INJECT $TWLINK REDIRECT
while [[ $(ps auxf --sort=+utime | grep -w 'nc -l -p '${PORT} | grep -v -E 'color=auto|grep') ]]; do echo "sleeping...."; sleep 0.5; done
echo "ASTRONAUT REDIRECTION $TWLINK AVAILABLE on http://$myIP:${PORT}"
cat ~/.zen/tmp/${MOATS}.index.redirect | nc -l -p ${PORT} -q 1 &
cat ~/.zen/tmp/123/${MOATS}.index.redirect | nc -l -p ${PORT} -q 1 &
###################################################################################################
end=`date +%s`
@ -251,7 +253,7 @@ while [[ ! -f ~/.zen/tmp/${MOATS}.index.redirect && ! $(ps auxf --sort=+utime |
[[ "$1" == "ONE" ]] && exit 0
rm ~/.zen/tmp/${MOATS}.myIP.http
rm ~/.zen/tmp/123/${MOATS}.myIP.http
HOMEPAGE=""
done

View File

@ -41,8 +41,10 @@
<form action = "http://127.0.0.1:1234" method = "GET">
Phrase Une : <input name=salt value=''></br>
Phrase Deux : <input name=pepper value=''></br>
Email : <input name=email value=''></br>
<input type='submit' value='OK'>
( GChange <input type="checkbox" id="g1pub" name="g1pub" checked> )
<input type='submit' value='CONNEXION'>
</form>
</center>