Skip to content

Instantly share code, notes, and snippets.

@mariodian
Created December 4, 2019 11:39
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mariodian/65641792700d237d30f3f47d24c746e0 to your computer and use it in GitHub Desktop.
Save mariodian/65641792700d237d30f3f47d24c746e0 to your computer and use it in GitHub Desktop.
Read SMS on ZTE
#!/bin/bash
URL=http://192.168.0.1
REFERER="$URL/index.html"
URL_SET="$URL/goform/goform_set_cmd_process"
URL_GET="$URL/goform/goform_get_cmd_process"
CONTENT_PREVIEW_LENGTH=40
command -v jq >/dev/null 2>&1 || { echo >&2 "'jq' is required but not installed. Aborting."; exit 1; }
list_messages() {
DATA_TOTAL=$(curl -s --header "Referer: $REFERER" $URL_GET\?isTest\=false\&cmd\=sms_data_total\&page=0\&data_per_page\=500\&mem_store\=1\&tags\=10\&order_by\=order+by+id+desc)
LIST=$(echo $DATA_TOTAL | tr -d ' ' | jq -c '.messages | values []');
for SMS in $LIST; do
ID=$(echo $SMS | jq --raw-output .id)
NUMBER=$(echo $SMS | jq --raw-output .number)
CONTENT=$(echo $SMS | jq --raw-output .content | tr '\0' '\n' | xxd -r -p | tr -d '\0')
CONTENT_PREVIEW=$(echo $CONTENT | head -c $CONTENT_PREVIEW_LENGTH)
echo "[$ID] $NUMBER - $CONTENT_PREVIEW"
done;
if [ ! -z "$ID" ]; then
prompt
else
echo "You currently have no messages."
fi;
}
prompt () {
echo ""
echo "[E]xit, [L]ist all messages, [R]ead message, [D]elete message:"
while read -n 1 -s ACTION; do
shopt -s nocasematch
case "$ACTION" in
E)
exit
;;
L)
list_messages
;;
R)
read_message
;;
D)
delete_message
;;
*)
echo "Please, try again."
;;
esac
done;
}
read_message () {
echo ""
echo "Which message ID do you want to read?"
while read ID; do
SMS=$(echo $LIST | jq ". | select(.id==\"$ID\")")
echo ""
if [ ! -z "$SMS" ]; then
NUMBER=$(echo $SMS | jq --raw-output .number)
CONTENT=$(echo $SMS | jq --raw-output .content | tr '\0' '\n' | xxd -r -p | tr -d '\0')
echo "[$ID] $NUMBER - $CONTENT"
else
echo "Message with this ID doesn't exist."
fi;
prompt
done;
}
delete_message () {
echo ""
echo "Which message do you want to delete?"
echo "[A]ll, [n]umber:"
while read ID; do
shopt -s nocasematch
case "$ID" in
A)
delete_all_messages
;;
*)
delete_message_by_id
;;
esac
prompt
done;
}
delete_all_messages () {
echo ""
for SMS in $LIST; do
ID=$(echo $SMS | jq --raw-output .id)
IDS+="$ID;"
done;
if [ ! -z "$ID" ]; then
DELETE=$(curl -s --header "Referer: $REFERER" -d "isTest=false&goformId=DELETE_SMS&msg_id=$IDS&notCallback=true" $URL_SET | jq --raw-output .result)
if [ "$DELETE" == "success" ]; then
echo "All messages deleted successfully."
else
echo "Messages could not be deleted."
fi;
fi;
}
delete_message_by_id () {
echo ""
SMS=$(echo $LIST | jq ". | select(.id==\"$ID\")")
if [ ! -z "$SMS" ]; then
DELETE=$(curl -s --header "Referer: $REFERER" -d "isTest=false&goformId=DELETE_SMS&msg_id=$ID;&notCallback=true" $URL_SET | jq --raw-output .result)
if [ "$DELETE" == "success" ]; then
echo "Message ID $ID deleted successfully."
else
echo "Message could not be deleted."
fi;
else
echo "Message with this ID doesn't exist."
fi;
}
IS_LOGGED=$(curl -s --header "Referer: $REFERER" $URL_GET\?multi_data\=1\&isTest\=false\&sms_received_flag_flag\=0\&sts_received_flag_flag\=0\&cmd\=loginfo | jq --raw-output .loginfo)
# Login
if [ "$IS_LOGGED" == "ok" ]; then
echo "Logged in to ZTE"
else
LOGIN=$(curl -s --header "Referer: $REFERER" -d 'isTest=false&goformId=LOGIN&password=YWRtaW4=' $URL_SET | jq --raw-output .result)
echo "Loggining in to ZTE"
# Disable wifi
curl -s --header "Referer: $REFERER" -d 'goformId=SET_WIFI_INFO&isTest=false&m_ssid_enable=0&wifiEnabled=0' $URL_SET > /dev/null
if [ "$LOGIN" == "0" ]; then
echo "Logged in to ZTE"
else
echo "Could not login to ZTE"
exit
fi
fi
list_messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment