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.99 and 2.105

version 2.99, 2013/09/28 09:25:35 version 2.105, 2015/10/19 14:00:33
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.98 2013-09-28 09:22:42 nepto Exp $  # $Platon: scripts/shell/firewall/fw-universal.sh,v 2.104 2015/10/12 22:41:24 rajo Exp $
 #  #
 # Changelog:  # Changelog:
 # 2003-10-24 - created  # 2003-10-24 - created
Line 1011  allow_input()
Line 1011  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";
   
Line 1039  allow_input()
Line 1043  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
Line 1053  allow_input()
Line 1061  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
Line 1119  allow_input()
Line 1131  allow_input()
                                         port="ALL";                                          port="ALL";
                                 fi                                  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 ]; then counter=0; print_info ""; fi;                                  if [ $(( ++counter )) -ge 5 -o "x$port" = "x10050" ]; then counter=0; print_info ""; fi;
                                 echo $port | grep -q ,                                  echo $port | grep -q ,
                                 multiport="$?";                                  multiport="$?";
                                 if [ "$multiport" -eq 0 ]; then                                  if [ "$multiport" -eq 0 ]; then
Line 1213  allow_output()
Line 1225  allow_output()
         output_icmp_str="";          output_icmp_str="";
   
         for iface in $INTERFACES; do          for iface in $INTERFACES; do
                   gateway="Gateway_$iface";
                 riface="IFname_$iface";                  riface="IFname_$iface";
                 IPS="IP_$iface";                  IPS="IP_$iface";
   
Line 1221  allow_output()
Line 1234  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}"
   
   
                 # TCP                  # TCP
                 if [ -z "$ACCEPT_OUTPUT_TCP" ]; then                  if [ -z "$ACCEPT_OUTPUT_TCP" ]; then
                         for ip in ${!IPS}; do                          if [ -n "${!gateway}" ]; then
                                 output_tcp_str="$output_tcp_str $ip($iface)";                                  for ip in ${!IPS}; do
                                 $IPTABLES -A OUTPUT -p TCP -o ${!riface} -s $ip -j ACCEPT                                          output_tcp_str="$output_tcp_str $ip:${!riface}:${!gateway}";
                         done                                          $IPTABLES -A OUTPUT -p TCP -o ${!riface} -s $ip -j ACCEPT
                                   done
                           fi
                 else                  else
                         print_info -en "$iface: Accepting OUTPUT TCP connections to ports:"                          print_info -en "$iface: Accepting OUTPUT TCP connections to ports:"
                         for port in $ACCEPT_OUTPUT_TCP; do                          for port in $ACCEPT_OUTPUT_TCP; do
Line 1251  allow_output()
Line 1267  allow_output()
   
                 # UDP                  # UDP
                 if [ -z "$ACCEPT_OUTPUT_UDP" ]; then                  if [ -z "$ACCEPT_OUTPUT_UDP" ]; then
                         for ip in ${!IPS}; do                          if [ -n "${!gateway}" ]; then
                                 output_udp_str="$output_udp_str $ip($iface)";                                  for ip in ${!IPS}; do
                                 $IPTABLES -A OUTPUT -p UDP -o ${!riface} -s $ip -j ACCEPT                                          output_udp_str="$output_udp_str $ip:${!riface}:${!gateway}";
                         done                                          $IPTABLES -A OUTPUT -p UDP -o ${!riface} -s $ip -j ACCEPT
                                   done
                           fi
                 else                  else
                         print_info -en "$iface: Accepting OUTPUT UDP connections to ports:"                          print_info -en "$iface: Accepting OUTPUT UDP connections to ports:"
                         for port in $ACCEPT_OUTPUT_UDP; do                          for port in $ACCEPT_OUTPUT_UDP; do
Line 1278  allow_output()
Line 1296  allow_output()
                 fi                  fi
   
                 # ICMP                  # ICMP
                 for ip in ${!IPS}; do                  if [ -n "${!gateway}" ]; then
                         output_icmp_str="$output_icmp_str $ip($iface)";                          for ip in ${!IPS}; do
                         $IPTABLES -A OUTPUT -p ICMP -o ${!riface} -s $ip -j ACCEPT                                  output_icmp_str="$output_icmp_str $ip:${!riface}:${!gateway}";
                 done                                  $IPTABLES -A OUTPUT -p ICMP -o ${!riface} -s $ip -j ACCEPT
                           done
                   fi
         done          done
   
         if [ -n "$output_tcp_str" ]; then          if [ -n "$output_tcp_str" ]; then
                 print_info "Accepting OUTPUT TCP packets from $output_tcp_str done."                  print_info "Accepting OUTPUT TCP packets through $output_tcp_str done."
         fi          fi
         if [ -n "$output_udp_str" ]; then          if [ -n "$output_udp_str" ]; then
                 print_info "Accepting OUTPUT UDP packets from $output_udp_str done."                  print_info "Accepting OUTPUT UDP packets through $output_udp_str done."
         fi          fi
         if [ -n "$output_icmp_str" ]; then          if [ -n "$output_icmp_str" ]; then
                 print_info "Accepting OUTPUT ICMP packets from $output_icmp_str done."                  print_info "Accepting OUTPUT ICMP packets through $output_icmp_str done."
         fi          fi
 } # }}}  } # }}}
   
Line 1650  while (my $line = <STDIN>) {
Line 1670  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}++;
Line 1670  while (my $line = <STDIN>) {
Line 1691  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];
           }
   
 }  }
   
Line 1683  map { printf "IPcount_%s=\"%s\";    export
Line 1711  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";
Line 1733  printf "interfaces=\"%s\";     export inter
Line 1761  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:

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

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