|
|
@@ -1,4 +1,4 @@
|
|
|
-#!/bin/sh
|
|
|
+#!/bin/bash
|
|
|
### BEGIN INIT INFO
|
|
|
# Provides: firewall.sh
|
|
|
# Required-Start: $syslog $network
|
|
|
@@ -36,6 +36,7 @@ cat <<-EOF
|
|
|
OPTIONS
|
|
|
-v --verbose : verbose mode
|
|
|
-h --help : display this help message
|
|
|
+ -l --logging : enables logging (prefix: iptables-logging)
|
|
|
|
|
|
AUTHOR
|
|
|
Original author: Nicolargo
|
|
|
@@ -43,7 +44,7 @@ cat <<-EOF
|
|
|
EOF
|
|
|
}
|
|
|
|
|
|
-options=$(getopt -l "help,verbose" -o "hv" -- "$@")
|
|
|
+options=$(getopt -l "help,verbose,logging" -o "hvl" -- "$@")
|
|
|
|
|
|
if [[ $? != 0 ]] ; then
|
|
|
help_message_lfirewall
|
|
|
@@ -53,6 +54,7 @@ fi
|
|
|
eval set -- "$options"
|
|
|
|
|
|
verbose=0
|
|
|
+logging=" "
|
|
|
|
|
|
while :
|
|
|
do
|
|
|
@@ -66,8 +68,18 @@ do
|
|
|
exit 0
|
|
|
;;
|
|
|
-v|--verbose)
|
|
|
- verbose=1
|
|
|
- set -xv
|
|
|
+ verbose=$(( verbose + 1 ))
|
|
|
+ if [[ ${verbose} -gt 1 ]]
|
|
|
+ then
|
|
|
+ set -x
|
|
|
+ fi
|
|
|
+ if [[ ${verbose} -gt 2 ]]
|
|
|
+ then
|
|
|
+ set -v
|
|
|
+ fi
|
|
|
+ ;;
|
|
|
+ -l|--logging)
|
|
|
+ logging="-j LOG --log-prefix 'iptables-logging'"
|
|
|
;;
|
|
|
--)
|
|
|
shift
|
|
|
@@ -132,6 +144,9 @@ do_exec () {
|
|
|
echo "Nothing to be done for $1"
|
|
|
;;
|
|
|
esac
|
|
|
+ if [[ ${verbose} -ge 1 ]] ; then
|
|
|
+ echo $IP_TABLES $iptables_option $*
|
|
|
+ fi
|
|
|
$IP_TABLES $iptables_option $*
|
|
|
}
|
|
|
|
|
|
@@ -150,6 +165,10 @@ do_check () {
|
|
|
;;
|
|
|
esac
|
|
|
default_option=-C
|
|
|
+ if [[ ${verbose} -ge 1 ]] ; then
|
|
|
+ echo $do_log "$the_action:" $IP_TABLES -C $*
|
|
|
+ echo $IP_TABLES -C $*
|
|
|
+ fi
|
|
|
$do_log "$the_action:" $IP_TABLES -C $*
|
|
|
$IP_TABLES -C $*
|
|
|
global_status=$((global_status+$?))
|
|
|
@@ -271,17 +290,24 @@ fw_start () {
|
|
|
iptables -t filter -A INPUT -p tcp --dport 22 -j ACCEPT
|
|
|
}
|
|
|
|
|
|
+do_this(){
|
|
|
+ if [[ ${verbose} -ge 1 ]] ; then
|
|
|
+ echo $*
|
|
|
+ fi
|
|
|
+ $*
|
|
|
+}
|
|
|
+
|
|
|
##########################
|
|
|
# Stop the Firewall rules
|
|
|
##########################
|
|
|
|
|
|
fw_stop () {
|
|
|
- $IP_TABLES -F
|
|
|
- $IP_TABLES -t nat -F
|
|
|
- $IP_TABLES -t mangle -F
|
|
|
- $IP_TABLES -P INPUT DROP
|
|
|
- $IP_TABLES -P FORWARD DROP
|
|
|
- $IP_TABLES -P OUTPUT ACCEPT
|
|
|
+ do_this $IP_TABLES -F
|
|
|
+ do_this $IP_TABLES -t nat -F
|
|
|
+ do_this $IP_TABLES -t mangle -F
|
|
|
+ do_this $IP_TABLES -P INPUT DROP
|
|
|
+ do_this $IP_TABLES -P FORWARD DROP
|
|
|
+ do_this $IP_TABLES -P OUTPUT ACCEPT
|
|
|
}
|
|
|
|
|
|
##########################
|
|
|
@@ -289,12 +315,12 @@ fw_stop () {
|
|
|
##########################
|
|
|
|
|
|
fw_clear () {
|
|
|
- $IP_TABLES -F
|
|
|
- $IP_TABLES -t nat -F
|
|
|
- $IP_TABLES -t mangle -F
|
|
|
- $IP_TABLES -P INPUT ACCEPT
|
|
|
- $IP_TABLES -P FORWARD ACCEPT
|
|
|
- $IP_TABLES -P OUTPUT ACCEPT
|
|
|
+ do_this $IP_TABLES -F
|
|
|
+ do_this $IP_TABLES -t nat -F
|
|
|
+ do_this $IP_TABLES -t mangle -F
|
|
|
+ do_this $IP_TABLES -P INPUT ACCEPT
|
|
|
+ do_this $IP_TABLES -P FORWARD ACCEPT
|
|
|
+ do_this $IP_TABLES -P OUTPUT ACCEPT
|
|
|
}
|
|
|
|
|
|
##########################
|
|
|
@@ -302,11 +328,19 @@ fw_clear () {
|
|
|
##########################
|
|
|
|
|
|
fw_save () {
|
|
|
+ if [[ ${verbose} -ge 1 ]] ; then
|
|
|
+ echo "$IP_TABLES-save > /etc/iptables.backup"
|
|
|
+ fi
|
|
|
+
|
|
|
$IP_TABLES-save > /etc/iptables.backup
|
|
|
}
|
|
|
|
|
|
fw_restore () {
|
|
|
if [ -e /etc/iptables.backup ]; then
|
|
|
+ if [[ ${verbose} -ge 1 ]] ; then
|
|
|
+ echo "$IP_TABLES-save > /etc/iptables.backup"
|
|
|
+ fi
|
|
|
+
|
|
|
$IP_TABLES-restore < /etc/iptables.backup
|
|
|
fi
|
|
|
}
|