#!/sbin/openrc-run

. "$ZAPRET_BASE"/init.d/sysv/functions

extra_commands="start_fw stop_fw start_daemons stop_daemons"

name="zapret"
description="DPI bypass toolkit"
description_start_fw="Apply firewall rules"
description_stop_fw="Remove firewall rules"
description_start_daemons="Run daemons"
description_stop_daemons="Stop daemons"

depend() {
	need net
	use dns logger netmount
}

start() {
	start_daemons
	[ "$INIT_APPLY_FW" != "1" ] || start_fw
}

stop() {
	stop_daemons
	[ "$INIT_APPLY_FW" != "1" ] || stop_fw
}

start_fw() {
	ebegin "Applying firewall rules"
	zapret_apply_firewall
	eend $? "Failed to apply firewall rules"
}

stop_fw() {
	ebegin "Removing firewall rules"
	zapret_unapply_firewall
	eend $? "Failed to remove firewall rules"
}

start_daemons() {
	ebegin "Starting daemons"
	zapret_run_daemons
	eend $? "Failed to start daemons"
}

stop_daemons() {
	ebegin "Stopping daemons"
	zapret_stop_daemons
	eend $? "Failed to stop daemons"
}

