#!/bin/bash
##
# Advanced Policy Firewall (APF) v2.0.2
#             (C) 2002-2026, R-fx Networks <proj@rfxn.com>
#             (C) 2026, Ryan MacDonald <ryan@rfxn.com>
# This program may be freely redistributed under the terms of the GNU GPL v2
##
### BEGIN INIT INFO
# Provides:          apf
# Required-Start:    $network $local_fs $remote_fs
# Required-Stop:     $network $local_fs $remote_fs
# Should-Start:
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start apf at boot time
# chkconfig: 345 55 25
# description: Advanced Policy Firewall (APF); iptables firewall wrapper
### END INIT INFO

INSTALL_PATH="/etc/apf"

case "$1" in
start)
	echo -n "Starting APF: "
	"/usr/sbin/apf" --start >> /dev/null 2>&1
	echo "done"
	;;
stop)
	echo -n "Stopping APF: "
	"/usr/sbin/apf" --stop >> /dev/null 2>&1
	echo "done"
	;;
restart)
	$0 stop
	$0 start
	;;
status)
	. "$INSTALL_PATH/conf.apf"
	. "$INSTALL_PATH/internals/internals.conf"
	if $IPT $IPT_FLAGS -n -L TALLOW > /dev/null 2>&1; then
		echo "APF is running."
	else
		echo "APF is not running."
		exit 3
	fi
	;;
*)
	echo "usage: $0 {start|stop|restart|status}"
	exit 1
esac
exit 0
