making it work

This commit is contained in:
fred 2022-10-30 03:02:59 +01:00
parent 3d86a14879
commit e192c217ee
4 changed files with 133 additions and 98 deletions

View File

@ -67,17 +67,16 @@ while true; do
## BARE URL CONTACT - PUBLISH HTML HOMEPAGE (ADD HTTP HEADER)
if [[ $URL == "/" ]]; then
echo "API NULL CALL : http://$myIP:1234"
echo "___________________________ Launching homepage.html"
echo "___________________________ Preparing register.html"
echo "HTTP/1.1 200 OK
Server: Astroport
Content-Type: text/html; charset=UTF-8
" > ~/.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
sed "s~127.0.0.1~$myIP~g" $HOME/.zen/Astroport.ONE/templates/register.html >> ~/.zen/tmp/123/${MOATS}.index.redirect
sed -i "s~_IPFSNODEID_~${IPFSNODEID}~g" ~/.zen/tmp/123/${MOATS}.index.redirect
sed -i "s~_HOSTNAME_~$(hostname)~g" ~/.zen/tmp/123/${MOATS}.index.redirect
cat ~/.zen/tmp/123/${MOATS}.index.redirect | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &
end=`date +%s`
echo Execution time was `expr $end - $start` seconds.
continue
@ -110,13 +109,13 @@ sed -i "s~_HOSTNAME_~$(hostname)~g" ~/.zen/tmp/123/${MOATS}.index.redirect
TYPE=$(urldecode ${arr[4]} | xargs)
WHAT=$(urldecode ${arr[5]} | xargs)
echo "API ZERO CALL : \"$SALT\" \"$PEPPER\""
echo "API CALL CREDENTIALS : \"$SALT\" \"$PEPPER\""
echo "\"$SALT\" \"$PEPPER\"" > ~/.zen/tmp/123/${MOATS}.secret.june
# CALCULATING G1PUB
${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" | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &) && continue
[[ ! $G1PUB ]] && (echo "ERROR - CORE COMPUTATION DISFUNCTON" | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &) && continue
echo "G1PUB : $G1PUB"
## CALCULATING IPNS ADDRESS
ipfs key rm gchange > /dev/null 2>&1
@ -166,6 +165,10 @@ Content-Type: text/html; charset=UTF-8
" > ~/.zen/tmp/123/${MOATS}.index.redirect
cat ~/.zen/tmp/123/${MOATS}.messaging.json >> ~/.zen/tmp/123/${MOATS}.index.redirect
cat ~/.zen/tmp/123/${MOATS}.index.redirect | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &
end=`date +%s`
echo Execution time was `expr $end - $start` seconds.
continue
fi
######################## MESSAGING END
@ -175,6 +178,10 @@ cat ~/.zen/tmp/123/${MOATS}.messaging.json >> ~/.zen/tmp/123/${MOATS}.index.redi
if [[ "$TYPE" == "g1pub" && ${arr[7]} == "" ]]; then
## NO EMAIL = REDIRECT TO GCHANGE PROFILE
sed "s~_TWLINK_~https://www.gchange.fr/#/app/user/$G1PUB/~g" ~/.zen/Astroport.ONE/templates/index.redirect > ~/.zen/tmp/123/${MOATS}.index.redirect
cat ~/.zen/tmp/123/${MOATS}.index.redirect | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &
end=`date +%s`
echo Execution time was `expr $end - $start` seconds.
continue
fi
########################################
#TESTCRAFT=ON nodeid dataid
@ -206,7 +213,10 @@ cat ~/.zen/tmp/123/${MOATS}.messaging.json >> ~/.zen/tmp/123/${MOATS}.index.redi
## TODO ADD data.json to PLAYER TW
echo "OK - $NODEID GONE GET YOUR /ipfs/$DATAID"
(echo "/ipns/${IPFSNODEID}/$NODEID/${MOATS}/ " | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &) && continue
echo "/ipns/${IPFSNODEID}/$NODEID/${MOATS}/ " | nc -l -p ${PORT} -q 1 > /dev/null 2>&1 &
end=`date +%s`
echo Execution time was `expr $end - $start` seconds.
continue
fi
##############################################

View File

@ -1,88 +0,0 @@
#!/bin/bash
################################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
################################################################################
# Construction du canal 'qo-op' à partir des journaux qo-op_$PLAYER
#
################################################################################
################################################################################
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")
# Check who is currently current connected PLAYER
PLAYER=$(cat ~/.zen/game/players/.current/.player 2>/dev/null) || ( echo "noplayer" && exit 1 )
PSEUDO=$(cat ~/.zen/game/players/.current/.pseudo 2>/dev/null) || ( echo "nopseudo" && exit 1 )
G1PUB=$(cat ~/.zen/game/players/.current/.g1pub 2>/dev/null) || ( echo "nog1pub" && exit 1 )
IPFSNODEID=$(cat ~/.zen/game/players/.current/.ipfsnodeid 2>/dev/null) || ( echo "noipfsnodeid" && exit 1 )
# Astroport Station "Captain" connected?
source ~/.zen/ipfs.sync; echo "CAPTAIN is $CAPTAIN"
[[ $PLAYER != $CAPTAIN ]] && echo "CAPTAIN RUN ONLY. EXIT" && exit 1
MOANS=$(ipfs key list -l | grep -w moa | cut -d ' ' -f 1) ## GET CAPTAIN PLAYER NS PUBKEY
[[ $MOANS == "" ]] && echo "NO MOA KEY EXIT" && exit 1
CAPTAINNS=$(ipfs key list -l | grep -w $CAPTAIN | cut -d ' ' -f 1) ## GET CAPTAIN PLAYER NS PUBKEY
CAPTAINMOANS=$(ipfs key list -l | grep -w moa_$CAPTAIN | cut -d ' ' -f 1)
CAPTAINQOOPNS=$(ipfs key list -l | grep -w qo-op_$CAPTAIN | cut -d ' ' -f 1)
# Copying homepage.html template
cat ${MY_PATH}/../templates/homepage.html > ~/.zen/game/players/$CAPTAIN/moa/slick.html
sed -i "s~_IPNSL_~/ipns/$MOANS~g" ~/.zen/game/players/$CAPTAIN/moa/slick.html
TAGS=$(${MY_PATH}/get_tagcloud_data.sh | tail -n 1)
sed -i "s~_TAGCLOUD_~$TAGS~g" ~/.zen/game/players/$CAPTAIN/moa/slick.html
cp -R ${MY_PATH}/../templates/styles ~/.zen/game/players/$CAPTAIN/moa/
cp -R ${MY_PATH}/../templates/js ~/.zen/game/players/$CAPTAIN/moa/
sed -i "s~_PLAYER_~${PLAYER}~g" ~/.zen/game/players/$CAPTAIN/moa/slick.html
sed -i "s~_PSEUDO_~${PSEUDO}~g" ~/.zen/game/players/$CAPTAIN/moa/slick.html
#echo "## PUBLISHING ${CAPTAIN} /ipns/$CAPTAINNS"
IPUSH=$(ipfs add -rwHq ~/.zen/game/players/$CAPTAIN/moa/* | tail -n 1)
ipfs name publish --key=${CAPTAIN} /ipfs/$IPUSH 2>/dev/null
echo "http://127.0.0.1:8080/ipns/$CAPTAINNS/slick.html"
echo
# CHECK tokenring
# Indicate who is next.
# If it is my turn...
# UPDATE TW UPDATE CHAIN
for astronaut in $(ls ~/.zen/game/players/); do
[[ $astronaut == $CAPTAIN ]] && continue
moans=$(cat ~/.zen/game/players/$astronaut/.moans)
# CHECK DIFFERENCES FROM LATEST TIME CHECK
## GETTING LAST 'player_moa' ONLINE VERSION
echo "Getting $astronaut/.moans /ipns/$moans"
cp ~/.zen/game/players/$astronaut/moa/index.html ~/.zen/tmp/index.html
ipfs --timeout=10s get -o ~/.zen/game/players/$astronaut/moa/ /ipns/$moans
IPUSH=$(ipfs add -Hq ~/.zen/game/players/$astronaut/moa/index.html | tail -n 1)
if [[ $IPUSH != "Qmc5m94Gu7z62RC8waSKkZUrCCBJPyHbkpmGzEePxy2oXJ" ]]; then
# Qmc5m94Gu7z62RC8waSKkZUrCCBJPyHbkpmGzEePxy2oXJ = VIDE !!
echo $IPUSH > ~/.zen/game/players/$astronaut/moa/$astronaut.moa.chain
echo $MOATS > ~/.zen/game/players/$astronaut/moa/$astronaut.moa.ts
num=$(cat ~/.zen/game/players/$astronaut/moa/$astronaut.moa.n 2>/dev/null) || num=0
echo $(expr $num + 1) > ~/.zen/game/players/$astronaut/moa/$astronaut.moa.n
ipfs name publish --key=moa_${astronaut} /ipfs/$IPUSH 2>/dev/null
# Avance la blockchain CAPTAIN pour archiver les '$astronaut.moa.chain' des Etats modifiés
[[ $(cat ~/.zen/game/players/$CAPTAIN/moa/$astronaut.moa.chain 2>/dev/null) != "$IPUSH" ]] &&\
echo $IPUSH > ~/.zen/game/players/$CAPTAIN/moa/$astronaut.moa.chain && \
echo $MOATS > ~/.zen/game/players/$CAPTAIN/moa/$astronaut.moa.ts && \
echo "$astronaut 'moa' UPDATE : $MOATS $IPUSH" && \
diff ~/.zen/tmp/index.html ~/.zen/game/players/$astronaut/moa/index.html | sed -n -e 's/^> //p'
# echo "<div class='multiple'><h4><a href='http://127.0.0.1:8080/ipns/"${moans}"' target=${moans}>$astronaut</a></h4></div>" >> ~/.zen/game/players/$CAPTAIN/moa/slick.div
fi
done
exit 0

View File

@ -8,7 +8,7 @@ Content-Type: text/html; charset=UTF-8
<!doctype html>
<html>
<head>
<meta http-equiv="refresh" content="60; url='http://127.0.0.1:12345'" />
<meta http-equiv="refresh" content="12; url='http://127.0.0.1:12345'" />
<style>
#reduce42 {
width:42%;
@ -29,13 +29,13 @@ Content-Type: text/html; charset=UTF-8
<body>
<center>
<h2>Astronaute - Ouvrez votre TW Astroport Ŋ1</h2>
<h2>Astronaute<br> - TW Astroport Ŋ1 -</h2>
<form action = "http://127.0.0.1:1234" method = "GET">
<br>
Phrase Une : <input name=salt value=''></br>
Phrase Deux : <input name=pepper value=''></br>
( TW officiel <input type="checkbox" id="official" name="official"> - Visiteur <input type="checkbox" id="g1pub" name="g1pub" checked> )</br></br>
<input type='submit' value='MON TW'>
<input type='submit' value='CONNECTION'>
</form>
<p>
@ -43,7 +43,7 @@ Content-Type: text/html; charset=UTF-8
</p>
<div id="yellow">
<h3><a href="http://127.0.0.1:12345"> CLIQUEZ POUR VOIR ... </a></h3>
<h3><a href="http://127.0.0.1:12345"> >>> CLIQUEZ ICI <<< </a></h3>
</div>
<script>
const el = document.getElementById('yellow');

113
templates/register.html Normal file
View File

@ -0,0 +1,113 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>[Astroport] Ouvrez votre TW :: Station _HOSTNAME_ (_IPFSNODEID_) </title>
<link rel="icon" type="image/png" href="http://127.0.0.1:8080/ipfs/QmaCh8mywWfxkXF3JziFzqZS6yZFo3eNS5fSfnzJqdSQvX/logo.png" />
<link rel="stylesheet" href="http://127.0.0.1:8080/ipfs/QmaCh8mywWfxkXF3JziFzqZS6yZFo3eNS5fSfnzJqdSQvX/decoration.css" type="text/css" />
<link rel="stylesheet" href="http://127.0.0.1:8080/ipfs/QmaCh8mywWfxkXF3JziFzqZS6yZFo3eNS5fSfnzJqdSQvX/layout.css" type="text/css" />
</head>
<body>
<header>
<h6>
<a href="http://127.0.0.1:1234/"> <span>"Astroport /ipfs/"</span></a> (TW)
</h6>
</header>
<main>
<center>
<b>--- Astronaute ---</b><br>
Créez votre TW sur IPFS<br>
<h2>Astroport Ŋ1 Swarm#0</h2>
<form id="formlink" action = "http://127.0.0.1:1234" method = "GET">
<br>
<b>Associez vos phrases clefs à une adresse email</b></br></br>
Phrase Une ("identifiant") <input name=salt value=''></br>
Phrase Deux ("mot de passe") <input name=pepper value=''></br></br>
Activation de votre AstroBot à 20h12 <input type="checkbox" id="g1pub" name="g1pub"></br></br>
Email : <input name=email value=''></br></br>
<input type='submit' value='CREER VOTRE TW'>
</form>
<p>
<b>Besoin d'aide ? Contactez support@qo-op.com</b>
</p>
</center>
<article>
<div class="row justify-center">
<h1 class="video-title">
<a href="https://git.p2p.legal/qo-op/Astroport.ONE" target="code">'Astroport' opère une digitalisation 100% blockchain</a>.<br>
<a target="code" href="http://opencollective.com/monnaie-libre/projects/bunker-box">Copiez, conservez, partagez, diffusez vos chaines multimédia et json dans IPFS, entre amis!<br>
Prenez possession de votre TW. Rendez in-censurable, in-arrêtable la liberté d'expression.</a>
</h1>
</div>
</article>
<article>
<div class="row justify-center">
</div>
</article>
<article>
<div class="row justify-center">
<p><h3> >>> Reformons INTERNET - Installez IPFS - Activez <a href="https://git.p2p.legal/qo-op/Astroport.ONE" target="code"><b>Astroport.ONE</b></a> <<< </h3>
<ul>
<li>Installez 'go-ipfs' <a href="https://docs.ipfs.tech/install/command-line/#official-distributions" target="code">KUBO</a> sur votre système</li>
<li>Ajoutez <a href="https://docs.ipfs.tech/install/ipfs-companion/" target="code"><b>ipfs-companion</b></a> à votre navigateur</li>
</ul>
</p>
</div>
</article>
<center>
<h6>
<a href="http://madeinzion.org"> Made In Zion _\/_ </a> powered by <a href="http://astroport.com"><span>"</span>Astroport<span>"</span></a>
</h6>
</center>
</main>
</body>
<script>
var arrTimes = [];
var i = 0; // start
var timesToTest = 3;
var tThreshold = 300; //ms
var testImage = "http://libra.copylaradio.com:8080/ipfs/QmUUyiuCM4yXgaeGyqC2SVUUXZksuxhDfHQYpUpZPuL2oS/astroport.jpg"; // small image in your server
var dummyImage = new Image();
var isConnectedFast = false;
testLatency(function(avg){
isConnectedFast = (avg <= tThreshold);
/** output */
document.body.appendChild(
document.createTextNode("Time: " + (avg.toFixed(2)) + "ms - Bunker BOX ready ? " + isConnectedFast)
);
});
/** test and average time took to download image from server, called recursively timesToTest times */
function testLatency(cb) {
var tStart = new Date().getTime();
if (i<timesToTest-1) {
dummyImage.src = testImage + '?t=' + tStart;
dummyImage.onload = function() {
var tEnd = new Date().getTime();
var tTimeTook = tEnd-tStart;
arrTimes[i] = tTimeTook;
testLatency(cb);
i++;
};
} else {
/** calculate average of array items then callback */
var sum = arrTimes.reduce(function(a, b) { return a + b; });
var avg = sum / arrTimes.length;
cb(avg);
}
}
</script>
</html>