-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallerid.py
More file actions
executable file
·99 lines (76 loc) · 2.3 KB
/
Copy pathcallerid.py
File metadata and controls
executable file
·99 lines (76 loc) · 2.3 KB
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
96
97
98
#!/usr/bin/env python
''' callerid.py is built to automate the change of the callerid in voip.ms web interface as it doesn't support common voip clients caller id delegation well '''
import sys, requests, re
# configuration
username = 'changeme'
password = 'changeme'
# global variables
callerid = ''
# input validation
re_callerid_allowed = re.compile('(\+|[0-9])')
re_callerid_format = re.compile('^(\+|00)[0-9]{8,}$')
# read callerid from command line args
if len(sys.argv) == 2:
callerid = sys.argv[1].strip()
# strip alle except allowed chars
callerid = ''.join(re_callerid_allowed.findall(callerid))
# check whether caller id fits required format
match = re_callerid_format.match(callerid)
if match:
print 'Caller ID: ', match.group()
else:
print 'Caller ID does not match required format'
sys.exit(2)
else:
print 'Usage: ./callerid.py +41234567890'
sys.exit(2)
# setup session object (cookiejar)
s = requests.Session()
'''
# DEBUG set proxy and disable TLS verification
s.proxies = { "https" : "https://127.0.0.1:8080" }
s.verify=False
'''
# fetch default login form and default cookie (october_session)
print 'Fetch default page...',
r=s.get('https://voip.ms/login')
print 'ok'
# prepare login params
data={
'action':'login',
'lastur':'',
'col_email': username,
'col_password': password
}
# authenticate user
print 'Service logon...',
r=s.post(url='https://voip.ms/m/login.php',data=data, allow_redirects=False)
# redirects to /m/index.php if successfull
if r.headers.get('location') == '/m/index.php':
print 'ok'
else:
print 'error. login failed. check credentials'
sys.exit(2)
# prepare caller id params
data={
'callerid': callerid,
'button2': 'Apply',
'action': 'callerid'
}
# update caller ID
print 'Set caller id...',
r=s.post(url='https://voip.ms/m/settings.php',data=data)
# site confirms with 'Caller id set to...' if successfull
if r.text.find('Caller id set to ') > 0:
print 'ok'
else:
print 'error. unable to set caller'
# logout
print 'Logout...',
r=s.get(url='https://voip.ms/m/logout.php', allow_redirects=False)
# redirects to /m/login.php?logout=true if successfull
if r.headers.get('location') == '/m/login.php?logout=true':
print 'ok'
print 'Done.'
else:
print 'error. logout failed.'