This repository was archived by the owner on Feb 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovisioning_to_mxv.py
More file actions
88 lines (69 loc) · 3.62 KB
/
provisioning_to_mxv.py
File metadata and controls
88 lines (69 loc) · 3.62 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
import json
import csv
import argparse
import http.client
import base64
fieldnames = ("TenantID","First Name","Last Name","Extension","Voice DID","Fax DID","Caller ID","ID for MS Exchange","Home Phone","Cell Phone","Fax Number",
"E-mail","Alternate E-mail","User Name","Password","PIN","Pseudonym","User Profile","ID","Admin Profile","Paging Profile","Recording Profile","Home MX",
"Current MX", "Default Role","Assigned Device(s)","CallGroup","AA")
admin_endpoint = ""
def conn_to_admin(ahost,no_ssl):
if no_ssl:
return http.client.HTTPConnection(ahost,timeout=5)
else:
return http.client.HTTPSConnection(ahost,timeout=5)
def main(ahost, admin_name=None, admin_pass=None, no_ssl=False):
admin_conn = conn_to_admin(ahost,no_ssl)
headers = {"Content-type": "application/json"}
if admin_name is not None and admin_pass is not None:
userAndPass = base64.b64encode(str.encode(admin_name) + b":" + str.encode(admin_pass)).decode("ascii")
headers["Authorization"] = "Basic %s" % userAndPass
try:
admin_conn.request("GET", admin_endpoint + "/users", headers=headers)
except Exception as e:
print("Connection error")
print(e)
exit(1)
response = admin_conn.getresponse()
if response.status != 200:
print(response.status, response.reason)
admin_conn.close()
exit(2)
user_list = json.loads(response.read())['users']
with open("mxv_user_list.csv","w") as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=fieldnames, dialect='excel')
writer.writeheader()
for user in user_list:
try:
admin_conn.request("GET", admin_endpoint + "/users/" + user, headers=headers)
except Exception as e:
print("Connection error")
print(e)
admin_conn.close()
exit(1)
response = admin_conn.getresponse()
user_data = json.loads(response.read())
mx = user_data['services']['MX']
# Write to CSV file
writer.writerow({"TenantID" : user_data['tenant'] if 'tenant' in user_data else None,
"First Name" : mx['first_name'],
"Last Name" : mx['last_name'],
"Cell Phone" : mx['mobile_number'],
"E-mail" : user,
"User Name" : mx['account_name'],
"Password" : mx['account_pwd'],
"PIN" : mx['account_pin'],
"Extension" : mx['extension'] if 'extension' in mx else None,
"ID" : mx['id'] if 'id' in mx else None
})
admin_conn.close()
exit(0)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--admin-name', dest='admin_name', help='Admin username for provisioning if configured', metavar='NAME')
parser.add_argument('--admin-pass', dest='admin_pass', help='Admin password for provisioning if configured', metavar='PASS')
parser.add_argument('--no-ssl', dest='no_ssl', action='store_true', help='If provided, connection is on unsecured HTTP. Default is False')
requiredArg = parser.add_argument_group('required arguments')
requiredArg.add_argument('--admin-host', dest='admin_host', help='Provisioning server administrator API host address', metavar='<example.com>', required=True)
args = parser.parse_args()
main(args.admin_host, args.admin_name, args.admin_pass, args.no_ssl)