#!/bin/sh

# PROVIDE: amavis_p0fanalyzer
# REQUIRE: DAEMON
# KEYWORD: shutdown

. /etc/rc.subr

name=amavis_p0fanalyzer
rcvar=amavis_p0fanalyzer_enable

load_rc_config $name

: ${amavis_p0fanalyzer_enable:=no}
: ${amavis_p0fanalyzer_p0f_filter:=tcp dst port 25}
: ${amavis_p0fanalyzer_pidfile1=/var/run/p0fanalyzer1.pid}
: ${amavis_p0fanalyzer_pidfile2=/var/run/p0fanalyzer2.pid}
: ${amavis_p0fanalyzer_flags=2345}
: ${amavis_p0fanalyzer_svcj_options:="net_basic"}

start_cmd=p0fanalyzer_start
stop_cmd=p0fanalyzer_stop

p0fanalyzer_start()
{
	echo "Starting p0f-analyzer." && \
	  %%DAEMON%% ${amavis_p0fanalyzer_pidfile1} \
	  %%PREFIX%%/bin/p0f "${amavis_p0fanalyzer_p0f_filter}" 2>&1 | \
	  %%DAEMON%% ${amavis_p0fanalyzer_pidfile2} \
	  %%PREFIX%%/sbin/p0f-analyzer.pl ${amavis_p0fanalyzer_flags}
}

p0fanalyzer_stop()
{
	test -s ${amavis_p0fanalyzer_pidfile1} && /bin/kill `cat ${amavis_p0fanalyzer_pidfile2}`
	test -s ${amavis_p0fanalyzer_pidfile1} && /bin/kill `cat ${amavis_p0fanalyzer_pidfile1}`
}

run_rc_command $1
