From eacd5037fc9ca5de9a33c2f7b97876f551fe88d8 Mon Sep 17 00:00:00 2001 From: qo-op Date: Thu, 8 Apr 2021 02:16:49 +0200 Subject: [PATCH] Manage Stargates (renewed encryted IPNS keys published with friends) --- cron_MINUTE.sh | 60 ++++++++++++------------- zen/manage_stargates.sh | 97 +++++++++++++++++++++++++++++++++++++++++ zen/stream/install.sh | 38 ++++++++++++++++ 3 files changed, 164 insertions(+), 31 deletions(-) create mode 100644 zen/manage_stargates.sh diff --git a/cron_MINUTE.sh b/cron_MINUTE.sh index cbf5e5c..74e4871 100755 --- a/cron_MINUTE.sh +++ b/cron_MINUTE.sh @@ -173,7 +173,7 @@ fi # MIDNIGHT:01 : CLEANING & UPDATE ################################################################## ################################################################## -if [[ "$timebar" == "00:01" || "$runtime" == "5" ]]; then +if [[ "$timebar" == "00:01" || "$runtime" == "5" || $(($runtime % 1380)) == 0 ]]; then echo ' # ____ ____ ____ ___ # / __ \/ __ \ _ / __ < / @@ -194,17 +194,16 @@ echo ' youtube-dl -U -################################################################## - + ################################################################## if [[ $dayoftheweek == 1 ]]; then -# EVERY MONDAY -# _____ __ __ ___ -# / ___// /_____ _________ _____ ____ / |/ /___ __ __ -# \__ \/ __/ __ \/ ___/ __ `/ __ `/ _ \ / /|_/ / __ `/ |/_/ -# ___/ / /_/ /_/ / / / /_/ / /_/ / __/ / / / / /_/ /> < -# /____/\__/\____/_/ \__,_/\__, /\___/ /_/ /_/\__,_/_/|_| -# /____/ -# 1/2 HDD for IPFS size - dicotomic adaptation 7th EVERY MONTH + # EVERY MONDAY + # _____ __ __ ___ + # / ___// /_____ _________ _____ ____ / |/ /___ __ __ + # \__ \/ __/ __ \/ ___/ __ `/ __ `/ _ \ / /|_/ / __ `/ |/_/ + # ___/ / /_/ /_/ / / / /_/ / /_/ / __/ / / / / /_/ /> < + # /____/\__/\____/_/ \__,_/\__, /\___/ /_/ /_/\__,_/_/|_| + # /____/ + # 1/2 HDD for IPFS size - dicotomic adaptation 7th EVERY MONTH availableDiskSize=$(df -P ~/ | awk 'NR>1{sum+=$4}END{print sum}') availableDiskSize="$(($availableDiskSize * 1024))" @@ -219,25 +218,24 @@ echo ' [[ -f /tmp/astroport.log ]] && tar cvzf ~/.zen/astroport.$weeknumber.log.tgz /tmp/astroport.log && echo "" > /tmp/astroport.log fi -################################################################## - -## CREATE STARTGATE LEVEL KEYS -# _ open _ -# ___| |_ __ _ _ __ __ _ __ _| |_ ___ -#/ __| __/ _` | '__/ _` |/ _` | __/ _ \ -#\__ \ || (_| | | | (_| | (_| | || __/ -#|___/\__\__,_|_| \__, |\__,_|\__\___| -# |___/ -# IPNS KEYS used to publish with star friends (creates your 5 swarm subnets) -if [[ ! -f ~/.zen/key/1/stargate ]]; then -[[ ! -d ~/.zen/key/ ]] && mkdir -p ~/.zen/key/1 ~/.zen/key/2 ~/.zen/key/3 ~/.zen/key/4 ~/.zen/key/5 -stargate_1=$(ipfs key gen star_1) && key_1=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_1 ~/.zen/key/1/ && echo "$stargate_1" > ~/.zen/key/1/stargate -stargate_2=$(ipfs key gen star_2) && key_2=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_2 ~/.zen/key/2/ && echo "$stargate_2" > ~/.zen/key/2/stargate -stargate_3=$(ipfs key gen star_3) && key_3=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_3 ~/.zen/key/3/ && echo "$stargate_3" > ~/.zen/key/3/stargate -stargate_4=$(ipfs key gen star_4) && key_4=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_4 ~/.zen/key/4/ && echo "$stargate_4" > ~/.zen/key/4/stargate -stargate_5=$(ipfs key gen star_5) && key_5=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_5 ~/.zen/key/5/ && echo "$stargate_5" > ~/.zen/key/5/stargate -# CYPHERED (SIGNED) THEY ARE SEND to regulate (could depends on DEFCON security level) -# gchange_IPFS_swarm.sh monitor ~/.zen/key/send file to execute "mailing" -fi + + ################################################################## + ## CHECK STARTGATE LEVEL KEYS + # _ open _ + # ___| |_ __ _ _ __ __ _ __ _| |_ ___ + #/ __| __/ _` | '__/ _` |/ _` | __/ _ \ + #\__ \ || (_| | | | (_| | (_| | || __/ + #|___/\__\__,_|_| \__, |\__,_|\__\___| + # |___/ + # IPNS KEYS used to publish with star friends (creates 5 levels of streaming / file sharing) + # RESET + ipfs key rm star_1 + ipfs key rm star_2 + ipfs key rm star_3 + ipfs key rm star_4 + ipfs key rm star_5 + rm -Rf ~/.zen/key/ + # RENEW & SEND STARS TO FRIENDS + $MY_PATH/zen/manage_stargates.sh fi diff --git a/zen/manage_stargates.sh b/zen/manage_stargates.sh new file mode 100644 index 0000000..0d7eae7 --- /dev/null +++ b/zen/manage_stargates.sh @@ -0,0 +1,97 @@ +#!/bin/bash +######################################################################## +# Author: +# Version: 0.1 +# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/) +######################################################################## +MY_PATH="`dirname \"$0\"`" # relative +MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized +ME="${0##*/}" +YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) && [[ ! $YOU ]] && echo "ipfs NOT RUNNING. EXIT" && exit 1 +G1PUB=$(cat ~/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2) && [[ ! $G1PUB ]] && echo "ERREUR G1PUB. EXIT" && exit 1 +IPFSNODEID=$(ipfs id -f='\n') +[[ -f ~/.zen/ipfs/.$IPFSNODEID/_xbian.zuid ]] && AXID=$(cat ~/.zen/ipfs/.$IPFSNODEID/_xbian.zuid); +[[ -f ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_title ]] && XZUID=$(cat ~/.zen/ipfs/.$IPFSNODEID/G1SSB/_g1.gchange_title) + +######################################################################## +## MANAGE "Stargates" 1 to 5. +## Create and renew ~/.zen/key/ +## Place them into ~/.zen/ipfs/.$IPFSNODEID/FRIENDS/* +######################################################################## + +[[ ! -d ~/.zen/key/ ]] && mkdir -p ~/.zen/key/1 ~/.zen/key/2 ~/.zen/key/3 ~/.zen/key/4 ~/.zen/key/5 + +######################################################################## +## ipns key generation procedure +######################################################################## +if [[ ! $(ipfs key list -l | grep "star_") ]]; then + [[ ! -d ~/.zen/key/ ]] && mkdir -p ~/.zen/key/1 ~/.zen/key/2 ~/.zen/key/3 ~/.zen/key/4 ~/.zen/key/5 + stargate_1=$(ipfs key gen star_1) && key_1=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_1 ~/.zen/key/1/ && echo "$stargate_1" > ~/.zen/key/1/stargate + stargate_2=$(ipfs key gen star_2) && key_2=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_2 ~/.zen/key/2/ && echo "$stargate_2" > ~/.zen/key/2/stargate + stargate_3=$(ipfs key gen star_3) && key_3=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_3 ~/.zen/key/3/ && echo "$stargate_3" > ~/.zen/key/3/stargate + stargate_4=$(ipfs key gen star_4) && key_4=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_4 ~/.zen/key/4/ && echo "$stargate_4" > ~/.zen/key/4/stargate + stargate_5=$(ipfs key gen star_5) && key_5=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_5 ~/.zen/key/5/ && echo "$stargate_5" > ~/.zen/key/5/stargate +else + ipfs key list -l | grep "star_" + echo "IPNS star keys already existing... Please remove all 'star_*' ipns keys before running" + exit 1 +fi + +echo "******************************************************************" +echo "STARGATE1 http://127.0.0.1:8181/ipns/$(cat ~/.zen/key/1/stargate)" +echo "STARGATE2 http://127.0.0.1:8181/ipns/$(cat ~/.zen/key/2/stargate)" +echo "STARGATE3 http://127.0.0.1:8181/ipns/$(cat ~/.zen/key/3/stargate)" +echo "STARGATE4 http://127.0.0.1:8181/ipns/$(cat ~/.zen/key/4/stargate)" +echo "STARGATE5 http://127.0.0.1:8181/ipns/$(cat ~/.zen/key/5/stargate)" +echo "******************************************************************" + +######################################################################## +## ipns 5 stargates keys distribution to friends +######################################################################## +for friendgate in $(ls -d ~/.zen/ipfs/.$IPFSNODEID/FRIENDS/*/); do + echo "$friendgate" + fg1pub=$(echo $friendgate | cut -d '/' -f 8 ) + stars=$(cat ${friendgate}stars.level) + echo "OPENING $stars STARGATES with my friend $fg1pub" + + [[ "$stars" == "" && "$fg1pub" != "" ]] && echo "NO STAR NO FRIEND" && rm -f ~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub && continue + + # DELETE OLD TRANSMITED STARGATES IPNS LINKS + rm -f ~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate* + + # DISTRIBUTE ENCRYPT AND PUBLISH NEW STARGATES KEY + case $stars in + 1) + $MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt" + ;; + 2) + $MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt" + $MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/2/stargate -o "~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate2.encrypt" + ;; + 3) + $MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt" + $MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/2/stargate -o "~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate2.encrypt" + $MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/3/stargate -o "~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate3.encrypt" + ;; + 4) + $MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt" + $MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/2/stargate -o "~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate2.encrypt" + $MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/3/stargate -o "~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate3.encrypt" + $MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/4/stargate -o "~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate4.encrypt" + ;; + 5) + $MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt" + $MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/2/stargate -o "~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate2.encrypt" + $MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/3/stargate -o "~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate3.encrypt" + $MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/4/stargate -o "~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate4.encrypt" + $MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/5/stargate -o "~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate5.encrypt" + ;; + esac + echo "http://127.0.0.1:8181/.$IPFSNODEID/FRIENDS/$fg1pub/ stargate refresh done" +done + +# REFRESH IPNS SELF PUBLISH +######################################################################## +~/.zen/astrXbian/zen/ipns_self_publish.sh +######################################################################## +exit 0 diff --git a/zen/stream/install.sh b/zen/stream/install.sh index cf87306..14d3663 100755 --- a/zen/stream/install.sh +++ b/zen/stream/install.sh @@ -56,3 +56,41 @@ rm -rf "$BASE_DIR/tmp" # Add entry into nginx home screen APP="

