Commit f992f1b7 authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(Captiveportal, new) add wrapper class for config.xml (read user template code)

(cherry picked from commit cb08c275)
parent 1b23e3b5
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
""" """
import os.path import os.path
import stat import stat
import xml.etree.ElementTree
from ConfigParser import ConfigParser from ConfigParser import ConfigParser
class Config(object): class Config(object):
...@@ -75,3 +76,29 @@ class Config(object): ...@@ -75,3 +76,29 @@ class Config(object):
else: else:
result[zoneid]['allowedmacaddresses'] = list() result[zoneid]['allowedmacaddresses'] = list()
return result return result
class OPNSenseConfig(object):
""" Read configuration data from config.xml
"""
def __init__(self):
self.load_config()
def load_config(self):
""" load config.xml
"""
tree = xml.etree.ElementTree.parse('/conf/config.xml')
self.rootNode = tree.getroot()
def get_template(self, fileid):
""" fetch template content from config.xml
:param fileid: internal fileid (field in template node)
:return: string, bse64 encoded data or None if not found
"""
templates = self.rootNode.findall("./OPNsense/captiveportal/templates/template")
if templates is not None:
for template in templates:
if template.find('fileid') is not None and template.find('content') is not None :
if template.find('fileid').text == fileid:
return template.find('content').text
return None
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment