Add the -p option to the compile command

git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@3311 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb
This commit is contained in:
teastep 2006-01-17 23:27:54 +00:00
parent 2b96059e7d
commit 49cb3fa6c6
7 changed files with 222 additions and 58 deletions

View File

@ -18,3 +18,5 @@ Changes in 3.1.x.
8) Add error checking to generated script.
9) Merge Fabio Longerai's 'length' patch.
10) Add the "-p" option to the compile command.

View File

@ -100,6 +100,11 @@ save_command()
echo "${INDENT}${@}" >> $RESTOREBASE
}
save_command_unindented()
{
echo "${@}" >> $RESTOREBASE
}
#
# Write a progress_message command to $RESTOREBASE
#
@ -146,7 +151,7 @@ append_file() # $1 = File Name
{
save_command "cat > /var/lib/shorewall/$1 << __EOF__"
cat $STATEDIR/$1 >> $RESTOREBASE
save_command __EOF__
save_command_unindented __EOF__
}
#
@ -1476,7 +1481,7 @@ EOF
save_command " cat > /etc/iproute2/rt_tables << __EOF__"
cat /etc/iproute2/rt_tables >> $RESTOREBASE
save_command __EOF__
save_command_unindented __EOF__
fi
@ -8926,7 +8931,7 @@ compile_stop_firewall() {
stop_firewall() {
detetechain() {
deletechain() {
qt $IPTABLES -L \$1 -n && qt $IPTABLES -F \$1 && qt $IPTABLES -X \$1
}
@ -8936,7 +8941,11 @@ stop_firewall() {
}
setpolicy() {
$IPTABLES -P $1 $2
$IPTABLES -P \$1 \$2
}
setcontinue() {
$IPTABLES -A \$1 -m state --state ESTABLISHED,RELATED -j ACCEPT
}
case \$COMMAND in
@ -9261,6 +9270,7 @@ compile_firewall() # $1 = File Name
#
# END OVERLOADED FUNCTIONS
#
verify_os_version
verify_ip
@ -9280,8 +9290,9 @@ compile_firewall() # $1 = File Name
[ -n "$RESTOREBASE" ] || startup_error "Cannot create temporary file in /var/lib/shorewall"
[ -z "$PROGRAM" ] && save_command "#! $SHOREWALL_SHELL --"
cat >> $RESTOREBASE << __EOF__
#! $SHOREWALL_SHELL
#
# Compiled startup file generated by Shorewall $VERSION - $(date)"
#
@ -9336,29 +9347,28 @@ run_tc() {
fi
}
__EOF__
f=$(find_file params)
initialize() {
#
# These variables are required by the library functions called in this script
#
[ -n \${COMMAND:=restart} ]
[ -n \${QUIET:=0} ]
MODULESDIR="$MODULESDIR"
MODULE_SUFFIX="$MODULE_SUFFIX"
LOGLIMIT="$LOGLIMIT"
LOGTAGONLY="$LOGTAGONLY"
LOGRULENUMBERS="$LOGRULENUMBERS"
LOGFORMAT="$LOGFORMAT"
RESTOREFILE="$RESTOREFILE"
[ -f $f ] && \
save_command ". $(resolve_file $f)"
cat >> $RESTOREBASE << __EOF__
#
# These variables are required by the library functions called in this script
#
[ -n \${COMMAND:=restart} ];
[ -n \${QUIET:=0} ]
MODULESDIR="$MODULESDIR"
MODULE_SUFFIX="$MODULE_SUFFIX"
LOGLIMIT="$LOGLIMIT"
LOGTAGONLY="$LOGTAGONLY"
LOGRULENUMBERS="$LOGRULENUMBERS"
LOGFORMAT="$LOGFORMAT"
RESTOREFILE="$RESTOREFILE"
STOPPING=
STOPPING=
#
# The library requires that /var/lib/shorewall exist
#
mkdir -p /var/lib/shorewall
}
__EOF__
if [ -n "$PROGRAM" ]; then
save_command "define_firewall() {"
INDENT=" "
@ -9366,6 +9376,7 @@ __EOF__
if [ -z "$EXPORT" ]; then
cat >> $RESTOREBASE << __EOF__
${INDENT}if [ ! -f /usr/share/shorewall/version ] || [ \$(cat /usr/share/shorewall/version) != $VERSION ]; then
${INDENT} error_message "ERROR: This script requires Shorewall version $VERSION"
${INDENT} exit 2
@ -9381,6 +9392,7 @@ __EOF__
progress_message2 "Initializing..."
save_progress_message "Initializing..."
initialize_netfilter
progress_message2 "Compiling Proxy ARP"; setup_proxy_arp
@ -9478,10 +9490,13 @@ __EOF__
if [ -n "$PROGRAM" ]; then
INDENT=
save_command "}"
write_globals
save_command ""
fi
cat $(find_file prog.header) $RESTOREBASE $(find_file prog.footer) > $outfile
rm $RESTOREBASE
else
mv -f $RESTOREBASE $outfile
fi
chmod 700 $outfile

View File

@ -588,7 +588,14 @@ for f in macro.* ; do
echo
echo "Macro ${f#*.} file installed as ${PREFIX}/usr/share/shorewall/$f"
done
#
# Install the program skeleton files
#
for f in prog.* ; do
install_file $f ${PREFIX}/usr/share/shorewall/$f 0600
echo
echo "Program skeleton file ${f#*.} installed as ${PREFIX}/usr/share/shorewall/$f"
done
#
# Create the version file
#

70
Shorewall/prog.footer Normal file
View File

@ -0,0 +1,70 @@
################################################################################
# Give Usage Information #
################################################################################
usage() {
echo "Usage: $0 start|stop|reload|restart|status"
exit 1
}
################################################################################
# E X E C U T I O N B E G I N S H E R E #
################################################################################
initialize
COMMAND="$1"
case "$COMMAND" in
start)
echo "Starting Shorewall...."
define_firewall
status=$?
echo "done."
;;
stop)
echo "Stopping Shorewall...."
stop_firewall
status=0
echo "done."
;;
restart)
echo "Restarting Shorewall...."
define_firewall
status=$?
echo "done."
;;
clear)
echo "Clearing Shorewall...."
clear_firewall
status=0
echo "done."
;;
status)
echo "Shorewall Status at $HOSTNAME - $(date)"
echo
if iptables -L shorewall -n > /dev/null 2>&1; then
echo "Shorewall is running"
status=0
else
echo "Shorewall is stopped"
status=4
fi
if [ -f /var/lib/shorewall/state ]; then
state="$(cat /var/lib/shorewall/state)"
case $state in
Stopped*|Clear*)
status=3
;;
esac
else
state=Unknown
fi
echo "State:$state"
echo
;;
*)
usage
status=2
;;
esac
exit $status

