| 1 | 1 | simandl | #!/usr/bin/env sh |
| 2 | | | |
| 3 | | | if ! [ -e settings ]; then OUTFILE="settings"; else OUTFILE="settings.new"; fi |
| 4 | | | |
| 5 | | | # |
| 6 | | | # configure path to "iptables" |
| 7 | | | # |
| 8 | | | COMMAND=`locate iptables|grep bin/iptables\$|head -n 1` |
| 9 | | | if [ "$COMMAND" = "" ]; then COMMAND=`locate ipchains|grep bin/ipchains\$|head -n 1`; fi |
| 10 | | | |
| 11 | | | cat > $OUTFILE <<EOF |
| 12 | | | # path to iptables or ipchains command |
| 13 | | | # |
| 14 | | | EOF |
| 15 | | | echo "IPTABLES=\"$COMMAND\"" >> $OUTFILE |
| 16 | | | echo >> $OUTFILE |
| 17 | | | |
| 18 | | | cat >> $OUTFILE << EOF |
| 19 | | | |
| 20 | | | # Which kind of legend shall be used |
| 21 | | | # set STYLE="bytes" to display all values in bytes/s |
| 22 | | | # set STYLE="bits" to display all values in bits/s |
| 23 | | | # |
| 24 | | | EOF |
| 25 | | | |
| 26 | | | var=`cat settings|grep "^STYLE="` |
| 27 | | | if [ "$var" = "" ]; then var="STYLE=\"bytes\""; fi |
| 28 | | | echo "$var" >> $OUTFILE |
| 29 | | | |
| 30 | | | # |
| 31 | | | # configure interfaces |
| 32 | | | # |
| 33 | | | |
| 34 | | | INTERFACES=`netstat -i|grep [0-9] |awk '{print $1}'` |
| 35 | | | |
| 36 | | | if [ "$OUTFILE" = "settings.new" ]; then |
| 37 | | | INTIF=`cat settings | grep "^INTIF=" | sed -e "s/INTIF=//g ; s/\"//g"` |
| 38 | | | EXTIF=`cat settings | grep "^EXTIF=" | sed -e "s/EXTIF=//g ; s/\"//g"` |
| 39 | | | else |
| 40 | | | INTIF="" |
| 41 | | | EXTIF="" |
| 42 | | | fi |
| 43 | | | |
| 44 | | | if [ "$INTIF" = "" ] || [ "$EXTIF" = "" ]; then |
| 45 | | | echo |
| 46 | | | echo "Configuring local interfaces. |
| 47 | | | (i)nternal means an interface pointiong to your local machines (intranet) |
| 48 | | | (e)xternal means an interface connecten with the internet |
| 49 | | | (n)one means you don't want to account this interface. |
| 50 | | | |
| 51 | | | Please answer these:" |
| 52 | | | for nn in $INTERFACES; do |
| 53 | | | where="x" |
| 54 | | | while [ "$where" != "i" ] && [ "$where" != "e" ] && [ "$where" != "n" ]; do |
| 55 | | | echo -n "found: $nn - (i)nternal, (e)xternal or (n)one ? " |
| 56 | | | read where |
| 57 | | | case $where in |
| 58 | | | n) ;; |
| 59 | | | i) INTIF="$INTIF,$nn" ;; |
| 60 | | | e) EXTIF="$EXTIF,$nn" ;; |
| 61 | | | *) echo "please answer with \"i\" \"e\" or \"n\"" ;; |
| 62 | | | esac |
| 63 | | | echo |
| 64 | | | done |
| 65 | | | done |
| 66 | | | fi |
| 67 | | | |
| 68 | | | cat >> $OUTFILE << EOF |
| 69 | | | |
| 70 | | | # list of interfaces for internal / external hosts |
| 71 | | | # INTIF=<interfaces connected to your local network (intranet)> |
| 72 | | | # EXTIF=<interfaces connected to the internet> |
| 73 | | | # |
| 74 | | | EOF |
| 75 | | | |
| 76 | | | echo "INTIF=\"$INTIF\"" |sed -e "s/=\",/=\"/g" >> $OUTFILE |
| 77 | | | echo "EXTIF=\"$EXTIF\"" |sed -e "s/=\",/=\"/g" >> $OUTFILE |
| 78 | | | echo >> $OUTFILE |
| 79 | | | |
| 80 | | | # |
| 81 | | | # write template for the rest |
| 82 | | | # |
| 83 | | | echo "# list hosts on internal devices here, multiple lines of the form:" >> $OUTFILE |
| 84 | | | echo "# DEVINT=\"<host>,<description>\"" >> $OUTFILE |
| 85 | | | echo "# DEVINT=\"!<host>,<description>\"" >> $OUTFILE |
| 86 | | | echo "#" >> $OUTFILE |
| 87 | | | if [ "$OUTFILE" = "settings.new" ]; then |
| 88 | | | cat settings|grep "^DEVINT=" >> $OUTFILE |
| 89 | | | fi |
| 90 | | | echo >> $OUTFILE |
| 91 | | | |
| 92 | | | echo "# list hosts on external devices here, multiple lines of the form:" >> $OUTFILE |
| 93 | | | echo "# DEVEXT=\"<host>,<description>\"" >> $OUTFILE |
| 94 | | | echo "# DEVEXT=\"!<host>,<description>\"" >> $OUTFILE |
| 95 | | | echo "#" >> $OUTFILE |
| 96 | | | if [ "$OUTFILE" = "settings.new" ]; then |
| 97 | | | cat settings|grep "^DEVEXT=" >> $OUTFILE |
| 98 | | | fi |
| 99 | | | |
| 100 | | | echo |
| 101 | | | echo "Please check the settings file and adapt it to satisfy your needs." |
| 102 | | | echo "maybe you have to configure some destination networks." |
| 103 | | | if [ "$OUTFILE" = "settings.new" ]; then |
| 104 | | | mkdir -p backup |
| 105 | | | NOW=`date +%Y%m%d-%H%M%S` |
| 106 | | | mv -f settings backup/settings-$NOW |
| 107 | | | mv -f settings.new settings |
| 108 | | | echo "a backup of the previous settings has been saved." |
| 109 | | | fi |
| 110 | | | echo |
| 111 | | | |