Commit 6eac30f0 authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(captiveportal, new) work in progress rc scripts

parent de1449b7
......@@ -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
......@@ -106,6 +106,8 @@ def main():
time.sleep(5)
except KeyboardInterrupt:
break
except SystemExit:
break
except:
syslog.syslog(syslog.LOG_ERR, traceback.format_exc())
......
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