Firewall-SOSDG/tools/configure-firewall

83 lines
2.8 KiB
Plaintext
Raw Permalink Normal View History

2010-11-18 12:03:57 -07:00
#!/bin/bash
# By Brielle Bruns <bruns@2mbit.com>
# URL: http://www.sosdg.org/freestuff/firewall
# License: GPLv3
#
# Copyright (C) 2009 - 2010 Brielle Bruns
# Copyright (C) 2009 - 2010 The Summit Open Source Development Group
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
CONFIGTOOL_VER="0.1"
WHIPTAIL="/usr/bin/whiptail"
TMPCONFIG=`mktemp`
2010-11-18 12:23:49 -07:00
WHICH="/usr/bin/which"
AUTOCONFIG_BIN="iptables:IPTABLES ip6tables:IP6TABLES modprobe:MODPROBE"
2010-11-18 12:03:57 -07:00
# These are string variables
2010-11-18 12:54:43 -07:00
TOOL_TITLE="Welcome to the Firewall/SOSDG Config Tool v${CONFIGTOOL_VER}"
2010-11-18 12:30:35 -07:00
WELCOME_BODY="This tool is a quick way to do a basic setup of the firewall script.\n\nThe results of this tool will be output to a file of your choosing at the end of configuration.\nContinue?"
2010-11-18 12:23:49 -07:00
AUTOCONFIG_PATHS="Would you like to try to configure paths of important programs automatically?"
2010-11-18 12:54:43 -07:00
FAILED_BINS="The following binaries were not found on this system:"
FAILED_BINS_FOOT="Please edit the config file by hand and put in the proper path."
2010-11-18 12:23:49 -07:00
2010-11-18 12:03:57 -07:00
if [ ! -x $WHIPTAIL ]; then
echo "Error: please make sure you have whiptail installed, and the WHIPTAIL variable
is set correctly in the tool."
2010-11-18 12:23:49 -07:00
rm -f "$TMPCONFIG"
2010-11-18 12:03:57 -07:00
exit 1
fi
2010-11-18 12:54:43 -07:00
if ! ( $WHIPTAIL --title "${TOOL_TITLE}" --yesno "${WELCOME_BODY}" 12 70 --no-button "Quit" ); then
2010-11-18 12:03:57 -07:00
echo "Quitting config tool."
2010-11-18 12:23:49 -07:00
rm -f "$TMPCONFIG"
exit 1
fi
if [ -w "$TMPCONFIG" ]; then
2010-11-18 12:23:49 -07:00
echo "# Automatically generated config file, please check before actually using." >"${TMPCONFIG}"
else
echo "Error: could not write tmp file for config generation."
2010-11-18 12:03:57 -07:00
exit 1
2010-11-18 12:23:49 -07:00
fi
2010-11-18 12:54:43 -07:00
if ( $WHIPTAIL --title "${TOOL_TITLE}" --yesno "${AUTOCONFIG_PATHS}" 10 40 ); then
unset FAILED_CMD_PATH
2010-11-18 12:23:49 -07:00
for i in $AUTOCONFIG_BIN; do
IFS_OLD=${IFS};IFS=:
BIN_PATH=($i)
IFS=${IFS_OLD}
if ( ${WHICH} ${BIN_PATH[0]} &>/dev/null ); then
2010-11-18 12:23:49 -07:00
BIN_FULL="`${WHICH} ${BIN_PATH[0]}`"
2010-11-18 12:37:45 -07:00
echo "${BIN_PATH[1]}=\"${BIN_FULL}\"" >>"${TMPCONFIG}"
2010-11-18 12:54:43 -07:00
else
FAILED_CMD_PATH="${FAILED_CMD_PATH} ${BIN_PATH[0]}"
echo "#${BIN_PATH[1]}=\"\"" >>"${TMPCONFIG}"
2010-11-18 12:23:49 -07:00
fi
done
2010-11-18 12:57:30 -07:00
if [ "$FAILED_CMD_PATH" ]; then
2010-11-18 12:54:43 -07:00
$WHIPTAIL --title "${TOOL_TITLE}" --msgbox "${FAILED_BINS}\n${FAILED_CMD_PATH}\n${FAILED_BINS_FOOT}" 10 60
fi
else
for i in $AUTOCONFIG_BIN; do
IFS_OLD=${IFS};IFS=:
BIN_PATH=($i)
IFS=${IFS_OLD}
echo "#${BIN_PATH[1]}=\"\"" >>"${TMPCONFIG}"
2010-11-18 12:23:49 -07:00
fi