forked from usecallmanagernz/usecallmanagernz.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphone-services-xml.html
More file actions
559 lines (433 loc) · 23 KB
/
Copy pathphone-services-xml.html
File metadata and controls
559 lines (433 loc) · 23 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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
<!DOCTYPE html>
<html>
<head>
<title>Phone Services</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="includes/theme.css">
<link rel="stylesheet" type="text/css" href="includes/prettify.css">
<script type="text/javascript" src="includes/jquery.js"></script>
<script type="text/javascript" src="includes/prettify.js"></script>
<script type="text/javascript">
jQuery (window).on ("load", function () {
prettyPrint ();
});
</script>
</head>
<body>
<header>
<img src="images/logo.png">
<h2><<span>proxy</span>></h2><h1><span>USECALLMANAGER</span>.nz</h1><h2></<span>proxy</span>></h2>
</header>
<main>
<nav>
<ul>
<li><span class="icon">home</span> <a href="document-overview.html">Document Overview</a></li>
<li><span class="icon">build</span> <a href="patching-asterisk.html">Patching Asterisk</a></li>
</ul>
<ul>
<li><h3>Network Configuration</h3></li>
<li><span class="icon">settings_ethernet</span> <a href="dhcpd-conf.html">DHCP Options</a></li>
<li><span class="icon">file_download</span> <a href="apache-conf.html">HTTP Provisioning</a></li>
<li><span class="icon">file_download</span> <a href="tftpd-conf.html">TFTP Provisioning</a></li>
</ul>
<ul>
<li><h3>Phone Configuration</h3></li>
<li><span class="icon">settings_phone</span> <a href="sepmac-cnf-xml.html">SEPMAC.cnf.xml</a></li>
<li><span class="icon">dialpad</span> <a href="dial-template-xml.html">Dial Templates</a></li>
<li><span class="icon">import_contacts</span> <a href="app-dial-rules-xml.html">Application Dial Rules</a></li>
<li><span class="icon">power_input</span> <a href="soft-keys-xml.html">Soft Keys</a></li>
<li><span class="icon">format_list_bulleted</span> <a href="line-keys-xml.html">Line Keys</a></li>
<li><span class="icon">done</span> <a href="feature-policy-xml.html">Feature Policy</a></li>
<li><span class="icon">language</span> <a href="network-locale.html">Network Locale</a></li>
<li><span class="icon">face</span> <a href="user-locale.html">User Locale</a></li>
<li><span class="icon">file_upload</span> <a href="load-information.html">Firmware Load Information</a></li>
<li><span class="icon">wallpaper</span> <a href="image-list-xml.html">Background Images</a></li>
<li><span class="icon">ring_volume</span> <a href="ring-list-xml.html">Ring Tones</a></li>
<li><span class="icon">security</span> <a href="itl-file-tlv.html">Device Security</a></li>
<li><span class="icon">vpn_key</span> <a href="vpn-group.html">VPN Connection</a></li>
</ul>
<ul>
<li><h3>Asterisk Configuration</h3></li>
<li><span class="icon">dialer_sip</span> <a href="sip-conf.html">SIP Peers</a></li>
<li><span class="icon">settings_power</span> <a href="sip-notify-conf.html">SIP Notify Commands</a></li>
<li><span class="icon">format_list_numbered</span> <a href="extensions-conf.html">Dialplan Extensions</a></li>
<li><span class="icon">local_parking</span> <a href="res-parking-conf.html">Call Parking</a></li>
<li><span class="icon">code</span> <a href="sippeer-options.html">SIPPEER Options</a></li>
<li><span class="icon">volume_up</span> <a href="rtp-streaming.html">RTP Streaming</a></li>
<li><span class="icon">keyboard_arrow_right</span> <a href="command-line.html">Command Line</a></li>
</ul>
<ul>
<li><h3>XML Services</h3></li>
<li><span class="icon selected">settings</span> <b>Phone Services</b></li>
<li><span class="icon">phone_forwarded</span> <a href="cgi-execute-xml.html">CGI Execute</a></li>
</ul>
<ul>
<li><h3>Additional Features</h3></li>
<li><span class="icon">extension</span> <a href="as-feature-events.html">AS Feature Events</a></li>
</ul>
</nav>
<article>
<h1>Phone Services</h1>
The phone can make HTTP requests to a remote web-server to display text, menus and images as well as check whether a <a href="cgi-execute-xml.html">CGI Execute</a> requests will be allowed. URLs assigned to fixed-keys (eg: services, directories) and line keys are defined in <a href="sepmac-cnf-xml.html#line">SEPMAC.cnf.xml</a>. An archive containing a sample WSGI application can be downloaded from the URL below.<br>
<br>
<span class="icon">file_download</span> <a href="https://github.com/usecallmanagernz/services/archive/v2.2.tar.gz">services-2.2.tar.gz</a> (11K) <span class="icon">event</span> 05/11/2020 <span class="icon">security</span> SHA256:b75a24037a1a69298a8d64edcb2d17c51c45bb4f3aa34375cdbc0948d7e70355.<br>
<br>
See <span class="icon">open_in_browser</span> <a href="https://developer.cisco.com/site/ip-phone-services/overview/" target="_blank">Cisco Unified IP Phone Services Application Development Notes</a> for a list of XML objects the each phone model supports.<br>
<br>
<h2 id="authenticationURL">authenticationURL</h2>
If defined, the phone will make requests to this URL containing the username and password that was included in the <code class="literal">Authorization</code> header in the request to <b>http://<i>x.x.x.x</i>/CGI/Execute</b>. See <a href="cgi-execute-xml.html">CGI Execute</a> for more information.<br>
<br>
The script handling the request must respond exactly with <code class="literal">AUTHORIZED</code> (with no newline character at end) otherwise the request will be denied. Example below provides this on <code class="literal">/authentication</code>.<br>
<br>
<code class="prettify lang-python">#!/usr/bin/python3
import os.path
import re
from flask import Blueprint, Response, request, g
import config
blueprint = Blueprint('authentication', __name__)
@blueprint.route('/authentication')
def cgi_authentication():
username = request.args.get('UserID', '')
password = request.args.get('Password', '')
if username != config.cgi_username or password != config.cgi_password:
return Response('UNAUTHORIZED', mimetype = 'text/plain'), 200
return Response('AUTHORIZED', mimetype = 'text/plain'), 200
@blueprint.before_request
def before_request():
device_name = request.args.get('devicename', '')
# check that the device name is valid
if not re.search(r'(?x) ^ SEP [0-9A-F]{12} $', device_name) or \
not os.path.exists(f'{config.tftpboot_dir}/{device_name}.cnf.xml'):
return Response('ERROR'), 403
g.device_name = device_name
return None
@blueprint.errorhandler(Exception)
def error_handler(error):
return Response('ERROR', mimetype = 'text/plain'), 500</code>
<br>
<h2 id="directoryURL">directoryURL</h2>
The URL accessed when the directories button is pressed. Example below provides this on <code class="literal">/directory</code> and <code class="literal">/directory/79xx</code> (<b>7900</b> series). Requires that the Asterisk manager web-interface is enabled.<br>
<br>
<code class="prettify lang-python">#!/usr/bin/python3
import os.path
import re
from math import ceil
from urllib.parse import quote_plus
from html import escape
from lxml import etree
import requests
from flask import Blueprint, Response, request, g
import config
blueprint = Blueprint('directory', __name__)
@blueprint.route('/directory')
def directory_index():
content = '<?xml version="1.0" encoding="UTF-8"?>' \
'<CiscoIPPhoneMenu>' \
'<Title>Local Directory</Title>'
for index in ('1', '2ABC', '3DEF', '4GHI', '5JKL', '6MNO', '7PRQS', '8TUV', '9WXYZ', '0'):
content += '<MenuItem>' \
'<Name>' + escape(index) + '</Name>' \
'<URL>' + request.url_root + 'directory/entries?name=' + quote_plus(g.device_name) + '&amp;index=' + quote_plus(index) + '</URL>' \
'</MenuItem>'
if g.is_79xx:
content += '<Prompt>Your current options</Prompt>'
content += '<SoftKeyItem>' \
'<Name>Exit</Name>' \
'<Position>' + ('3' if g.is_79xx else '1') + '</Position>' \
'<URL>Init:Directories</URL>' \
'</SoftKeyItem>' \
'<SoftKeyItem>' \
'<Name>' + ('Select' if g.is_79xx else 'View') + '</Name>' \
'<Position>' + ('1' if g.is_79xx else '2') + '</Position>' \
'<URL>SoftKey:Select</URL>' \
'</SoftKeyItem>' \
'<SoftKeyItem>' \
'<Name>Help</Name>' \
'<Position>' + ('2' if g.is_79xx else '3') + '</Position>' \
'<URL>' + request.url_root + 'directory/help?name=' + quote_plus(g.device_name) + '</URL>' \
'</SoftKeyItem>' \
'</CiscoIPPhoneMenu>'
return Response(content, mimetype = 'text/xml'), 200
@blueprint.route('/directory/entries')
def directory_entries():
index = request.args.get('index', '')
if not len(index):
return directory_index()
session = requests.Session()
response = session.get(config.manager_url, timeout = 5, params = {'Action': 'Login',
'Username': config.manager_username,
'Secret': config.manager_secret})
response.raise_for_status()
response = session.get(config.manager_url, timeout = 5, params = {'Action': 'VoicemailUsersList'})
response.raise_for_status()
document = etree.fromstring(response.content)
entries = []
for element in document.findall('response/generic[@event="VoicemailUserEntry"]'):
extension = element.get('voicemailbox')
name = element.get('fullname', '')
if name[0].upper() not in index:
continue
entries.append((extension, name))
entries.sort(key = lambda entry: entry[1])
response = session.get(config.manager_url, timeout = 5, params = {'Action': 'Logoff'})
response.raise_for_status()
# 10 entries per page
pages = ceil(len(entries) / 10)
try:
page = int(request.args.get('page', '1'))
if page > pages:
raise ValueError
except ValueError:
page = 1
content = '<?xml version="1.0" encoding="UTF-8"?>' \
'<CiscoIPPhoneDirectory>' \
'<Title>' + escape(index) + (' ' + str(page) + '/' + str(pages) if pages > 1 else '') + '</Title>'
for extension, name in entries[(page - 1) * 10:page * 10]:
content += '<DirectoryEntry>' \
'<Name>' + escape(name) + '</Name>' \
'<Telephone>' + quote_plus(extension) + '</Telephone>' \
'</DirectoryEntry>'
if g.is_79xx:
content += '<Prompt>Select entry</Prompt>'
content += '<SoftKeyItem>' \
'<Name>Exit</Name>' \
'<Position>' + ('3' if g.is_79xx else '1') + '</Position>' \
'<URL>' + request.url_root + 'directory?name=' + quote_plus(g.device_name) + '</URL>' \
'</SoftKeyItem>' \
'<SoftKeyItem>' \
'<Name>' + ('Dial' if g.is_79xx else 'Call') + '</Name>' \
'<Position>' + ('1' if g.is_79xx else '2') + '</Position>' \
'<URL>SoftKey:Select</URL>' \
'</SoftKeyItem>'
if page < pages:
content += '<SoftKeyItem>' \
'<Name>Next</Name>' \
'<URL>' + request.url_root + 'directory/entries?name=' + quote_plus(g.device_name) + '&amp;index=' + quote_plus(index) + '&amp;page=' + str(page + 1) + '</URL>' \
'<Position>' + ('2' if g.is_79xx else '3') + '</Position>' \
'</SoftKeyItem>'
if page > 1:
content += '<SoftKeyItem>' \
'<Name>Previous</Name>' \
'<URL>' + request.url_root + 'directory/entries?name=' + quote_plus(g.device_name) + '&amp;index=' + quote_plus(index) + '&amp;page=' + str(page - 1) + '</URL>' \
'<Position>' + ('4' if g.is_79xx else '4') + '</Position>' \
'</SoftKeyItem>'
content += '</CiscoIPPhoneDirectory>'
return Response(content, mimetype = 'text/xml'), 200
@blueprint.route('/directory/help')
def directory_help():
content = '<?xml version="1.0" encoding="UTF-8"?>' \
'<CiscoIPPhoneText>' \
'<Title>How To Use</Title>' \
'<Text>Use the keypad or navigation key to select the first letter of the person\'s name.</Text>'
if g.is_79xx:
content += '<Prompt>Your current options</Prompt>'
content += '<SoftKeyItem>' \
'<Name>Back</Name>' \
'<URL>SoftKey:Exit</URL>' \
'<Position>' + ('3' if g.is_79xx else '1') + '</Position>' \
'</SoftKeyItem>' \
'</CiscoIPPhoneText>'
return Response(content, mimetype = 'text/xml'), 200
@blueprint.route('/directory/79xx')
def directory_menuitem():
# 79xx series need a menu item before the index
content = '<?xml version="1.0" encoding="UTF-8"?>' \
'<CiscoIPPhoneMenu>' \
'<MenuItem>' \
'<Name>Local Directory</Name>' \
'<URL>' + request.url_root + 'directory?name=' + quote_plus(g.device_name) + '</URL>' \
'</MenuItem>' \
'</CiscoIPPhoneMenu>'
return Response(content, mimetype = 'text/xml'), 200
@blueprint.before_request
def before_request():
device_name = request.args.get('name', '')
if not re.search(r'(?x) ^ SEP [0-9A-F]{12} $', device_name) or \
not os.path.exists(f'{config.tftpboot_dir}/{device_name}.cnf.xml'):
return Response('Invalid device', mimetype = 'text/plain'), 500
g.device_name = device_name
g.is_79xx = re.search(r'(?x) ^ CP-79', request.headers.get('X-CiscoIPPhoneModelName', ''))
return None
@blueprint.errorhandler(Exception)
def error_handler(error):
return Response(str(error), mimetype = 'text/plain'), 500</code>
<br>
<h2 id="servicesURL">servicesURL</h2>
The URL accessed when the services or applications button is pressed. Example below provides this on <code class="literal">/services</code>. Requires that the Asterisk manager web-interface is enabled.<br>
<br>
<code class="prettify lang-python">#!/usr/bin/python3
import os.path
import re
from urllib.parse import quote_plus
from html import escape
from lxml import etree
import requests
from flask import Blueprint, Response, request, g
import config
blueprint = Blueprint('services', __name__)
@blueprint.route('/services')
def services_menu():
content = '<?xml version="1.0" encoding="UTF-8"?>' \
'<CiscoIPPhoneMenu>' \
'<Title>Services</Title>' \
'<MenuItem>' \
'<Name>Parked Calls</Name>' \
'<URL>' + request.url_root + 'services/parked-calls?name=' + quote_plus(g.device_name) + '</URL>' \
'</MenuItem>'
if g.is_79xx:
content += '<Prompt>Your current options</Prompt>'
content += '<SoftKeyItem>' \
'<Name>Exit</Name>' \
'<Position>' + ('3' if g.is_79xx else '1') + '</Position>' \
'<URL>Init:Services</URL>' \
'</SoftKeyItem>' \
'<SoftKeyItem>' \
'<Name>Select</Name>' \
'<Position>' + ('1' if g.is_79xx else '2') + '</Position>' \
'<URL>SoftKey:Select</URL>' \
'</SoftKeyItem>' \
'</CiscoIPPhoneMenu>'
return Response(content, mimetype = 'text/xml'), 200
@blueprint.route('/services/parked-calls')
def parked_calls():
session = requests.Session()
response = session.get(config.manager_url, timeout = 5, params = {'Action': 'Login',
'Username': config.manager_username,
'Secret': config.manager_secret})
response.raise_for_status()
response = session.get(config.manager_url, timeout = 5, params = {'Action': 'ParkedCalls'})
response.raise_for_status()
document = etree.fromstring(response.content)
calls = []
for element in document.findall('response/generic[@event="ParkedCall"]'):
extension = element.get('exten')
name = element.get('calleridname') or element.get('calleridnum')
calls.append((extension, name))
calls.sort(key = lambda call: call[0])
response = session.get(config.manager_url, timeout = 5, params = {'Action': 'Logoff'})
response.raise_for_status()
content = '<?xml version="1.0" encoding="UTF-8"?>' \
'<CiscoIPPhoneDirectory>' \
'<Title>Parked Calls</Title>'
for extension, name in calls:
content += '<DirectoryEntry>' \
'<Name>' + escape(name) + '</Name>' \
'<Telephone>' + quote_plus(extension) + '</Telephone>' \
'</DirectoryEntry>'
if g.is_79xx:
content += '<Prompt>Select call</Prompt>'
content += '<SoftKeyItem>' \
'<Name>Exit</Name>' \
'<Position>' + ('3' if g.is_79xx else '1') + '</Position>' \
'<URL>' + request.url_root + 'services?name=' + quote_plus(g.device_name) + '</URL>' \
'</SoftKeyItem>' \
'<SoftKeyItem>' \
'<Name>' + ('Dial' if g.is_79xx else 'Call') + '</Name>' \
'<Position>' + ('1' if g.is_79xx else '2') + '</Position>' \
'<URL>SoftKey:Select</URL>' \
'</SoftKeyItem>' \
'<SoftKeyItem>' \
'<Name>Update</Name>' \
'<Position>' + ('2' if g.is_79xx else '3') + '</Position>' \
'<URL>SoftKey:Update</URL>' \
'</SoftKeyItem>' \
'</CiscoIPPhoneDirectory>'
return Response(content, mimetype = 'text/xml'), 200
@blueprint.before_request
def before_request():
device_name = request.args.get('name', '')
if not re.search(r'(?x) ^ SEP [0-9A-F]{12} $', device_name) or \
not os.path.exists(f'{config.tftpboot_dir}/{device_name}.cnf.xml'):
return Response('Invalid device', mimetype = 'text/plain'), 500
g.device_name = device_name
g.is_79xx = re.search(r'(?x) ^ CP-79', request.headers.get('X-CiscoIPPhoneModelName', ''))
return None
@blueprint.errorhandler(Exception)
def error_handler(error):
return Response(str(error), mimetype = 'text/plain'), 500</code>
<br>
<h2 id="problemReportUploadURL">problemReportUploadURL</h2>
The URL that the logs are uploaded to when the report problem option is selected. Example below provides this on <code class="literal">/problem-report</code>. <b>7800</b> and <b>8800</b> series only.<br>
<br>
<code class="prettify lang-python">#!/usr/bin/python3
import os.path
import re
from datetime import datetime
from flask import Blueprint, Response, request, g
import config
blueprint = Blueprint('problem_report', __name__)
@blueprint.route('/problem-report', methods = ['POST'])
def problem_report():
prt_file = request.files.get('prt_file')
if prt_file is None:
return Response('Missing problem report', mimetype = 'text/plain'), 500
timestamp = datetime.now().strftime('%Y%m%d%H%M%S')
prt_file.save(f'{config.reports_dir}/{g.device_name}-{timestamp}.tar.gz')
return Response('Log saved', mimetype = 'text/plain'), 200
@blueprint.before_request
def before_request():
device_name = request.form.get('devicename', '')
if not re.search(r'(?x) ^ SEP [0-9A-F]{12} $', device_name) or \
not os.path.exists(f'{config.tftpboot_dir}/{device_name}.cnf.xml'):
return Response('Invalid device', mimetype = 'text/plain'), 403
g.device_name = device_name
return None
@blueprint.errorhandler(Exception)
def error_handler(error):
return Response(str(error), mimetype = 'text/plain'), 500</code>
<br>
<h2 id="WSGIApplication">WSGI Application</h2>
Entry point for the WSGI application. Additional configuration can be specified by the <code class="literal">FLASK_CONFIG</code> environment variable.<br>
<br>
<code class="prettify lang-python">#!/usr/bin/python3
from flask import Flask, Response
import authentication
import services
import directory
import problem_report
application = Flask(__name__)
application.config.from_envvar('FLASK_CONFIG', silent = True)
application.register_blueprint(authentication.blueprint)
application.register_blueprint(services.blueprint)
application.register_blueprint(directory.blueprint)
application.register_blueprint(problem_report.blueprint)
@application.route('/')
def index():
return Response('', mimetype = 'text/plain'), 200
@application.errorhandler(Exception)
def error_handler(error):
return Response(str(error), mimetype = 'text/plain'), 500
if __name__ == '__main__':
application.run()</code>
<br>
<h2 id="AppConfig">Application Configuration</h2>
Parses <code class="literal">config.yml</code> which contains the paths and credentials for the application. A different location can be specified by the <code class="literal">SERVICES_CONFIG</code> environment variable.<br>
<br>
<code class="prettify lang-python">#!/usr/bin/python3
import os
import yaml
tftpboot_dir = '/var/lib/tftpboot'
reports_dir = '/var/log/cisco'
cgi_username = 'cisco'
cgi_password = 'cisco'
manager_url = 'http://localhost:8088/mxml'
manager_username = 'asterisk'
manager_secret = 'asterisk'
config_file = os.environ.get('SERVICES_CONFIG', 'config.yml')
if os.path.exists(config_file):
with open(config_file) as file:
document = yaml.safe_load(file)
if document:
tftpboot_dir = document.get('tftpboot-dir', tftpboot_dir)
reports_dir = document.get('reports-dir', reports_dir)
cgi_username = document.get('cgi-username', cgi_username)
cgi_password = document.get('cgi-password', cgi_password)
manager_url = document.get('manager-url', manager_url)
manager_username = document.get('manager-username', manager_username)
manager_secret = document.get('manager-secret', manager_secret)</code>
</article>
</main>
<footer></footer>
</body>
</html>