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
6eac30f0
Commit
6eac30f0
authored
Oct 09, 2015
by
Ad Schellevis
Committed by
Franco Fichtner
Oct 11, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(captiveportal, new) work in progress rc scripts
parent
de1449b7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
55 deletions
+107
-55
captiveportal.sh
src/opnsense/scripts/OPNsense/CaptivePortal/captiveportal.sh
+105
-55
cp-background-process.py
...e/scripts/OPNsense/CaptivePortal/cp-background-process.py
+2
-0
No files found.
src/opnsense/scripts/OPNsense/CaptivePortal/captiveportal.sh
View file @
6eac30f0
...
...
@@ -24,70 +24,120 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
CPWORKDIR
=
"/var/captiveportal"
CPDEFAULTTEMPLATE
=
"/usr/local/opnsense/scripts/OPNsense/CaptivePortal/htdocs_default"
# extract all zones from captive portal configuration
CPZONES
=
`
cat
/usr/local/etc/captiveportal.conf |
grep
"
\[
zone_"
|
sed
's/\[zone_//'
|
sed
's/\]//'
`
# initialize captiveportal work directory
mkdir
-p
$CPWORKDIR
# startup API dispatcher, forwards captive portal api request to shared OPNsense API
if
[
-f
/var/run/lighttpd-api-dispatcher.pid
]
;
then
echo
"Stopping API dispatcher"
/bin/pkill
-TERM
-F
/var/run/lighttpd-api-dispatcher.pid
fi
echo
"Starting API dispatcher"
/usr/local/sbin/lighttpd
-f
/var/etc/lighttpd-api-dispatcher.conf
# startup / bootstrap zones
for
zoneid
in
$CPZONES
do
# bootstrap captiveportal jail
zonedirname
=
"zone
$zoneid
"
echo
"Install : zone
$zoneid
"
if
[
-d
$CPWORKDIR
/
$zonedirname
/tmp
]
;
then
# remove temp (flush)
rm
-rf
$CPWORKDIR
/
$zonedirname
/tmp
fi
mkdir
$CPWORKDIR
/
$zonedirname
/tmp
chmod
770
$CPWORKDIR
/
$zonedirname
/tmp
chown
www:www
$CPWORKDIR
/
$zonedirname
/tmp
# load standard rc
.
/etc/rc.subr
# sync default template
/usr/local/bin/rsync
-a
$CPDEFAULTTEMPLATE
/
*
$CPWORKDIR
/
$zonedirname
/htdocs/
name
=
captiveportal
start_precmd
=
captiveportal_prestart
start_cmd
=
"
${
name
}
_start"
stop_cmd
=
"
${
name
}
_stop"
# todo, overlay custom user layout if available
captiveportal_load_rc_config
()
{
CPWORKDIR
=
"/var/captiveportal"
CPDEFAULTTEMPLATE
=
"/usr/local/opnsense/scripts/OPNsense/CaptivePortal/htdocs_default"
# stop running instance
zonepid
=
"/var/run/lighttpd-cp-zone-
$zoneid
.pid"
if
[
-f
$zonepid
]
;
then
echo
"Stop : zone
$zoneid
"
/bin/pkill
-TERM
-F
/var/run/lighttpd-cp-zone-
$zoneid
.pid
rm
/var/run/lighttpd-cp-zone-
$zoneid
.pid
fi
# extract all zones from captive portal configuration
CPZONES
=
`
cat
/usr/local/etc/captiveportal.conf |
grep
"
\[
zone_"
|
sed
's/\[zone_//'
|
sed
's/\]//'
`
}
# start new instance
echo
"Start : zone
$zoneid
"
/usr/local/sbin/lighttpd
-f
/var/etc/lighttpd-cp-zone-
$zoneid
.conf
done
captiveportal_prestart
()
{
# initialize captiveportal work directory
mkdir
-p
$CPWORKDIR
}
captiveportal_start
()
{
if
[
!
-f
/var/run/lighttpd-api-dispatcher.pid
]
;
then
echo
"Starting API dispatcher"
/usr/local/sbin/lighttpd
-f
/var/etc/lighttpd-api-dispatcher.conf
# cleanup removed zones
for
installed_zoneid
in
`
ls
$CPWORKDIR
|
sed
's/zone//g'
`
do
if
[
-d
$CPWORKDIR
/zone
$installed_zoneid
]
;
then
# startup / bootstrap zones
for
zoneid
in
$CPZONES
do
is_installed
=
0
if
[
"
$zoneid
"
-eq
"
$installed_zoneid
"
]
;
then
is_installed
=
1
# bootstrap captiveportal jail
zonedirname
=
"zone
$zoneid
"
echo
"Install : zone
$zoneid
"
if
[
-d
$CPWORKDIR
/
$zonedirname
/tmp
]
;
then
# remove temp (flush)
rm
-rf
$CPWORKDIR
/
$zonedirname
/tmp
fi
if
[
"
$is_installed
"
-eq
0
]
;
then
echo
"Uninstall : zone
$installed_zoneid
"
# todo, insert rm
mkdir
$CPWORKDIR
/
$zonedirname
/tmp
chmod
770
$CPWORKDIR
/
$zonedirname
/tmp
chown
www:www
$CPWORKDIR
/
$zonedirname
/tmp
# sync default template
/usr/local/bin/rsync
-a
$CPDEFAULTTEMPLATE
/
*
$CPWORKDIR
/
$zonedirname
/htdocs/
# todo, overlay custom user layout if available
# start new instance
echo
"Start : zone
$zoneid
"
/usr/local/sbin/lighttpd
-f
/var/etc/lighttpd-cp-zone-
$zoneid
.conf
done
# cleanup removed zones
for
installed_zoneid
in
`
ls
$CPWORKDIR
|
sed
's/zone//g'
`
do
if
[
-d
$CPWORKDIR
/zone
$installed_zoneid
]
;
then
for
zoneid
in
$CPZONES
do
is_installed
=
0
if
[
"
$zoneid
"
-eq
"
$installed_zoneid
"
]
;
then
is_installed
=
1
fi
if
[
"
$is_installed
"
-eq
0
]
;
then
echo
"Uninstall : zone
$installed_zoneid
"
# todo, insert rm
fi
done
fi
done
echo
"start captiveportal background process"
/usr/local/opnsense/scripts/OPNsense/CaptivePortal/cp-background-process.py stop
else
echo
"already running"
fi
}
# stop captive portal (sub) processes
captiveportal_stop
()
{
# startup API dispatcher, forwards captive portal api request to shared OPNsense API
if
[
-f
/var/run/lighttpd-api-dispatcher.pid
]
;
then
echo
"Stopping API dispatcher"
/bin/pkill
-TERM
-F
/var/run/lighttpd-api-dispatcher.pid
if
[
-f
/var/run/lighttpd-api-dispatcher.pid
]
;
then
# in case pkill didn't do anything, always remove pid file
rm
/var/run/lighttpd-api-dispatcher.pid
fi
fi
done
# stopping zone http servers
for
zoneid
in
$CPZONES
do
# stop running instance
zonepid
=
"/var/run/lighttpd-cp-zone-
$zoneid
.pid"
if
[
-f
$zonepid
]
;
then
echo
"Stop : zone
$zoneid
"
/bin/pkill
-TERM
-F
$zonepid
rm
$zonepid
fi
done
# stopping unconfigured zones (not in $CPZONES list)
for
zonepid
in
`
ls
/var/run/lighttpd-cp-zone-
*
.pid 2>/dev/null
`
do
/bin/pkill
-TERM
-F
$zonepid
rm
$zonepid
done
if
[
-f
/var/run/captiveportal.db.pid
]
;
then
echo
"stop captiveportal background process"
/bin/pkill
-TERM
-F
/var/run/captiveportal.db.pid
fi
}
captiveportal_load_rc_config
load_rc_config
$name
run_rc_command
$1
src/opnsense/scripts/OPNsense/CaptivePortal/cp-background-process.py
View file @
6eac30f0
...
...
@@ -106,6 +106,8 @@ def main():
time
.
sleep
(
5
)
except
KeyboardInterrupt
:
break
except
SystemExit
:
break
except
:
syslog
.
syslog
(
syslog
.
LOG_ERR
,
traceback
.
format_exc
())
...
...
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