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.83 and 2.91

version 2.83, 2011/11/18 23:49:00 version 2.91, 2012/02/14 22:52:12
Line 1 
Line 1 
 #!/bin/bash  #!/bin/bash
   
 ### BEGIN INIT INFO  ### BEGIN INIT INFO
 # Provides:             firewall  # Provides:          firewall
 # Required-Start:       networking  # Required-Start:    $network
 # Required-Stop:  # Required-Stop:     $remote_fs
 # Default-Start:        S  # Default-Start:     S
 # Default-Stop:  # Default-Stop:      0 6
 # Short-Description:    firewalling rules  # Short-Description: Starts firewall
   # Description:       Handle universal firewall script by Platon Group
   #                    http://platon.sk/cvs/cvs.php/scripts/shell/firewall/
   # Author:            Lubomir Host <rajo@platon.sk>
   # Copyright:         (c) 2003-2011 Platon Group
 ### END INIT INFO  ### END INIT INFO
   
 #  #
Line 18 
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.82 2011-11-18 23:26:18 rajo Exp $  # $Platon: scripts/shell/firewall/fw-universal.sh,v 2.90 2012-02-11 19:38:51 rajo Exp $
 #  #
 # Changelog:  # Changelog:
 # 2003-10-24 - created  # 2003-10-24 - created
 # 2011-07-20 - implemented XEN_MODE  # 2011-07-20 - implemented XEN_MODE
 #  #
   
 ### BEGIN INIT INFO  
 # Provides:          firewall  
 # Required-Start:    $network $remote_fs  
 # Required-Stop:     $network $remote_fs  
 # Default-Start:     2 3 4 5  
 # Default-Stop:      0 1 6  
 # Short-Description: Starts firewall  
 # Description:       Handle universal firewall script by Platon Group  
 #                    http://platon.sk/cvs/cvs.php/scripts/shell/firewall/  
 # Author:            Lubomir Host <rajo@platon.sk>  
 # Copyright:         (c) 2003-2011 Platon Group  
 ### END INIT INFO  
   
 umask 077 # security  umask 077 # security
   
Line 84  IPTABLES="${IPTABLES:=$DEBUG/sbin/iptabl
Line 76  IPTABLES="${IPTABLES:=$DEBUG/sbin/iptabl
 IPTABLES_SAVE="${IPTABLES_SAVE:=$DEBUG/sbin/iptables-save}"  IPTABLES_SAVE="${IPTABLES_SAVE:=$DEBUG/sbin/iptables-save}"
 IPTABLES_RESTORE="${IPTABLES_RESTORE:=$DEBUG/sbin/iptables-restore}"  IPTABLES_RESTORE="${IPTABLES_RESTORE:=$DEBUG/sbin/iptables-restore}"
   
   IPTABLES_TABLES="${IPTABLES_TABLES:=filter nat mangle}"
   
   
 if [ "x$LOGGING" = "xoff" ]; then  if [ "x$LOGGING" = "xoff" ]; then
         IPTABLES_LOG=": log turned off"          IPTABLES_LOG=": log turned off"
 else  else
Line 99  PERL="${PERL:=/usr/bin/perl}"
Line 94  PERL="${PERL:=/usr/bin/perl}"
 # shaping  # shaping
 TC="${TC:=/sbin/tc}"  TC="${TC:=/sbin/tc}"
   
   # update script
   UPDATE_SCRIPT="${UPDATE_SCRIPT:=update_from_cvs}"
   
 # loopback interface  # loopback interface
 LO_IFACE="${LO_IFACE:=lo}"  LO_IFACE="${LO_IFACE:=lo}"
 # Hide NAT clients behind firewall  # Hide NAT clients behind firewall
Line 290  remove_chains()
Line 288  remove_chains()
                 $IPTABLES --flush spoof                  $IPTABLES --flush spoof
                 # TODO!!!                  # TODO!!!
         else          else
                 for table in filter nat mangle; do                  for table in $IPTABLES_TABLES; do
                         $IPTABLES -t $table -F # clear all chains                          $IPTABLES -t $table -F # clear all chains
                         $IPTABLES -t $table -X # remove all chains                          $IPTABLES -t $table -X # remove all chains
                         $IPTABLES -t $table -Z # zero counts                          $IPTABLES -t $table -Z # zero counts
