summaryrefslogtreecommitdiff
blob: 0a6595b05817089eccf8b6e1e23adddaa799dbcb (plain)
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
#!/sbin/runscript
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-analyzer/honeyd/files/honeyd.initd,v 1.3 2007/01/28 15:02:47 pva Exp $

depend() {
	need net
}

start() {
	local options

	ebegin "Starting honeyd"

	if [[ -z "${HONEYD_NET}" ]] ; then
		eerror "HONEYD_NET variable must be set in /etc/conf.d/honeyd"
		eend 1
		return 1
	fi
	
	# add route
	for HNET in ${HONEYD_NET} ; do
		if ! netstat -arn | egrep "^${HNET}[[:space:]]*127.0.0.1" ; then
			route add -net ${HNET} gw 127.0.0.1
		fi
	done

	if [[ -n "${HONEYD_LOG}" ]] ; then
		options="${options} -l ${HONEYD_LOG}"
		# create logdir if it doesn't exist
		[[ ! -d "${HONEYD_LOG%/*}" ]] && mkdir ${HONEYD_LOG%/*}
	fi

	# supports webserver feature?
	if [[ "$(/usr/sbin/honeyd --help 2>&1 | grep webserver)" != "" ]] ; then
		# run webserver?
		if [[ ${HONEYD_HTTPD} -eq 1 ]] ; then
			options="${options} --webserver-port ${HONEYD_HTTPD_PORT} \
				--webserver-root ${HONEYD_HTTPD_ROOT} --fix-webserver-permissions"
		else
			options="${options} --disable-webserver"
		fi
	fi

	options="${options} -i ${HONEYD_IF:-lo} ${HONEYD_OPTS}"

	start-stop-daemon --start --quiet --exec /usr/sbin/honeyd \
			-- ${options} ${HONEYD_NET} >/dev/null 2>&1
	eend $?
}

stop() {
	ebegin "Stopping honeyd"
	start-stop-daemon --stop --quiet --retry 5 --exec /usr/sbin/honeyd
	retval=$?
	for HNET in ${HONEYD_NET} ; do
		route del -net ${HNET} gw 127.0.0.1
	done
	eend ${retval}
}