Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # require termux-api jq
- # Please ensure you have give Termux:API permission to list and send SMS
- cd "$(dirname "$(realpath "$0")")"
- # Only single instance
- exec 9>./gs-gateway-sms-v3.lock
- if ! flock -n 9; then
- echo "Another instance running"
- exit 1
- fi
- #***!!!SECRET!!!***
- GS_SERVER="https://example.com/gs-gateway-sms-v3/gs-gateway-sms-v3.php"
- GS_DEVICE="example"
- #***!!!/SECRET!!!***
- # Last timestamp file
- if [ ! -f ./.gs-gateway-sms-v3-timestamp.txt ]; then
- echo "1970-01-01 00:00">./.gs-gateway-sms-v3-timestamp.txt
- fi
- echo "GS--Gateway SMS v3 (Device)"
- while true; do
- # Process Inbox
- now=$( date -Iseconds|cut -c1-16 )
- begin=$( cat ./.gs-gateway-sms-v3-timestamp.txt )
- end="${now/T/ }"
- echo "Iteration ${end}..."
- sleep 61
- echo "List inbox from ${begin} to ${end}"
- smses=$( termux-sms-list -l 1000000 -t inbox | jq -c -M '[.[]|del(.threadid,.type,.read)|select("'"${begin}"'"<=.received and .received<"'"${end}"'")]' )
- length=$( jq ".|length" <<< $smses )
- if [ "${length}" -gt 0 ]; then
- jq -c -M .[] <<< $smses | while read -r sms; do
- number=$( jq -r .number <<< $sms )
- body=$( jq -r .body <<< $sms )
- received=$( jq -r .received <<< $sms )
- echo "INBOX: ${number} at ${received}: ${body}"
- if [ -f ./beep.mp3 ]; then
- play-audio ./beep.mp3
- fi
- done
- echo $smses > ./.gs-gateway-sms-v3-smses.json
- roger=$( curl -s -F "smses=@./.gs-gateway-sms-v3-smses.json" "${GS_SERVER}?inbox=${GS_DEVICE}" )
- if [ "${roger}" == "ROGER" ]; then
- echo "Inbox Roger"
- echo "${end}">./.gs-gateway-sms-v3-timestamp.txt
- else
- echo "ERROR: Inbox Not Roger"
- echo "${roger}"
- if [ -f ./warn.mp3 ]; then
- play-audio ./warn.mp3
- fi
- sleep 60
- fi
- else
- echo "Inbox is empty."
- fi
- # Process Outbox
- echo "List outbox"
- smses=$( curl -s "${GS_SERVER}?outbox=${GS_DEVICE}" )
- length=$( jq ". |length" <<< $smses )
- if [ "${length}" -gt 0 ]; then
- jq -c -M .[] <<< $smses | while read -r sms; do
- number=$( jq -r .number <<< $sms )
- body=$( jq -r .body <<< $sms )
- echo "OUTBOX: ${number}: ${body}"
- if [ -f ./beep.mp3 ]; then
- play-audio ./beep.mp3
- fi
- termux-sms-send -n "${number}" "${body}"
- sleep 5
- done
- for i in {1..10}; do
- roger=$( curl -s "${GS_SERVER}?roger=${GS_DEVICE}" )
- if [ "${roger}" == "ROGER" ]; then
- echo "Outbox Roger"
- break
- else
- echo "ERROR: Outbox Not Roger--Habis nih nanti pulsa kesayanganku..."
- echo "${roger}"
- if [ -f ./warn.mp3 ]; then
- play-audio ./warn.mp3
- fi
- sleep 60
- fi
- done
- else
- echo "Outbox is empty."
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement