Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Thursday, March 28, 2024

Diff for scripts/shell/firewall/fw-universal.sh between version 2.105 and 2.109

version 2.105, 2015/10/19 14:00:33 version 2.109, 2016/02/26 07:01:10
Line 22 
Line 22 
 # 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.104 2015/10/12 22:41:24 rajo Exp $  # $Platon: scripts/shell/firewall/fw-universal.sh,v 2.108 2016/02/26 03:11:01 nepto Exp $
 #  #
 # Changelog:  # Changelog:
 # 2003-10-24 - created  # 2003-10-24 - created
Line 39  DEFAULT_FIREWALL_CONFIG="${DEFAULT_FIREW
Line 39  DEFAULT_FIREWALL_CONFIG="${DEFAULT_FIREW
 DEFAULT_FIREWALL_CONFIG_DIR="${DEFAULT_FIREWALL_CONFIG_DIR:=/etc/default/firewall.d}"  DEFAULT_FIREWALL_CONFIG_DIR="${DEFAULT_FIREWALL_CONFIG_DIR:=/etc/default/firewall.d}"
 DEFAULT_CACHE_DIR="${DEFAULT_CACHE_DIR:=/var/cache/firewall}"  DEFAULT_CACHE_DIR="${DEFAULT_CACHE_DIR:=/var/cache/firewall}"
   
   DIST_FIREWALL_CONFIG_DIR="${DIST_FIREWALL_CONFIG_DIR:=/etc/firewall/firewall.d}"
   
 # quiet output? {{{  # quiet output? {{{
 if [ "x$1" = "xblock" ] || [ "x$QUIET" = "xyes" ]; then  if [ "x$1" = "xblock" ] || [ "x$QUIET" = "xyes" ]; then
         print_info()          print_info()
