Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Štvrtok, 28. marec 2024

Rozdiely pre scripts/shell/firewall/fw-universal.sh medzi verziami 2.110 a 2.119

verzia 2.110, 2016/05/05 21:07:54 verzia 2.119, 2019/02/14 07:41:47
Riadok 4 
Riadok 4 
 # Provides:          firewall  # Provides:          firewall
 # Required-Start:    $network  # Required-Start:    $network
 # Required-Stop:     $remote_fs  # Required-Stop:     $remote_fs
 # Default-Start:     S  # Default-Start:     2 3 4 5
 # Default-Stop:      0 6  # Default-Stop:      0 6
 # Short-Description: Starts firewall  # Short-Description: Starts firewall
 # Description:       Handle universal firewall script by Platon Group  # Description:       Handle universal firewall script by Platon Group
 #                    http://platon.sk/cvs/cvs.php/scripts/shell/firewall/  #                    http://platon.sk/cvs/cvs.php/scripts/shell/firewall/
 # Author:            Lubomir Host <rajo@platon.sk>  # Author:            Lubomir Host <rajo@platon.sk>
 # Copyright:         (c) 2003-2011 Platon Group  # Copyright:         (c) 2003-2018 Platon Group
 ### END INIT INFO  ### END INIT INFO
   
 #  #
Riadok 18 
Riadok 18 
 # Can be started by init or by hand.  # Can be started by init or by hand.
 #  #
 # Developed by Lubomir Host 'rajo' <rajo AT platon.sk>  # Developed by Lubomir Host 'rajo' <rajo AT platon.sk>
 # Copyright (c) 2003-2011 Platon Group, http://platon.sk/  # Copyright (c) 2003-2018 Platon Group, http://platon.sk/
 # 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.109 2016/02/26 07:01:10 nepto Exp $  # $Platon: scripts/shell/firewall/fw-universal.sh,v 2.118 2018/12/10 11:46:12 nepto Exp $
 #  #
 # Changelog:  # Changelog:
 # 2003-10-24 - created  # 2003-10-24 - created
 # 2011-07-20 - implemented XEN_MODE  # 2011-07-20 - implemented XEN_MODE
   # 2018-03-01 - fixed Default-Start for SystemD on Stretch (nepto)
 #  #
   
   
Riadok 42  DEFAULT_CACHE_DIR="${DEFAULT_CACHE_DIR:=
Riadok 43  DEFAULT_CACHE_DIR="${DEFAULT_CACHE_DIR:=
 DIST_FIREWALL_CONFIG_DIR="${DIST_FIREWALL_CONFIG_DIR:=/etc/firewall/firewall.d}"  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$QUIET" = "xyes" ]; then
         print_info()          print_info()
         {          {
                 echo -n ""                  echo -n ""
Riadok 57  fi
Riadok 58  fi
   
 # Define function which can be used in config file  # Define function which can be used in config file
 # Usage:  # Usage:
 #   load_subnets eth0_ACCEPT_INPUT_TCP Slovakia 22  #   load_subnets eth0_ACCEPT_INPUT_TCP Slovakia.txt 22
 load_subnets()  load_subnets()
 { # {{{  { # {{{
         cfgvar=$1          cfgvar="$1";
         cfgfile="$2.txt"          cfgfile="$2";
         port=$3          port="$3";
   
         echo "LOAD_SUBNETS $*"          print_info "LOAD_SUBNETS: $*";
   
         if [ -f "$DEFAULT_FIREWALL_CONFIG_DIR/subnets/$cfgfile" ]; then          if [ -f "$DEFAULT_FIREWALL_CONFIG_DIR/subnets/$cfgfile" ]; then
                 cfgfound="$DEFAULT_FIREWALL_CONFIG_DIR/subnets/$cfgfile";                  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          else
                 if [ -f "$DIST_FIREWALL_CONFIG_DIR/subnets/$cfgfile" ]; then                  print_info "LOAD_SUBNETS: config file not found: $cfgfile";
                         cfgfound="$DIST_FIREWALL_CONFIG_DIR/subnets/$cfgfile";                  return 1
                 else          fi fi
                         print_info "LOAD_SUBNETS: Config file '$cfgfile' not found"  
                         return 1  
                 fi  
         fi  
         LOADED_CONFIG_FILES="$LOADED_CONFIG_FILES $cfgfound";          LOADED_CONFIG_FILES="$LOADED_CONFIG_FILES $cfgfound";
   
         lines=0          print_info "LOAD_SUBNETS: found $cfgfile: $cfgfound";
         print_info "LOAD_SUBNETS: Mapping $cfgfound map file to $cfgvar, port $port"          print_info "LOAD_SUBNETS: mapping $cfgfile to $cfgvar, port $port"
   
           lines=0;
         while read subnet ; do          while read subnet ; do
                 case "$subnet" in                  case "$subnet" in
                         ""|\#*)                          ""|\#*)
                                 continue                                  continue
                                 ;;                                  ;;
                 esac                  esac
                 print_info "LOAD_SUBNETS: $cfgvar=\"\$$cfgvar $subnet:$port\""                  eval "$cfgvar=\"\$$cfgvar $subnet:$port\"";
                 eval "$cfgvar=\"\$$cfgvar $subnet:$port\""                  lines=$(($lines + 1));
                 lines=$(($lines + 1))  
         done < $cfgfound          done < $cfgfound
         print_info "LOAD_SUBNETS: $cfgvar='${!cfgvar}'"          print_info "LOAD_SUBNETS: $lines subnets loaded from $cfgfile"
         print_info "LOAD_SUBNETS: $lines subnets loaded from '$cfgfile' into '$cfgvar'"  
   
 } # }}}  } # }}}
   
 if [ -f "$DEFAULT_FIREWALL_CONFIG" ]; then  if [ -f "$DEFAULT_FIREWALL_CONFIG" ]; then
Riadok 756  drop_output()
Riadok 754  drop_output()
                         print_info " done."                          print_info " done."
                 fi                  fi
         done          done
   } # }}}
   
   do_ban_single_ip()
   { # {{{
           if [ -z "$1" ]; then
                   print_info "do_ban_single_ip(): empty banned_ip";
                   return;
           fi
           for banned_ip in $*; do
                   # This does immediate connection termination, but it must be inserted
                   # and thus not appended into chain, otherwise connection will still
                   # remain alive. Former forward chain rule was removed as unneccessary.
                   #   -- Nepto [2018-08-23]
                   #   -- Plantroon [2018-12-10]
                   $IPTABLES -I INPUT -s $banned_ip -j DROP;
           done
 } # }}}  } # }}}
   
 bann_ip_adresses()  bann_ip_adresses()
Riadok 778  bann_ip_adresses()
Riadok 791  bann_ip_adresses()
         if [ ! -z "$BANNED_IP" ]; then          if [ ! -z "$BANNED_IP" ]; then
                 print_info -en "Dropping ALL packets from IP:"                  print_info -en "Dropping ALL packets from IP:"
                 for banned_ip in $BANNED_IP; do                  for banned_ip in $BANNED_IP; do
                         print_info -en " $banned_ip"                          print_info -en " $banned_ip";
                         $IPTABLES -A INPUT              -s $banned_ip -j DROP                          do_ban_single_ip "$banned_ip";
   
                         if [ "X$XEN_MODE" = "Xon" ]; then  
                                         print_info -ne " XEN_MODE ";  
                         else  
                                 $IPTABLES -A FORWARD    -s $banned_ip -j DROP  
                         fi  
                 done                  done
                 print_info " done."                  print_info " done."
         fi          fi
Riadok 809  allow_accept_all()
Riadok 816  allow_accept_all()
         fi          fi
 } # }}}  } # }}}
   
   allow_accept_vrrp()
   { # {{{
           if [ ! -z "$IFACE_ACCEPT_VRRP" ]; then
                   print_info -en "Accepting VRRP packets on interfaces:"
                   for iface in $IFACE_ACCEPT_VRRP; do
                           print_info -en " $iface"
                           $IPTABLES -A INPUT  -i $iface -d 224.0.0.18/32 -p vrrp -j ACCEPT;
                           $IPTABLES -A OUTPUT -i $iface -d 224.0.0.18/32 -p vrrp -j ACCEPT;
                   done
                   print_info " done."
           fi
   } # }}}
   
 drop_input()  drop_input()
 { # {{{  { # {{{
         if [ ! -z "$NAT_LAN_IFACE" ]; then          if [ ! -z "$NAT_LAN_IFACE" ]; then
Riadok 1069  allow_input()
Riadok 1089  allow_input()
                 print_info " done."                  print_info " done."
         fi          fi
   
         # We are using REAL_INTERFACES instead of INTERFACES here, because we want          # We are using INTERFACES + lo instead of INTERFACES here, because we want
         # to do redirects for "lo" interface as well. However for "lo" it is done          # to do redirects for "lo" interface as well. However for "lo" it is done
         # quite differently. See http://ix.sk/0WY2j for more information on this.          # quite differently. See http://ix.sk/0WY2j for more information on this.
         #   -- Nepto [2015-10-19]          #   -- Nepto [2015-10-19]
         for iface in $REAL_INTERFACES; do          for iface in lo $INTERFACES; do
                 riface="IFname_$iface";                  riface="IFname_$iface";
                 IPS="IP_$iface";                  IPS="IP_$iface";
   
Riadok 1618  shaping_status()
Riadok 1638  shaping_status()
   
 # }}}  # }}}
   
   check_banned_ip()
   { # {{{
           output="`grep \"$1\" $DEFAULT_FIREWALL_CONFIG_DIR/BANNED_IP.conf`";
           if [ "$?" -eq 0 -a -n "$output" ]; then
                   return 0;
           fi
           return 1;
   } # }}}
   
 add_banned_ip()  add_banned_ip()
 { # {{{  { # {{{
         echo "# `date '+%Y-%m-%d %X' `" >> $DEFAULT_FIREWALL_CONFIG_DIR/BANNED_IP.conf          echo "# `date '+%F %T'`" >> $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 1633  add_banned_ip()
Riadok 1662  add_banned_ip()
         fi          fi
         read_config_ips $TMPFILE >> $DEFAULT_FIREWALL_CONFIG_DIR/BANNED_IP.conf          read_config_ips $TMPFILE >> $DEFAULT_FIREWALL_CONFIG_DIR/BANNED_IP.conf
         rm -f $TMPFILE          rm -f $TMPFILE
         # start with new firewalling rules  
         $0 start  
 } # }}}  } # }}}
   
 deploy_block()  deploy_block()
Riadok 1889  done
Riadok 1916  done
 REAL_INTERFACES="`echo $x_REAL_INTERFACES | awk -v RS=' ' '{ print; }' | sort -u`"  REAL_INTERFACES="`echo $x_REAL_INTERFACES | awk -v RS=' ' '{ print; }' | sort -u`"
 INTERFACES_ACCEPT_ALL="$IFACE_ACCEPT_ALL"  INTERFACES_ACCEPT_ALL="$IFACE_ACCEPT_ALL"
   
   retcode=0;
 case "$1" in  case "$1" in
         start)          start)
                 print_info -n "Starting $DESC: "                  print_info -n "Starting $DESC: "