Line 771  drop_input()
Line 769  drop_input()
         if [ ! -z "$ALL_DROP_INPUT_TCP" ]; then          if [ ! -z "$ALL_DROP_INPUT_TCP" ]; then
                 print_info -en "Drop ALL INPUT TCP connections on ports:"                  print_info -en "Drop ALL INPUT TCP connections on ports:"
                 for port in $ALL_DROP_INPUT_TCP; do                  for port in $ALL_DROP_INPUT_TCP; do
                           echo $port | grep -q ,
                           multiport="$?";
                           if [ "$multiport" -eq 0 ]; then
                                   port_rule="--match multiport --dports $port"
                           else
                                   port_rule="--dport $port"
                           fi
                         for riface in $REAL_INTERFACES; do                          for riface in $REAL_INTERFACES; do
                                 print_info -en " $port($riface)"                                  print_info -en " $port($riface)"
                                 $IPTABLES -A INPUT -i $riface -p TCP --dport $port -j DROP                                  $IPTABLES -A INPUT -i $riface -p TCP $port_rule -j DROP
                         done                          done
                 done                  done
                 print_info " done."                  print_info " done."
Line 781  drop_input()
Line 786  drop_input()
         if [ ! -z "$ALL_DROP_INPUT_UDP" ]; then          if [ ! -z "$ALL_DROP_INPUT_UDP" ]; then
                 print_info -en "Drop ALL INPUT UDP connections on ports:"                  print_info -en "Drop ALL INPUT UDP connections on ports:"
                 for port in $ALL_DROP_INPUT_UDP; do                  for port in $ALL_DROP_INPUT_UDP; do
                           echo $port | grep -q ,
                           multiport="$?";
                           if [ "$multiport" -eq 0 ]; then
                                   port_rule="--match multiport --dports $port"
                           else
                                   port_rule="--dport $port"
                           fi
                         for riface in $REAL_INTERFACES; do                          for riface in $REAL_INTERFACES; do
                                 print_info -en " $port($riface)"                                  print_info -en " $port($riface)"
                                 $IPTABLES -A INPUT -i $riface -p UDP --dport $port -j DROP                                  $IPTABLES -A INPUT -i $riface -p UDP $port_rule -j DROP
                         done                          done
                 done                  done
                 print_info " done."                  print_info " done."
Line 791  drop_input()
Line 803  drop_input()
         if [ ! -z "$REAL_DROP_INPUT_TCP" ]; then          if [ ! -z "$REAL_DROP_INPUT_TCP" ]; then
                 print_info -en "Drop REAL all INPUT TCP connections for ALL interfaces on ports:"                  print_info -en "Drop REAL all INPUT TCP connections for ALL interfaces on ports:"
                 for port in $REAL_DROP_INPUT_TCP; do                  for port in $REAL_DROP_INPUT_TCP; do
                           echo $port | grep -q ,
                           multiport="$?";
                           if [ "$multiport" -eq 0 ]; then
                                   port_rule="--match multiport --dports $port"
                           else
                                   port_rule="--dport $port"
                           fi
                         print_info -en " $port(ALL)"                          print_info -en " $port(ALL)"
                         $IPTABLES -A INPUT -p TCP --dport $port -j DROP                          $IPTABLES -A INPUT -p TCP $port_rule -j DROP
                 done                  done
                 print_info " done."                  print_info " done."
         fi          fi
         if [ ! -z "$REAL_DROP_INPUT_UDP" ]; then          if [ ! -z "$REAL_DROP_INPUT_UDP" ]; then
                 print_info -en "Drop REAL all INPUT UDP connections for ALL interfaces on ports:"                  print_info -en "Drop REAL all INPUT UDP connections for ALL interfaces on ports:"
                 for port in $REAL_DROP_INPUT_UDP; do                  for port in $REAL_DROP_INPUT_UDP; do
                           echo $port | grep -q ,
                           multiport="$?";
                           if [ "$multiport" -eq 0 ]; then
                                   port_rule="--match multiport --dports $port"
                           else
                                   port_rule="--dport $port"
                           fi
                         print_info -en " $port(ALL)"                          print_info -en " $port(ALL)"
                         $IPTABLES -A INPUT -p UDP --dport $port -j DROP                          $IPTABLES -A INPUT -p UDP $port_rule -j DROP
                 done                  done
                 print_info " done."                  print_info " done."
         fi          fi
Line 811  reject_input()
Line 837  reject_input()
         if [ ! -z "$ALL_REJECT_INPUT_TCP" ]; then          if [ ! -z "$ALL_REJECT_INPUT_TCP" ]; then
                 print_info -en "Reject ALL INPUT TCP connections on ports:"                  print_info -en "Reject ALL INPUT TCP connections on ports:"
                 for port in $ALL_REJECT_INPUT_TCP; do                  for port in $ALL_REJECT_INPUT_TCP; do
                           echo $port | grep -q ,
                           multiport="$?";
                           if [ "$multiport" -eq 0 ]; then
                                   port_rule="--match multiport --dports $port"
                           else
                                   port_rule="--dport $port"
                           fi
                         for riface in $REAL_INTERFACES; do                          for riface in $REAL_INTERFACES; do
                                 print_info -en " $port($riface)"                                  print_info -en " $port($riface)"
                                 $IPTABLES -A INPUT -i $riface -p TCP --dport $port -j REJECT --reject-with $REJECT_WITH                                  $IPTABLES -A INPUT -i $riface -p TCP $port_rule -j REJECT --reject-with $REJECT_WITH
                         done                          done
                 done                  done
                 print_info " done."                  print_info " done."
Line 821  reject_input()
Line 854  reject_input()
         if [ ! -z "$ALL_REJECT_INPUT_UDP" ]; then          if [ ! -z "$ALL_REJECT_INPUT_UDP" ]; then
                 print_info -en "Reject ALL INPUT UDP connections on ports:"                  print_info -en "Reject ALL INPUT UDP connections on ports:"
                 for port in $ALL_REJECT_INPUT_UDP; do                  for port in $ALL_REJECT_INPUT_UDP; do
                           echo $port | grep -q ,
                           multiport="$?";
                           if [ "$multiport" -eq 0 ]; then
                                   port_rule="--match multiport --dports $port"
                           else
                                   port_rule="--dport $port"
                           fi
                         for riface in $REAL_INTERFACES; do                          for riface in $REAL_INTERFACES; do
                                 print_info -en " $port($riface)"                                  print_info -en " $port($riface)"
                                 $IPTABLES -A INPUT -i $riface -p UDP --dport $port -j REJECT --reject-with $REJECT_WITH                                  $IPTABLES -A INPUT -i $riface -p UDP $port_rule -j REJECT --reject-with $REJECT_WITH
                         done                          done
                 done                  done
                 print_info " done."                  print_info " done."