Line 910  reject_input()
Line 912  reject_input()
 allow_input()  allow_input()
 { # {{{  { # {{{
         if [ ! -z "$ALL_ACCEPT_INPUT_TCP" ]; then          if [ ! -z "$ALL_ACCEPT_INPUT_TCP" ]; then
                 print_info -en "Accepting ALL INPUT TCP connections on ports:"                  print_info -e "Accepting ALL INPUT TCP connections on ports:"
                 for port in $ALL_ACCEPT_INPUT_TCP; do                  for port in $ALL_ACCEPT_INPUT_TCP; do
                         src_ip=""                          src_ip=""
                         eval `echo $port | awk -v FS=: '/:/ { printf "src_ip=\"%s\"; port=\"%s\";", $1, $2; }'`                          eval `echo $port | awk -v FS=: '/:/ { printf "src_ip=\"%s\"; port=\"%s\";", $1, $2; }'`
Line 923  allow_input()
Line 925  allow_input()
                         fi                          fi
                         for iface in $INTERFACES; do                          for iface in $INTERFACES; do
                                 riface="IFname_$iface";                                  riface="IFname_$iface";
                                   if [ "$last_port" != "$port" -a -n "$src_ip" ]; then counter=0; print_info ""; fi
                                 print_info -en " $port($iface)"`[ ! -z "$src_ip" ] && echo "[$src_ip]"`                                  print_info -en " $port($iface)"`[ ! -z "$src_ip" ] && echo "[$src_ip]"`
                                   if [ $(( ++counter )) -ge 5 ]; then counter=0; print_info ""; fi;
                                   last_port="$port";
                                 IPS="IP_$iface";                                  IPS="IP_$iface";
                                 for ip in ${!IPS}; do                                  for ip in ${!IPS}; do
                                         if [ -z "$src_ip" ]; then                                          if [ -z "$src_ip" ]; then
Line 937  allow_input()
Line 942  allow_input()
                 print_info " done."                  print_info " done."
         fi          fi
         if [ ! -z "$ALL_ACCEPT_INPUT_UDP" ]; then          if [ ! -z "$ALL_ACCEPT_INPUT_UDP" ]; then
                 print_info -en "Accepting ALL INPUT UDP connections on ports:"                  print_info -e "Accepting ALL INPUT UDP connections on ports:"
                 for port in $ALL_ACCEPT_INPUT_UDP; do                  for port in $ALL_ACCEPT_INPUT_UDP; do
                         src_ip=""                          src_ip=""
                         eval `echo $port | awk -v FS=: '/:/ { printf "src_ip=\"%s\"; port=\"%s\";", $1, $2; }'`                          eval `echo $port | awk -v FS=: '/:/ { printf "src_ip=\"%s\"; port=\"%s\";", $1, $2; }'`
Line 950  allow_input()
Line 955  allow_input()
                         fi                          fi
                         for iface in $INTERFACES; do                          for iface in $INTERFACES; do
                                 riface="IFname_$iface";                                  riface="IFname_$iface";
                                   if [ "$last_port" != "$port" -a -n "$src_ip" ]; then counter=0; print_info ""; fi
                                 print_info -en " $port($iface)"`[ ! -z "$src_ip" ] && echo "[$src_ip]"`                                  print_info -en " $port($iface)"`[ ! -z "$src_ip" ] && echo "[$src_ip]"`
                                   if [ $(( ++counter )) -ge 5 ]; then counter=0; print_info ""; fi;
                                   last_port="$port";
                                 IPS="IP_$iface";                                  IPS="IP_$iface";
                                 if [ "x$port" = "x67" ]; then # DHCP requests doesn't have destination IP specified                                  if [ "x$port" = "x67" ]; then # DHCP requests doesn't have destination IP specified
                                         $IPTABLES -A INPUT -i ${!riface} -p UDP --dport $port -j ACCEPT                                          $IPTABLES -A INPUT -i ${!riface} -p UDP --dport $port -j ACCEPT
Line 969  allow_input()
Line 977  allow_input()
         fi          fi
   
         if [ ! -z "$REAL_ACCEPT_INPUT_TCP" ]; then          if [ ! -z "$REAL_ACCEPT_INPUT_TCP" ]; then
                 print_info -en "Accepting REAL all INPUT TCP connections for ALL interfaces on ports:"                  print_info -e "Accepting REAL all INPUT TCP connections for ALL interfaces on ports:"
                 for port in $REAL_ACCEPT_INPUT_TCP; do                  for port in $REAL_ACCEPT_INPUT_TCP; do
                         src_ip=""                          src_ip=""
                         eval `echo $port | awk -v FS=: '/:/ { printf "src_ip=\"%s\"; port=\"%s\";", $1, $2; }'`                          eval `echo $port | awk -v FS=: '/:/ { printf "src_ip=\"%s\"; port=\"%s\";", $1, $2; }'`
                           if [ "$last_port" != "$port" -a -n "$src_ip" ]; then counter=0; print_info ""; fi
                         print_info -en " $port(ALL)"`[ ! -z "$src_ip" ] && echo "[$src_ip]"`                          print_info -en " $port(ALL)"`[ ! -z "$src_ip" ] && echo "[$src_ip]"`
                           if [ $(( ++counter )) -ge 5 ]; then counter=0; print_info ""; fi;
                           last_port="$port";
                         echo $port | grep -q ,                          echo $port | grep -q ,
                         multiport="$?";                          multiport="$?";
                         if [ "$multiport" -eq 0 ]; then                          if [ "$multiport" -eq 0 ]; then
Line 990  allow_input()
Line 1001  allow_input()
                 print_info " done."                  print_info " done."
         fi          fi
         if [ ! -z "$REAL_ACCEPT_INPUT_UDP" ]; then          if [ ! -z "$REAL_ACCEPT_INPUT_UDP" ]; then
                 print_info -en "Accepting REAL all INPUT UDP connections for ALL interfaces on ports:"                  print_info -e "Accepting REAL all INPUT UDP connections for ALL interfaces on ports:"
                 for port in $REAL_ACCEPT_INPUT_UDP; do                  for port in $REAL_ACCEPT_INPUT_UDP; do
                         src_ip=""                          src_ip=""
                         eval `echo $port | awk -v FS=: '/:/ { printf "src_ip=\"%s\"; port=\"%s\";", $1, $2; }'`                          eval `echo $port | awk -v FS=: '/:/ { printf "src_ip=\"%s\"; port=\"%s\";", $1, $2; }'`
                           if [ "$last_port" != "$port" -a -n "$src_ip" ]; then counter=0; print_info ""; fi
                         print_info -en " $port(ALL)"`[ ! -z "$src_ip" ] && echo "[$src_ip]"`                          print_info -en " $port(ALL)"`[ ! -z "$src_ip" ] && echo "[$src_ip]"`
                           if [ $(( ++counter )) -ge 5 ]; then counter=0; print_info ""; fi;
                           last_port="$port";
                         echo $port | grep -q ,                          echo $port | grep -q ,
                         multiport="$?";                          multiport="$?";
                         if [ "$multiport" -eq 0 ]; then                          if [ "$multiport" -eq 0 ]; then
Line 1122  allow_input()
Line 1136  allow_input()
   
                 # ACCEPT {{{                  # ACCEPT {{{
                 if [ ! -z "$ACCEPT_INPUT_TCP" ]; then                  if [ ! -z "$ACCEPT_INPUT_TCP" ]; then
                         print_info -en "$iface: Accepting INPUT TCP connections on ports:"                          print_info -e "$iface: Accepting INPUT TCP connections on ports:"
                         counter=0;                          counter=0;
                         for port in $ACCEPT_INPUT_TCP; do                          for port in $ACCEPT_INPUT_TCP; do
                                 src_ip=""                                  src_ip=""
Line 1130  allow_input()
Line 1144  allow_input()
                                 if [ -n "$src_ip" -a "$port" = "0" ]; then                                  if [ -n "$src_ip" -a "$port" = "0" ]; then
                                         port="ALL";                                          port="ALL";
                                 fi                                  fi
                                   if [ "$last_port" != "$port" -a -n "$src_ip" ]; then counter=0; print_info ""; fi
                                 print_info -en " $port"`[ ! -z "$src_ip" ] && echo "[$src_ip]"`                                  print_info -en " $port"`[ ! -z "$src_ip" ] && echo "[$src_ip]"`
                                 if [ $(( ++counter )) -ge 5 -o "x$port" = "x10050" ]; then counter=0; print_info ""; fi;                                  if [ $(( ++counter )) -ge 5 ]; then counter=0; print_info ""; fi;
                                   last_port="$port";
                                 echo $port | grep -q ,                                  echo $port | grep -q ,
                                 multiport="$?";                                  multiport="$?";
                                 if [ "$multiport" -eq 0 ]; then                                  if [ "$multiport" -eq 0 ]; then
Line 1234  allow_output()
Line 1250  allow_output()
                 accept_output_udp="${iface}_ACCEPT_OUTPUT_UDP"                  accept_output_udp="${iface}_ACCEPT_OUTPUT_UDP"
                 ACCEPT_OUTPUT_UDP="${!accept_output_udp}"                  ACCEPT_OUTPUT_UDP="${!accept_output_udp}"
   
                   # UDP *must* go before TCP
                   #
                   # Reason: we need to have working DNS resolving, which works over
                   # port 53/UDP. Resolving is required for those rules, which use
                   # hostname instead of IP address, for example cvs.platon.sk:2401.
   
                 # TCP                  # UDP
                 if [ -z "$ACCEPT_OUTPUT_TCP" ]; then                  if [ -z "$ACCEPT_OUTPUT_UDP" ]; then
                         if [ -n "${!gateway}" ]; then                          if [ -n "${!gateway}" ]; then
                                 for ip in ${!IPS}; do                                  for ip in ${!IPS}; do
                                         output_tcp_str="$output_tcp_str $ip:${!riface}:${!gateway}";                                          output_udp_str="$output_udp_str $ip:${!riface}:${!gateway}";
                                         $IPTABLES -A OUTPUT -p TCP -o ${!riface} -s $ip -j ACCEPT                                          $IPTABLES -A OUTPUT -p UDP -o ${!riface} -s $ip -j ACCEPT
                                 done                                  done
                         fi                          fi
                 else                  else
                         print_info -en "$iface: Accepting OUTPUT TCP connections to ports:"                          print_info -en "$iface: Accepting OUTPUT UDP connections to ports:"
                         for port in $ACCEPT_OUTPUT_TCP; do                          for port in $ACCEPT_OUTPUT_UDP; do
                                 dest_ip=""                                  dest_ip=""
                                 eval `echo $port | awk -v FS=: '/:/ { printf "dest_ip=\"%s\"; port=\"%s\";", $1, $2; }'`                                  eval `echo $port | awk -v FS=: '/:/ { printf "dest_ip=\"%s\"; port=\"%s\";", $1, $2; }'`
                                 if [ -n "$dest_ip" -a "$port" = "0" ]; then                                  if [ -n "$dest_ip" -a "$port" = "0" ]; then
Line 1253  allow_output()
Line 1274  allow_output()
                                 fi                                  fi
                                 print_info -en " $port"`[ ! -z "$dest_ip" ] && echo "[$dest_ip]"`                                  print_info -en " $port"`[ ! -z "$dest_ip" ] && echo "[$dest_ip]"`
                                 if [ -z "$dest_ip" ]; then                                  if [ -z "$dest_ip" ]; then
                                         $IPTABLES -A OUTPUT -o ${!riface} -p TCP --dport $port -j ACCEPT                                          $IPTABLES -A OUTPUT -o ${!riface} -p UDP --dport $port -j ACCEPT
                                 else                                  else
                                         if [ "$port" = "ALL" ]; then                                          if [ "$port" = "ALL" ]; then
                                                 $IPTABLES -A OUTPUT -o ${!riface} -d $dest_ip -p TCP -j ACCEPT                                                  $IPTABLES -A OUTPUT -o ${!riface} -d $dest_ip -p UDP -j ACCEPT
                                         else                                          else
                                                 $IPTABLES -A OUTPUT -o ${!riface} -d $dest_ip -p TCP --dport $port -j ACCEPT                                                  $IPTABLES -A OUTPUT -o ${!riface} -d $dest_ip -p UDP --dport $port -j ACCEPT
                                         fi                                          fi
                                 fi                                  fi
                         done                          done
                         print_info " done."                          print_info " done."
                 fi                  fi
   
                 # UDP                  # TCP
                 if [ -z "$ACCEPT_OUTPUT_UDP" ]; then                  if [ -z "$ACCEPT_OUTPUT_TCP" ]; then
                         if [ -n "${!gateway}" ]; then                          if [ -n "${!gateway}" ]; then
                                 for ip in ${!IPS}; do                                  for ip in ${!IPS}; do
                                         output_udp_str="$output_udp_str $ip:${!riface}:${!gateway}";                                          output_tcp_str="$output_tcp_str $ip:${!riface}:${!gateway}";
                                         $IPTABLES -A OUTPUT -p UDP -o ${!riface} -s $ip -j ACCEPT                                          $IPTABLES -A OUTPUT -p TCP -o ${!riface} -s $ip -j ACCEPT
                                 done                                  done
                         fi                          fi
                 else                  else
                         print_info -en "$iface: Accepting OUTPUT UDP connections to ports:"                          print_info -en "$iface: Accepting OUTPUT TCP connections to ports:"
                         for port in $ACCEPT_OUTPUT_UDP; do                          for port in $ACCEPT_OUTPUT_TCP; do
                                 dest_ip=""                                  dest_ip=""
                                 eval `echo $port | awk -v FS=: '/:/ { printf "dest_ip=\"%s\"; port=\"%s\";", $1, $2; }'`                                  eval `echo $port | awk -v FS=: '/:/ { printf "dest_ip=\"%s\"; port=\"%s\";", $1, $2; }'`
                                 if [ -n "$dest_ip" -a "$port" = "0" ]; then                                  if [ -n "$dest_ip" -a "$port" = "0" ]; then
Line 1283  allow_output()
Line 1304  allow_output()
                                 fi                                  fi
                                 print_info -en " $port"`[ ! -z "$dest_ip" ] && echo "[$dest_ip]"`                                  print_info -en " $port"`[ ! -z "$dest_ip" ] && echo "[$dest_ip]"`
                                 if [ -z "$dest_ip" ]; then                                  if [ -z "$dest_ip" ]; then
                                         $IPTABLES -A OUTPUT -o ${!riface} -p UDP --dport $port -j ACCEPT                                          $IPTABLES -A OUTPUT -o ${!riface} -p TCP --dport $port -j ACCEPT
                                 else                                  else
                                         if [ "$port" = "ALL" ]; then                                          if [ "$port" = "ALL" ]; then
                                                 $IPTABLES -A OUTPUT -o ${!riface} -d $dest_ip -p UDP -j ACCEPT                                                  $IPTABLES -A OUTPUT -o ${!riface} -d $dest_ip -p TCP -j ACCEPT
                                         else                                          else
                                                 $IPTABLES -A OUTPUT -o ${!riface} -d $dest_ip -p UDP --dport $port -j ACCEPT                                                  $IPTABLES -A OUTPUT -o ${!riface} -d $dest_ip -p TCP --dport $port -j ACCEPT
                                         fi                                          fi
                                 fi                                  fi
                         done                          done
Line 1653  remote()
Line 1674  remote()
         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()
Line 1846  case "$1" in
Line 1896  case "$1" in
                 mangle_prerouting                  mangle_prerouting
                 mangle_output                  mangle_output
                 accept_related                  accept_related
                   accept_loopback
                 log_new_connections                  log_new_connections
                 drop_output                  drop_output
                   allow_output
                   allow_icmp
                   echo "----[ INCOMMING TRAFFIC ]------------------------------------------------"
                 drop_input                  drop_input
                 reject_input                  reject_input
                 allow_input                  allow_input
                 allow_output  
                 allow_icmp  
                 accept_loopback  
                 masquerade                  masquerade
                 forward_on                  forward_on
                 log_input_drop                  log_input_drop
Line 1913  case "$1" in
Line 1964  case "$1" in
         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

Legend:
Removed from v.2.105  
changed lines
  Added in v.2.109

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top