Riadok 1904  case "$1" in
Riadok 1931  case "$1" in
                 #                  #
                 bann_ip_adresses                  bann_ip_adresses
                 allow_accept_all                  allow_accept_all
                   allow_accept_vrrp
                 nmap_scan_filter                  nmap_scan_filter
                 invalid_packet_filter                  invalid_packet_filter
                 anti_spoof_filter                  anti_spoof_filter
Riadok 1916  case "$1" in
Riadok 1944  case "$1" in
                 drop_output                  drop_output
                 allow_output                  allow_output
                 allow_icmp                  allow_icmp
                 echo "----[ INCOMMING TRAFFIC ]------------------------------------------------"                  print_info "----[ INCOMMING TRAFFIC ]------------------------------------------------"
                 drop_input                  drop_input
                 reject_input                  reject_input
                 allow_input                  allow_input
Riadok 1960  case "$1" in
Riadok 1988  case "$1" in
         purge)          purge)
                 find $DEFAULT_CACHE_DIR -type f -ls -exec rm -f {} \;                  find $DEFAULT_CACHE_DIR -type f -ls -exec rm -f {} \;
                 ;;                  ;;
   
         block)          block)
                 shift;                  shift;
                 add_banned_ip $*;                  for banned_ip in $*; do
                 # start the some script twice to refresh rules (new blocked IP's)                          check_banned_ip "$banned_ip";
                 QUIET=yes $0 start;                          if [ "$?" -eq 0 ]; then
                                   print_info "Already blocked IP address: $banned_ip";
                                   retcode=1;
                           else
                                   print_info "Blocking IP address: $banned_ip";
                                   add_banned_ip "$banned_ip";
                                   do_ban_single_ip "$banned_ip";
                           fi
                   done
                 ;;                  ;;
         update)          update)
                 update;                  update;
Riadok 1985  case "$1" in
Riadok 2022  case "$1" in
                 ;;                  ;;
 esac  esac
   
 exit 0  exit "$retcode";
   
 # vim600: fdm=marker fdl=0 fdc=3  # vim600: fdm=marker fdl=0 fdc=3
   

Legend:
Odstranené z verzie2.110  
zmenené riadky
  Pridané vo verzii2.119

Platon Group <platon@platon.sk> http://platon.sk/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok