sms_received.sh 1.92 KB
Newer Older
zicmama's avatar
zicmama committed
1 2 3 4
#!/bin/bash
################################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
5
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
zicmama's avatar
zicmama committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
################################################################################
source /root/G1SMS/shell/init.sh
source /root/G1SMS/shell/functions.sh

#SECURITY
security

# Get global variables from gammu-smsd
PHONE="$SMS_1_NUMBER"
TEXT="$SMS_1_TEXT"

log "##################################"
log "$(date)"
log "SMS received $PHONE $TEXT"

# No Reply to MySelf (or enjoy SMS LOOP of the death)
if [ "$PHONE" == "$MASTERPHONE" ]; then exit; fi
23
if [ "$PHONE" == "Orange Info" ]; then exit; fi
zicmama's avatar
zicmama committed
24 25 26 27 28 29 30 31 32 33 34

# Extract Received Command (if new update sms_AIDE.sh)
CMD=$(echo "$TEXT" | cut -d ' ' -f 1)
log "COMMAND $CMD"

# Handle commands
case "$CMD" in
	A)
		./shell/sms_AIDE.sh "$PHONE" &
		;;
	N|D)
35 36
		MEMBERUID=$(echo "$TEXT" | cut -d ' ' -f 2)
		./shell/sms_NEW.sh "$PHONE" "$MEMBERUID" &
zicmama's avatar
zicmama committed
37 38 39 40
		;;
	P)
		DEST=$(echo "$TEXT" | cut -d ' ' -f 2)
		LOVE=$(echo "$TEXT" | cut -d ' ' -f 3)
41 42 43 44
		# PI EasterEgg. Any 3.14 amount is G1 Unit
		if [ "$LOVE" == "3.14" ]; then
			LOVE=$(bc -l <<< "scale=0; $LOVE * 100 / $DUFACTOR")
		fi
zicmama's avatar
zicmama committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58
		checkdest=$(echo "$DEST" | grep -E "^\-?[0-9]+$") # Test if number
		checklove=$(echo "$LOVE" | grep -E "^\-?[0-9]+$") # Test number
		if [[ ${#DEST} == 10 && "$checkdest" != '' && "$checklove" != '' ]]; then
	        ./shell/sms_PAY.sh "$PHONE" "$DEST" "$LOVE" &
		else
			./shell/sms_ERROR.sh "$PHONE" "$TEXT" &
		fi
        ;;
	C)
		./shell/sms_COUNT.sh "$PHONE" &
		;;
	RIB)
    	NAME=$(echo "$TEXT" | cut -d ' ' -f 2)
		./shell/sms_SETRIB.sh "$PHONE" "$NAME" &
59
		;;
zicmama's avatar
zicmama committed
60 61 62 63
	U)
    	UNIT=$(echo "$TEXT" | cut -d ' ' -f 2)
		./shell/sms_SETUNIT.sh "$PHONE" "$UNIT" &
		;;
64
	Delivered|Pending|Failed)
zicmama's avatar
zicmama committed
65 66 67 68 69 70 71 72 73 74
		# If delivered/pending notification come back (gammu/phone config)
		exit
		;;
	*)
		./shell/sms_ERROR.sh "$PHONE" "$TEXT" &
		;;
esac

exit