Advertisement
sohotcall

gs-gateway-sms-v3.sh -- GS Gateway SMS v3

Apr 8th, 2021
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.77 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # require termux-api jq
  4. # Please ensure you have give Termux:API permission to list and send SMS
  5.  
  6. cd "$(dirname "$(realpath "$0")")"
  7.  
  8. # Only single instance
  9. exec 9>./gs-gateway-sms-v3.lock
  10. if ! flock -n 9; then
  11.  echo "Another instance running"
  12.  exit 1
  13. fi
  14.  
  15. #***!!!SECRET!!!***
  16. GS_SERVER="https://example.com/gs-gateway-sms-v3/gs-gateway-sms-v3.php"
  17. GS_DEVICE="example"
  18. #***!!!/SECRET!!!***
  19.  
  20.  
  21. # Last timestamp file
  22. if [ ! -f ./.gs-gateway-sms-v3-timestamp.txt ]; then
  23.  echo "1970-01-01 00:00">./.gs-gateway-sms-v3-timestamp.txt
  24. fi
  25.  
  26. echo "GS--Gateway SMS v3 (Device)"
  27. while true; do
  28.  # Process Inbox
  29.  now=$( date -Iseconds|cut -c1-16 )
  30.  begin=$( cat ./.gs-gateway-sms-v3-timestamp.txt )
  31.  end="${now/T/ }"
  32.  echo "Iteration ${end}..."
  33.  sleep 61
  34.  echo "List inbox from ${begin} to ${end}"
  35.  smses=$( termux-sms-list -l 1000000 -t inbox | jq -c -M '[.[]|del(.threadid,.type,.read)|select("'"${begin}"'"<=.received and .received<"'"${end}"'")]' )
  36.  length=$( jq ".|length" <<< $smses )
  37.  if [ "${length}" -gt 0 ]; then
  38.    jq -c -M .[] <<< $smses | while read -r sms; do
  39.      number=$( jq -r .number <<< $sms )
  40.      body=$( jq -r .body <<< $sms )
  41.      received=$( jq -r .received <<< $sms )
  42.      echo "INBOX: ${number} at ${received}: ${body}"
  43.      if [ -f ./beep.mp3 ]; then
  44.        play-audio ./beep.mp3
  45.      fi
  46.    done
  47.    echo $smses > ./.gs-gateway-sms-v3-smses.json
  48.    roger=$( curl -s -F "smses=@./.gs-gateway-sms-v3-smses.json" "${GS_SERVER}?inbox=${GS_DEVICE}" )
  49.    if [ "${roger}" == "ROGER" ]; then
  50.      echo "Inbox Roger"
  51.      echo "${end}">./.gs-gateway-sms-v3-timestamp.txt
  52.    else
  53.      echo "ERROR: Inbox Not Roger"
  54.      echo "${roger}"
  55.      if [ -f ./warn.mp3 ]; then
  56.        play-audio ./warn.mp3
  57.      fi
  58.      sleep 60
  59.    fi
  60.  else
  61.    echo "Inbox is empty."
  62.  fi
  63.  
  64.  # Process Outbox
  65.  echo "List outbox"
  66.  smses=$( curl -s "${GS_SERVER}?outbox=${GS_DEVICE}" )
  67.  length=$( jq ". |length" <<< $smses )
  68.  if [ "${length}" -gt 0 ]; then
  69.    jq -c -M .[] <<< $smses | while read -r sms; do
  70.      number=$( jq -r .number <<< $sms )
  71.      body=$( jq -r .body <<< $sms )
  72.      echo "OUTBOX: ${number}: ${body}"
  73.      if [ -f ./beep.mp3 ]; then
  74.        play-audio ./beep.mp3
  75.      fi
  76.      termux-sms-send -n "${number}" "${body}"
  77.      sleep 5
  78.    done
  79.    for i in {1..10}; do
  80.      roger=$( curl -s "${GS_SERVER}?roger=${GS_DEVICE}" )
  81.      if [ "${roger}" == "ROGER" ]; then
  82.        echo "Outbox Roger"
  83.        break
  84.      else
  85.        echo "ERROR: Outbox Not Roger--Habis nih nanti pulsa kesayanganku..."
  86.        echo "${roger}"
  87.        if [ -f ./warn.mp3 ]; then
  88.          play-audio ./warn.mp3
  89.        fi
  90.        sleep 60
  91.      fi
  92.    done
  93.  else
  94.    echo "Outbox is empty."
  95.  fi
  96. done
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement