-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfgadm.in
114 lines (104 loc) · 2 KB
/
fgadm.in
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/sh
FILTER=@SYSCONFDIR@/rules.filter
CONF=@SYSCONFDIR@/filtergen.conf
FILTERGEN=@SBINDIR@/filtergen
# move to the config directory so relative includes work
if ! test -d @SYSCONFDIR@ ; then
echo @SYSCONFDIR@ not found
exit 1
fi
cd @SYSCONFDIR@
# load config options
if [ -f $CONF ]; then
. $CONF
fi
# sanity check config values
case "$BACKEND" in
iptables|ip6tables|iptables-restore|ip6tables-restore|ipchains|ipfilter|cisco) ;;
*) BACKEND="iptables" ;;
esac
# check validity of input file
check () {
$FILTERGEN $FGOPTS -t $BACKEND $FILTER
}
reload () {
if [ -f $FILTER ]; then
echo "Generating $BACKEND packet filter."
case "$BACKEND" in
iptables|iptables-restore|ip6tables|ip6tables-restore|ipchains)
if [ -x /sbin/$BACKEND ]; then
if $FILTERGEN $FGOPTS -t $BACKEND $FILTER > /dev/null ; then
$FILTERGEN $FGOPTS -t $BACKEND $FILTER | /bin/sh
else
echo "Errors found in $FILTER. Not reloading."
RETVAL=1
fi
else
echo "/sbin/$BACKEND not found. Not reloading."
RETVAL=1
fi
;;
*)
echo "Operation not supported for $BACKEND backend."
;;
esac
else
echo "$RULES not found. Not reloading."
RETVAL=1
fi
}
stop () {
echo "Stopping current packet filter."
case "$BACKEND" in
iptables|ipchains)
if [ -x /sbin/$BACKEND ]; then
$FILTERGEN -t $BACKEND -F ACCEPT | /bin/sh
else
echo "/sbin/$BACKEND not found"
RETVAL=1
fi
;;
*)
echo "Operation not supported for $BACKEND backend."
;;
esac
}
save () {
case "$BACKEND" in
iptables)
if [ -f /etc/redhat-release ]; then
/sbin/service iptables save
fi
;;
ipchains)
if [ -f /etc/redhat-release ]; then
/sbin/service ipchains save
fi
;;
*)
echo "Operation not supported for $BACKEND backend."
;;
esac
}
usage () {
echo <<EOF
usage: $0 [check|reload|stop|save]
EOF
}
case "$1" in
check)
check
;;
reload)
reload
;;
stop)
stop
;;
save)
save
;;
*)
usage
;;
esac