#!/bin/bash ################################################################################ # Author: Fred (support@qo-op.com) # Version: 1.0 # 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##*/}" ################################################################################ # Create different king of G1BILLET(s) with $MONTANT DU or TW IPNS # ${MY_PATH}/G1BILLETS.sh 5 986397643 ticket # MONTANT # STYLE # ################################################################################ MONTANT="$1" [[ $MONTANT == "0" ]] && MONTANT="" ### COMMAND MODE ### if [[ $MONTANT != "daemon" ]]; then [[ $MONTANT == "" ]] && MONTANT="___" STYLE="$2" ## CHECK IF STYLE IS EMAIL => astro IPFS G1BILLET if [[ "${STYLE}" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$ ]]; then echo "ASTROPORT NEW PLAYER" # echo "PLAYER : $STYLE" EMAIL=${STYLE} STYLE="astro" fi ## PLANCHE PDF DE 6 BILLETS PAR DEFAUT NBbillets=6 [[ "${STYLE}" != "" ]] && NBbillets=1 echo "CREATION $NBbillets x G1BILLET - $STYLE -" # CHECK IF $STYLE IMAGES EXIST [[ ! -f ${MY_PATH}/images/g1${STYLE}.png ]] && echo "AJOUTER : ./images/g1${STYLE}.jpg" && exit 1 [[ ! -f ${MY_PATH}/images/fond${STYLE}.jpg ]] && echo "STYLE INCONNU ? ./images/fond${STYLE}.jpg" && exit 1 [[ ! -f ${MY_PATH}/images/logo${STYLE}.png ]] && echo "AJOUTER : ./images/logo${STYLE}.jpg" && exit 1 UNIQID=$(${MY_PATH}/diceware.sh 1 | xargs)${RANDOM:0:2}$(${MY_PATH}/diceware.sh 1 | xargs) # CREATION DE $NBbillets BILLETS DE $MONTANT DU boucle=0; while [ $boucle -lt $NBbillets ] do boucle=$((boucle+1)) mkdir -p "${MY_PATH}/tmp/g1billet/${UNIQID}" SALT=$(${MY_PATH}/diceware.sh 4 | xargs) SECRET=$(${MY_PATH}/diceware.sh 4 | xargs) # CREATION CLEF BILLET BILLETPUBKEY=$(python3 ${MY_PATH}/key_create_dunikey.py "$SALT" "$SECRET") rm -f /tmp/secret.dunikey echo "$boucle : $BILLETPUBKEY" # CREATION FICHIER IMAGE BILLET dans ${MY_PATH}/tmp/g1billet/${UNIQID} $(${MY_PATH}/MAKE_G1BILLET.sh "${SALT}" "${SECRET}" "${MONTANT}" "${BILLETPUBKEY}" "${UNIQID}" "${STYLE}" "${ASTRONAUTENS}" "${EMAIL}") done if [[ "${STYLE}" != "" ]] then # ONE FILE ONLY cp ${MY_PATH}/tmp/g1billet/${UNIQID}/*.jpg ${MY_PATH}/tmp/g1billet/${UNIQID}.jpg # CLEANING TEMP FILES rm -Rf ${MY_PATH}/tmp/g1billet/${UNIQID} # ALLOWS ANY USER TO DELETE chmod 777 ${MY_PATH}/tmp/g1billet/${UNIQID}.jpg export ZFILE="${MY_PATH}/tmp/g1billet/${UNIQID}.jpg" else # MONTAGE DES IMAGES DES BILLETS VERS ${MY_PATH}/tmp/g1billet/${UNIQID}.pdf montage ${MY_PATH}/tmp/g1billet/${UNIQID}/*.jpg -tile 2x3 -geometry 964x459 ${MY_PATH}/tmp/g1billet/${UNIQID}.pdf # NB!! if "not autorized" then edit /etc/ImageMagick-6/policy.xml and comment # # CLEANING TEMP FILES rm -Rf ${MY_PATH}/tmp/g1billet/${UNIQID} # ALLOWS ANY USER TO DELETE chmod 777 ${MY_PATH}/tmp/g1billet/${UNIQID}.pdf export ZFILE="${MY_PATH}/tmp/g1billet/${UNIQID}.pdf" fi ########################################################################### ## ASTRO : FIND TW ADDRESS + EMAIL = CREATE PLAYER on 1234 API if [[ "$STYLE" == "astro" ]]; then ${MY_PATH}/keygen -t ipfs -o ${MY_PATH}/tmp/g1billet.${UNIQID}.ipns.key "$SALT" "$SECRET" ASTRONAUTENS=$(ipfs key import ${UNIQID} -f pem-pkcs8-cleartext ${MY_PATH}/tmp/g1billet.${UNIQID}.ipns.key) rm -f ${MY_PATH}/tmp/g1billet.${UNIQID}.ipns.key ipfs key rm ${UNIQID} && echo "/ipns/$ASTRONAUTENS" UN=$(echo ${SALT} | jq -Rr @uri) ## URL ENCODED DE=$(echo ${SECRET} | jq -Rr @uri) ## URL ENCODED [[ ${EMAIL} ]] \ && echo curl -s 'https://astroport.copylaradio.com/?salt='$UN'&pepper='$DE'&g1pub=on&email='$EMAIL \ && curl -s 'https://astroport.copylaradio.com/?salt='$UN'&pepper='$DE'&g1pub=on&email='$EMAIL fi ########################################################################### [[ $XDG_SESSION_TYPE == 'x11' ]] && xdg-open "$ZFILE" echo "$ZFILE" ### LAST LINE : INFORM DAEMON else ################################################################################ ################################################################################ ################################################################################ ## MAKE IT A NETWORK MICRO SERVICE -- PORTS : INPUT=33101 OUTPUT=33102 ############## CLEAN START DAEMON MODE ### pidportinuse=$(ps axf --sort=+utime | grep -w "nc -l -p 33101" | grep -v -E 'color=auto|grep' | awk '{gsub(/^ +| +$/,"")} {print $0}' | tail -n 1 | cut -d " " -f 1) [[ $pidportinuse ]] && echo "KILLING OLD DEAMON 33101 $pidportinuse" && kill -9 $pidportinuse && killall G1BILLETS.sh && exit 1 pidportinuse=$(ps axf --sort=+utime | grep -w "nc -l -p 33102" | grep -v -E 'color=auto|grep' | awk '{gsub(/^ +| +$/,"")} {print $0}' | tail -n 1 | cut -d " " -f 1) [[ $pidportinuse ]] && kill -9 $pidportinuse && echo "KILLING NOT COLLECTED THREAD $pidportinuse" ##################################################################### myIP=$(hostname -I | awk '{print $1}' | head -n 1) isLAN=$(route -n |awk '$1 == "0.0.0.0" {print $2}' | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/") if [[ $isLAN ]]; then HNAME="http://g1billet.localhost" else HNAME="http://vmi891906.contaboserver.net" fi RNAME="$HNAME:33102" HTTPWELLCOME='HTTP/1.1 200 OK Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true Access-Control-Allow-Methods: GET Server: Astroport Content-Type: text/html; charset=UTF-8