54
Shorewall/prog.header Normal file
View File

@ -0,0 +1,54 @@
#!/bin/sh
RCDLINKS="2,S41 3,S41 6,K41"
#
# Generated by the Shoreline Firewall (Shorewall) Packet Filtering Firewall - V3.2
#
# Generated $(date) by $USER
#
# This program is under GPL [http://www.gnu.org/copyleft/gpl.htm]
#
# (c) 2006 - Tom Eastep (teastep@shorewall.net)
#
# On most distributions, this file should be called /etc/init.d/shorewall.
#
# Complete documentation is available at http://shorewall.net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of Version 2 of the GNU General Public License
# as published by the Free Software Foundation.
#
# 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, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA
#
# If an error occurs while starting or restarting the firewall, the
# firewall is automatically stopped.
#
# Commands are:
#
# start Starts the firewall
# restart Restarts the firewall
# reload Reload the firewall
# clear Removes all firewall rules
# stop Stops the firewall
# status Displays firewall status
#
# chkconfig: 2345 25 90
# description: Packet filtering firewall
### BEGIN INIT INFO
# Provides: firewall
# Required-Start: $network
# Required-Stop:
# Default-Start: 2 3 5
# Default-Stop: 0 1 6
# Description: starts and stops the shorewall-generated firewall
### END INIT INFO

View File

@ -34,6 +34,11 @@ New Features in 3.1.3
2) When a compiled script encounters an error, the firewall is now put in the
"stopped" state without the need for running "/sbin/shorewall stop".
3) The -p option now generates a complete firewall program that can be installed
in /etc/init.d (on SuSE) and installed using "insserv". If the system where
you install the program does not have Shorewall installed, you will need to
generate the program with the "-e" option.
Migration Considerations:
None.
@ -54,6 +59,8 @@ New Features:
additional consideration a) below).
Also allows the generated script to run
on a system without Shorewall installed.
-p Generate a complete program that can start,
stop, restart, clear and status the firewall
<config directory> Is an optional directory to be searched for
configuration files prior to those listed
in CONFIG_DIR in /etc/shorewall/shorewall.conf.
@ -132,6 +139,11 @@ New Features:
"iptables-restore" and multiple executions of "iptables". The system is a
1.4Ghz Celeron with 512MB RAM.
The "-p' option creates a complete program. This program is suitable for
installation into /etc/init.d and, when generated with the "-e" option
can serve as your firewall on a system that doesn't even have Shorewall
installed.
2) You may now repeat the -q option to cause Shorewall to be extra quiet.
Example:

View File

@ -154,12 +154,16 @@ fi
%attr(0600,root,root) /usr/share/shorewall/macro.VNCL
%attr(0600,root,root) /usr/share/shorewall/macro.Web
%attr(0600,root,root) /usr/share/shorewall/macro.Webmin
%attr(0600,root,root) /usr/share/shorewall/prog.footer
%attr(0600,root,root) /usr/share/shorewall/prog.header
%attr(0600,root,root) /usr/share/shorewall/rfc1918
%attr(0600,root,root) /usr/share/shorewall/configpath
%doc COPYING INSTALL changelog.txt releasenotes.txt tunnel ipsecvpn Samples
%changelog
* Sun Tue 17 2006 Tom Eastep tom@shorewall.net
- Added program skeleton Files
* Sun Jan 15 2006 Tom Eastep tom@shorewall.net
- Updated to 3.1.2-1
* Thu Jan 12 2006 Tom Eastep tom@shorewall.net