Commit 9c5f5101 authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(Captiveportal, new) add overlay user template (web) package to backend code

(cherry picked from commit 47ee5c58)
parent a0685638
......@@ -78,9 +78,10 @@ captiveportal_start()
chown www:www $CPWORKDIR/$zonedirname/tmp
# sync default template
/usr/local/bin/rsync -a $CPDEFAULTTEMPLATE/* $CPWORKDIR/$zonedirname/htdocs/
/usr/local/bin/rsync --delete -ar $CPDEFAULTTEMPLATE/ $CPWORKDIR/$zonedirname/htdocs/
# todo, overlay custom user layout if available
# overlay custom user layout if available.
/usr/local/opnsense/scripts/OPNsense/CaptivePortal/overlay_template.py $zoneid
# start new instance
echo "Start : zone $zoneid"
......
......@@ -77,6 +77,15 @@ class Config(object):
result[zoneid]['allowedmacaddresses'] = list()
return result
def fetch_template_data(self, zoneid):
""" fetch template content from config
"""
for section in self._conf_handle.sections():
if section.find('template_for_zone_') == 0 and section.split('_')[-1] == str(zoneid):
if self._conf_handle.has_option(section, 'content'):
return self._conf_handle.get(section, 'content')
return None
class OPNSenseConfig(object):
""" Read configuration data from config.xml
"""
......
#!/usr/local/bin/python2.7
"""
Copyright (c) 2015 Deciso B.V. - Ad Schellevis
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------------
overlay user web template package on installed default template, default template should be installed
in /var/captiveportal/zone<zoneid>/htdocs/ first.
"""
import os
import sys
import ujson
import binascii
import zipfile
import StringIO
from lib import Config
if len(sys.argv) > 1:
cnf = Config()
target_directory = '/var/captiveportal/zone%s/htdocs/' % sys.argv[1]
template_data = cnf.fetch_template_data(sys.argv[1])
if template_data is not None and len(template_data) > 20:
print ('overlay user template package for zone %s' % sys.argv[1] )
zip_content = template_data.decode('base64')
input_data = StringIO.StringIO(zip_content)
with zipfile.ZipFile(input_data, mode='r', compression=zipfile.ZIP_DEFLATED) as zf_in:
for zf_info in zf_in.infolist():
if zf_info.filename[-1] != '/':
target_filename = '%s%s' % (target_directory, zf_info.filename)
file_target_directory = '/'.join(target_filename.split('/')[:-1])
if not os.path.isdir(file_target_directory):
os.makedirs(file_target_directory)
with open(target_filename, 'wb') as f_out:
f_out.write(zf_in.read(zf_info.filename))
sys.exit(0)
......@@ -8,6 +8,9 @@ hardtimeout={{ cpZone.hardtimeout|default("0") }}
concurrentlogins={{cpZone.concurrentlogins|default("0")}}
allowedAddresses={{cpZone.allowedAddresses|default("")}}
allowedMACAddresses={{cpZone.allowedMACAddresses|default("")}}
[template_for_zone_{{cpZone.zoneid}}]
content={{helpers.getUUID(cpZone.template).content}}
{% endif %}
{% endfor %}
{% endif %}
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