Line 831  reject_input()
Line 871  reject_input()
         if [ ! -z "$REAL_REJECT_INPUT_TCP" ]; then          if [ ! -z "$REAL_REJECT_INPUT_TCP" ]; then
                 print_info -en "Reject REAL all INPUT TCP connections for ALL interfaces on ports:"                  print_info -en "Reject REAL all INPUT TCP connections for ALL interfaces on ports:"
                 for port in $REAL_REJECT_INPUT_TCP; do                  for port in $REAL_REJECT_INPUT_TCP; do
                           echo $port | grep -q ,
                           multiport="$?";
                           if [ "$multiport" -eq 0 ]; then
                                   port_rule="--match multiport --dports $port"
                           else
                                   port_rule="--dport $port"
                           fi
                         print_info -en " $port(ALL)"                          print_info -en " $port(ALL)"
                         $IPTABLES -A INPUT -p TCP --dport $port -j REJECT --reject-with $REJECT_WITH                          $IPTABLES -A INPUT -p TCP $port_rule -j REJECT --reject-with $REJECT_WITH
                 done                  done
                 print_info " done."                  print_info " done."
         fi          fi
         if [ ! -z "$REAL_REJECT_INPUT_UDP" ]; then          if [ ! -z "$REAL_REJECT_INPUT_UDP" ]; then
                 print_info -en "Reject REAL all INPUT UDP connections for ALL interfaces on ports:"                  print_info -en "Reject REAL all INPUT UDP connections for ALL interfaces on ports:"
                 for port in $REAL_REJECT_INPUT_UDP; do                  for port in $REAL_REJECT_INPUT_UDP; do
                           echo $port | grep -q ,
                           multiport="$?";
                           if [ "$multiport" -eq 0 ]; then
                                   port_rule="--match multiport --dports $port"
                           else
                                   port_rule="--dport $port"
                           fi
                         for riface in $REAL_INTERFACES; do                          for riface in $REAL_INTERFACES; do
                                 print_info -en " $port(ALL)"                                  print_info -en " $port(ALL)"
                                 $IPTABLES -A INPUT -p UDP --dport $port -j REJECT --reject-with $REJECT_WITH                                  $IPTABLES -A INPUT -p UDP $port_rule -j REJECT --reject-with $REJECT_WITH
                         done                          done
                 done                  done
                 print_info " done."                  print_info " done."
Line 864  allow_input()
Line 918  allow_input()
                         fi                          fi
                         for iface in $INTERFACES; do                          for iface in $INTERFACES; do
                                 riface="IFname_$iface";                                  riface="IFname_$iface";
                                 print_info -en " $port($iface)"`[ ! -z $src_ip ] && echo "[$src_ip]"`                                  print_info -en " $port($iface)"`[ ! -z "$src_ip" ] && echo "[$src_ip]"`
                                 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 891  allow_input()
Line 945  allow_input()
                         fi                          fi
                         for iface in $INTERFACES; do                          for iface in $INTERFACES; do
                                 riface="IFname_$iface";                                  riface="IFname_$iface";
                                 print_info -en " $port($iface)"`[ ! -z $src_ip ] && echo "[$src_ip]"`                                  print_info -en " $port($iface)"`[ ! -z "$src_ip" ] && echo "[$src_ip]"`
                                 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 914  allow_input()
Line 968  allow_input()
                 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; }'`
                         print_info -en " $port(ALL)"`[ ! -z $src_ip ] && echo "[$src_ip]"`                          print_info -en " $port(ALL)"`[ ! -z "$src_ip" ] && echo "[$src_ip]"`
                         echo $port | grep -q ,                          echo $port | grep -q ,
                         multiport="$?";                          multiport="$?";
                         if [ "$multiport" -eq 0 ]; then                          if [ "$multiport" -eq 0 ]; then
Line 935  allow_input()
Line 989  allow_input()
                 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; }'`
                         print_info -en " $port(ALL)"`[ ! -z $src_ip ] && echo "[$src_ip]"`                          print_info -en " $port(ALL)"`[ ! -z "$src_ip" ] && echo "[$src_ip]"`
                         echo $port | grep -q ,                          echo $port | grep -q ,
                         multiport="$?";                          multiport="$?";
                         if [ "$multiport" -eq 0 ]; then                          if [ "$multiport" -eq 0 ]; then
Line 1005  allow_input()
Line 1059  allow_input()
                         for port in $REJECT_INPUT_TCP; do                          for port in $REJECT_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; }'`
                                 print_info -en " $port"`[ ! -z $src_ip ] && echo "[$src_ip]"`                                  print_info -en " $port"`[ ! -z "$src_ip" ] && echo "[$src_ip]"`
                                 echo $port | grep -q ,                                  echo $port | grep -q ,
                                 multiport="$?";                                  multiport="$?";
                                 if [ "$multiport" -eq 0 ]; then                                  if [ "$multiport" -eq 0 ]; then
