59 lines
1.9 KiB
Bash
Executable File
59 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
################################################################################
|
|
# Author: Fred (support@qo-op.com)
|
|
# 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
|
|
|
|
source $MY_PATH/init.sh
|
|
source $MY_PATH/functions.sh
|
|
|
|
PHONE=$1
|
|
VALEUR=$2
|
|
TODAY=$(date '+%Y%m%d')
|
|
log "__SUB:sms_AUTH.sh ($PHONE, $VALEUR)"
|
|
|
|
## INITIALIZE RESULT FILE
|
|
[[ $VALEUR == "" ]] && echo "Indiquez la valeur des G1Billets" && exit 1
|
|
[[ $PHONE != "" ]] && sms_INIT_ACCOUNT "$PHONE" "NOSMS" || exit 1
|
|
[[ $UNKNOWN == "unknown" ]] && echo "G1sms Wallet $PHONE inconnu! Envoyer N au $MASTERPHONE" && exit 1
|
|
|
|
# Get AMOUNTG1, AMOUNTLOVE, AMOUNTDU
|
|
AMOUNTG1=$(silkaj_balance $PUBKEY)
|
|
AMOUNTDU=$(bc -l <<< "scale=2; $AMOUNTG1 / $DUFACTOR")
|
|
AMOUNTLOVE=$(bc -l <<< "scale=0; $AMOUNTG1 * 100 / $DUFACTOR")
|
|
|
|
# Convert amount to G1 unit
|
|
VIR=$(bc -l <<< "scale=2; $VALEUR * $DUFACTOR / 100")
|
|
|
|
# Need at least $MIN G1 available!
|
|
MIN=$(bc -l <<< "$AMOUNTG1 - $LIMIT")
|
|
testmin=$( echo "${VIR} < ${MIN}" | bc -l )
|
|
SMSPIN=$((1000 + RANDOM % 9999))
|
|
|
|
log "__SUB:sms_AUTH.sh: CODE $SMSPIN : $VIR < $MIN ? $testmin"
|
|
if [[ "$testmin" -eq "1" ]]
|
|
then
|
|
mess="CODE: $SMSPIN
|
|
A saisir pour vous authentifier...
|
|
[G1] Zen Astroport Satellite #$(cat /etc/hostname)"
|
|
# Send response SMS
|
|
sms_SEND "$PHONE" "$mess"
|
|
echo $SMSPIN > /tmp/$PHONE.PIN.auth
|
|
echo $SMSPIN
|
|
else
|
|
text="Solde: $AMOUNTLOVE LOVE ($AMOUNTG1 G1 = $AMOUNTDU DU)
|
|
Insuffisant (minimum $VIR G1 + $LIMIT G1)"
|
|
sms_ERROR "$PHONE" "$text"
|
|
echo "Minimum $VIR G1 + $LIMIT G1"
|
|
fi
|
|
|
|
[[ -f /home/$YOU/.zen/g1sms_wallets/$PHONE ]] && chown -R $YOU /home/$YOU/.zen/g1sms_wallets/$PHONE
|
|
|
|
log "__SUB:sms_AUTH.sh: END sms_AUTH.sh "
|
|
log "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
|
|
|
|
exit 0
|