Skip to content

Commit cb72d66

Browse files
committed
firewall service handler
1 parent 14230b2 commit cb72d66

File tree

4 files changed

+102
-9
lines changed

4 files changed

+102
-9
lines changed

bin/v-restart-service

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,17 @@ check_args '1' "$#" 'SERVICE'
2727
# Action #
2828
#----------------------------------------------------------#
2929

30-
service $service restart >/dev/null 2>&1
31-
if [ $? -ne 0 ]; then
32-
exit $E_RESTART
30+
if [ "$service" != "iptables" ]; then
31+
service $service restart >/dev/null 2>&1
32+
if [ $? -ne 0 ]; then
33+
exit $E_RESTART
34+
fi
35+
else
36+
$BIN/v-stop-firewall
37+
$BIN/v-update-firewall
38+
if [ $? -ne 0 ]; then
39+
exit $E_RESTART
40+
fi
3341
fi
3442

3543

bin/v-start-service

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,16 @@ check_args '1' "$#" 'SERVICE'
2727
# Action #
2828
#----------------------------------------------------------#
2929

30-
service $service start >/dev/null 2>&1
31-
if [ $? -ne 0 ]; then
32-
exit $E_RESTART
30+
if [ "$service" != 'iptables' ]; then
31+
service $service start >/dev/null 2>&1
32+
if [ $? -ne 0 ]; then
33+
exit $E_RESTART
34+
fi
35+
else
36+
$BIN/v-update-firewall
37+
if [ $? -ne 0 ]; then
38+
exit $E_RESTART
39+
fi
3340
fi
3441

3542

bin/v-stop-firewall

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
# info: stop system firewall
3+
# options: NONE
4+
#
5+
# The function stops iptables
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Defining absolute path for iptables and modprobe
13+
iptables="/sbin/iptables"
14+
modprobe="/sbin/modprobe"
15+
16+
# Includes
17+
source /etc/profile.d/vesta.sh
18+
source $VESTA/func/main.sh
19+
source $VESTA/conf/vesta.conf
20+
21+
22+
#----------------------------------------------------------#
23+
# Verifications #
24+
#----------------------------------------------------------#
25+
26+
#is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
27+
28+
29+
#----------------------------------------------------------#
30+
# Action #
31+
#----------------------------------------------------------#
32+
33+
# Creating temporary file
34+
tmp=$(mktemp)
35+
36+
# Flushing INPUT chain
37+
echo "$iptables -P INPUT ACCEPT" >> $tmp
38+
echo "$iptables -F INPUT" >> $tmp
39+
40+
# Deleting vesta chain
41+
echo "$iptables -X vesta" >> $tmp
42+
43+
# Applying rules
44+
bash $tmp 2>/dev/null
45+
46+
# Deleting temporary file
47+
rm -f $tmp
48+
49+
# Saving rules to the master iptables file
50+
if [ -e "/etc/redhat-release" ]; then
51+
/sbin/iptables-save > /etc/sysconfig/iptables
52+
if [ -z "$(ls /etc/rc3.d/S*iptables 2>/dev/null)" ]; then
53+
/sbin/chkconfig iptables off
54+
fi
55+
else
56+
/sbin/iptables-save > /etc/iptables.rules
57+
preup="/etc/network/if-pre-up.d/iptables"
58+
if [ ! -e "$preup" ]; then
59+
echo '#!/bin/sh' > $preup
60+
echo "/sbin/iptables-restore < /etc/iptables.rules" >> $preup
61+
echo "exit 0" >> $preup
62+
chmod +x $preup
63+
fi
64+
fi
65+
66+
67+
#----------------------------------------------------------#
68+
# Vesta #
69+
#----------------------------------------------------------#
70+
71+
exit

bin/v-stop-service

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,16 @@ check_args '1' "$#" 'SERVICE'
2727
# Action #
2828
#----------------------------------------------------------#
2929

30-
service $service stop >/dev/null 2>&1
31-
if [ $? -ne 0 ]; then
32-
exit $E_RESTART
30+
if [ "$service" != 'iptables' ]; then
31+
service $service stop >/dev/null 2>&1
32+
if [ $? -ne 0 ]; then
33+
exit $E_RESTART
34+
fi
35+
else
36+
$BIN/v-stop-firewall
37+
if [ $? -ne 0 ]; then
38+
exit $E_RESTART
39+
fi
3340
fi
3441

3542

0 commit comments

Comments
 (0)