-
Notifications
You must be signed in to change notification settings - Fork 2
/
gvoicebash
executable file
·95 lines (80 loc) · 2.71 KB
/
gvoicebash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# Usage
#
# -u Google account email address - example [email protected]
# -p Google account password - example mygvoicepass123
# -n Phone number where to send message - example 6170000000
# -m String to send as message, between quotes - example "Hello World"
if [ "$1" == "help" ] || [ "$1" == "--help" ] || [ "$1" == "-h" ]
then
echo
echo "Usage:"
echo
echo " -u USERNAME - example -u [email protected]"
echo " -p PASSWORD - example -p yourgooglepassword"
echo " -n NNUMBER - example -n destinationnumber"
echo " -m MESSAGE (between quotes) - example -m \"Your message between double quotes\""
echo
echo "gvoicebash -u [email protected] -p pass -n 617000000 -m \"Hello World\""
echo
exit 0
fi
# Process and assign opts values to variables
while getopts u:p:n:m: option
do
case "${option}"
in
u) USER=${OPTARG};;
p) PASS=${OPTARG};;
n) DESTINATION_NUMBER=${OPTARG};;
m) MESSAGE=$OPTARG;;
esac
done
# Write test for arguments here
####################
# Global variables #
####################
GOOGLE_LOGIN="https://www.google.com/accounts/ClientLogin"
GOOGLE_INBOX="https://www.google.com/voice/m/"
GOOGLE_SMS="https://www.google.com/voice/m/sendsms"
########################
# Supporting functions #
########################
# Get auth token from Google
function getLoginAuth() {
local TOKEN=$(curl --data "accountType=GOOGLE&Email=$1&Passwd=$2&service=grandcentral&source=gvoice.sh" $GOOGLE_LOGIN 2>&1)
for i in $(echo $TOKEN | tr " " "\n" 2>&1)
do
if [[ "$i" == *Auth=* ]]
then
local TOKEN_VALUE=$(echo $i | sed s/Auth=//)
fi
done
echo $TOKEN_VALUE
}
function get_rnr_se() {
local TOKEN=$(getLoginAuth $1 $2)
local RNR=$(curl --header "Authorization: GoogleLogin auth=$TOKEN" $GOOGLE_INBOX 2>&1)
RNR_VALUE="${RNR##*_rnr_se\"\ value=\"}"
RNR_VALUE="${RNR_VALUE%name=\"number\"*}"
RNR_VALUE="${RNR_VALUE%\"/>*}"
echo $RNR_VALUE
}
function sms() {
local RNR_ENC=$(echo -n $(get_rnr_se $1 $2) | perl -pe's/([^-_.~A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg')
local NUMBER_ENC=$(echo -n "$3" | perl -pe's/([^-_.~A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg')
local MESS_ENC=$(echo -n "$4" | perl -pe's/([^-_.~A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg')
local TOKEN=$(getLoginAuth $1 $2)
local RESULT=$(curl -v --header "Authorization: GoogleLogin auth=$TOKEN" --data "id=&c=&number=$NUMBER_ENC&smstext=$MESS_ENC&_rnr_se=$RNR_ENC" $GOOGLE_SMS 2>&1)
echo $RESULT
}
####################
# CONTROLLING CODE #
####################
RESULT=$(sms $USER $PASS $DESTINATION_NUMBER "$MESSAGE")
if [[ "$RESULT" == *Text\ sent\ to* ]]
then
echo "Message sent successfully"
else
echo "ERROR: Message was not sent. Type --help for usage."
fi