forked from axiom-team/astroport
183 lines
7.3 KiB
Bash
Executable File
183 lines
7.3 KiB
Bash
Executable File
#!/bin/bash
|
|
################################################################################
|
|
# Author: Fred (support@qo-op.com) & poka
|
|
# Version: 1.0
|
|
# License: AGPL (http://www.google.com/search?q=AGPL)
|
|
################################################################################
|
|
|
|
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);
|
|
|
|
echo "I am $(whoami), IPFS is run by $YOU"
|
|
if [[ $(whoami) == "root" ]]; then
|
|
exec su "$YOU" "$0" -- "$@"
|
|
fi
|
|
# Execute Kalkun daemon
|
|
[[ -f /var/www/kalkun/scripts/daemon.sh ]] && /var/www/kalkun/scripts/daemon.sh
|
|
|
|
cd $MY_PATH
|
|
source ./init.sh
|
|
source ./functions.sh
|
|
|
|
# TODO ACTIVATE IN PROD
|
|
# security
|
|
|
|
##################################################################
|
|
# Get global variables from gammu-smsd
|
|
PHONE="$SMS_1_NUMBER"
|
|
TEXT="$SMS_1_TEXT"
|
|
# Extract Received Command (PUBLISH OFFICIALS in file sms_AIDE.sh)
|
|
CMD=$(echo "$TEXT" | awk '{print toupper($1)}')
|
|
|
|
##################################################################
|
|
# Check if PHONE is already registred in G1sms+ SWARM
|
|
##################################################################
|
|
if [[ ! -f "/home/$YOU/.zen/g1sms_wallets/$PHONE/MASTERPHONE.sms" && "$CMD" != "ADMIN" ]]
|
|
then
|
|
HPHONE=$(echo -n $PHONE | sha256sum | cut -d ' ' -f 1)
|
|
NODEPHONE=$(cat /home/$YOU/.zen/ipfs_swarm/$HPHONE@*/MASTERPHONE.sms 2>/dev/null)
|
|
if [[ "$NODEPHONE" != "$MASTERPHONE" && "$NODEPHONE" != "" ]]; then
|
|
sms_SEND "$PHONE" "[G1sms+] Vous avez déjà un compte portefeuille sur $NODEPHONE (Envoyez lui RAZ si vous voulez fermer votre compte)"
|
|
log "ALERT!! $PHONE compte existant sur le NODE G1sms+ ($NODEPHONE)"
|
|
exit
|
|
fi
|
|
else
|
|
# Refresh MasterPhone (usefull in case of MASTERPHONE SIM number change)
|
|
echo "$MASTERPHONE" > "/home/$YOU/.zen/g1sms_wallets/$PHONE/MASTERPHONE.sms"
|
|
fi
|
|
|
|
##################################################################
|
|
# Handle commands CMD
|
|
##################################################################
|
|
case "$CMD" in
|
|
DESTROY|RAZ)
|
|
# SEND DESTROY Member or DESTROY DON to empty you PHONE wallet and remove it
|
|
MEMBERUID=$(echo "$TEXT" | awk '{print $2}' | grep -E "([A-Za-z0-9\-\_]+$)")
|
|
./sms_DESTROY.sh "$PHONE" "$MEMBERUID" &
|
|
;;
|
|
A|AIDE|HELP)
|
|
./sms_AIDE.sh "$PHONE" &
|
|
;;
|
|
N|D)
|
|
MEMBERUID=$(echo "$TEXT" | awk '{print $2}' | grep -E "([A-Za-z0-9\-\_]+$)")
|
|
./sms_NEW.sh "$PHONE" "$MEMBERUID" &
|
|
;;
|
|
P|PAY)
|
|
DEST=$(echo "$TEXT" | awk '{print $2}' | grep -E "^\-?[0-9]+$")
|
|
MONEY=$(echo "$TEXT" | awk '{print $3}' | grep -E "^\-?[0-9]+$")
|
|
if [[ ${#DEST} == 10 && "$DEST" != "" && "$MONEY" != "" ]]; then
|
|
./sms_PAY.sh "$PHONE" "$DEST" "$MONEY" &
|
|
else
|
|
./sms_ERROR.sh "$PHONE" "ex:: P 0612345678 100 = Envoyer 100 $UNIT au portefeuille G1sms+ +33612345678" &
|
|
fi
|
|
;;
|
|
VIR)
|
|
montant=$(echo "$TEXT" | awk '{print $2}' | grep -E "^\-?[0-9]+$")
|
|
membre=$(echo "$TEXT" | awk '{print $3}' | grep -E "([A-Za-z0-9\-\_]+$)")
|
|
if [[ "$montant" != "" && "$membre" != "" ]]; then
|
|
./sms_VIR.sh "$PHONE" "$montant" "$membre" &
|
|
else
|
|
./sms_ERROR.sh "$PHONE" "ex:: VIR 100 mot5678 = Envoyer 100 $UNIT au portefeuille G1sms+ 'mot5678' (On peut aussi utiliser le pseudo d'un Membre)" &
|
|
fi
|
|
;;
|
|
REC)
|
|
# ex: "REC 2000 John J 12" (Virer 2000 UNIT au G1sms+ wallet de John pour les 12 prochains jours)
|
|
AMOUNT=$(echo "$TEXT" | awk '{print $2}' | grep -E "^\-?[0-9]+$")
|
|
VIRDEST=$(echo "$TEXT" | awk '{print $3}' | grep -E "([A-Za-z0-9\-\_]+$)")
|
|
PERIOD=$(echo "$TEXT" | awk '{print toupper($4)}' | grep -E "([A-Za-z0-9\-\_]+$)")
|
|
TIME=$(echo "$TEXT" | awk '{print $5}' | grep -E "^\-?[0-9]+$")
|
|
if [[ "$VIRDEST" != "" && "$AMOUNT" != "" && "$PERIOD" != "" && "$TIME" != "" ]]; then
|
|
./sms_REC.sh "$PHONE" "$VIRDEST" "$AMOUNT" "$PERIOD" "$TIME" &
|
|
else
|
|
./sms_ERROR.sh "$PHONE" "ex:: REC 20 Fred M 12 => Virer 20 $UNIT au portefeuille G1sms+ de Fred pendant 12 Mois (Choisir la période: J,S,M,A)." &
|
|
fi
|
|
;;
|
|
C|S|SOLDE)
|
|
./sms_COUNT.sh "$PHONE" &
|
|
;;
|
|
EMAIL)
|
|
# RECUPERE EMAIL ASSOCIE AU G1SMS WALLET
|
|
MAIL=$(echo "$TEXT" | awk '{print tolower($2)}' | grep -E "[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}")
|
|
if [[ "$MAIL" != "" ]]; then
|
|
./sms_EMAIL.sh "$PHONE" "$MAIL" &
|
|
else
|
|
./sms_ERROR.sh "$PHONE" "$TEXT votre adresse est incorrecte..." &
|
|
fi
|
|
;;
|
|
BILL)
|
|
# PREMIERS G1billets (à gratter)... COLLECTOR ;) ONLY FOR A4 PRINTER !!
|
|
VAL=$(echo "$TEXT" | awk '{print $2}' | grep -E "^\-?[0-9]+$")
|
|
if [[ "$VAL" != "" ]]; then
|
|
./sms_BILLET.sh "$PHONE" "$VAL" &
|
|
else
|
|
./sms_ERROR.sh "$PHONE" "ex:: BILL 20 => Créer et imprimer 6 G1Billets de '20 LOVE' sur une feuille A4 (cout 120 $UNIT + $BILLCOM )" &
|
|
fi
|
|
;;
|
|
CHK)
|
|
W1=$(echo "$TEXT" | awk '{print tolower($2)}' | grep -E "^[a-z0-9]+$")
|
|
W2=$(echo "$TEXT" | awk '{print tolower($3)}' | grep -E "^[a-z0-9]+$")
|
|
W3=$(echo "$TEXT" | awk '{print tolower($4)}' | grep -E "^[a-z0-9]+$")
|
|
W4=$(echo "$TEXT" | awk '{print tolower($5)}' | grep -E "^[a-z0-9]+$")
|
|
W5=$(echo "$TEXT" | awk '{print tolower($6)}' | grep -E "^[a-z0-9]+$")
|
|
W6=$(echo "$TEXT" | awk '{print tolower($7)}' | grep -E "^[a-z0-9]+$")
|
|
W7=$(echo "$TEXT" | awk '{print tolower($8)}' | grep -E "^[a-z0-9]+$")
|
|
if [[ "$W1" != "" && "$W2" != "" ]]; then
|
|
./sms_BILLETCHK.sh "$PHONE" "$W1" "$W2" "$W3" "$W4" "$W5" "$W6" "$W7" &
|
|
else
|
|
./sms_ERROR.sh "$PHONE" "Mauvais Format. Le code doit comporter 2 mots minimum pour vérifier la valeur du billet, + code secret pour l'encaisser..." &
|
|
fi
|
|
;;
|
|
TAG)
|
|
# NOUVEAU TAG (pubkey, BI) pour terminaux DAB et TX sur IPFS.
|
|
# ex: TAG 200 (Create & Print One 200 "PubKey / BI" Qrcode Notes)
|
|
VAL=$(echo "$TEXT" | awk '{print $2}' | grep -E "^\-?[0-9]+$")
|
|
NUM=$(echo "$TEXT" | awk '{print $3}' | grep -E "^\-?[0-9]+$")
|
|
if [[ "$VAL" != "" ]]; then
|
|
./sms_G1TAG.sh "$PHONE" "$VAL" "$NUM" &
|
|
else
|
|
./sms_ERROR.sh "$PHONE" "ex:: TAG 2 12 => Créer 12 G1Tag de 2 G1" &
|
|
fi
|
|
;;
|
|
U|UNIT)
|
|
# Choisir son UNIT préférée (G1, DU, LOVE)
|
|
UNIT=$(echo "$TEXT" | awk '{print toupper($2)}'| grep -E "^[A-Za-z0-9]+$")
|
|
./sms_SETUNIT.sh "$PHONE" "$UNIT" &
|
|
;;
|
|
OU)
|
|
# CHOISIR SON DISTRIBUTEUR DE G1Tag
|
|
NODEUIDNA=$(echo "$TEXT" | awk '{print $2}'| grep -E "([A-Za-z0-9\-\_]+$)")
|
|
./sms_WHERE.sh "$PHONE" "$NODEUIDNA" &
|
|
;;
|
|
ABO)
|
|
# GERER SES ABONNEMENT CANAUX INFO SMS
|
|
SERVICE=$(echo "$TEXT" | awk '{print toupper($2)}'| grep -E "([A-Za-z0-9\-\_]+$)")
|
|
./sms_ABO.sh "$PHONE" "$SERVICE" &
|
|
;;
|
|
DELIVERED|PENDING|FAILED)
|
|
# If delivered/pending notification come back (gammu/phone config)
|
|
exit
|
|
;;
|
|
ADMIN)
|
|
# If Phone is ADMIN
|
|
if [[ "$PHONE" == "$ADMINPHONE" ]]; then
|
|
CMD=$(echo "$TEXT" | awk '{print toupper($2)}')
|
|
PARAM=$(echo "$TEXT" | awk '{print substr($0,index($0,$3))}')
|
|
./sms_ADMIN.sh "$CMD" "$PARAM" &
|
|
fi
|
|
;;
|
|
*)
|
|
#./sms_ERROR.sh "$PHONE" "$TEXT" &
|
|
log "SMS forward to $ADMINPHONE"
|
|
sms_SEND "$ADMINPHONE" "ADMIN! BAD SMS FROM $PHONE
|
|
$TEXT"
|
|
;;
|
|
esac
|
|
|
|
# MONITORING: SEND INCOMING MESSAGE COPY TO ADMINPHONE
|
|
if [[ "$PHONE" != "$ADMINPHONE" && "$CPERROR" == "YES" ]]; then sms_SEND "$ADMINPHONE" "ADMIN! MONITOR: $PHONE : $TEXT"; fi
|
|
|
|
echo $PUBKEY
|
|
exit
|
|
|