jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [trunk/] [modules/] [networks/] [setup] - Rev 16 Go to most recent revision

Compare with Previous - Blame - Download


#!/usr/bin/env sh

if ! [ -e settings ]; then OUTFILE="settings"; else OUTFILE="settings.new"; fi

#
# configure path to "iptables"
#
COMMAND=`locate iptables|grep bin/iptables\$|head -n 1`
if [ "$COMMAND" = "" ]; then COMMAND=`locate ipchains|grep bin/ipchains\$|head -n 1`; fi

cat > $OUTFILE <<EOF
# path to iptables or ipchains command
#
EOF
echo "IPTABLES=\"$COMMAND\"" >> $OUTFILE
echo >> $OUTFILE

cat >> $OUTFILE << EOF

# Which kind of legend shall be used
# set  STYLE="bytes"  to display all values in bytes/s
# set  STYLE="bits"   to display all values in bits/s
#
EOF

var=`cat settings|grep "^STYLE="`
if [ "$var" = "" ]; then var="STYLE=\"bytes\""; fi
echo "$var" >> $OUTFILE

#
# configure interfaces
#

INTERFACES=`netstat -i|grep [0-9] |awk '{print $1}'`

if [ "$OUTFILE" = "settings.new" ]; then
  INTIF=`cat settings | grep "^INTIF=" | sed -e "s/INTIF=//g ; s/\"//g"`
  EXTIF=`cat settings | grep "^EXTIF=" | sed -e "s/EXTIF=//g ; s/\"//g"`
else
  INTIF=""
  EXTIF=""
  fi 
 
if [ "$INTIF" = "" ] || [ "$EXTIF" = "" ]; then
  echo
  echo "Configuring local interfaces.
(i)nternal means an interface pointiong to your local machines (intranet)
(e)xternal means an interface connecten with the internet
(n)one means you don't want to account this interface.

Please answer these:"
  for nn in $INTERFACES; do
    where="x"
    while [ "$where" != "i" ] && [ "$where" != "e" ] && [ "$where" != "n" ]; do
      echo -n "found: $nn  -  (i)nternal, (e)xternal or (n)one ? "
      read where
      case $where in
        n) ;;
        i) INTIF="$INTIF,$nn" ;;
        e) EXTIF="$EXTIF,$nn" ;;
        *) echo "please answer with \"i\" \"e\" or \"n\"" ;;
        esac
      echo
      done
    done
  fi

cat >> $OUTFILE << EOF

# list of interfaces for internal / external hosts
#   INTIF=<interfaces connected to your local network (intranet)>
#   EXTIF=<interfaces connected to the internet>
#
EOF

echo "INTIF=\"$INTIF\"" |sed -e "s/=\",/=\"/g" >> $OUTFILE
echo "EXTIF=\"$EXTIF\"" |sed -e "s/=\",/=\"/g" >> $OUTFILE
echo >> $OUTFILE

#
# write template for the rest
#
echo "# list hosts on internal devices here, multiple lines of the form:" >> $OUTFILE
echo "#  DEVINT=\"<host>,<description>\"" >> $OUTFILE
echo "#  DEVINT=\"!<host>,<description>\"" >> $OUTFILE
echo "#" >> $OUTFILE
if [ "$OUTFILE" = "settings.new" ]; then
  cat settings|grep "^DEVINT=" >> $OUTFILE
  fi
echo >> $OUTFILE

echo "# list hosts on external devices here, multiple lines of the form:" >> $OUTFILE
echo "#  DEVEXT=\"<host>,<description>\"" >> $OUTFILE
echo "#  DEVEXT=\"!<host>,<description>\"" >> $OUTFILE
echo "#" >> $OUTFILE
if [ "$OUTFILE" = "settings.new" ]; then
  cat settings|grep "^DEVEXT=" >> $OUTFILE
  fi

echo
echo "Please check the settings file and adapt it to satisfy your needs."
echo "maybe you have to configure some destination networks."
if [ "$OUTFILE" = "settings.new" ]; then
  mkdir -p backup
  NOW=`date +%Y%m%d-%H%M%S`
  mv -f settings backup/settings-$NOW
  mv -f settings.new settings
  echo "a backup of the previous settings has been saved."
  fi
echo


Powered by WebSVN 2.2.1