Skip to content

Instantly share code, notes, and snippets.

@stesee
Forked from mariodian/zte-sms-control.sh
Last active September 26, 2021 12:35
Show Gist options
  • Save stesee/a729a6ed9f23744112a2bc55dbfbe676 to your computer and use it in GitHub Desktop.
Save stesee/a729a6ed9f23744112a2bc55dbfbe676 to your computer and use it in GitHub Desktop.
Read SMS on ZTE
#!/bin/bash
# Based on
# Authentication https://github.com/d3suu/ZTE_MF971V_CurlAuth/blob/master/zte_login_pin.sh
# SMS parsing https://gist.github.com/mariodian/65641792700d237d30f3f47d24c746e0
# Cookie things https://stackoverflow.com/questions/15995919/how-to-use-curl-to-send-cookies
URL=http://192.168.1.1
PASSWORD="XXXX"
REFERER="$URL/index.html"
URL_SET="$URL/goform/goform_set_cmd_process"
URL_GET="$URL/goform/goform_get_cmd_process"
HASHED_PASSWORD=$(printf $PASSWORD | base64 -)
LOGIN_QUERY="isTest=false&goformId=LOGIN&password=$HASHED_PASSWORD"
COOKIE_STORE="/tmp/cookie7"
SMS_FILE_DESTINATION="$HOME/SMS"
CreateDestination() {
if [[ ! -d "$SMS_FILE_DESTINATION" ]]; then
echo "$SMS_FILE_DESTINATION does not exist on your filesystem. Will be created now."
fi
mkdir "$SMS_FILE_DESTINATION"
if [[ ! -d "$SMS_FILE_DESTINATION" ]]; then
echo "Failed to create $SMS_FILE_DESTINATION exiting now."
fi
}
Authenticate() {
IS_LOGGED=$(curl -b $COOKIE_STORE -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"
return 0
else
LOGIN=$(curl -c $COOKIE_STORE -X POST --header "Referer: $URL_GET" --header "X-Requested-With: XMLHttpRequest" --data "$LOGIN_QUERY" $URL/goform/goform_set_cmd_process | jq --raw-output .result)
echo "Loggining in to ZTE"
if [ "$LOGIN" == "0" ]; then
echo "Logged in to ZTE $URL"
return 0
else
echo "Could not login to ZTE $URL"
fi
fi
return 1
}
Write_Messages_To_Disk() {
# curl 'http://192.168.1.1/goform/goform_get_cmd_process?isTest\=false\&cmd\=sms_data_total\&page\=0\&data_per_page\=500\&mem_store\=1\&tags\=10\&order_by\=order+by+id+desc\&_\=1627202935085' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0' -H 'Accept: application/json, text/javascript, */*; q\=0.01' -H 'Accept-Language: de,en-US;q=0.7,en;q=0.3' --compressed -H 'X-Requested-With: XMLHttpRequest' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Referer: http://192.168.1.1/index.html' -H 'Cookie: zwsd="0a6cb8b9c17a5162d757773c4ec0359b"'
DATA_TOTAL=$(curl -b $COOKIE_STORE -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 []')
i=0
for SMS in $LIST; do
i=$((i+1))
ID=$(echo $SMS | jq --raw-output .id)
NUMBER=$(echo $SMS | jq --raw-output .number)
DATE=$(echo $SMS | jq --raw-output .date)
CONTENT=$(echo $SMS | jq --raw-output .content | tr '\0' '\n' | xxd -r -p | tr -d '\0')
FILE="$SMS_FILE_DESTINATION/[$ID]-$NUMBER.md"
echo "[$ID] $NUMBER $DATE
$CONTENT" >"$FILE"
done
if [ ! -z "$ID" ]; then
echo "You currently have $i messages."
else
echo "You currently have no messages."
fi
}
command -v jq >/dev/null 2>&1 || {
echo >&2 "'jq' is required but not installed. Aborting."
exit 1
}
CreateDestination
if Authenticate; then
Write_Messages_To_Disk
fi
rm -R $COOKIE_STORE
chmod 777 $SMS_FILE_DESTINATION -R
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment