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

Diff for scripts/shell/firewall/fw-universal.sh between version 2.35 and 2.36

version 2.35, 2006/01/10 01:33:26 version 2.36, 2006/01/12 20:05:34
Line 5 
Line 5 
 # 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-2005 Platon SDG, http://platon.sk/  # Copyright (c) 2003-2006 Platon SDG, 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.
 #  #
Line 78  TRACEROUTE_DEST_PORTS="33434:33523"    # Tr
Line 78  TRACEROUTE_DEST_PORTS="33434:33523"    # Tr
 # allow some ICMP packets - needed for ping etc.  # allow some ICMP packets - needed for ping etc.
 ACCEPT_ICMP_PACKETS="${ACCEPT_ICMP_PACKETS:=echo-reply destination-unreachable echo-request time-exceeded}"  ACCEPT_ICMP_PACKETS="${ACCEPT_ICMP_PACKETS:=echo-reply destination-unreachable echo-request time-exceeded}"
   
   print_first()
   { # {{{
           echo $1
   } # }}}
   
   get_first_ip_addr()
   { # {{{
           varname="$1"
           print_first `echo ${!varname} | sort -g`
   } # }}}
   
 # load necessary modules from $MODULES variable  # load necessary modules from $MODULES variable
 load_modules()  load_modules()
Line 132  print_iface_status()
Line 142  print_iface_status()
         # Print interfaces:          # Print interfaces:
         echo "# iface   | IP addr       | Gateway       | broadcast     | netmask       | HW addr"          echo "# iface   | IP addr       | Gateway       | broadcast     | netmask       | HW addr"
         for iface in $interfaces; do          for iface in $interfaces; do
                 IP="IP_$iface"; Gateway="Gateway_$iface"; Bcast="Bcast_$iface"; Mask="Mask_$iface"; HWaddr="HWaddr_$iface";                  IPS="IP_$iface";
                 echo "$iface    | ${!IP}        | ${!Gateway}   | ${!Bcast}     | ${!Mask}      | ${!HWaddr}"                  for IP in ${!IPS}; do
                           Gateway="Gateway_$iface"; Bcast="Bcast_$iface"; Mask="Mask_$iface"; HWaddr="HWaddr_$iface";
                           echo "$iface    | ${IP} | ${!Gateway}   | ${!Bcast}     | ${!Mask}      | ${!HWaddr}"
                   done
         done          done
 } # }}}  } # }}}
   
Line 333  masquerade()
Line 346  masquerade()
         echo " done."          echo " done."
                 echo -en "NAT: Masquerading local subnet: $NAT_SUBNET_IFACE --> $NAT_LAN_IFACE"                  echo -en "NAT: Masquerading local subnet: $NAT_SUBNET_IFACE --> $NAT_LAN_IFACE"
   
                 ip="IP_$NAT_SUBNET_IFACE";                  ip="`get_first_ip_addr IP_$NAT_SUBNET_IFACE`"
                 netmask="Mask_$NAT_SUBNET_IFACE"                  netmask="Mask_$NAT_SUBNET_IFACE"
                 localnet="${!ip}/${!netmask}"                  localnet="${!ip}/${!netmask}"
   
                 lan_ip="IP_$NAT_LAN_IFACE"                  lan_ip="`get_first_ip_addr IP_$NAT_LAN_IFACE`"
   
                 # alow packets from private subnet                  # alow packets from private subnet
                 $IPTABLES -A FORWARD -s ! $localnet -i $NAT_SUBNET_IFACE -j DROP                  $IPTABLES -A FORWARD -s ! $localnet -i $NAT_SUBNET_IFACE -j DROP