Line 1014  allow_input()
Line 1068  allow_input()
                                         port_rule="--dport $port"                                          port_rule="--dport $port"
                                 fi                                  fi
                                 for ip in ${!IPS}; do                                  for ip in ${!IPS}; do
                                         if [ -z $src_ip ]; then                                          if [ -z "$src_ip" ]; then
                                                 $IPTABLES -A INPUT -i ${!riface} -d $ip -p TCP $port_rule -j REJECT --reject-with $REJECT_WITH                                                  $IPTABLES -A INPUT -i ${!riface} -d $ip -p TCP $port_rule -j REJECT --reject-with $REJECT_WITH
                                         else                                          else
                                                 $IPTABLES -A INPUT -i ${!riface} -s $src_ip -d $ip -p TCP $port_rule -j REJECT --reject-with $REJECT_WITH                                                  $IPTABLES -A INPUT -i ${!riface} -s $src_ip -d $ip -p TCP $port_rule -j REJECT --reject-with $REJECT_WITH
Line 1029  allow_input()
Line 1083  allow_input()
                         for port in $REJECT_INPUT_UDP; do                          for port in $REJECT_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; }'`
                                 print_info -en " $port"`[ ! -z $src_ip ] && echo "[$src_ip]"`                                  print_info -en " $port"`[ ! -z "$src_ip" ] && echo "[$src_ip]"`
                                 echo $port | grep -q ,                                  echo $port | grep -q ,
                                 multiport="$?";                                  multiport="$?";
                                 if [ "$multiport" -eq 0 ]; then                                  if [ "$multiport" -eq 0 ]; then
Line 1038  allow_input()
Line 1092  allow_input()
                                         port_rule="--dport $port"                                          port_rule="--dport $port"
                                 fi                                  fi
                                 for ip in ${!IPS}; do                                  for ip in ${!IPS}; do
                                         if [ -z $src_ip ]; then                                          if [ -z "$src_ip" ]; then
                                                 $IPTABLES -A INPUT -i ${!riface} -d $ip -p UDP $port_rule -j REJECT --reject-with $REJECT_WITH                                                  $IPTABLES -A INPUT -i ${!riface} -d $ip -p UDP $port_rule -j REJECT --reject-with $REJECT_WITH
                                         else                                          else
                                                 $IPTABLES -A INPUT -i ${!riface} -s $src_ip -d $ip -p UDP $port_rule -j REJECT --reject-with $REJECT_WITH                                                  $IPTABLES -A INPUT -i ${!riface} -s $src_ip -d $ip -p UDP $port_rule -j REJECT --reject-with $REJECT_WITH
Line 1052  allow_input()
Line 1106  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 -en "$iface: Accepting INPUT TCP connections on ports:"
                           counter=0;
                         for port in $ACCEPT_INPUT_TCP; do                          for port in $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 [ -n "$src_ip" -a "$port" = "0" ]; then                                  if [ -n "$src_ip" -a "$port" = "0" ]; then
                                         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;
                                 echo $port | grep -q ,                                  echo $port | grep -q ,
                                 multiport="$?";                                  multiport="$?";
                                 if [ "$multiport" -eq 0 ]; then                                  if [ "$multiport" -eq 0 ]; then
Line 1067  allow_input()
Line 1123  allow_input()
                                         port_rule="--dport $port"                                          port_rule="--dport $port"
                                 fi                                  fi
                                 for ip in ${!IPS}; do                                  for ip in ${!IPS}; do
                                         if [ -z $src_ip ]; then                                          if [ -z "$src_ip" ]; then
                                                 $IPTABLES -A INPUT -i ${!riface} -d $ip -p TCP $port_rule -j ACCEPT                                                  $IPTABLES -A INPUT -i ${!riface} -d $ip -p TCP $port_rule -j ACCEPT
                                         else                                          else
                                                 if [ "$port" = "ALL" ]; then                                                  if [ "$port" = "ALL" ]; then
