| verzia 2.109, 2016/02/26 07:01:10 |
verzia 2.110, 2016/05/05 21:07:54 |
|
|
| # 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.108 2016/02/26 03:11:01 nepto Exp $ |
# $Platon: scripts/shell/firewall/fw-universal.sh,v 2.109 2016/02/26 07:01:10 nepto Exp $ |
| # |
# |
| # Changelog: |
# Changelog: |
| # 2003-10-24 - created |
# 2003-10-24 - created |
|
|
| fi |
fi |
| # }}} |
# }}} |
| |
|
| |
# Define function which can be used in config file |
| |
# Usage: |
| |
# load_subnets eth0_ACCEPT_INPUT_TCP Slovakia 22 |
| |
load_subnets() |
| |
{ # {{{ |
| |
cfgvar=$1 |
| |
cfgfile="$2.txt" |
| |
port=$3 |
| |
|
| |
echo "LOAD_SUBNETS $*" |
| |
|
| |
if [ -f "$DEFAULT_FIREWALL_CONFIG_DIR/subnets/$cfgfile" ]; then |
| |
cfgfound="$DEFAULT_FIREWALL_CONFIG_DIR/subnets/$cfgfile"; |
| |
else |
| |
if [ -f "$DIST_FIREWALL_CONFIG_DIR/subnets/$cfgfile" ]; then |
| |
cfgfound="$DIST_FIREWALL_CONFIG_DIR/subnets/$cfgfile"; |
| |
else |
| |
print_info "LOAD_SUBNETS: Config file '$cfgfile' not found" |
| |
return 1 |
| |
fi |
| |
fi |
| |
LOADED_CONFIG_FILES="$LOADED_CONFIG_FILES $cfgfound"; |
| |
|
| |
lines=0 |
| |
print_info "LOAD_SUBNETS: Mapping $cfgfound map file to $cfgvar, port $port" |
| |
while read subnet ; do |
| |
case "$subnet" in |
| |
""|\#*) |
| |
continue |
| |
;; |
| |
esac |
| |
print_info "LOAD_SUBNETS: $cfgvar=\"\$$cfgvar $subnet:$port\"" |
| |
eval "$cfgvar=\"\$$cfgvar $subnet:$port\"" |
| |
lines=$(($lines + 1)) |
| |
done < $cfgfound |
| |
print_info "LOAD_SUBNETS: $cfgvar='${!cfgvar}'" |
| |
print_info "LOAD_SUBNETS: $lines subnets loaded from '$cfgfile' into '$cfgvar'" |
| |
|
| |
} # }}} |
| |
|
| if [ -f "$DEFAULT_FIREWALL_CONFIG" ]; then |
if [ -f "$DEFAULT_FIREWALL_CONFIG" ]; then |
| print_info "Reading config file $DEFAULT_FIREWALL_CONFIG" |
print_info "Reading config file $DEFAULT_FIREWALL_CONFIG" |
| . $DEFAULT_FIREWALL_CONFIG |
. $DEFAULT_FIREWALL_CONFIG |
|
|
| |
|
| config=""; |
config=""; |
| if [ -r "$DEFAULT_FIREWALL_CONFIG" ]; then |
if [ -r "$DEFAULT_FIREWALL_CONFIG" ]; then |
| config="$config ` cat \"$DEFAULT_FIREWALL_CONFIG\" `"; |
config="$config ` md5sum \"$DEFAULT_FIREWALL_CONFIG\" `"; |
| fi |
fi |
| if [ -r "$0" ]; then |
if [ -r "$0" ]; then |
| config="$config ` cat \"$0\" `"; |
config="$config ` md5sum \"$0\" `"; |
| fi |
fi |
| if [ -r "$DEFAULT_FIREWALL_CONFIG_DIR/deploy-servers.list" ]; then |
if [ -r "$DEFAULT_FIREWALL_CONFIG_DIR/deploy-servers.list" ]; then |
| config="$config ` cat \"$DEFAULT_FIREWALL_CONFIG_DIR/deploy-servers.list\" `"; |
config="$config ` md5sum \"$DEFAULT_FIREWALL_CONFIG_DIR/deploy-servers.list\" `"; |
| fi |
fi |
| if [ -r "$DEFAULT_FIREWALL_CONFIG_DIR/BANNED_IP.conf" ]; then |
if [ -r "$DEFAULT_FIREWALL_CONFIG_DIR/BANNED_IP.conf" ]; then |
| config="$config ` cat \"$DEFAULT_FIREWALL_CONFIG_DIR/BANNED_IP.conf\" `"; |
config="$config ` md5sum \"$DEFAULT_FIREWALL_CONFIG_DIR/BANNED_IP.conf\" `"; |
| fi |
fi |
| |
for lc in $LOADED_CONFIG_FILES; do |
| |
echo "CHECKSUM $lc"; |
| |
config="$config ` md5sum \"$lc\" `"; |
| |
done |
| md5key=`echo "config='$config' parsed_interfaces='$parsed_interfaces' parsed_routes='$parsed_routes'" | md5sum | $AWK '{print $1;}'`; |
md5key=`echo "config='$config' parsed_interfaces='$parsed_interfaces' parsed_routes='$parsed_routes'" | md5sum | $AWK '{print $1;}'`; |
| CACHE_FILE="$DEFAULT_CACHE_DIR/$md5key" |
CACHE_FILE="$DEFAULT_CACHE_DIR/$md5key" |
| |
|
|
|
| done |
done |
| } # }}} |
} # }}} |
| |
|
| map_subnet() |
|
| { # {{{ |
|
| cfgvar=$1 |
|
| cfgfile=$2 |
|
| port=$3 |
|
| |
|
| if [ -f "$DEFAULT_FIREWALL_CONFIG_DIR/subnets/$cfgfile" ]; then |
|
| cfgfound="$DEFAULT_FIREWALL_CONFIG_DIR/subnets/$cfgfile"; |
|
| else |
|
| if [ -f "$DIST_FIREWALL_CONFIG_DIR/subnets/$cfgfile" ]; then |
|
| cfgfound="$DIST_FIREWALL_CONFIG_DIR/subnets/$cfgfile"; |
|
| else |
|
| "Config file '$cfgfile' not found" |
|
| exit 1 |
|
| fi |
|
| fi |
|
| |
|
| echo "Mapping $cfgfound map file to $cfgvar, port $port" |
|
| while read subnet ; do |
|
| case "$subnet" in |
|
| ""|\#*) |
|
| continue |
|
| ;; |
|
| esac |
|
| echo "$cfgvar=\"\$$cfgvar $subnet:$port\"" >> "$DEFAULT_FIREWALL_CONFIG_DIR/$cfgfile" |
|
| done < $cfgfound |
|
| |
|
| } # }}} |
|
| |
|
| # 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() |
|
|
| remote) |
remote) |
| remote; |
remote; |
| ;; |
;; |
| map-subnet) |
|
| shift; |
|
| map_subnet $*; |
|
| ;; |
|
| *) |
*) |
| 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 |