]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame_incremental - src/initscripts/init.d/snort
Updated lcd4linux pack with backup and init files
[people/pmueller/ipfire-2.x.git] / src / initscripts / init.d / snort
... / ...
CommitLineData
1#!/bin/sh
2########################################################################
3# Begin $rc_base/init.d/snort
4#
5# Description : Snort Initscript
6#
7# Authors : Michael Tremer for ipfire.org - mitch@ipfire.org
8#
9# Version : 01.00
10#
11# Notes :
12#
13########################################################################
14
15. /etc/sysconfig/rc
16. ${rc_functions}
17
18PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin; export PATH
19
20eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
21eval $(/usr/local/bin/readhash /var/ipfire/snort/settings)
22
23if [ "$ENABLE_SNORT_ORANGE" == "on" ]; then
24 HOME_NET+="$ORANGE_ADDRESS,"
25 DEVICES+="$ORANGE_DEV "
26fi
27
28if [ "$ENABLE_SNORT_GREEN" == "on" ]; then
29 HOME_NET+="$GREEN_ADDRESS,"
30 DEVICES+="$GREEN_DEV "
31fi
32
33if [ "$ENABLE_SNORT_BLUE" == "on" ]; then
34 HOME_NET+="$BLUE_ADDRESS,"
35 DEVICES+="$BLUE_DEV "
36fi
37
38if [ "$ENABLE_SNORT" == "on" ]; then
39 LOCAL_IP=`cat /var/ipfire/red/local-ipaddress`
40 if [ "$LOCAL_IP" ]; then
41 HOME_NET+="$LOCAL_IP,"
42 else
43 exit 1 ## Add error handling here
44 fi
45 DEVICES+=`cat /var/ipfire/red/iface 2>/dev/null`
46fi
47
48COUNT=`echo $HOME_NET | wc -m`
49HOME_NET=`echo $HOME_NET | cut -c $[$COUNT - 2]`
50
51echo "var HOME_NET [$HOME_NET]" > /etc/snort/vars
52echo "var EXTERNAL_NET ANY" >> /etc/snort/vars
53
54DNS1=`cat /var/ipfire/red/dns1 2>/dev/null`
55DNS2=`cat /var/ipfire/red/dns2 2>/dev/null`
56
57if [ "$DNS2" ]; then
58 echo "var DNS_SERVERS [$DNS1,$DNS2]" >> /etc/snort/vars
59else
60 echo "var DNS_SERVERS $DNS1" >> /etc/snort/vars
61fi
62
63case "$1" in
64 start)
65 for DEVICE in $DEVICES; do
66 boot_mesg "Starting Intrusion Detection System on $DEVICE..."
67 /usr/sbin/snort -c /etc/snort/snort.conf -i $DEVICE -D -l /var/log/snort --create-pidfile --nolock-pidfile --pid-path /var/run/
68 evaluate_retval
69 chmod 644 /var/run/snort_$DEVICE.pid
70 done
71
72
73 if [ -r /var/ipfire/guardian/enable ]; then
74 IFACE=`/bin/cat /var/ipfire/red/iface 2>/dev/null | /usr/bin/tr -d '\012'`
75 sed -e "s/^Interface.*/Interface ${IFACE}/" /var/ipfire/guardian/guardian.conf > temp
76 mv temp /var/ipfire/guardian/guardian.conf
77 chown nobody.root /var/ipfire/guardian/guardian.conf
78
79 boot_mesg "Starting Guardian..."
80 loadproc /usr/local/bin/guardian.pl -c /var/ipfire/guardian/guardian.conf
81 fi
82 ;;
83
84 stop)
85 DEVICES=""
86 if [ -r /var/run/snort_$BLUE_DEV.pid ]; then
87 DEVICES+="$BLUE_DEV "
88 fi
89
90 if [ -r /var/run/snort_$GREEN_DEV.pid ]; then
91 DEVICES+="$GREEN_DEV "
92 fi
93
94 if [ -r /var/run/snort_$ORANGE_DEV.pid ]; then
95 DEVICES+="$ORANGE_DEV "
96 fi
97
98 RED=`cat /var/ipfire/red/iface 2>/dev/null`
99 if [ -r /var/run/snort_$RED.pid ]; then
100 DEVICES+=`cat /var/ipfire/red/iface 2>/dev/null`
101 fi
102
103 for DEVICE in $DEVICES; do
104 boot_mesg "Stopping Intrusion Detection System on $DEVICE..."
105 killproc -p /var/run/snort_$DEVICE.pid /var/run
106 done
107
108 rm /var/run/snort_* >/dev/null 2>/dev/null
109
110 if [ -r /var/ipfire/guardian/enable ]; then
111 boot_mesg "Stopping Guardian..."
112 killproc /usr/local/bin/guardian.pl
113 fi
114 ;;
115
116 status)
117 statusproc /usr/sbin/snort
118 ;;
119
120 restart)
121 $0 stop
122 $0 start
123 ;;
124
125 *)
126 echo "Usage: $0 {start|stop|restart|status}"
127 exit 1
128 ;;
129esac
130
131chmod 644 /var/log/snort/* 2>/dev/null
132
133# End $rc_base/init.d/snort