Line 1096  allow_input()
Line 1152  allow_input()
                                 else                                  else
                                         port_rule="--dport $port"                                          port_rule="--dport $port"
                                 fi                                  fi
                                 print_info -en " $port"`[ ! -z $src_ip ] && echo "[$src_ip]"`                                  print_info -en " $port"`[ ! -z "$src_ip" ] && echo "[$src_ip]"`
                                 #$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
                                 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
                                 else                                  else
                                         for ip in ${!IPS}; do                                          for ip in ${!IPS}; do
                                                 if [ -z $src_ip ]; then                                                  if [ -z "$src_ip" ]; then
                                                         $IPTABLES -A INPUT -i ${!riface} -d $ip -p UDP $port_rule -j ACCEPT                                                          $IPTABLES -A INPUT -i ${!riface} -d $ip -p UDP $port_rule -j ACCEPT
                                                 else                                                  else
                                                         if [ "$port" = "ALL" ]; then                                                          if [ "$port" = "ALL" ]; then
Line 1339  shaping_on()
Line 1395  shaping_on()
 { # {{{  { # {{{
   
         mark_idx=1          mark_idx=1
         if [ ! -z $SHAPING_IFACE ]; then          if [ ! -z "$SHAPING_IFACE" ]; then
                 for iface in $SHAPING_IFACE; do                  for iface in $SHAPING_IFACE; do
                         echo "Shaping for interface $iface"                          echo "Shaping for interface $iface"
                         shaping_classes="${iface}_SHAPING_CLASSES"                          shaping_classes="${iface}_SHAPING_CLASSES"
Line 1353  shaping_on()
Line 1409  shaping_on()
                                 burst="${iface}_SHAPING_BURST_${class}"                                  burst="${iface}_SHAPING_BURST_${class}"
                                 netmask="${iface}_SHAPING_NETMASK_${class}"                                  netmask="${iface}_SHAPING_NETMASK_${class}"
                                 echo -e "\tshaping \"$class\" traffic: rate=${!rate} burst=${!burst} netmask=${!netmask}"                                  echo -e "\tshaping \"$class\" traffic: rate=${!rate} burst=${!burst} netmask=${!netmask}"
                                 if [ -z ${!netmask} ]; then                                  if [ -z "${!netmask}" ]; then
                                         $IPTABLES -t mangle -A OUTPUT -j MARK --set-mark 0x$mark_idx                                          $IPTABLES -t mangle -A OUTPUT -j MARK --set-mark 0x$mark_idx
                                 else                                  else
                                         $IPTABLES -t mangle -A OUTPUT -d ${!netmask} -j MARK --set-mark 0x$mark_idx                                          $IPTABLES -t mangle -A OUTPUT -d ${!netmask} -j MARK --set-mark 0x$mark_idx
                                 fi                                  fi
   
                                 if [ -z ${!rate} ]; then                                  if [ -z "${!rate}" ]; then
                                         # SFQ for local traffic                                          # SFQ for local traffic
                                         $TC qdisc add dev $iface parent 1:$mark_idx handle $((10 + $mark_idx)): sfq perturb 10                                          $TC qdisc add dev $iface parent 1:$mark_idx handle $((10 + $mark_idx)): sfq perturb 10
                                 else                                  else
Line 1377  shaping_on()
Line 1433  shaping_on()
   
 shaping_off()  shaping_off()
 { # {{{  { # {{{
         if [ ! -z $SHAPING_IFACE ]; then          if [ ! -z "$SHAPING_IFACE" ]; then
                 echo -en "Shaping turned off for interface"                  echo -en "Shaping turned off for interface"
                 for iface in $SHAPING_IFACE; do                  for iface in $SHAPING_IFACE; do
                         echo -en " $iface"                          echo -en " $iface"
Line 1389  shaping_off()
Line 1445  shaping_off()
   
 shaping_status()  shaping_status()
 { # {{{  { # {{{
         if [ ! -z $SHAPING_IFACE ]; then          if [ ! -z "$SHAPING_IFACE" ]; then
                 echo "# Shaping status: "                  echo "# Shaping status: "
                 $TC qdisc list                  $TC qdisc list
         else          else
Line 1401  shaping_status()
Line 1457  shaping_status()
   
 add_banned_ip()  add_banned_ip()
 { # {{{  { # {{{
         echo "# `date '+%Y-%m-%d %X' ` - ${SSH_CLIENT:=local}" >> $DEFAULT_FIREWALL_CONFIG_DIR/BANNED_IP.conf          echo "# `date '+%Y-%m-%d %X' `" >> $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
                 print_info "Reading banned IP's from STDIN:"                  #print_info "Reading banned IP's from STDIN:"
                 cat >> $TMPFILE                  cat >> $TMPFILE
         else          else
                 for IP in $*; do                  for IP in $*; do
Line 1414  add_banned_ip()
Line 1470  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()
Line 1424  deploy_block()
Line 1482  deploy_block()
         fi          fi
         print_info "Deploying to local rules ..."          print_info "Deploying to local rules ..."
         add_banned_ip $*          add_banned_ip $*
         # start the some script twice to refresh rules (new blocked IP's)          # start the same script twice to refresh rules (new blocked IP's)
         QUIET=yes $0 start          QUIET=yes $0 start
         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
         for i in $*; do          for i in $*; do
                 echo $i >> $TMPFILE;                  echo "block $i" >> $TMPFILE;
         done          done
         while read conn keyfile          while read conn keyfile
         do          do
            case "$conn" in                  case "$conn" in
                    ""|\#*)                          ""|\#*)
                            continue                                  continue
                            ;;                                  ;;
            esac                  esac
            print_info "Deploying to $conn ...";                  print_info "=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
            cat $TMPFILE | ssh -i $keyfile $conn $0 block                  print_info "Deploying to $conn ...";
                   cat $TMPFILE | ssh -i $keyfile $conn $0 remote
         done < $DEFAULT_FIREWALL_CONFIG_DIR/deploy-servers.list          done < $DEFAULT_FIREWALL_CONFIG_DIR/deploy-servers.list
         rm -f $TMPFILE          rm -f $TMPFILE
 } # }}}  } # }}}
   
   update_from_cvs()
   { # {{{
           cd /etc/firewall && cvs up -d
   } # }}}
   
   update()
   { # {{{
           $UPDATE_SCRIPT
   } # }}}
   
   deploy_update()
   { # {{{
           print_info "Updating local firewall ..."
           $0 update
   
           # start the same script twice to refresh rules (updated scripts and configs)
           QUIET=yes $0 start
           while read conn keyfile
           do
                   case "$conn" in
                           ""|\#*)
                                   continue
                                   ;;
                   esac
   
                   print_info "=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
                   print_info "Updating $conn ...";
                   echo "update" | ssh -i $keyfile $conn $0 remote
           done < $DEFAULT_FIREWALL_CONFIG_DIR/deploy-servers.list
   } # }}}
   
   remote()
   { # {{{
           while read comnd par
           do
                   case "$comnd" in
                           block)
                                   echo "Blocking '$par'..."
                                   add_banned_ip $par
                                   ;;
                           update)
                                   echo "Updating firewall scripts..."
                                   update
                                   ;;
                           ""|\#*)
                                   echo "Line '$comnd $par' ignored"
                                   continue
                                   ;;
                   esac
           done
   } # }}}
   
 # 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 1682  case "$1" in
Line 1793  case "$1" in
                 # start the some script twice to refresh rules (new blocked IP's)                  # start the some script twice to refresh rules (new blocked IP's)
                 QUIET=yes $0 start;                  QUIET=yes $0 start;
                 ;;                  ;;
           update)
                   update;
                   ;;
         deploy-block)          deploy-block)
                 shift;                  shift;
                 deploy_block $*;                  deploy_block $*;
                 ;;                  ;;
           deploy-update)
                   deploy_update;
                   ;;
           remote)
                   remote;
                   ;;
         *)          *)
                 echo "Usage: $0 {start|stop|really-off|status|purge|block|deploy-block}" >&2                  echo "Usage: $0 {start|stop|really-off|status|purge|block|deploy-block|deploy-update|update}" >&2
                 exit 1                  exit 1
                 ;;                  ;;
 esac  esac

Legend:
Removed from v.2.83  
changed lines
  Added in v.2.91

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