You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

51 lines
2.7 KiB

#!/bin/bash
################################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# 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
########################################################################
YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) || er+=" ipfs daemon not running"
IPFSNODEID=$(ipfs id -f='<id>\n') || er+=" ipfs id problem"
G1PUB=$(cat ~/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2) || er+=" G1PUB problem"
[[ "$YOU" == "" || "$IPFSNODEID" == "" || "$G1PUB" == "" ]] && echo "ERROR : $er " && exit 1
########################################################################
## ACTIVATE / DESACTIVATE SSH FORWARD to fred@ONELOVE
########################################################################
ARG=$(echo "$1" | awk '{ print tolower($0) }')
if [[ ! $(cat ~/.ssh/authorized_keys | grep "fred@ONELOVE") ]]
then
# ADD fred@ONELOVE to ~/.ssh/authorized_keys
echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFLHW8P88C/B7622yXzdAn1ZcTBfE1A4wMqajBwAoHwUVTOUaYfvkiSxbzb5H9dPTAXhQU6ZfuLa70kTo1m2b9TKH0tD6hR3RiKJ0NIjCHYEypcPGpLmHaZWnBKPq3IUU24qFVdUJxnTkDdFUszYMNoV4nqlXY/ZYdNpic8L1jPPyfOLLfPFkuSxagyQj4FGJq77UQE5j+skMJS3ISkazNTLqOCGLFJ5qtBC11BvQaCJ4cQ2Ss7ejPYhpx16NLJfg9VtG4dv9ZebEIl2pf7niiQGSPrDMFWHuQcGAuHt/patr0BcvfvD3Gv+qNsVfAJCNZ2U5NHEMKIhgj1ilNPEw7 fred@ONELOVE" >> ~/.ssh/authorized_keys
fi
IPFSADMINID=$(cat ~/.zen/astrXbian/A_swarm_admin.txt)
## NOT forwarding for myself
if [[ "$G1PUB" != "$IPFSADMINID" ]]
then
if [[ "$ARG" == "close" ]]
then
ipfs p2p close -p /x/$G1PUB-ssh
## SEND MESSAGE
echo "ipfs p2p close -p /x/$G1PUB-ssh" > /tmp/ssh.forward
~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey -n "https://data.gchange.fr" send -d $IPFSADMINID -t "SSH-STOP" -f /tmp/ssh.forward
echo "STOP"
fi
if [[ "$ARG" == "" || "$ARG" == "open" ]]; then
ipfs p2p listen /x/$G1PUB-ssh /ip4/127.0.0.1/tcp/22
## SEND MESSAGE
PORT="10${RANDOM:0:3}" # RANDOM PORT
[[ ! -f /tmp/ssh.forward.port ]] echo "$PORT" > /tmp/ssh.forward.port
PORT=$(cat /tmp/ssh.forward.port)
echo "ipfs p2p forward /x/$G1PUB-ssh /ip4/127.0.0.1/tcp/$PORT /p2p/$IPFSNODEID
ssh $USER@localhost -p $PORT" > /tmp/ssh.forward
~/.zen/astrXbian/zen/jaklis/jaklis.py -k ~/.zen/secret.dunikey -n "https://data.gchange.fr" send -d $IPFSADMINID -t "SSH-OPEN" -f /tmp/ssh.forward
echo "Demande de dépannage envoyé à $IPFSADMINID (~/.zen/astrXbian/A_swarm_admin.txt)"
fi
fi