]> git.pld-linux.org Git - packages/filtergen.git/blame - filter.init
- tabs in preamble
[packages/filtergen.git] / filter.init
CommitLineData
b3aa5a3a 1#!/bin/sh
2# ipchains/iptables rules generator
3#
4# chkconfig: 345 15 85
5# description: ipchains/iptables rules generator
6
7# Source function library
8. /etc/rc.d/init.d/functions
9
b3aa5a3a 10# Get service config
11CONFIG=/etc/filter/simple.conf
12GEN_CONFIG=/etc/filter/generated_rules
13SUBSYS=/var/lock/subsys/filter
14[ -f /etc/sysconfig/filter ] && . /etc/sysconfig/filter
15
b3aa5a3a 16confstatus() {
81666989 17 if [ ! -e "$GEN_CONFIG" ]; then
18 confstatus=3
19 elif [ "$GEN_CONFIG" -ot "$CONFIG" ]; then
20 confstatus=2
21 elif [ "$SUBSYS" -ot "$GEN_CONFIG" ]; then
22 confstatus=1
23 else
24 confstatus=0
25 fi
b3aa5a3a 26}
27
28find_filter() {
81666989 29 iptables=`which iptables 2> /dev/null`
30 ipchains=`which ipchains 2> /dev/null`
31 if [ -n "$iptables" ]; then
32 filter=$iptables
33 elif [ -n "$ipchains" ]; then
34 filter=$ipchains
35 else
36 nls "ipchains/iptables not found. Cannot continue"
37 filter=
38 exit 1
39 fi
b3aa5a3a 40}
41
89908a9f 42RETVAL=0
b3aa5a3a 43# See how we were called.
44case "$1" in
45 start)
81666989 46 confstatus
47 if [ $confstatus -ge 0 ]; then
48 if [ $confstatus -gt 0 ]; then
49 $0 init
50 fi
51 show "Setting filter rules"
52 busy
53 sh "$GEN_CONFIG"
89908a9f 54 [ $? -ne 0 ] && RETVAL=1
55 if [ $RETVAL -eq 0 ]; then
81666989 56 touch "$SUBSYS"
57 ok
58 else
59 fail
60 fi
61 fi
62 ;;
b3aa5a3a 63 stop)
81666989 64 show "Flushing filter rules"
65 find_filter
66 $filter -F
67 RETVAL=$?
68 if [ $RETVAL = 0 ]; then
69 rm -f "$SUBSYS"
70 ok
71 else
72 fail
73 fi
74 ;;
b3aa5a3a 75 init)
81666989 76 show "Generating %s" "$GEN_CONFIG"
77 find_filter
78 umask 077
79 filtergen "$CONFIG" `basename $filter` > "$GEN_CONFIG"
80 ;;
89908a9f 81 restart|force-reload)
81666989 82 $0 stop
83 $0 start
89908a9f 84 exit $?
81666989 85 ;;
b3aa5a3a 86 status)
81666989 87 confstatus
88 case "$confstatus" in
89 3)
90 nls "%s not generated" "$GEN_CONFIG"
91 ;;
92 2)
93 nls "%s outdated" "$GEN_CONFIG"
94 ;;
95 1)
96 nls "%s not applied" "$GEN_CONFIG"
97 ;;
98 0)
99 nls "filter rules applied"
100 ;;
101 esac
89908a9f 102 [ "$confstatus" -ne 0 ] && RETVAL=3
81666989 103 ;;
b3aa5a3a 104 *)
89908a9f 105 msg_usage "$0 {start|stop|init|restart|force-reload|status}"
106 exit 3
81666989 107 ;;
b3aa5a3a 108esac
109
110exit $RETVAL
This page took 0.080722 seconds and 4 git commands to generate.