-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.py
executable file
·197 lines (173 loc) · 6.26 KB
/
run.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/env python3
import json
import tornado.ioloop
import tornado.web
import tornado.httpserver
import os
import ssl
from CallHistory import AsteriskCallHistory
class HomeHandler(tornado.web.RequestHandler):
def get(self):
currentCalls = callhistory.getCurrentStatus()
peers = callhistory.getPeers()
mboxes = callhistory.getVoiceMails()
contacts = callhistory.getContacts('cidname')
self.render("home.html",
title="Call History",
currentCalls=currentCalls,
peers=peers,
mboxes=mboxes)
class ContactsHandler(tornado.web.RequestHandler):
def get(self):
dbtable = 'cidname'
contacts = callhistory.getContacts(dbtable)
self.render("contacts.html",
title="Call History",
contacts=contacts)
def post(self):
dbtable = 'cidname'
method = self.get_argument('method', '')
if method == 'new':
name = self.get_argument('cnt_name', '')
number = self.get_argument('cnt_number', '')
if not name:
login_response = {
'error': True,
'msg': 'Please enter a name.'
}
elif not number:
login_response = {
'error': True,
'msg': 'Please enter a number.'
}
else:
print("add:", number, name)
msg = callhistory.addContact(dbtable, number, name)
login_response = {
'error': False,
'msg': msg
}
elif method == 'del':
number = self.get_argument('cnt_number', '')
print("del:", number)
if not number:
login_response = {
'error': True,
'msg': 'Please enter a number.'
}
else:
msg = callhistory.delContact(dbtable, number)
login_response = {
'error': False,
'msg': 'Thank You.'
}
else:
login_response = {
'error': True,
'msg': 'Not supported.'
}
self.write(login_response)
class BlockedContactsHandler(tornado.web.RequestHandler):
def get(self):
dbtable = 'blockcaller'
contacts = callhistory.getContacts(dbtable)
self.render("blockedcontacts.html",
title="Call History",
contacts=contacts)
def post(self):
dbtable = 'blockcaller'
method = self.get_argument('method', '')
if method == 'new':
name = self.get_argument('cnt_name', '')
number = self.get_argument('cnt_number', '')
if not name:
login_response = {
'error': True,
'msg': 'Please enter a name.'
}
elif not number:
login_response = {
'error': True,
'msg': 'Please enter a number.'
}
else:
msg = callhistory.addContact(dbtable, number, name)
login_response = {
'error': False,
'msg': msg
}
elif method == 'del':
number = self.get_argument('cnt_number', '')
print("del:", number)
if not number:
login_response = {
'error': True,
'msg': 'Please enter a number.'
}
else:
msg = callhistory.delContact(dbtable, number)
login_response = {
'error': False,
'msg': 'Thank You.'
}
else:
login_response = {
'error': True,
'msg': 'Not supported.'
}
self.write(login_response)
class HistoryExternalHandler(tornado.web.RequestHandler):
def get(self):
historyExternal, historyInternal, historyAll = callhistory.getCallHistory(int(1000))
#print(historyExternal)
#print(historyInternal)
self.render("history_external.html",
title="Call History",
external=historyExternal)
class HistoryInternalHandler(tornado.web.RequestHandler):
def get(self):
historyExternal, historyInternal, historyAll = callhistory.getCallHistory(int(1000))
self.render("history_internal.html",
title="Call History",
internal=historyInternal)
class HistoryHandler(tornado.web.RequestHandler):
def get(self):
historyExternal, historyInternal, historyAll = callhistory.getCallHistory(int(1000))
self.render("history.html",
title="Call History",
historyall=historyInternal)
def make_app(cert, key):
settings = {
"debug": True,
"template_path": webDirectory,
"static_path": webDirectory
}
application = tornado.web.Application([
(r"/", HomeHandler),
(r"/home.html", HomeHandler),
(r"/contacts.html", ContactsHandler),
(r"/blockedcontacts.html", BlockedContactsHandler),
(r"/history_external.html", HistoryExternalHandler),
(r"/history_internal.html", HistoryInternalHandler),
(r"/history.html", HistoryHandler)
], **settings)
if cert is not None and key is not None:
http_server = tornado.httpserver.HTTPServer(application,
ssl_options={
"certfile": cert,
"keyfile": key
}
)
else:
http_server = tornado.httpserver.HTTPServer(application)
return http_server
if __name__ == "__main__":
wd = os.path.dirname(os.path.realpath(__file__))
webDirectory = os.path.join(wd, 'web')
configfile = os.path.join(wd, "configuration.json")
with open(configfile) as data_file:
configuration = json.load(data_file)
callhistory = AsteriskCallHistory(configuration)
app = make_app(configuration['options'].get('cert'), configuration['options'].get('key'))
app.listen(5002)
tornado.ioloop.IOLoop.current().start()