2019-11-27 23:43:32 +01:00
#!/bin/bash
################################################################################
# SWARM de développement G1sms+.
# PUBKEY G1 DU SWARMMASTER: 8qs69HriAdytcCLzvQGJ15XBwpjAVFx8JoVM2ahue1y7
# ipfs ls /ipns/QmZHTne3bjtMgaXWRqSbdKchJbgq2NaAeVSzFUN7ceYpif
#
# G1sms+ est totalement décentralisé! Il peut être fait de multiples SWARM de Services dont les codes évoluent de façon décentralisé.
# Puis se mettent à jour autour des $ADMINPHONE par consensus d'utilisateurs ;)
#
# Log => tail -f /tmp/g1sms.log -n 200
# gammu => tail -f /tmp/smsd.log -n 200
#
# 2 commands needed to make the ramdisk if planning to run from ramdisk to gain some speed
# sudo mkdir /mnt/ramdisk
# sudo mount -t tmpfs -o size=50m tmpfs /mnt/ramdisk
#
# Utiliser la commande ./search fournie pour fouiller dans le code, mais tout est ordonnancé d'ici, donc vous êtes au bon endroit pour commencer à farfouiller.
###############################################################################
# EN FAISANT PARTIE DU SWARM G1sms+ VOUS VOUS ENGAGEZ A ASSURER LA SECURITE
# PHYSIQUE ET INFORMATIQUE DE VOTRE NOEUD ET NE PAS INTRODUIRE DE CODE MALVEILLANT
# DANS LE GROUPE SI VOUS ETES AMENES A EN PROPOSER UNE MISE A JOUR.
# UNE COMMISSION EST PERCU SUR CERTAINS TRANSFERTS.
# ELLE EST PROVISION EN CAS DE FRAUDE ET SA REATRIBUTION POURRA EVOLUER...
#
# Author: Fred (support@qo-op.com)
# Version: 0.1
# License: GPL (http://www.google.com/search?q=GPL)
################################################################################
export YOU = $( ps aux --sort= +utime | grep ipfs | tail -n 1 | cut -d " " -f 1)
export CHEMIN = " /home/ $YOU /G1sms+ "
cd $CHEMIN
source ./shell/init.sh
source ./shell/functions.sh
##################################################################
# 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)}' )
log "##########################################################################################"
log "#############################################"
log "#############################################"
log " $( date) "
log " SMS received $PHONE $TEXT "
log "#############################################"
log " NODE: ALL WALLETS: ipfs ls /ipns/ $IPFSNODEID "
log " NODE: G1wallet: cat ./wallets/. $IPFSNODEID /NODE.pub "
log "#############################################"
##################################################################
# BASIC SECURITY & ANTI SPAM
##################################################################
security
##################################################################
# Refresh All peers SWARM Wallets.
##################################################################
ipfs_swarm_wallets_refresh
##################################################################
# Check if PHONE is already registred in G1sms+ SWARM
##################################################################
2019-11-29 16:30:34 +01:00
if [ [ ! -f " ./wallets/ $PHONE /MASTERPHONE.sms " && " $CMD " != "ADMIN" ] ]
2019-11-27 23:43:32 +01:00
then
NODEPHONE = $( cat " ./wallets_swarm/ $PHONE /MASTERPHONE.sms " )
if [ [ " $NODEPHONE " != " $MASTERPHONE " && " $NODEPHONE " != "" ] ] ; then
sms_SEND " $PHONE " " [G1sms+] Vous avez déjà un compte portefeuille sur $NODEPHONE (Envoyez lui DESTROY avant de pouvoir "
log " ALERT!! $PHONE compte existant sur le NODE G1sms+ ( $NODEPHONE ) "
exit
fi
2019-11-29 16:30:34 +01:00
else
# Refresh MasterPhone (usefull in case of MASTERPHONE SIM number change)
echo " $MASTERPHONE " > " ./wallets/ $PHONE /MASTERPHONE.sms "
2019-11-27 23:43:32 +01:00
fi
##################################################################
# Handle commands CMD
##################################################################
case " $CMD " in
2019-11-29 16:30:34 +01:00
DESTROY| RAZ)
2019-11-27 23:43:32 +01:00
# 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\-\_]+ $) " )
./shell/sms_DESTROY.sh " $PHONE " " $MEMBERUID " &
; ;
A| AIDE)
./shell/sms_AIDE.sh " $PHONE " &
; ;
N| D)
# 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\-\_]+ $) " )
./shell/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
./shell/sms_PAY.sh " $PHONE " " $DEST " " $MONEY " &
else
./shell/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
./shell/sms_VIR.sh " $PHONE " " $montant " " $membre " &
else
./shell/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
./shell/sms_REC.sh " $PHONE " " $VIRDEST " " $AMOUNT " " $PERIOD " " $TIME " &
else
./shell/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)
./shell/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
./shell/sms_EMAIL.sh " $PHONE " " $MAIL " &
else
./shell/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
./shell/sms_BILLET.sh " $PHONE " " $VAL " &
else
./shell/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 " != "" && " $W3 " != "" && " $W4 " != "" ] ] ; then
./shell/sms_BILLETCHK.sh " $PHONE " " $W1 " " $W2 " " $W3 " " $W4 " " $W5 " " $W6 " " $W7 " &
else
./shell/sms_ERROR.sh " $PHONE " "Mauvais Format. Le code doit comporter 4 mots pour vérifier la valeur du billet, 7 mots 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
./shell/sms_G1TAG.sh " $PHONE " " $VAL " " $NUM " &
else
./shell/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]+ $" )
./shell/sms_SETUNIT.sh " $PHONE " " $UNIT " &
; ;
OU)
# CHOISIR SON DISTRIBUTEUR DE G1Tag
NODEUIDNA = $( echo " $TEXT " | awk '{print $2}' | grep -E " ([A-Za-z0-9\-\_]+ $) " )
./shell/sms_WHERE.sh " $PHONE " " $NODEUIDNA " &
; ;
ABO)
# GERER SES ABONNEMENT CANAUX INFO SMS
CANAL = $( echo " $TEXT " | awk '{print $2}' | grep -E " ([A-Za-z0-9\-\_]+ $) " )
YESNO = $( echo " $TEXT " | awk '{print $3}' | grep -E " ([A-Za-z0-9\-\_]+ $) " )
./shell/sms_ABO.sh " $PHONE " " $CANAL " " $YESNO " &
; ;
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))}' )
./shell/sms_ADMIN.sh " $CMD " " $PARAM " &
fi
; ;
*)
#./shell/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