-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendsms.py
64 lines (43 loc) · 1.18 KB
/
sendsms.py
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
""" Sending sms via modem """
#!/usr/bin/python
# coding: utf8
from time import gmtime, strftime
import sys
import urllib.parse
import logging
import auth
def send_sms():
""" Send sms """
if len(sys.argv) <= 1 :
logging.error("host not defined")
sys.exit(0)
if len(sys.argv) <= 2:
logging.error("recipient number not defined")
sys.exit(0)
if len(sys.argv) <= 3:
logging.error("message is empty")
sys.exit(0)
host = sys.argv[1]
number = sys.argv[2]
text = sys.argv[3]
# Prepare sms
url = f"http://{host}/goform/goform_set_cmd_process"
session = auth.get_auth_session(host)
if session is None:
logging.error("Session not started")
sys.exit(0)
text = text.encode("utf-16-be")
msg = "".join(f"{c:02x}" for c in text)
time = strftime("%y;%m;%d;%H;%M;%S;+5", gmtime())
sms = urllib.parse.urlencode({
"notCallback": "true",
"goformId": "SEND_SMS",
"isTest": "false",
"Number": number,
"sms_time": time,
"MessageBody": msg,
"encode_type": "UNICODE",
"ID": "-1"
})
session.post(url, sms)
send_sms()