summaryrefslogtreecommitdiff
path: root/net-mgmt/p0f/files/p0f.in
blob: 8f209a68e9025137b63314ebe8108be95f48eed3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: p0f
# REQUIRE: LOGIN
# KEYWORD: shutdown

# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:

# p0f_enable (bool):	Set it to YES to enable p0f.
#			Default: NO.
#
# p0f_user (str)	User to drop privileges and change to.
#			Default: p0f.
#
# p0f_sock (path):	Path to socket used to communicate with p0f.
#			Default: /var/run/p0f.sock
#
# p0f_db (path):	Location of fingerprint db.
#			Default: %%PREFIX%%/etc/p0f.fp
#
# p0f_flags (str):	Options passed to the p0f daemon.
#			Default: "-d -u ${p0f_user} -s ${p0f_sock} -f ${p0f_db}"
#
# command_args (str):	Optional pcap-style traffic filtering rules.
#			See p0f README for details.

. /etc/rc.subr

name="p0f"
rcvar=p0f_enable

load_rc_config "$name"

: ${p0f_enable:="NO"}
: ${p0f_user:="p0f"}
: ${p0f_sock:="/var/run/${name}.sock"}
: ${p0f_db:="%%PREFIX%%/etc/p0f.fp"}
: ${p0f_flags:="-d -u ${p0f_user} -s ${p0f_sock} -f ${p0f_db}"}

command="%%PREFIX%%/bin/${name}"

pidfile="/var/run/${name}.pid"
required_files="${p0f_db}"

start_cmd="${name}_start"
stop_postcmd="rm -f ${p0f_sock} $pidfile"

extra_commands="reload"

p0f_get_pid() {
	PID=$(/bin/ps waux | /usr/bin/grep ${command} | /usr/bin/grep -v grep | /usr/bin/grep ${p0f_sock} | /usr/bin/awk '{print $2}')
}

p0f_start() {
	p0f_get_pid
	if [ -z "${PID}" ] ; then
		echo "Starting ${name}."
		if [ ! -z "${command_args}" ] ; then
			${command} ${p0f_flags} "${command_args}"
		else
			${command} ${p0f_flags}
		fi
		if [ ! -z "${pidfile}" ] ; then
			p0f_get_pid
			[ -z "${PID}" ] || echo ${PID} > ${pidfile}
		fi
	else
		echo "${name} already running? (pid=${PID})."
	fi
}

run_rc_command "$1"