~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to utopic/etc/init.d/uif

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /bin/bash
2
 
### BEGIN INIT INFO
3
 
# Provides:          uif
4
 
# Required-Start:    $network $syslog $remote_fs
5
 
# Required-Stop:     $network $syslog $remote_fs
6
 
# Default-Start:     2 3 4 5
7
 
# Default-Stop:      0 1 6
8
 
# Short-Description: Universal Internet Firewall
9
 
# Description:       Start the firewall defined in /etc/uif/uif.conf.
10
 
### END INIT INFO
11
 
#
12
 
# Version:      @(#)/etc/init.d/uif  1.0.9  June-2013 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
13
 
#
14
 
 
15
 
# RedHat specific settings - ignore for real systems ---------------------------
16
 
# chkconfig: - 60 95
17
 
# description: provides iptables packet filtering
18
 
 
19
 
. /lib/lsb/init-functions
20
 
 
21
 
PATH=/usr/sbin:/sbin:$PATH
22
 
UIF=/usr/sbin/uif
23
 
 
24
 
IPV6MODE=0
25
 
 
26
 
# Include firewall defaults if available
27
 
if [ -f /etc/default/uif ] ; then
28
 
        . /etc/default/uif
29
 
fi
30
 
 
31
 
#THIS IS DEFAULT ANYWAY#[ -z "$OPTIONS" ] && OPTIONS="-c /etc/uif/uif.conf"
32
 
 
33
 
# Binaries installed?
34
 
if [ ! -f /sbin/iptables ]; then
35
 
        log_failure_msg "uif: iptables not found - aborting"
36
 
        exit 1
37
 
fi
38
 
 
39
 
if [ $IPV6MODE = 1 -a ! -f /sbin/ip6tables ] ; then
40
 
        log_failure_msg "uif: ip6tables not found - aborting"
41
 
        exit 1
42
 
fi
43
 
 
44
 
# uif installed? Without this script makes no sense...
45
 
[ -f $UIF ] || exit 1
46
 
 
47
 
 
48
 
# As the name says. If the kernel supports modules, it'll try to load
49
 
# the ones listed in "MODULES".
50
 
load_modules() {
51
 
        [ -f /proc/modules ] || return
52
 
        LIST=`/sbin/lsmod|awk '!/Module/ {print $1}'`
53
 
 
54
 
        for mod in $MODULES; do
55
 
                echo $LIST | grep -q $mod || modprobe $mod || /bin/true
56
 
        done
57
 
}
58
 
 
59
 
 
60
 
case "$1" in
61
 
 
62
 
start)
63
 
        log_daemon_msg "Starting uif"
64
 
        logger "Starting uif"
65
 
        [ -f /proc/modules ] && { log_progress_msg "modules"; load_modules; }
66
 
 
67
 
        log_progress_msg "IPv4-rules"
68
 
        EMSG=`$UIF $OPTIONS 2>&1`
69
 
        RET4=$?
70
 
        if [ $RET4 -ne 0 ]; then
71
 
 
72
 
                logger "Starting uif failed: $EMSG"
73
 
 
74
 
                [ -n "$MAILTO" ] && \
75
 
                echo -e "Hi. This is your firewall script - which has failed" \
76
 
                "to execute in a proper way.\nHere is the error message:\n" \
77
 
                "\n$EMSG\n\nPlease fix to be sure..." | mail -s "Firewall script failure" $MAILTO
78
 
 
79
 
                log_end_msg $RET4
80
 
                echo
81
 
                echo -e "Error message: $EMSG\n"
82
 
                exit 1
83
 
        fi
84
 
        if [ $IPV6MODE = 1 ] ; then
85
 
                log_progress_msg "IPv6-rules"
86
 
                EMSG=`$UIF -6 $OPTIONS 2>&1`
87
 
                RET6=$?
88
 
                if [ $RET6 -ne 0 ]; then
89
 
 
90
 
                        logger "Starting uif failed: $EMSG"
91
 
 
92
 
                        [ -n "$MAILTO" ] && \
93
 
                        echo -e "Hi. This is your IPv6 firewall script - which has failed" \
94
 
                        "to execute in a proper way.\nHere is the error message:\n" \
95
 
                        "\n$EMSG\n\nPlease fix to be sure..." | mail -s "Firewall script failure" $MAILTO
96
 
 
97
 
                        log_end_msg $RET6
98
 
                        echo
99
 
                        echo -e "Error message: $EMSG\n"
100
 
                        exit 1
101
 
                fi
102
 
        else
103
 
                RET6=0;
104
 
        fi
105
 
 
106
 
        log_end_msg $(($RET4+$RET6))
107
 
        ;;
108
 
 
109
 
stop)
110
 
        log_daemon_msg "Stopping uif"
111
 
        logger "Stopping uif"
112
 
        if [ $IPV6MODE = 1 ] ; then
113
 
                log_progress_msg "IPv4"
114
 
        fi
115
 
        $UIF -d
116
 
        if [ $IPV6MODE = 1 ] ; then
117
 
                log_progress_msg "IPv6"
118
 
                $UIF -6 -d
119
 
        fi
120
 
        log_end_msg 0
121
 
        ;;
122
 
 
123
 
print)
124
 
        echo "Printing rules based on your current configuration"