Line 440  drop_output()
Line 453  drop_output()
 { # {{{  { # {{{
   
         for iface in $INTERFACES; do          for iface in $INTERFACES; do
                 ip="IP_$iface";  
                 drop_output_tcp="${iface}_DROP_OUTPUT_TCP"                  drop_output_tcp="${iface}_DROP_OUTPUT_TCP"
                 DROP_OUTPUT_TCP="${!drop_output_tcp}"                  DROP_OUTPUT_TCP="${!drop_output_tcp}"
                 drop_output_udp="${iface}_DROP_OUTPUT_UDP"                  drop_output_udp="${iface}_DROP_OUTPUT_UDP"
Line 519  allow_input()
Line 531  allow_input()
                 echo -en "Accepting ALL INPUT TCP connections on ports:"                  echo -en "Accepting ALL INPUT TCP connections on ports:"
                 for port in $ALL_ACCEPT_INPUT_TCP; do                  for port in $ALL_ACCEPT_INPUT_TCP; do
                         for iface in $INTERFACES; do                          for iface in $INTERFACES; do
                                 ip="IP_$iface";  
                                 echo -en " $port($iface)"                                  echo -en " $port($iface)"
                                 $IPTABLES -A INPUT -i $iface -d ${!ip} -p TCP --dport $port -j ACCEPT                                  IPS="IP_$iface";
                                   for ip in ${!IPS}; do
                                           $IPTABLES -A INPUT -i $iface -d $ip -p TCP --dport $port -j ACCEPT
                                   done
                         done                          done
                 done                  done
                 echo " done."                  echo " done."
Line 530  allow_input()
Line 544  allow_input()
                 echo -en "Accepting ALL INPUT UDP connections on ports:"                  echo -en "Accepting ALL INPUT UDP connections on ports:"
                 for port in $ALL_ACCEPT_INPUT_UDP; do                  for port in $ALL_ACCEPT_INPUT_UDP; do
                         for iface in $INTERFACES; do                          for iface in $INTERFACES; do
                                 ip="IP_$iface";  
                                 echo -en " $port($iface)"                                  echo -en " $port($iface)"
                                 $IPTABLES -A INPUT -i $iface -p UDP --dport $port -j ACCEPT                                  IPS="IP_$iface";
                                   for ip in ${!IPS}; do
                                           $IPTABLES -A INPUT -i $iface -d $ip -p UDP --dport $port -j ACCEPT
                                   done
                         done                          done
                 done                  done
                 echo " done."                  echo " done."
         fi          fi
   
         for iface in $INTERFACES; do          for iface in $INTERFACES; do
                 ip="IP_$iface";                  IPS="IP_$iface";
                 accept_input_tcp="${iface}_ACCEPT_INPUT_TCP"                  accept_input_tcp="${iface}_ACCEPT_INPUT_TCP"
                 ACCEPT_INPUT_TCP="${!accept_input_tcp}"                  ACCEPT_INPUT_TCP="${!accept_input_tcp}"
                 accept_input_udp="${iface}_ACCEPT_INPUT_UDP"                  accept_input_udp="${iface}_ACCEPT_INPUT_UDP"
Line 549  allow_input()
Line 565  allow_input()
                         echo -en "$iface: Accepting INPUT TCP connections on ports:"                          echo -en "$iface: Accepting INPUT TCP connections on ports:"
                         for port in $ACCEPT_INPUT_TCP; do                          for port in $ACCEPT_INPUT_TCP; do
                                 echo -en " $port"                                  echo -en " $port"
                                 $IPTABLES -A INPUT -i $iface -d ${!ip} -p TCP --dport $port -j ACCEPT                                  for ip in ${!IPS}; do
                                           $IPTABLES -A INPUT -i $iface -d $ip -p TCP --dport $port -j ACCEPT
                                   done
                         done                          done
                         echo " done."                          echo " done."
                 fi                  fi
Line 560  allow_input()
Line 578  allow_input()
                                 echo -en " $port"                                  echo -en " $port"
                                 #$IPTABLES -A INPUT -i $iface -d ${!INET_IP} -p UDP --dport $port -j ACCEPT                                  #$IPTABLES -A INPUT -i $iface -d ${!INET_IP} -p UDP --dport $port -j ACCEPT
                                 #$IPTABLES -A INPUT -i $iface --source 192.168.1.0/16 -p UDP --dport $port -j ACCEPT                                  #$IPTABLES -A INPUT -i $iface --source 192.168.1.0/16 -p UDP --dport $port -j ACCEPT
                                 $IPTABLES -A INPUT -i $iface -p UDP --dport $port -j ACCEPT                                  for ip in ${!IPS}; do
                                           $IPTABLES -A INPUT -i $iface -d $ip -p UDP --dport $port -j ACCEPT
                                   done
                         done                          done
                         echo " done."                          echo " done."
                 fi                  fi
Line 568  allow_input()
Line 588  allow_input()
   
         # Enable outgoing TRACEROUTE requests (required e.g. by Skype, http://www.skype.com)          # Enable outgoing TRACEROUTE requests (required e.g. by Skype, http://www.skype.com)
         if [ ! -z "$TRACEROUTE_IFACE" ]; then          if [ ! -z "$TRACEROUTE_IFACE" ]; then
                 ip="IP_$ANTISPOOF_IFACE";                  ip="`get_first_ip_addr IP_$ANTISPOOF_IFACE`";
                 echo -en "Accepting traceroute:"                  echo -en "Accepting traceroute:"
   
                 $IPTABLES -A OUTPUT -o $ANTISPOOF_IFACE -p UDP \                  $IPTABLES -A OUTPUT -o $ANTISPOOF_IFACE -p UDP \
                         --sport $TRACEROUTE_SRC_PORTS --dport $TRACEROUTE_DEST_PORTS \                          --sport $TRACEROUTE_SRC_PORTS --dport $TRACEROUTE_DEST_PORTS \
                         -s ${!ip} -d $ANYWHERE -j ACCEPT                          -s $ip -d $ANYWHERE -j ACCEPT
   
                 for iface in $TRACEROUTE_IFACE; do                  for iface in $TRACEROUTE_IFACE; do
                         $IPTABLES -A FORWARD -p UDP -i $iface --sport $TRACEROUTE_SRC_PORTS \                          $IPTABLES -A FORWARD -p UDP -i $iface --sport $TRACEROUTE_SRC_PORTS \
Line 591  allow_output()
Line 611  allow_output()
         # Povolíme odchozí pakety, které mají naše IP adresy          # Povolíme odchozí pakety, které mají naše IP adresy
         echo -en "Accepting OUTPUT packets from"          echo -en "Accepting OUTPUT packets from"
         for iface in $INTERFACES; do          for iface in $INTERFACES; do
                 ip="IP_$iface";                  IPS="IP_$iface";
                 echo -en " ${!ip}($iface)"                  for ip in ${!IPS}; do
                 $IPTABLES -A OUTPUT -o $iface -s ${!ip} -j ACCEPT                          echo -en " $ip($iface)"
                           $IPTABLES -A OUTPUT -o $iface -s $ip -j ACCEPT
                   done
         done;          done;
         echo " done.";          echo " done.";
   
Line 612  allow_icmp()
Line 634  allow_icmp()
         for type in $ACCEPT_ICMP_PACKETS; do          for type in $ACCEPT_ICMP_PACKETS; do
                 echo -en " $type"                  echo -en " $type"
                 for iface in $INTERFACES; do                  for iface in $INTERFACES; do
                         ip="IP_$iface";                          IPS="IP_$iface";
                         $IPTABLES -A INPUT -i $iface -d ${!ip} -p ICMP --icmp-type $type -j ACCEPT                          for ip in ${!IPS}; do
                                   $IPTABLES -A INPUT -i $iface -d $ip -p ICMP --icmp-type $type -j ACCEPT
                           done
                 done                  done
         done          done
         #$IPTABLES_LOG -A INPUT  -p ICMP -j LOG --log-prefix "IN  ICMP: "          #$IPTABLES_LOG -A INPUT  -p ICMP -j LOG --log-prefix "IN  ICMP: "
Line 669  do_ip_accounting()
Line 693  do_ip_accounting()
                         $IPTABLES -N $IPACCT_OUT_NAME   # upload: from client to server                          $IPTABLES -N $IPACCT_OUT_NAME   # upload: from client to server
                         $IPTABLES -A $IPACCT_OUT_NAME                          $IPTABLES -A $IPACCT_OUT_NAME
   
                         ip="IP_$NAT_SUBNET_IFACE";                          ip="`get_first_ip_addr IP_$NAT_SUBNET_IFACE`";
                         netmask="Mask_$NAT_SUBNET_IFACE"                          netmask="Mask_$NAT_SUBNET_IFACE"
                         localnet="${!ip}/${!netmask}"                          localnet="${!ip}/${!netmask}"
   
Line 707  accept_related()
Line 731  accept_related()
   
         echo -en "Accepting ESTABLISHED, RELATED packets for IP:"          echo -en "Accepting ESTABLISHED, RELATED packets for IP:"
         for iface in $INTERFACES; do          for iface in $INTERFACES; do
                 ip="IP_$iface";                  IPS="IP_$iface";
                 echo -en " ${!ip}($iface)"                  for ip in ${!IPS}; do
                           echo -en " $ip($iface)"
                   done
                 $IPTABLES -A INPUT      -m state --state ESTABLISHED,RELATED -j ACCEPT                  $IPTABLES -A INPUT      -m state --state ESTABLISHED,RELATED -j ACCEPT
                 $IPTABLES -A OUTPUT     -m state --state ESTABLISHED,RELATED -j ACCEPT                  $IPTABLES -A OUTPUT     -m state --state ESTABLISHED,RELATED -j ACCEPT
         done          done
Line 733  parse_ifconfig()
Line 759  parse_ifconfig()
 { # {{{  { # {{{
         # Parse output from ifconfig:          # Parse output from ifconfig:
         parsed_interfaces=`$IFCONFIG | \          parsed_interfaces=`$IFCONFIG | \
                 $AWK 'BEGIN { interfaces=""; }                  $AWK '
                         /^[a-zA-Z0-9]+[ \t]+/ { # Linux  BEGIN {
                                 iface=$1;          iface_count = 0;
                                 interfaces = sprintf("%s %s", interfaces, iface);  }
                                 printf "\nIFACE_%s=\"%s\";      export IFACE_%s;\n", iface, iface, iface;  
                                 printf "HWaddr_%s=\"%s\";       export HWaddr_%s;\n", iface, $5, iface;  /^[a-zA-Z0-9:]+[ \t]+/ { # Linux interface
                         }          split($1, fields, ":");
                         /^[ \t]+inet addr:/ { # Linux          iface = fields[1];
                                 split($0, fields, "[ \t:]+");          ipcount[iface]++;
                                 printf "IP_%s=\"%s\";   export IP_%s;\n", iface, fields[4], iface;          hwaddr[iface] = $NF;
                                 printf "Bcast_%s=\"%s\";        export Bcast_%s;\n", iface, fields[6], iface;          iface_count++;
                                 printf "Mask_%s=\"%s\"; export Mask_%s;\n", iface, fields[8],  iface;  }
                         }  
                         /^[a-zA-Z0-9]+:/ { # FreeBSD  /^[ \t]+inet addr:/ { # Linux IP address
                                 iface = $1;          split($0, fields, "[ \t:]+");
                                 sub(":", "", iface);          ip[iface, ipcount[iface]] = fields[4];
                                 interfaces = sprintf("%s %s", interfaces, iface);          bcast[iface] = fields[6]; # bad for loopback interface, but we don t need this
                                 printf "\nIFACE_%s=\"%s\";      export IFACE_%s;\n", iface, iface, iface;          idx = length(fields);
                         }          mask[iface] = fields[idx];
                         /^[ \t]+inet [0-9]+/ { # FreeBSD  }
                                 printf "IP_%s=\"%s\";   export IP_%s;\n", iface, $2, iface;  
                                 printf "Bcast_%s=\"%s\";        export Bcast_%s;\n", iface, $6, iface;  /^[ \t]+inet6 addr:/ { # Linux IPv6 address
                                 printf "Mask_%s=\"%s\"; export Mask_%s;\n", iface, $4,  iface;          split($0, fields, "[ \t]+");
                         }          ip6[iface] = fields[4];
                         /^[ \t]+ether/ { # FreeBSD          scope6[iface] = fields[5];
                                 printf "HWaddr_%s=\"%s\";       export HWaddr_%s;\n", iface, $2, iface;  }
                         }  
                         END { printf "\ninterfaces=\"%s\";      export interfaces;\n", interfaces; }  END {
           for (i in ip6)          { printf "IFACE_6_%s=\"%s\";    export IFACE_6_%s;\n",  i, ip6[i],              i; }
           for (i in scope6)       { printf "SCOPE_6_%s=\"%s\";    export SCOPE_6_%s;\n",  i, scope6[i],   i; }
           for (i in bcast)        { printf "Bcast_%s=\"%s\";              export Bcast_%s;\n",    i, bcast[i],    i; }
           for (i in mask)         { printf "Mask_%s=\"%s\";               export Mask_%s;\n",             i, mask[i],             i; }
           for (i in hwaddr)       { printf "HWaddr_%s=\"%s\";             export HWaddr_%s;\n",   i, hwaddr[i],   i; }
           for (i in ipcount)      { printf "IPcount_%s=\"%s\";    export IPcount_%s;\n",  i, ipcount[i],  i; }
           for (i in ipcount) {
                   printf "IP_%s=\"", i;
                   for (n = 1; n <= ipcount[i]; n++) {
                           printf "%s ", ip[i, n];
                   }
                   printf "\";     export IP_%s;\n", i;
           }
           printf "interfaces=\"";
           for (i in ipcount) { printf "%s ", i; }
           printf "\";     export interfaces;\n";
   }
         '`          '`
         eval "$parsed_interfaces";          eval "$parsed_interfaces";
   

Legend:
Removed from v.2.35  
changed lines
  Added in v.2.36

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