]>
Commit | Line | Data |
---|---|---|
bd3a8a50 | 1 | #!/bin/sh |
83843a1c MT |
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 | |
bd3a8a50 | 10 | # |
83843a1c MT |
11 | # Notes : |
12 | # | |
13 | ######################################################################## | |
14 | ||
15 | . /etc/sysconfig/rc | |
16 | . ${rc_functions} | |
bd3a8a50 | 17 | |
1b73b07e CS |
18 | PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin; export PATH |
19 | ||
bd3a8a50 | 20 | eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) |
83843a1c | 21 | eval $(/usr/local/bin/readhash /var/ipfire/snort/settings) |
bd3a8a50 | 22 | |
8dc25f04 AF |
23 | case "$1" in |
24 | start) | |
25 | if [ "$BLUE_NETADDRESS" ]; then | |
26 | BLUE_NET="$BLUE_NETADDRESS/$BLUE_NETMASK," | |
27 | BLUE_IP="$BLUE_ADDRESS," | |
28 | fi | |
bd3a8a50 | 29 | |
8dc25f04 AF |
30 | if [ "$ORANGE_NETADDRESS" ]; then |
31 | ORANGE_NET="$ORANGE_NETADDRESS/$ORANGE_NETMASK," | |
32 | ORANGE_IP="$ORANGE_ADDRESS," | |
33 | fi | |
bd3a8a50 | 34 | |
8dc25f04 AF |
35 | if [ "$ENABLE_SNORT_ORANGE" == "on" ]; then |
36 | DEVICES+="$ORANGE_DEV " | |
37 | HOMENET+="$ORANGE_IP" | |
38 | else | |
39 | HOMENET+="$ORANGE_NET" | |
40 | fi | |
bd3a8a50 | 41 | |
8dc25f04 AF |
42 | if [ "$ENABLE_SNORT_BLUE" == "on" ]; then |
43 | DEVICES+="$BLUE_DEV " | |
44 | HOMENET+="$BLUE_IP" | |
45 | else | |
46 | HOMENET+="$BLUE_NET" | |
47 | fi | |
bd3a8a50 | 48 | |
8dc25f04 AF |
49 | if [ "$ENABLE_SNORT_GREEN" == "on" ]; then |
50 | DEVICES+="$GREEN_DEV " | |
51 | HOMENET+="$GREEN_ADDRESS," | |
52 | else | |
53 | HOMENET+="$GREEN_NETADDRESS/$GREEN_NETMASK," | |
54 | fi | |
bd3a8a50 | 55 | |
8dc25f04 AF |
56 | if [ "$ENABLE_SNORT" == "on" ]; then |
57 | DEVICES+=`cat /var/ipfire/red/iface 2>/dev/null` | |
58 | LOCAL_IP=`cat /var/ipfire/red/local-ipaddress 2>/dev/null` | |
59 | if [ "$LOCAL_IP" ]; then | |
60 | HOMENET+="$LOCAL_IP," | |
61 | fi | |
62 | fi | |
63 | HOMENET+="127.0.0.1" | |
89f3d66c | 64 | echo "ipvar HOME_NET [$HOMENET]" > /etc/snort/vars |
83843a1c | 65 | |
8dc25f04 AF |
66 | DNS1=`cat /var/ipfire/red/dns1 2>/dev/null` |
67 | DNS2=`cat /var/ipfire/red/dns2 2>/dev/null` | |
bd3a8a50 | 68 | |
8dc25f04 | 69 | if [ "$DNS2" ]; then |
89f3d66c | 70 | echo "ipvar DNS_SERVERS [$DNS1,$DNS2]" >> /etc/snort/vars |
8dc25f04 | 71 | else |
89f3d66c | 72 | echo "ipvar DNS_SERVERS $DNS1" >> /etc/snort/vars |
8dc25f04 | 73 | fi |
ce0e83b3 | 74 | |
1b73b07e CS |
75 | for DEVICE in $DEVICES; do |
76 | boot_mesg "Starting Intrusion Detection System on $DEVICE..." | |
77 | /usr/sbin/snort -c /etc/snort/snort.conf -i $DEVICE -D -l /var/log/snort --create-pidfile --nolock-pidfile --pid-path /var/run/ | |
78 | evaluate_retval | |
0d7da887 | 79 | sleep 1 |
1b73b07e CS |
80 | chmod 644 /var/run/snort_$DEVICE.pid |
81 | done | |
82 | ||
83 | ||
84 | if [ -r /var/ipfire/guardian/enable ]; then | |
85 | IFACE=`/bin/cat /var/ipfire/red/iface 2>/dev/null | /usr/bin/tr -d '\012'` | |
86 | sed -e "s/^Interface.*/Interface ${IFACE}/" /var/ipfire/guardian/guardian.conf > temp | |
87 | mv temp /var/ipfire/guardian/guardian.conf | |
a61948ad | 88 | chown nobody.root /var/ipfire/guardian/guardian.conf |
1b73b07e CS |
89 | |
90 | boot_mesg "Starting Guardian..." | |
91 | loadproc /usr/local/bin/guardian.pl -c /var/ipfire/guardian/guardian.conf | |
92 | fi | |
93 | ;; | |
94 | ||
95 | stop) | |
96 | DEVICES="" | |
97 | if [ -r /var/run/snort_$BLUE_DEV.pid ]; then | |
98 | DEVICES+="$BLUE_DEV " | |
99 | fi | |
100 | ||
101 | if [ -r /var/run/snort_$GREEN_DEV.pid ]; then | |
102 | DEVICES+="$GREEN_DEV " | |
103 | fi | |
104 | ||
105 | if [ -r /var/run/snort_$ORANGE_DEV.pid ]; then | |
106 | DEVICES+="$ORANGE_DEV " | |
107 | fi | |
cf29614f | 108 | |
1b73b07e CS |
109 | RED=`cat /var/ipfire/red/iface 2>/dev/null` |
110 | if [ -r /var/run/snort_$RED.pid ]; then | |
111 | DEVICES+=`cat /var/ipfire/red/iface 2>/dev/null` | |
112 | fi | |
ce8e4c83 | 113 | |
1b73b07e CS |
114 | for DEVICE in $DEVICES; do |
115 | boot_mesg "Stopping Intrusion Detection System on $DEVICE..." | |
116 | killproc -p /var/run/snort_$DEVICE.pid /var/run | |
117 | done | |
118 | ||
119 | rm /var/run/snort_* >/dev/null 2>/dev/null | |
120 | ||
e4c3c620 | 121 | if ([ -r /var/ipfire/guardian/enable ] || [ ! -z $(pidofproc /usr/local/bin/guardian.pl) ]); then |
1b73b07e CS |
122 | boot_mesg "Stopping Guardian..." |
123 | killproc /usr/local/bin/guardian.pl | |
124 | fi | |
0ad0c03e AF |
125 | |
126 | # Don't report returncode of rm if snort was not started | |
127 | exit 0 | |
1b73b07e CS |
128 | ;; |
129 | ||
130 | status) | |
131 | statusproc /usr/sbin/snort | |
132 | ;; | |
133 | ||
134 | restart) | |
135 | $0 stop | |
136 | $0 start | |
137 | ;; | |
138 | ||
139 | *) | |
140 | echo "Usage: $0 {start|stop|restart|status}" | |
141 | exit 1 | |
142 | ;; | |
bd3a8a50 RZ |
143 | esac |
144 | ||
97bfe380 | 145 | chmod 644 /var/log/snort/* 2>/dev/null |
9c0d99da | 146 | |
bd3a8a50 | 147 | # End $rc_base/init.d/snort |