Skip to content

Commit

Permalink
Add 7900 series /information endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
gareth-palmer committed Mar 6, 2024
1 parent 82fe50c commit a57ec56
Show file tree
Hide file tree
Showing 6 changed files with 568 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ persistent=no
extension-pkg-whitelist=lxml

[MESSAGES CONTROL]
disable=missing-module-docstring,missing-class-docstring,missing-function-docstring,bad-whitespace,invalid-name,unused-argument,line-too-long,len-as-condition,duplicate-code,assigning-non-slot
disable=missing-module-docstring,missing-class-docstring,missing-function-docstring,invalid-name,unused-argument,line-too-long,len-as-condition,duplicate-code,assigning-non-slot,redefined-builtin

[REPORTS]
output-format=text
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Endpoints provided are:
* `/services` - Simple menu that can show the currently parked calls.
* `/directory` - Local directory that uses voicemail.conf.
* `/directory/79xx` - 7900 series need MenuItem before loading /directory.
* `/information` - 7900 series Info button phone help.
* `/problem-report` - 7800 and 8800 series problem report upload.

Settings for the application are loaded from `config.yml`, the location of
Expand All @@ -35,11 +36,25 @@ You can use the packages provided by your OS distribution or run
The following commands are for Apache on Ubuntu, you may need to adjust some
them for a different distributions.

Copy files and create a virtual-host for services via HTTP:

```
sudo mkdir -p /var/www/services
sudo cp *.py *.wsgi /var/www/services
sudo cp virtualhost.conf /etc/apache2/sites-available/xml-services
sudo a2ensite xml-services
```

Optionally, to enable secure services virtual-host via HTTPS.

```
sudo cp virtualhost-ssl.conf /etc/apache2/sites-available/secure-xml-services
sudo a2ensite secure-xml-services
```

Restart apache.

```
sudo systemctl restart apache2
```

Expand Down
2 changes: 2 additions & 0 deletions application.wsgi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ from flask import Flask, Response
import authentication
import services
import directory
import information
import problem_report


Expand All @@ -17,6 +18,7 @@ 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(information.blueprint)
application.register_blueprint(problem_report.blueprint)


Expand Down
66 changes: 66 additions & 0 deletions information.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python3
#
# Copyright (c) 2024 Gareth Palmer <[email protected]>
# This program is free software, distributed under the terms of
# the GNU General Public License Version 2.

import os.path
import re
from html import escape

from lxml import etree
from flask import Blueprint, Response, request, g
import config


blueprint = Blueprint('information', __name__)


@blueprint.route('/information')
def help_information():
id = request.args.get('id', '')

if not re.search(r'(?x) ^ [0-9]+ $', id):
return Response('Invalid id', mimetype = 'text/plain'), 500

document = etree.parse('./phone_help.xml')
element = document.find(f'HelpItem[ID="{id}"]')

if element:
title = element.find('Title').text
text = element.find('Text').text
else:
title = 'Information'
text = 'Sorry, no help on that topic.'

xml = '<?xml version="1.0" encoding="UTF-8"?>' \
'<CiscoIPPhoneText>' \
'<Title>' + escape(title) + '</Title>' \
'<Text>' + escape(text) + '</Text>' \
'<Prompt>Your current options</Prompt>' \
'<SoftKeyItem>' \
'<Name>Exit</Name>' \
'<Position>3</Position>' \
'<URL>Key:Info</URL>' \
'</SoftKeyItem>' \
'</CiscoIPPhoneText>'

return Response(xml, 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

return None


@blueprint.errorhandler(Exception)
def error_handler(error):
return Response(str(error), mimetype = 'text/plain'), 500
Loading

0 comments on commit a57ec56

Please sign in to comment.