2021-06-08 16:16:09 +02:00
#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# License: GPL (http://www.google.com/search?q=GPL)
########################################################################
2021-06-11 02:26:49 +02:00
## PUT YOUR PHONE COUNTRY CODE PREFIX HERE
2021-07-12 21:17:47 +02:00
## only works for station local country phone numbers!
2021-06-11 02:26:49 +02:00
prefix = "+33"
########################################################################
2021-06-09 16:34:48 +02:00
MY_PATH = " `dirname \" $0 \"` " # relative
MY_PATH = " `( cd \" $MY_PATH \" && pwd )` " # absolutized and normalized
2021-06-11 02:26:49 +02:00
########################################################################
2021-07-05 00:02:59 +02:00
YOU = $( ps auxf --sort= +utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) || er += " ipfs daemon not running"
[ [ ! -f /home/${ YOU } /.zen/secret.dunikey ] ] && echo " Crypto is missing... please provide /home/ ${ YOU } /.zen/secret.dunikey by installing 'astrXbian' TestNet " && exit 1
G1PUB = $( cat /home/${ YOU } /.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2)
2021-06-08 16:16:09 +02:00
########################################################################
2021-06-11 02:26:49 +02:00
# GET smsadmin PHONE NUMBER FROM ~/.zen/SMSADMIN FILE
2021-06-08 16:16:09 +02:00
########################################################################
2021-07-05 00:02:59 +02:00
[ [ ! -f /home/${ YOU } /.zen/SMSADMIN ] ] && echo " EXIT. Indiquez votre numéro de mobile dans /home/ ${ YOU } /.zen/SMSADMIN " && exit 1
SMSADMIN = " $( cat /home/${ YOU } /.zen/SMSADMIN) " ## FRENCH NUMBER
2021-06-11 02:26:49 +02:00
[ [ ${ SMSADMIN # " $prefix " } != " ${ SMSADMIN } " ] ] && smsadmin = 0${ SMSADMIN # " $prefix " } || smsadmin = " ${ SMSADMIN } " ## 06
2021-06-08 16:16:09 +02:00
2021-07-02 03:53:54 +02:00
########################################################################
## CHECK MADEINZION INTERNET SERVICES CONNEXION
ping -q -w 1 -c 1 data.gchange.fr 2>& 1>/dev/null && echo "GCHANGE+ OK" && GCHANGE = 1 || GCHANGE = 0
ping -q -w 1 -c 1 g1.data.e-is.pro 2>& 1>/dev/null && echo "CESIUM+ OK" && CESIUM = 1 || CESIUM = 0
ping -q -w 1 -c 1 oasis.astroport.com 2>& 1>/dev/null && echo "OASIS OK" && OASIS = 1 || OASIS = 0
ping -q -w 1 -c 1 taurus.copylaradio.com 2>& 1>/dev/null && echo "TAURUS OK" && TAURUS = 1 || TAURUS = 0
########################################################################
2021-06-08 16:16:09 +02:00
########################################################################
# GET INCOMING SMS CONTENT
2021-07-12 21:17:47 +02:00
# https://docs.gammu.org/smsd/run.html#environment
2021-06-08 16:16:09 +02:00
########################################################################
########################################################################
2021-06-11 02:26:49 +02:00
PHONE = " $SMS_1_NUMBER " # gammu-smsd
2021-06-21 18:24:58 +02:00
[ [ ! ${ PHONE } ] ] && PHONE = " $1 " # CLI MODE
2021-07-05 00:02:59 +02:00
[ [ " ${# PHONE } " < 10 || " ${# PHONE } " > 12 ] ] && echo " PHONE ${ PHONE } NON RECONNU. EXIT " && exit 1
2021-06-21 18:24:58 +02:00
## Remove prefix: phone contains local number
[ [ ${ PHONE # " $prefix " } != " ${ PHONE } " ] ] && phone = 0${ PHONE # " $prefix " } || phone = " ${ PHONE } "
2021-06-08 16:16:09 +02:00
2021-07-13 14:24:56 +02:00
########################################################################
# EXTRACT INCOMING SMS TEXT (long message compatible)
########################################################################
2021-07-12 19:44:18 +02:00
TEXT = ""
2021-07-12 21:17:47 +02:00
rm -f /tmp/sms_incoming 2>/dev/null
2021-07-12 19:50:42 +02:00
PROGRAM = /bin/echo
2021-07-12 19:44:18 +02:00
for i in ` seq $SMS_MESSAGES ` ; do
2021-07-12 20:12:29 +02:00
eval " $PROGRAM \"\${SMS_ ${ i } _TEXT}\" " >> /tmp/sms_incoming
2021-07-12 19:44:18 +02:00
done
2021-07-12 19:50:42 +02:00
2021-07-12 20:12:29 +02:00
TEXT = " $( cat /tmp/sms_incoming | tr -d '\n' ) "
2021-06-21 18:24:58 +02:00
[ [ ! ${ TEXT } ] ] && TEXT = " $2 " # CLI MODE
2021-07-02 03:53:54 +02:00
[ [ " ${ TEXT } " = = "" ] ] && echo "SMS IS EMPTY - EXIT -" && exit 1
########################################################################
2021-07-13 14:24:56 +02:00
# CHECK INTERNET CONNEXION or MAKE REPLAY SCRIPT
2021-07-02 03:53:54 +02:00
########################################################################
if [ [ $GCHANGE = = 0 ] ] ; then
echo "GCHANGE UNREACHABLE => CREATING timestamp.replay.sh - EXIT -"
echo " #!/bin/bash
2021-07-08 22:15:12 +02:00
sudo $MY_PATH /sms_received.sh \" ${ PHONE } \" \" ${ TEXT } \" " > /home/ ${ YOU } /.zen/SMS/ $( date -u +%s%N | cut -b1-13) .replay.sh
2021-07-08 00:55:55 +02:00
chmod +x /home/${ YOU } /.zen/SMS/*.replay.sh
2021-07-02 03:53:54 +02:00
exit 1
fi
2021-06-08 16:16:09 +02:00
########################################################################
## LOG
########################################################################
echo "#################################################################"
echo " SMS received : $( date) "
echo " PHONE: $PHONE "
echo " TEXT: $TEXT "
########################################################################
2021-07-08 06:44:43 +02:00
echo " ${ phone } ; ${ TEXT } " >> /home/${ YOU } /.zen/SMS/received.log
2021-06-08 16:16:09 +02:00
########################################################################
2021-07-13 14:24:56 +02:00
# EXTRACTION CMD : premier mot du SMS reçu
########################################################################
CMD = $( echo " $TEXT " | awk '{print toupper($1)}' )
########################################################################
# SWITCH CASE DEPENDING ON CMD
2021-06-08 16:16:09 +02:00
########################################################################
echo " COMMAND = $CMD "
2021-07-08 06:31:26 +02:00
[ [ ! $CMD ] ] && exit 1
2021-06-08 16:16:09 +02:00
# Handle commands
case " $CMD " in
2021-07-12 19:46:19 +02:00
"" )
## ASK FOR HELP
2021-07-13 14:24:56 +02:00
echo "SMS SANS MESSAGE - EXIT -" && exit 0
2021-07-12 19:46:19 +02:00
; ;
2021-07-02 05:28:10 +02:00
AIDE)
2021-06-08 16:16:09 +02:00
## ASK FOR HELP
2021-07-12 21:17:47 +02:00
$MY_PATH /sms/AIDE.sh " $phone " && exit 0
2021-06-08 16:16:09 +02:00
; ;
2021-06-30 21:22:33 +02:00
2021-07-02 05:28:10 +02:00
STOP)
## STOP RELATION WITH CMD GUILDE GROUP
2021-07-05 00:02:59 +02:00
GUILDE = $( echo " $TEXT " | awk '{print toupper($2)}' )
2021-07-12 21:17:47 +02:00
$MY_PATH /sms/ERASE.sh " $phone " " $GUILDE " && exit 0
2021-07-02 05:28:10 +02:00
; ;
2021-06-21 18:24:58 +02:00
*)
2021-06-21 19:18:43 +02:00
echo " MESSAGE DE $phone POUR $CMD "
2021-06-21 19:13:34 +02:00
MESSAGE = $( echo " $TEXT " | cut -d ' ' -f 2-)
2021-06-21 18:43:23 +02:00
if [ [ ${ MESSAGE } ] ] ; then
2021-06-21 18:24:58 +02:00
echo " ${ MESSAGE } " > /tmp/${ phone } _message
echo " ${ MESSAGE } "
fi
2021-07-13 14:24:56 +02:00
## CMD est une GUILDE ? Admin/Guide peuvent la créer, sinon Ciao !
2021-07-11 16:49:56 +02:00
IsItAGuide = $( ls /home/${ YOU } /.zen/SMS/GUILDES/*/INPUT/*_${ phone } _guide.txt 2>/dev/null)
2021-07-13 16:48:00 +02:00
[ [ ${ phone } != $SMSADMIN ] ] && [ [ ! $IsItAGuide ] ] && [ [ ! -d /home/${ YOU } /.zen/SMS/GUILDES/${ CMD } ] ] && echo " PAS ADMIN, PAS GUIDE, PAS DE GUILDE ${ CMD } - EXIT - " && exit 0
2021-07-13 14:24:56 +02:00
## LE MESSAGE PART POUR LA GUILDE /tmp/${phone}_message
$MY_PATH /sms/GUILDE.sh " ${ phone } " " $CMD " >> /home/${ YOU } /.zen/SMS/debug_${ phone } .log
cat /home/${ YOU } /.zen/SMS/debug_${ phone } .log ## SHOW DEBUG INFORMATIONS
## CORRECT FILESYSTEM RIGHTS
chown -R ${ YOU } :${ YOU } /home/${ YOU } /.zen/SMS
2021-06-08 16:16:09 +02:00
; ;
esac
2021-07-13 14:24:56 +02:00
## ADMIN / GUIDE COMMUNICATION
## SEND COPY OF INCOMING MESSAGE
if [ [ " ${ phone } " != " $SMSADMIN " ] ] ; then
2021-07-08 07:13:17 +02:00
adminhash = $( echo $SMSADMIN | sha256sum | cut -d ' ' -f1)
2021-07-13 14:24:56 +02:00
phonehash = $( echo ${ phone } | sha256sum | cut -d ' ' -f1)
2021-07-08 22:15:12 +02:00
ID = $( cat /home/${ YOU } /.zen/SMS/PHONE/${ phonehash } /xzuid.txt 2>/dev/null)
2021-07-13 14:24:56 +02:00
# ADMIN COPY
2021-07-08 07:13:17 +02:00
echo " #!/bin/bash
2021-07-13 14:24:56 +02:00
sudo gammu sendsms TEXT \" _PHONE_\" -text \" > $ID ${ phone } > $TEXT \" " > /home/ ${ YOU } /.zen/SMS/PHONE/ ${ adminhash } / $( date -u +%s%N | cut -b1-13) .tosend.sh
2021-07-08 07:13:17 +02:00
chmod +x /home/${ YOU } /.zen/SMS/PHONE/${ adminhash } /*.tosend.sh
2021-07-08 22:15:12 +02:00
2021-07-13 14:24:56 +02:00
## GUIDE COPY
# FIND /home/${YOU}/.zen/SMS/GUILDES/${guilde}/INPUT/$(SCORE)_${phone}_guide.txt
2021-07-09 14:08:24 +02:00
IsThereAGuide = $( ls /home/${ YOU } /.zen/SMS/GUILDES/${ CMD } /INPUT/*_guide.txt | head -n 1 2>/dev/null)
[ [ $IsThereAGuide ] ] && guidephone = $( echo $IsThereAGuide | cut -d '/' -f 9 | cut -f '_' -f 2) || echo "NO GUIDE" && exit 0
2021-07-13 14:24:56 +02:00
[ [ ${ guidephone } = = ${ phone } ] ] && echo " ${ phone } IS ${ CMD } GUIDE " && exit 0
2021-07-09 14:08:24 +02:00
guidescore = $( echo $IsThereAGuide | cut -d '/' -f 9 | cut -f '_' -f 1)
2021-07-13 14:24:56 +02:00
guidephonehash = $( echo ${ guidephone } | sha256sum | cut -d ' ' -f1)
2021-07-09 14:08:24 +02:00
echo " #!/bin/bash
2021-07-13 14:24:56 +02:00
sudo gammu sendsms TEXT \" _PHONE_\" -text \" > $ID ${ phone } > $TEXT \" " > /home/ ${ YOU } /.zen/SMS/PHONE/ ${ guidephonehash } / $( date -u +%s%N | cut -b1-13) .tosend.sh
2021-07-09 14:08:24 +02:00
chmod +x /home/${ YOU } /.zen/SMS/PHONE/${ guidephonehash } /*.tosend.sh
2021-07-08 22:15:12 +02:00
2021-07-08 07:13:17 +02:00
fi
2021-06-08 16:16:09 +02:00
exit 0