... | ... |
@@ -1,2 +1,27 @@ |
1 |
-# sms |
|
2 |
-This is a simple bash script that allows you to send sms-textmessages using the the HTTP-API of sms-revolution.ch |
|
1 |
+# SMS |
|
2 |
+This is a simple bash script that allows you to send sms-textmessages using the the HTTP-API of ```sms-revolution.ch``` |
|
3 |
+ |
|
4 |
+It supports a simple contact-list, and entering your message using vim. |
|
5 |
+ |
|
6 |
+## Recipient |
|
7 |
+When prompted ```To:``` you can either enter a number, corresponding to a entry in the contact-list (which will be printed), or enter a phone number (starting with ```0``` or ```+``` ). |
|
8 |
+The number will be posted to ```httpsms.php``` and phrased there. (aka. you can use any format, both when prompted and in the contact-list, that their backend can pharse) |
|
9 |
+ |
|
10 |
+Please note that ```contacts``` needs to be in the format of ```^name,phonenumber$```, one entry per line. (see ```contacts_example```) |
|
11 |
+ |
|
12 |
+## Message body |
|
13 |
+When prompted ```Message: ``` you can either enter your message directly or enter one of the following to get to the corresponding prompt/editor; |
|
14 |
+* ```cat``` cat (crtl-d to finish editing) |
|
15 |
+* ```sed``` sed (empty line to finish editing) |
|
16 |
+* ```vim``` vim (close editor to finish editing) (ps. preserves message if it is or can not be sent) |
|
17 |
+ |
|
18 |
+Before sending the message you are prompted whether it should be sent. (```n``` will set ``action=info``; the request will be sent, however ```httpsms.php``` will only return information (how it interpreted your input and whether the message could be sent) but not send the message. |
|
19 |
+ |
|
20 |
+## Config |
|
21 |
+```config_example``` should be more or less self-explanatory. Note that ```user``` is your sms-revolution.ch username and ```password``` the md5-hash of the coresponding password. And you are going to want to set ```action=info``` when first testing this script. |
|
22 |
+ |
|
23 |
+ |
|
24 |
+(ps. md5 is a fairly old, easy to dehash algorithm and http:// is not encrypted. Hence I strongly recommend using a unique password for that site. (you are going to be doing the equivalent of ```hanging your password on the nearest blackboard``` if you use their API.)) |
|
25 |
+ |
|
26 |
+ |
|
27 |
+http://sms-revolution.ch/API/wiki/index.php?title=SMS-Revolution.ch-API_SMS:_HTTP |
3 | 28 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,17 @@ |
1 |
+# your username |
|
2 |
+user= |
|
3 |
+# the md5-hash of your user-password |
|
4 |
+password= |
|
5 |
+# the id to send from. (1: your phonenumber. 2-5: sender id 1-4) |
|
6 |
+from=1 |
|
7 |
+# send sends the message, info only returns information. |
|
8 |
+# (ps. Use this for testing) |
|
9 |
+action=send |
|
10 |
+# 0: discount, 1: basic, 2: pro |
|
11 |
+typ=2 |
|
12 |
+# unix-timestamp at which the message will be sent. 0=now |
|
13 |
+timestamp=0 |
|
14 |
+# text or xml |
|
15 |
+return=text |
|
16 |
+# 1: returns different headers, 0: will always return 200 |
|
17 |
+httphead=1 |
... | ... |
@@ -1,18 +1,16 @@ |
1 | 1 |
#!/bin/bash |
2 |
-############# |
|
3 |
-user=raven |
|
4 |
-password=b89e8bd7e3e456ad7c137f70818052f7 |
|
5 |
-from=1 |
|
6 |
-action=send |
|
7 |
-typ=2 |
|
8 |
-timestamp=0 |
|
9 |
-return=text |
|
10 |
-httphead=1 |
|
2 |
+# find location of the script |
|
3 |
+# ## TODO Softcode this. |
|
4 |
+pwd=~/src/sms |
|
11 | 5 |
|
6 |
+# set user variables. (see config_example) |
|
7 |
+. ~/src/sms-data/config |
|
8 |
+ |
|
9 |
+# Where to store the tempfile when using vim |
|
12 | 10 |
sms_tempfile=~/.sms_temp |
13 |
-############## |
|
11 |
+########### |
|
14 | 12 |
n=1; |
15 |
-for entry in $(cat ~/src/sms/contacts);do |
|
13 |
+for entry in $(cat $pwd/../sms-data/contacts);do |
|
16 | 14 |
echo $n $entry; |
17 | 15 |
n=$(($n+1)) |
18 | 16 |
done; |
... | ... |
@@ -25,7 +23,7 @@ do |
25 | 23 |
case $toinput in |
26 | 24 |
[\+0][0-9]* ) nr=$toinput; break;; |
27 | 25 |
[1-9]* ) n=0; |
28 |
- for entry in $(cat ~/src/sms/contacts);do |
|
26 |
+ for entry in $(cat $pwd/../sms-data/contacts);do |
|
29 | 27 |
n=$(($n+1)) |
30 | 28 |
if (($n==$toinput)); then |
31 | 29 |
nr=$(echo $entry|cut -d ',' -f2) |
... | ... |
@@ -70,11 +68,13 @@ echo ----------- |
70 | 68 |
curl http://www.sms-revolution.ch/API/httpsms.php -d user=$user \ |
71 | 69 |
-d password=$password --data-urlencode "text=$messageinput" \ |
72 | 70 |
-d to=$nr -d from=$from -d action=$action -d typ=$typ \ |
73 |
- -d timestamp=$timestamp -d return=$return -d httphead=$httphead \ |
|
74 |
-if (($tempdata==1)); then |
|
75 |
- if $(echo $response | grep 200); then |
|
71 |
+ -d timestamp=$timestamp -d return=$return -d httphead=$httphead |
|
72 |
+ |
|
73 |
+# TODO get a usable return value from curl and actualy make this work. |
|
74 |
+if (($tempdata == 1)); then |
|
75 |
+ if $(echo $response | grep 100); then |
|
76 | 76 |
rm $sms_tempfile |
77 | 77 |
else |
78 |
- echo "response was not 200, leaving tempfile where it is" |
|
78 |
+ echo "response was not 100, leaving tempfile where it is" |
|
79 | 79 |
fi |
80 | 80 |
fi |