125
 
        $UIF $OPTIONS -pt
126
 
        if [ $IPV6MODE = 1 ] ; then
127
 
                $UIF -6 $OPTIONS -pt
128
 
        fi
129
 
 
130
 
        ;;
131
 
 
132
 
test|test4)
133
 
        if [ $IPV6MODE = 1 ] ; then
134
 
                echo -n "IPv4 Test: "
135
 
        fi
136
 
        echo -n "Activating IPv4 ruleset for $TIMEOUT seconds: modules, "
137
 
        trap 'echo "aborted, IPv4 rules restored"; exit 0' SIGINT
138
 
        load_modules
139
 
 
140
 
        echo -n "IPv4 rules - active, waiting - "
141
 
        EMSG=`$UIF -T $TIMEOUT $OPTIONS`
142
 
        if [ $? -eq 0 ]; then
143
 
                echo ok
144
 
                exit 0
145
 
        fi
146
 
        echo failed
147
 
        echo -e "Error message: $EMSG\n"
148
 
        ;;
149
 
test6)
150
 
        if [ $IPV6MODE = 1 ] ; then
151
 
                echo -n "IPv6 Test: "
152
 
                echo -n "Activating IPv6 ruleset for $TIMEOUT seconds: modules, "
153
 
                trap 'echo "aborted, IPv6 rules restored"; exit 0' SIGINT
154
 
                load_modules
155
 
 
156
 
                echo -n "IPv6 rules - active, waiting - "
157
 
                EMSG=`$UIF -6 -T $TIMEOUT $OPTIONS`
158
 
                if [ $? -eq 0 ]; then
159
 
                        echo ok
160
 
                        exit 0
161
 
                fi
162
 
                echo failed
163
 
        echo -e "Error message: $EMSG\n"
164
 
        fi
165
 
        ;;
166
 
 
167
 
status)
168
 
        if [ "`id -u`" != "0" ]; then
169
 
                echo "Can't retrieve status information. You need to be root."
170
 
                exit 1
171
 
        fi
172
 
        if [ $IPV6MODE = 1 ] ; then
173
 
                echo "IPv4 STATUS:"
174
 
        fi
175
 
        # Simple rule listing
176
 
        echo -e "\nRule listing:\n"
177
 
        iptables-save | sed "/^#/d"
178
 
 
179
 
        # Show accounting data
180
 
        if [ -n "$ACCOUNTPREFIX" ]; then
181
 
                echo -e "\n\nCurrent accounting information:\n"
182
 
                iptables -vnx -L 2>&1 | sed "/pkts/d" | sed -ne "/^Chain $ACCOUNTPREFIX/N" -e "s/\n/ /p" | \
183
 
                        sed "s/[ ][ ]*/ /g" | awk '{ print $2"\t"$6" Bytes"; }'
184
 
        fi
185
 
        if [ $IPV6MODE = 1 ] ; then
186
 
                echo "IPv6 STATUS:"
187
 
                # Simple rule listing
188
 
                echo -e "\nRule listing:\n"
189
 
                ip6tables-save | sed "/^#/d"
190
 
 
191
 
                # Show accounting data
192
 
                if [ -n "$ACCOUNTPREFIX" ]; then
193
 
                        echo -e "\n\nCurrent accounting information:\n"
194
 
                        ip6tables -vnx -L 2>&1 | sed "/pkts/d" | sed -ne "/^Chain $ACCOUNTPREFIX/N" -e "s/\n/ /p" | \
195
 
                            sed "s/[ ][ ]*/ /g" | awk '{ print $2"\t"$6" Bytes"; }'
196
 
                fi
197
 
        fi
198
 
        # Show last 10 policy violations
199
 
        if [ -n "$LOGPREFIX" ]; then
200
 
                if [ $IPV6MODE = 1 ] ; then
201
 
                        echo -e "\n\nLast 10 policy violations (IPv4 & IPv6 combined):"
202
 
                else
203
 
                        echo -e "\n\nLast 10 policy violations (IPv4 only):"
204
 
                fi
205
 
                dmesg | grep "`hostname`.* $LOGPREFIX .*:" 2> /dev/null | tail -n 10
206
 
        fi
207
 
 
208
 
        echo -e "\n\n"
209
 
        ;;
210
 
 
211
 
 
212
 
restart|reload|force-reload)
213
 
        $0 start
214
 
        ;;
215
 
 
216
 
flush)
217
 
        echo -n "Flushing IPv4 packet counters: "
218
 
        iptables -Z &> /dev/null
219
 
        if [ $? -eq 0 ]; then
220
 
                echo ok
221
 
        else
222
 
                echo failed
223
 
        fi
224
 
        if [ $IPV6MODE = 1 ] ; then
225
 
                echo -n "Flushing IPv6 packet counters: "
226
 
                ip6tables -Z &> /dev/null
227
 
                if [ $? -eq 0 ]; then
228
 
                        echo ok
229
 
                else
230
 
                        echo failed
231
 
                fi
232
 
        fi
233
 
 
234
 
        ;;
235
 
 
236
 
*)
237
 
        echo "Usage: $0 {start|stop|status|restart|reload|flush|print}"
238
 
        exit 1
239
 
esac
240
 
 
241
 
exit 0