forked from axiom-team/astroport
188 lines
8.1 KiB
Bash
Executable File
188 lines
8.1 KiB
Bash
Executable File
#!/bin/bash
|
|
################################################################################
|
|
# Author: Fred (support@qo-op.com)
|
|
# Version: 1.0
|
|
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
|
################################################################################
|
|
# Create and print 6 G1Billets de nn LOVE
|
|
MY_PATH="`dirname \"$0\"`" # relative
|
|
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
|
source $MY_PATH/init.sh
|
|
source $MY_PATH/functions.sh
|
|
|
|
log "__SUB:sms_BILLET.sh: ($1=phone, $2=VALbillet)"
|
|
|
|
phone="$1"
|
|
VALbillet="$2"
|
|
# 6 BILLETS DE $VALbillet LOVE PAR SMS !!
|
|
NBbillets=6
|
|
|
|
# Initialise PHONE, PIN, PUBKEY, UNIT, HIST + MEMBER + MEMRIB +...
|
|
sms_INIT_ACCOUNT "$phone" "NOSMS"
|
|
|
|
# FIXED LOVE UNIT (6 month maximum validity)
|
|
UNIT="LOVE"
|
|
|
|
log "__SUB:sms_BILLET.sh: MEMBER? $PHONE => $MEMBER"
|
|
|
|
if [[ $UNKNOWN == "unknown" || "$MEMBER" == "" ]]; then
|
|
sms_ERROR "$phone" "Porte-monnaie non identifié.
|
|
Envoyez N suivi de votre pseudo membre (en respectant Majuscule et minuscule)."
|
|
exit
|
|
fi
|
|
|
|
if [[ $SMSEMAIL == "" ]]; then
|
|
sms_ERROR "$phone" "Impossible de réaliser votre commande.
|
|
Envoyez \"EMAIL votre_email\" pour pouvoir recevoir vos billets..."
|
|
exit
|
|
fi
|
|
|
|
if [ $VALbillet -lt 10 ]; then
|
|
sms_ERROR "$phone" "Montant minimum 10 $UNIT !!"
|
|
exit
|
|
fi
|
|
|
|
if [ $VALbillet -gt 1000 ]; then
|
|
sms_ERROR "$phone" "Montant maximum: 1000 $UNIT !!"
|
|
exit
|
|
fi
|
|
|
|
# Check account amount
|
|
declare -a accounting
|
|
accounting=($(check_account))
|
|
log "$(declare -p accounting)"
|
|
AMOUNTG1=${accounting[0]}
|
|
AMOUNT=${accounting[1]}
|
|
UNIT=${accounting[2]}
|
|
AMOUNTDU=$(bc -l <<< "scale=2; $AMOUNTG1 / $DUFACTOR")
|
|
AMOUNTLOVE=$(bc -l <<< "scale=0; $AMOUNTG1 * 100 / $DUFACTOR")
|
|
|
|
# Convert amount to G1 unit
|
|
amount=$(bc <<< "$NBbillets * $VALbillet")
|
|
VIR=$(bc -l <<< "scale=2; $amount * $DUFACTOR / 100")
|
|
|
|
# Need at least $MIN G1 available! $BILLCOM G1 commission
|
|
MIN=$(bc -l <<< "$AMOUNTG1 - $LIMIT - $BILLCOM")
|
|
testmin=$( echo "${VIR} < ${MIN}" | bc -l )
|
|
log "__SUB:sms_BILLET.sh: TEST : $VIR < $MIN ? $testmin"
|
|
|
|
if [[ "$testmin" -eq "1" ]]
|
|
then
|
|
# Clean MEMBER directory
|
|
rm -f /home/$YOU/.zen/g1billets/MEMBERS/$MEMBER/*.jpg
|
|
boucle=0;
|
|
while [ $boucle -lt $NBbillets ]
|
|
do
|
|
# Creation du numéro de billet
|
|
NUMBER=$(./diceware.sh 2 | xargs)
|
|
bpath=$(echo $NUMBER | sed 's/ /_/g')
|
|
|
|
# Cas d'un billet existant
|
|
while [ -d "/home/$YOU/.zen/g1billets/$bpath" ]
|
|
do
|
|
NUMBER=$(./diceware.sh 2 | xargs)
|
|
bpath=$(echo $NUMBER | sed 's/ /_/g')
|
|
done
|
|
|
|
SECRET=$(./diceware.sh 4 | xargs)
|
|
|
|
boucle=$(bc -l <<< "$boucle + 1")
|
|
|
|
log "__SUB:sms_BILLET.sh: ->BILLET:$PHONE:$NUMBER:$VALbillet:$UNIT"
|
|
# CREATE "NUMBER SECRET" ACCOUNT for G1 transfert
|
|
TRANSAC=$(bc -l <<< "scale=2; $VIR / $NBbillets")
|
|
|
|
BILLETPUBKEY=$(python3 ./tools/key_create_dunikey.py "$NUMBER" "$SECRET")
|
|
# COPY authfile for Usage in 6 month...
|
|
log "__SUB:sms_BILLET.sh: authfile KEY : /home/$YOU/.zen/g1billets/$bpath/note.dunikey.IPFSPrivKey.gpg"
|
|
mkdir -p "/home/$YOU/.zen/g1billets/$bpath"
|
|
echo "${IPFSPrivKey}" | gpg -q --output "/home/$YOU/.zen/g1billets/$bpath/note.dunikey.IPFSPrivKey.gpg" --yes --pinentry-mode loopback --symmetric --passphrase-fd 0 "/tmp/secret.dunikey"
|
|
/home/$YOU/.zen/astroport/zen/tools/natools.py encrypt -p $NODE_G1PUBKEY -i "/tmp/secret.dunikey" -o "/home/$YOU/.zen/g1billets/$bpath/note.dunikey.$NODE_UIDNA.crypt"
|
|
rm -f /tmp/secret.dunikey
|
|
|
|
sleep 3
|
|
# Fill BILLET with TRANSAC amount
|
|
duniter_server=$(./tools/duniter_getnode.sh)
|
|
PAY=$(silkaj -p "$duniter_server" -af --file /home/$YOU/.zen/g1sms_wallets/$PHONE/secret.dunikey tx --output "$BILLETPUBKEY" --amount "$TRANSAC" --comment "[G1sms+] G1Billet $NUMBER" -y)
|
|
if [[ "$(echo $PAY | grep 'successful')" != "" && "$PAY" != "" ]]; then
|
|
# NOTES ARE FILES STORED IN DICEWARE COMPOSED SUBDIR
|
|
echo "$(date +%Y%m%d)" > "/home/$YOU/.zen/g1billets/$bpath/note.creationdate"
|
|
echo "$MEMBER" > "/home/$YOU/.zen/g1billets/$bpath/note.creator"
|
|
echo "$MEMRIB" > "/home/$YOU/.zen/g1billets/$bpath/note.memrib"
|
|
echo "$NUMBER" > "/home/$YOU/.zen/g1billets/$bpath/note.number"
|
|
echo "$PHONE" > "/home/$YOU/.zen/g1billets/$bpath/note.phone"
|
|
echo "$SECRET" > "/home/$YOU/.zen/g1billets/$bpath/note.secret"
|
|
echo "$VALbillet" > "/home/$YOU/.zen/g1billets/$bpath/note.love"
|
|
echo "$TRANSAC" > "/home/$YOU/.zen/g1billets/$bpath/note.g1"
|
|
echo "$BILLETPUBKEY" > "/home/$YOU/.zen/g1billets/$bpath/note.pubkey"
|
|
log "Remplissage: $TRANSAC G1... $BILLETPUBKEY = $PAY"
|
|
|
|
# CREATION FICHIER IMAGE BILLET
|
|
$(./sms_BILLET_MAKE.sh "$NUMBER" "$SECRET" "$VALbillet" "$UNIT" "$TRANSAC" "$BILLETPUBKEY" "$MEMBER" "$TRANSAC" "$PHONE")
|
|
log "./sms_BILLET_MAKE.sh \"$NUMBER\" \"$SECRET\" \"$VALbillet\" \"$UNIT\" \"$TRANSAC\" \"$BILLETPUBKEY\" \"$MEMBER\" \"$TRANSAC\" \"$PHONE\""
|
|
|
|
# Transaction to create Link BILLET <-> MEMBER RIB => Decrease BILLET value !
|
|
sleep 2
|
|
# PAY=$(silkaj transaction --auth-scrypt -salt="$NUMBER" -password="$SECRET" --amount="0.05" --output="$MEMRIB" --comment="THIRD_PARTY_MANAGER:$NODE_G1PUBKEY:G1SMS:BILLET:$VALbillet:$UNIT:$NUMBER" -y)
|
|
else
|
|
sms_ERROR "$PHONE" "Un problème est survenu. Contactez $ADMINPSEUDO au $ADMINPHONE"
|
|
# Copy & Send produced files
|
|
zip /tmp/$PHONE_Bills_$bpath.zip /home/$YOU/.zen/g1billets/MEMBERS/$MEMBER/*.*
|
|
mpack -s "[G1sms+]_G1Billets ($bpath) Erreur... création G1Billets..." -d /tmp/message_body.txt /tmp/$PHONE_Bills_$bpath.zip $SMSEMAIL && mv /tmp/$PHONE_Bills_$bpath.zip /home/$YOU/.zen/g1billets/MEMBERS/$MEMBER/ && log "__SUB:sms_BILLET.sh: ALERT sent....."
|
|
|
|
log "__SUB:sms_BILLET.sh: ERROR SILKAJ"
|
|
exit
|
|
fi
|
|
done
|
|
|
|
# + G1SMS Commission
|
|
sleep 2
|
|
COM=$(silkaj -p "$duniter_server" -af --file /home/$YOU/.zen/g1sms_wallets/$PHONE/secret.dunikey tx --output "$NODE_G1PUBKEY" --amount "$BILLCOM" --comment "[G1sms+] Achat G1Billets" -y)
|
|
|
|
# POUR IMPRIMER LES BILLETS! Brancher votre imprimante, configurer cups, activer code lp ;)
|
|
num=$(date +%Y%m%d)
|
|
log "__SUB:sms_BILLET.sh: PRINT $num $MEMBER"
|
|
montage /home/$YOU/.zen/g1billets/MEMBERS/$MEMBER/*.jpg -tile 2x3 -geometry 964x459 /tmp/$PHONE_Bills_$bpath.pdf && rm -f /home/$YOU/.zen/g1billets/MEMBERS/$MEMBER/*.jpg && log "__SUB:sms_BILLET.sh: PDF made /tmp/$PHONE_Bills_$bpath.pdf"
|
|
cd /tmp && zip $PHONE_Bills_$bpath.zip $PHONE_Bills_$bpath.pdf && log "__SUB:sms_BILLET.sh: Zip DONE :: /tmp$PHONE_Bills_$bpath.zip !!" && cd -
|
|
# rm -f /tmp/$PHONE_Bills_$bpath.pdf
|
|
|
|
# SEND EMAIL ZIP attached
|
|
echo "Commande #$NANODATE/$bpath
|
|
>> Planche de 6 G1Billets : $VALbillet LOVE <<
|
|
Envoyez-nous vos remarques...
|
|
|
|
https://g1sms.fr" > /tmp/message_body.txt
|
|
|
|
mpack -s "[G1sms+]_G1Billets ($bpath) A IMPRIMER et détruire cet email..." -d /tmp/message_body.txt /tmp/$PHONE_Bills_$bpath.zip $SMSEMAIL && log "__SUB:sms_BILLET.sh: EMAIL sent....."
|
|
|
|
log "__SUB:sms_BILLET.sh: G1Billets $PHONE_Bills_$bpath.pdf envoyé par email à $MEMBER : $SMSEMAIL "
|
|
mess="[G1SMS]
|
|
$NBbillets G1Billets de $VALbillet $UNIT ($TRANSAC G1) créé(s).
|
|
Envoyés vers $SMSEMAIL, vérifiez vos SPAM...
|
|
Support: $ADMINPSEUDO ($ADMINPHONE)
|
|
"
|
|
|
|
sms_SEND "$phone" "$mess"
|
|
# ADMIN ALERT SMS + TODO Add ADMINEMAIL parameter in "install.sh"
|
|
sms_SEND "$ADMINPHONE" "$MEMBER vient de créer $NBbillets G1Billets de $VALbillet $UNIT ($TRANSAC G1): $SMSEMAIL"
|
|
cat ./email.txt | sed s/EMAIL/support@qo-op.com/g | sed s/SUBJECT/Creation_G1Billets/g | sed s/MESSAGE/"$MEMBER ($PHONE) vient de creer $NBbillets G1Billets de $VALbillet $UNIT ($TRANSAC G1) vers $SMSEMAIL"/g | ssmtp "support@qo-op.com"
|
|
|
|
#####################################
|
|
# Amount too High, solde insuffisant
|
|
else
|
|
text="Solde: $AMOUNTLOVE LOVE ($AMOUNTG1 G1 = $AMOUNTDU DU)
|
|
Insuffisant pour créer $NBbillets billet(s) de $VALbillet $UNIT
|
|
(= $VIR G1 + Commission $BILLCOM G1)"
|
|
sms_ERROR "$phone" "$text"
|
|
|
|
sms_SEND "$phone" "Rechargez votre porte-monnaie!
|
|
https://g1.duniter.fr/api/#/v1/payment/$PUBKEY?amount=$VIR"
|
|
fi
|
|
|
|
[[ -d /home/$YOU/.zen/g1sms_wallets/$phone ]] && [[ $(whoami) == "root" ]] && chown -R $YOU /home/$YOU/.zen/g1sms_wallets/$phone
|
|
|
|
log "__SUB:sms_BILLET.sh: END sms_BILLET.sh"
|
|
log "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
|
|
|
|
exit
|