Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
9c5f5101
Commit
9c5f5101
authored
Oct 18, 2015
by
Ad Schellevis
Committed by
Franco Fichtner
Oct 18, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(Captiveportal, new) add overlay user template (web) package to backend code
(cherry picked from commit
47ee5c58
)
parent
a0685638
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
2 deletions
+73
-2
captiveportal
src/etc/rc.d/captiveportal
+3
-2
__init__.py
src/opnsense/scripts/OPNsense/CaptivePortal/lib/__init__.py
+9
-0
overlay_template.py
...nsense/scripts/OPNsense/CaptivePortal/overlay_template.py
+58
-0
captiveportal.conf
...rvice/templates/OPNsense/Captiveportal/captiveportal.conf
+3
-0
No files found.
src/etc/rc.d/captiveportal
View file @
9c5f5101
...
...
@@ -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
"
...
...
src/opnsense/scripts/OPNsense/CaptivePortal/lib/__init__.py
View file @
9c5f5101
...
...
@@ -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
"""
...
...
src/opnsense/scripts/OPNsense/CaptivePortal/overlay_template.py
0 → 100755
View file @
9c5f5101
#!/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
)
src/opnsense/service/templates/OPNsense/Captiveportal/captiveportal.conf
View file @
9c5f5101
...
...
@@ -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
%}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment