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.102 a 2.108

verzia 2.102, 2014/04/15 05:02:32 verzia 2.108, 2016/02/26 03:11:01
Riadok 22 
Riadok 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.101 2013-09-28 18:51:30 nepto Exp $  # $Platon: scripts/shell/firewall/fw-universal.sh,v 2.107 2016/02/26 02:53:42 nepto Exp $
 #  #
 # Changelog:  # Changelog:
 # 2003-10-24 - created  # 2003-10-24 - created
Riadok 39  DEFAULT_FIREWALL_CONFIG="${DEFAULT_FIREW
Riadok 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()
Riadok 910  reject_input()
Riadok 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; }'`
Riadok 923  allow_input()
Riadok 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
Riadok 937  allow_input()
Riadok 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; }'`
Riadok 950  allow_input()
Riadok 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
Riadok 969  allow_input()
Riadok 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
Riadok 990  allow_input()
Riadok 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
Riadok 1011  allow_input()
Riadok 1025  allow_input()
                 print_info " done."                  print_info " done."
         fi          fi
   
         for iface in $INTERFACES; do          # We are using REAL_INTERFACES instead of INTERFACES here, because we want
           # 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.
           #   -- Nepto [2015-10-19]
           for iface in $REAL_INTERFACES; do
                 riface="IFname_$iface";                  riface="IFname_$iface";
                 IPS="IP_$iface";                  IPS="IP_$iface";
   
Riadok 1039  allow_input()
Riadok 1057  allow_input()
                                                                         (NF == 3) { remote_ip = $1;          from_port = $2; to_port = $3; } \                                                                          (NF == 3) { remote_ip = $1;          from_port = $2; to_port = $3; } \
                                                                         END { printf "remote_ip=%s; from_port=%s; to_port=%s;", remote_ip, from_port, to_port; }'`                                                                          END { printf "remote_ip=%s; from_port=%s; to_port=%s;", remote_ip, from_port, to_port; }'`
                                 print_info -en " $remote_ip:$from_port->$to_port"                                  print_info -en " $remote_ip:$from_port->$to_port"
                                 $IPTABLES -t nat -A PREROUTING -p TCP -i ${!riface} -s $remote_ip -d $ip --dport $from_port -j REDIRECT --to-port $to_port                                  if [ "X$iface" = "Xlo" ]; then
                                           $IPTABLES -t nat -A OUTPUT -p TCP -s $remote_ip -d $ip --dport $from_port -j REDIRECT --to-port $to_port
                                   else
                                           $IPTABLES -t nat -A PREROUTING -p TCP -i ${!riface} -s $remote_ip -d $ip --dport $from_port -j REDIRECT --to-port $to_port
                                   fi
                         done                          done
                         print_info " done."                          print_info " done."
                 fi                  fi
Riadok 1053  allow_input()
Riadok 1075  allow_input()
                                                                         (NF == 3) { remote_ip = $1;          from_port = $2; to_port = $3; } \                                                                          (NF == 3) { remote_ip = $1;          from_port = $2; to_port = $3; } \
                                                                         END { printf "remote_ip=%s; from_port=%s; to_port=%s;", remote_ip, from_port, to_port; }'`                                                                          END { printf "remote_ip=%s; from_port=%s; to_port=%s;", remote_ip, from_port, to_port; }'`
                                 print_info -en " $remote_ip:$from_port->$to_port"                                  print_info -en " $remote_ip:$from_port->$to_port"
                                 $IPTABLES -t nat -A PREROUTING -p UDP -i ${!riface} -s $remote_ip -d $ip --dport $from_port -j REDIRECT --to-port $to_port                                  if [ "X$iface" = "Xlo" ]; then
                                           $IPTABLES -t nat -A OUTPUT -p UDP -s $remote_ip -d $ip --dport $from_port -j REDIRECT --to-port $to_port
                                   else
                                           $IPTABLES -t nat -A PREROUTING -p UDP -i ${!riface} -s $remote_ip -d $ip --dport $from_port -j REDIRECT --to-port $to_port
                                   fi
                         done                          done
                         print_info " done."                          print_info " done."
                 fi                  fi
Riadok 1110  allow_input()
Riadok 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=""
Riadok 1118  allow_input()
Riadok 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 "$port" -eq "10050" ]; 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
Riadok 1641  remote()
Riadok 1669  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()
Riadok 1658  while (my $line = <STDIN>) {
Riadok 1715  while (my $line = <STDIN>) {
                 $iface  = $1;                  $iface  = $1;
                 my $iface_hwaddr = $2;                  my $iface_hwaddr = $2;
                 my $x_iface     = $iface;                  my $x_iface     = $iface;
                 $iface  =~ s/:/_/; # convert "eth0:0" --> "eth0_0"                  $iface  =~ s/:$//g;
                   $iface  =~ s/:/_/g; # convert "eth0:0" --> "eth0_0"
                 $x_iface                = [ $x_iface =~ m/^([a-z0-9]+)/i ]->[0]; # convert "eth0:0" --> "eth0"                  $x_iface                = [ $x_iface =~ m/^([a-z0-9]+)/i ]->[0]; # convert "eth0:0" --> "eth0"
                 $ifname{$iface} = $x_iface;                  $ifname{$iface} = $x_iface;
                 $ipcount{$iface}++;                  $ipcount{$iface}++;
Riadok 1678  while (my $line = <STDIN>) {
Riadok 1736  while (my $line = <STDIN>) {
                 push @{$ip6{$iface}}, $fields[3];                  push @{$ip6{$iface}}, $fields[3];
                 $scope6{$iface} = [ $fields[4] =~ m/Scope:(.*)$/i ]->[0];                  $scope6{$iface} = [ $fields[4] =~ m/Scope:(.*)$/i ]->[0];
         }          }
           elsif ($line =~ m/^[ \t]+inet\s/) { # Linux IP address
                   die unless defined $iface;
                   my @fields = split(/[\s:]+/, $line);
                   push @{$ip{$iface}}, $fields[2];
                   $bcast{$iface} = (defined($fields[5]) and $fields[5] eq "broadcast") ? $fields[6] : "";
                   $mask{$iface} = $fields[4];
           }
   
 }  }
   
Riadok 1691  map { printf "IPcount_%s=\"%s\";    export
Riadok 1756  map { printf "IPcount_%s=\"%s\";    export
 map { printf "IFname_%s=\"%s\";         export IFname_%s;\n",   $_, $ifname{$_},        $_; } keys %ifname;  map { printf "IFname_%s=\"%s\";         export IFname_%s;\n",   $_, $ifname{$_},        $_; } keys %ifname;
 printf "interfaces=\"%s\";      export interfaces;\n", join(" ", sort keys %ip);  printf "interfaces=\"%s\";      export interfaces;\n", join(" ", sort keys %ip);
         '`          '`
         eval "$parsed_interfaces";  
         #echo "$parsed_interfaces";          #echo "$parsed_interfaces";
           eval "$parsed_interfaces";
   
         parsed_routes=`$PERL -e '          parsed_routes=`$PERL -e '
         $\ = "\n";          $\ = "\n";
Riadok 1741  printf "interfaces=\"%s\";     export inter
Riadok 1806  printf "interfaces=\"%s\";     export inter
   
         } # }}}          } # }}}
         '`          '`
           #echo $parsed_routes
         eval "$parsed_routes";          eval "$parsed_routes";
   
         # Now we have defined variables like this:          # Now we have defined variables like this:
Riadok 1825  case "$1" in
Riadok 1891  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
Riadok 1892  case "$1" in
Riadok 1959  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:
Odstranené z verzie2.102  
zmenené riadky
  Pridané vo verzii2.108

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