Skip to content

Commit

Permalink
Remove devicename SEPMAC.cnf.xml file check.
Browse files Browse the repository at this point in the history
  • Loading branch information
gareth-palmer committed May 13, 2024
1 parent 128a3ab commit 905f72a
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 74 deletions.
14 changes: 0 additions & 14 deletions authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,6 @@ def cgi_authentication():
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
2 changes: 0 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import yaml


tftpboot_dir = '/var/lib/tftpboot'
reports_dir = '/var/log/cisco'

cgi_username = 'cisco'
Expand All @@ -25,7 +24,6 @@
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)
Expand Down
5 changes: 0 additions & 5 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# This file contains the config needed for the phone XML services
# you can override the defalt location by setting the environment
# variable SERVIES_CONFIG.
#
# Location of the SEPMAC.cnf.xml provisioning files, this is used
# to verify that the supplied device name is valid.
#
# tftpboot-dir: /var/lib/tftpboot

# Where to write logs from the problem report tool.
#
Expand Down
27 changes: 10 additions & 17 deletions directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def directory_index():
for index in ('1', '2ABC', '3DEF', '4GHI', '5JKL', '6MNO', '7PRQS', '8TUV', '9WXYZ', '0'):
xml += '<MenuItem>' \
'<Name>' + escape(index) + '</Name>' \
'<URL>' + request.url_root + 'directory/entries?name=' + quote_plus(g.device_name) + '&amp;index=' + quote_plus(index) + '</URL>' \
'<URL>' + request.url_root + 'directory/entries?index=' + quote_plus(index) + '</URL>' \
'</MenuItem>'

if g.is_79xx:
Expand All @@ -47,7 +47,7 @@ def directory_index():
'<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>' \
'<URL>' + request.url_root + 'directory/help</URL>' \
'</SoftKeyItem>' \
'</CiscoIPPhoneMenu>'

Expand Down Expand Up @@ -75,13 +75,13 @@ def directory_entries():
entries = []

for element in document.findall('response/generic[@event="VoicemailUserEntry"]'):
extension = element.get('voicemailbox')
mailbox = element.get('voicemailbox')
name = element.get('fullname', '')

if name[0].upper() not in index:
continue

entries.append((extension, name))
entries.append((mailbox, name))

entries.sort(key = lambda entry: entry[1])

Expand All @@ -104,10 +104,10 @@ def directory_entries():
'<CiscoIPPhoneDirectory>' \
'<Title>' + escape(index) + (' ' + str(page) + '/' + str(pages) if pages > 1 else '') + '</Title>'

for extension, name in entries[(page - 1) * 10:page * 10]:
for mailbox, name in entries[(page - 1) * 10:page * 10]:
xml += '<DirectoryEntry>' \
'<Name>' + escape(name) + '</Name>' \
'<Telephone>' + quote_plus(extension) + '</Telephone>' \
'<Telephone>' + quote_plus(mailbox) + '</Telephone>' \
'</DirectoryEntry>'

if g.is_79xx:
Expand All @@ -116,7 +116,7 @@ def directory_entries():
xml += '<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>' \
'<URL>' + request.url_root + 'directory</URL>' \
'</SoftKeyItem>' \
'<SoftKeyItem>' \
'<Name>' + ('Dial' if g.is_79xx else 'Call') + '</Name>' \
Expand All @@ -127,14 +127,14 @@ def directory_entries():
if page < pages:
xml += '<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>' \
'<URL>' + request.url_root + 'directory/entries?index=' + quote_plus(index) + '&amp;page=' + str(page + 1) + '</URL>' \
'<Position>' + ('2' if g.is_79xx else '3') + '</Position>' \
'</SoftKeyItem>'

if page > 1:
xml += '<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>' \
'<URL>' + request.url_root + 'directory/entries?index=' + quote_plus(index) + '&amp;page=' + str(page - 1) + '</URL>' \
'<Position>' + ('4' if g.is_79xx else '4') + '</Position>' \
'</SoftKeyItem>'

Expand Down Expand Up @@ -170,7 +170,7 @@ def directory_menuitem():
'<CiscoIPPhoneMenu>' \
'<MenuItem>' \
'<Name>Local Directory</Name>' \
'<URL>' + request.url_root + 'directory?name=' + quote_plus(g.device_name) + '</URL>' \
'<URL>' + request.url_root + 'directory</URL>' \
'</MenuItem>' \
'</CiscoIPPhoneMenu>'

Expand All @@ -179,13 +179,6 @@ def directory_menuitem():

@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
Expand Down
13 changes: 0 additions & 13 deletions information.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,6 @@ def help_information():
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
20 changes: 6 additions & 14 deletions problem_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,22 @@

@blueprint.route('/problem-report', methods = ['POST'])
def problem_report():
device_name = request.form.get('devicename', '')

if not re.search(r'(?x) ^ SEP [0-9A-F]{12} $', device_name):
return Response('Invalid device', mimetype = 'text/plain'), 403

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')
prt_file.save(f'{config.reports_dir}/{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
11 changes: 2 additions & 9 deletions services.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def services_menu():
'<Title>Services</Title>' \
'<MenuItem>' \
'<Name>Parked Calls</Name>' \
'<URL>' + request.url_root + 'services/parked-calls?name=' + quote_plus(g.device_name) + '</URL>' \
'<URL>' + request.url_root + 'services/parked-calls</URL>' \
'</MenuItem>'

if g.is_79xx:
Expand Down Expand Up @@ -88,7 +88,7 @@ def parked_calls():
xml += '<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>' \
'<URL>' + request.url_root + 'services</URL>' \
'</SoftKeyItem>' \
'<SoftKeyItem>' \
'<Name>' + ('Dial' if g.is_79xx else 'Call') + '</Name>' \
Expand All @@ -107,13 +107,6 @@ def parked_calls():

@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
Expand Down

0 comments on commit 905f72a

Please sign in to comment.