2024-02-13 19:56:43 +01:00
|
|
|
#!/bin/bash
|
|
|
|
################################################################################
|
|
|
|
# Author: Fred (support@qo-op.com)
|
|
|
|
# Version: 0.2
|
|
|
|
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
|
|
|
################################################################################
|
|
|
|
# Activate SUPPORT MODE: open ssh over IPFS
|
|
|
|
MY_PATH="`dirname \"$0\"`" # relative
|
|
|
|
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
2024-02-13 23:01:50 +01:00
|
|
|
. "$MY_PATH/../tools/my.sh"
|
2024-02-13 19:56:43 +01:00
|
|
|
########################################################################
|
|
|
|
YOU=$(myIpfsApi) || er+=" ipfs daemon not running"
|
|
|
|
[[ "$YOU" == "" || "${IPFSNODEID}" == "" ]] && echo "ERROR : $er " && exit 1
|
|
|
|
########################################################################
|
|
|
|
## THIS SCRIPT COPY BOOSTRAP PUBKEY
|
|
|
|
### AND OPEN IPFS P2P SSH FORWARD ON CHANNEL
|
|
|
|
# Make Station publish SSH port on "/x/ssh-$(IPFSNODEID)"
|
|
|
|
########################################################################
|
|
|
|
## use STOP or OFF to finish forwarding
|
|
|
|
|
|
|
|
PARAM="$1"
|
|
|
|
if [[ "${PARAM,,}" == "off" || "${PARAM,,}" == "stop" ]]; then
|
|
|
|
ipfs p2p close --all
|
|
|
|
rm ~/.zen/tmp/${IPFSNODEID}/x_ssh.sh 2>/dev/null
|
|
|
|
rm ~/.zen/tmp/${IPFSNODEID}/y_ssh.pub 2>/dev/null
|
|
|
|
echo "STOP" && exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
############################################
|
2024-02-23 00:19:33 +01:00
|
|
|
## DISTRIBUTE DRAGON SSH WOT SEED
|
|
|
|
# A_boostrap_ssh.txt
|
2024-02-13 19:56:43 +01:00
|
|
|
############################################
|
|
|
|
while IFS= read -r line
|
|
|
|
do
|
|
|
|
LINE=$(echo "$line" | grep "ssh-ed25519" | grep -Ev "#") # Remove # & not ssh-ed25519
|
|
|
|
[[ ! ${LINE} ]] && continue
|
|
|
|
if [[ ! $(cat ~/.ssh/authorized_keys | grep "${LINE}") ]]
|
|
|
|
then
|
|
|
|
echo "# ADDING ${LINE} to ~/.ssh/authorized_keys"
|
|
|
|
mkdir -p ~/.ssh && echo "${LINE}" >> ~/.ssh/authorized_keys
|
|
|
|
else
|
|
|
|
echo "TRUSTING ${LINE}"
|
|
|
|
fi
|
|
|
|
done < ${MY_PATH}/../A_boostrap_ssh.txt
|
|
|
|
|
|
|
|
############################################
|
|
|
|
## PUBLISH SSH PUBKEY OVER IPFS
|
|
|
|
## KITTY ssh-keygen style
|
|
|
|
[[ -s ~/.ssh/id_ed25519.pub ]] && cp ~/.ssh/id_ed25519.pub ~/.zen/tmp/${IPFSNODEID}/y_ssh.pub
|
|
|
|
## DRAGONz PGP/SSH style (https://pad.p2p.legal/keygen)
|
|
|
|
gpg --export-ssh-key $(cat ~/.zen/game/players/.current/.player) 2>/dev/null > ~/.zen/tmp/${IPFSNODEID}/z_ssh.pub
|
2024-02-22 20:39:55 +01:00
|
|
|
[[ -z ~/.zen/tmp/${IPFSNODEID}/z_ssh.pub ]] && rm ~/.zen/tmp/${IPFSNODEID}/z_ssh.pub # remove empty file
|
2024-02-13 19:56:43 +01:00
|
|
|
|
|
|
|
############################################
|
|
|
|
### FORWARD SSH PORT over /x/ssh-${IPFSNODEID}
|
|
|
|
############################################
|
|
|
|
echo "Lanching /x/ssh-${IPFSNODEID}"
|
|
|
|
|
2024-02-23 00:19:33 +01:00
|
|
|
[[ ! $(ipfs p2p ls | grep "/x/ssh-${IPFSNODEID}") ]] \
|
|
|
|
&& ipfs p2p listen /x/ssh-${IPFSNODEID} /ip4/127.0.0.1/tcp/22
|
2024-02-13 19:56:43 +01:00
|
|
|
|
|
|
|
ipfs p2p ls
|
|
|
|
|
|
|
|
echo
|
|
|
|
############################################
|
|
|
|
## PREPARE x_ssh.sh
|
|
|
|
## REMOTE ACCESS COMMAND FROM DRAGONS
|
|
|
|
############################################
|
|
|
|
PORT=22000
|
|
|
|
PORT=$((PORT+${RANDOM:0:3}))
|
|
|
|
|
2024-03-01 16:45:34 +01:00
|
|
|
echo '#!/bin/bash
|
|
|
|
if [[ ! $(ipfs p2p ls | grep x/ssh-'${IPFSNODEID}') ]]; then
|
|
|
|
ipfs --timeout=10s ping -n 4 /p2p/'${IPFSNODEID}'
|
|
|
|
[[ $? == 0 ]] \
|
|
|
|
&& ipfs p2p forward /x/ssh-'${IPFSNODEID}' /ip4/127.0.0.1/tcp/'${PORT}' /p2p/'${IPFSNODEID}' \
|
|
|
|
&& ssh '${USER}'@127.0.0.1 -p '${PORT}'
|
|
|
|
|| echo "CONTACT IPFSNODEID FAILED - ERROR -"
|
2024-02-23 00:19:33 +01:00
|
|
|
fi
|
2024-03-01 16:45:34 +01:00
|
|
|
' > ~/.zen/tmp/${IPFSNODEID}/x_ssh.sh
|
2024-02-13 19:56:43 +01:00
|
|
|
|
|
|
|
cat ~/.zen/tmp/${IPFSNODEID}/x_ssh.sh
|
|
|
|
|
2024-03-01 20:24:49 +01:00
|
|
|
echo "
|
|
|
|
|
|
|
|
/| /\
|
|
|
|
/^^^/ |^\Z / |
|
|
|
|
| \Z / |
|
|
|
|
/ @ \Z / / \_______
|
|
|
|
( \ _ / \Z / / /
|
|
|
|
( ---- /G |\ |Z / / /
|
|
|
|
( / ---- \ /---'/\ |Z / / /
|
|
|
|
\/--' /--/ /Z / /
|
|
|
|
| /--/ |Z / / \_______
|
|
|
|
/ /--/ |Z \ / /
|
|
|
|
--/ /--/ \Z | / /
|
|
|
|
/ /--/ \Z / /
|
|
|
|
|--| \Z/ /
|
|
|
|
|---| / /----'
|
|
|
|
\---| /^^^^^^^^^^^^\Z
|
|
|
|
\-/ \Z
|
|
|
|
/ / | \Z
|
|
|
|
\---' |\________| |_______ |Z
|
|
|
|
\--' /\/ \|_|_|_|| |_|_|_|_|\_ |Z
|
|
|
|
'------' / / / |_ /Z
|
|
|
|
\---' | / `````` /Z
|
|
|
|
\--' /\/ \ _____________/Z
|
|
|
|
'------' \
|
|
|
|
|
|
|
|
"
|
|
|
|
|
2024-02-13 19:56:43 +01:00
|
|
|
############################################
|
2024-03-01 20:24:49 +01:00
|
|
|
echo "CONNECT WITH THIS COMMAND"
|
2024-02-13 19:56:43 +01:00
|
|
|
echo "ipfs cat /ipns/${IPFSNODEID}/x_ssh.sh | bash"
|
|
|
|
############################################
|
|
|
|
|
|
|
|
exit 0
|