IPFS Pi Stream Player

IPFS Video player for Pi Stream.
M3U8 Stream located over ipns
Go and play with built in video player
" sudo sed -i "s#<\!--APPLIST-->#$APP\n<\!--APPLIST-->#" "/var/www/html/index.html" + +## ACTIVATE nginx rtmp +# GUIDES +# https://bartsimons.me/nginx-rtmp-streaming-server-installation-guide/ +# https://blog.100tb.com/how-to-set-up-an-rtmp-server-on-ubuntu-linux-using-nginx +# https://obsproject.com/forum/resources/how-to-set-up-your-own-private-rtmp-server-using-nginx.50/ +# https://www.hostwinds.com/guide/live-streaming-from-a-vps-with-nginx-rtmp/ +# CONFIG +# https://github.com/arut/nginx-rtmp-module/wiki/Directives +# https://github.com/arut/nginx-rtmp-module/wiki/Directives#hls_variant +printf " +rtmp { + server { + listen 1935; + chunk_size 8192; + + application vod { + + play $HOME/live; + + } + + application stream { + live on; + record off; + + allow publish 127.0.0.1; + deny publish all; + allow play all; + } + + application src { + live on; + exec_push ffmpeg -i rtmp://localhost/src/$name -vcodec libx264 -vprofile baseline -g 10 -s 300x200 -acodec aac -ar 44100 -ac 1 -f flv rtmp://localhost/hls/$name 2>>/var/log/ffmpeg-$name.log; + } + } +} +" | sudo tee -a /etc/nginx/nginx.conf