verzia 2.87, 2012/02/10 23:01:58 |
verzia 2.90, 2012/02/11 19:38:51 |
|
|
# Licensed under terms of GNU General Public License. |
# Licensed under terms of GNU General Public License. |
# All rights reserved. |
# All rights reserved. |
# |
# |
# $Platon: scripts/shell/firewall/fw-universal.sh,v 2.86 2012-01-24 20:55:35 rajo Exp $ |
# $Platon: scripts/shell/firewall/fw-universal.sh,v 2.89 2012-02-11 19:06:20 rajo Exp $ |
# |
# |
# Changelog: |
# Changelog: |
# 2003-10-24 - created |
# 2003-10-24 - created |
Riadok 76 IPTABLES="${IPTABLES:=$DEBUG/sbin/iptabl |
|
Riadok 76 IPTABLES="${IPTABLES:=$DEBUG/sbin/iptabl |
|
IPTABLES_SAVE="${IPTABLES_SAVE:=$DEBUG/sbin/iptables-save}" |
IPTABLES_SAVE="${IPTABLES_SAVE:=$DEBUG/sbin/iptables-save}" |
IPTABLES_RESTORE="${IPTABLES_RESTORE:=$DEBUG/sbin/iptables-restore}" |
IPTABLES_RESTORE="${IPTABLES_RESTORE:=$DEBUG/sbin/iptables-restore}" |
|
|
|
IPTABLES_TABLES="${IPTABLES_TABLES:=filter nat mangle}" |
|
|
|
|
if [ "x$LOGGING" = "xoff" ]; then |
if [ "x$LOGGING" = "xoff" ]; then |
IPTABLES_LOG=": log turned off" |
IPTABLES_LOG=": log turned off" |
else |
else |
Riadok 285 remove_chains() |
|
Riadok 288 remove_chains() |
|
$IPTABLES --flush spoof |
$IPTABLES --flush spoof |
# TODO!!! |
# TODO!!! |
else |
else |
for table in filter nat mangle; do |
for table in $IPTABLES_TABLES; do |
$IPTABLES -t $table -F # clear all chains |
$IPTABLES -t $table -F # clear all chains |
$IPTABLES -t $table -X # remove all chains |
$IPTABLES -t $table -X # remove all chains |
$IPTABLES -t $table -Z # zero counts |
$IPTABLES -t $table -Z # zero counts |
Riadok 1454 shaping_status() |
|
Riadok 1457 shaping_status() |
|
|
|
add_banned_ip() |
add_banned_ip() |
{ # {{{ |
{ # {{{ |
echo "# `date '+%Y-%m-%d %X' ` - ${SSH_CLIENT:=local}" >> $DEFAULT_FIREWALL_CONFIG_DIR/BANNED_IP.conf |
echo "# `date '+%Y-%m-%d %X' `" >> $DEFAULT_FIREWALL_CONFIG_DIR/BANNED_IP.conf |
TMPFILE=`mktemp -t fw-universal.sh-XXXXXX` || exit 1 |
TMPFILE=`mktemp -t fw-universal.sh-XXXXXX` || exit 1 |
trap 'rm -f $TMPFILE' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
trap 'rm -f $TMPFILE' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
if [ -z "$*" ]; then |
if [ -z "$*" ]; then |
Riadok 1482 deploy_block() |
|
Riadok 1485 deploy_block() |
|
TMPFILE=`mktemp -t fw-universal.sh-XXXXXX` || exit 1 |
TMPFILE=`mktemp -t fw-universal.sh-XXXXXX` || exit 1 |
trap 'rm -f $TMPFILE' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
trap 'rm -f $TMPFILE' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
for i in $*; do |
for i in $*; do |
echo $i >> $TMPFILE; |
echo "block $i" >> $TMPFILE; |
done |
done |
while read conn keyfile |
while read conn keyfile |
do |
do |
case "$conn" in |
case "$conn" in |
""|\#*) |
""|\#*) |
continue |
continue |
;; |
;; |
esac |
esac |
print_info "Deploying to $conn ..."; |
print_info "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" |
cat $TMPFILE | ssh -i $keyfile $conn $0 block |
print_info "Deploying to $conn ..."; |
|
cat $TMPFILE | ssh -i $keyfile $conn $0 remote |
done < $DEFAULT_FIREWALL_CONFIG_DIR/deploy-servers.list |
done < $DEFAULT_FIREWALL_CONFIG_DIR/deploy-servers.list |
rm -f $TMPFILE |
rm -f $TMPFILE |
} # }}} |
} # }}} |
Riadok 1516 deploy_update() |
|
Riadok 1520 deploy_update() |
|
QUIET=yes $0 start |
QUIET=yes $0 start |
while read conn keyfile |
while read conn keyfile |
do |
do |
case "$conn" in |
case "$conn" in |
""|\#*) |
""|\#*) |
continue |
continue |
;; |
;; |
esac |
esac |
print_info "Updating $conn ..."; |
|
ssh -i $keyfile $conn $0 update |
print_info "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" |
|
print_info "Updating $conn ..."; |
|
echo "update" | ssh -i $keyfile $conn $0 remote |
done < $DEFAULT_FIREWALL_CONFIG_DIR/deploy-servers.list |
done < $DEFAULT_FIREWALL_CONFIG_DIR/deploy-servers.list |
} # }}} |
} # }}} |
|
|
|
remote() |
|
{ # {{{ |
|
while read comnd par |
|
do |
|
case "$comnd" in |
|
block) |
|
echo "Blocking '$par'..." |
|
add_banned_ip $par |
|
;; |
|
update) |
|
echo "Updating firewall scripts..." |
|
update |
|
;; |
|
""|\#*) |
|
echo "Line '$comnd $par' ignored" |
|
continue |
|
;; |
|
esac |
|
done |
|
} # }}} |
|
|
# Parse output from ifconfig: - tested on Linux and FreeBSD |
# Parse output from ifconfig: - tested on Linux and FreeBSD |
# http://platon.sk/cvs/cvs.php/scripts/shell/firewall/ifconfig-parse.sh |
# http://platon.sk/cvs/cvs.php/scripts/shell/firewall/ifconfig-parse.sh |
parse_ifconfig() |
parse_ifconfig() |
|
|
deploy-update) |
deploy-update) |
deploy_update; |
deploy_update; |
;; |
;; |
|
remote) |
|
remote; |
|
;; |
*) |
*) |
echo "Usage: $0 {start|stop|really-off|status|purge|block|deploy-block|deploy-update|update}" >&2 |
echo "Usage: $0 {start|stop|really-off|status|purge|block|deploy-block|deploy-update|update}" >&2 |
exit 1 |
exit 1 |