2006-10-28 00:42:05 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2008-05-04 02:18:47 +02:00
|
|
|
# Shorewall 4.2 -- /usr/share/shorewall/lib.cli.
|
2006-10-28 00:42:05 +02:00
|
|
|
#
|
2007-09-08 18:09:51 +02:00
|
|
|
# This program is under GPL [http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt]
|
2006-10-28 00:42:05 +02:00
|
|
|
#
|
2007-01-12 23:06:29 +01:00
|
|
|
# (c) 1999,2000,2001,2002,2003,2004,2005,2006,2007 - Tom Eastep (teastep@shorewall.net)
|
2006-10-28 00:42:05 +02:00
|
|
|
#
|
|
|
|
# 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
|
2007-09-08 18:09:51 +02:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2006-10-28 00:42:05 +02:00
|
|
|
#
|
|
|
|
# This library contains the command processing code common to /sbin/shorewall and
|
|
|
|
# /sbin/shorewall-lite.
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
# Fatal Error
|
|
|
|
#
|
|
|
|
fatal_error() # $@ = Message
|
|
|
|
{
|
|
|
|
echo " $@" >&2
|
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
|
|
|
# Display a chain if it exists
|
|
|
|
#
|
|
|
|
|
|
|
|
showfirstchain() # $1 = name of chain
|
|
|
|
{
|
|
|
|
awk \
|
|
|
|
'BEGIN {prnt=0; rslt=1; }; \
|
|
|
|
/^$/ { next; };\
|
|
|
|
/^Chain/ {if ( prnt == 1 ) { rslt=0; exit 0; }; };\
|
|
|
|
/Chain '$1'/ { prnt=1; }; \
|
|
|
|
{ if (prnt == 1) print; };\
|
|
|
|
END { exit rslt; }' $TMPFILE
|
|
|
|
}
|
|
|
|
|
|
|
|
showchain() # $1 = name of chain
|
|
|
|
{
|
|
|
|
if [ "$firstchain" = "Yes" ]; then
|
|
|
|
if showfirstchain $1; then
|
|
|
|
firstchain=
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
awk \
|
|
|
|
'BEGIN {prnt=0;};\
|
|
|
|
/^$|^ pkts/ { next; };\
|
|
|
|
/^Chain/ {if ( prnt == 1 ) exit; };\
|
|
|
|
/Chain '$1'/ { prnt=1; };\
|
|
|
|
{ if (prnt == 1) print; }' $TMPFILE
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# The 'awk' hack that compensates for bugs in iptables-save (or rather in the extension modules).
|
|
|
|
#
|
|
|
|
|
|
|
|
iptablesbug()
|
|
|
|
{
|
|
|
|
if qt mywhich awk ; then
|
|
|
|
awk 'BEGIN { sline=""; };\
|
|
|
|
/^-j/ { print sline $0; next };\
|
|
|
|
/-m policy.*-j/ { print $0; next };\
|
|
|
|
/-m policy/ { sline=$0; next };\
|
|
|
|
/--mask ff/ { sub( /--mask ff/, "--mask 0xff" ) };\
|
|
|
|
{ print ; sline="" }'
|
|
|
|
else
|
|
|
|
echo " WARNING: You don't have 'awk' on this system so the output of the save command may be unusable" >&2
|
|
|
|
cat
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Validate the value of RESTOREFILE
|
|
|
|
#
|
|
|
|
validate_restorefile() # $* = label
|
|
|
|
{
|
|
|
|
case $RESTOREFILE in
|
|
|
|
*/*)
|
|
|
|
error_message "ERROR: $@ must specify a simple file name: $RESTOREFILE"
|
|
|
|
exit 2
|
|
|
|
;;
|
2006-12-03 19:18:21 +01:00
|
|
|
.safe|.try)
|
2006-11-30 01:16:25 +01:00
|
|
|
;;
|
2006-12-03 19:18:21 +01:00
|
|
|
.*|NONE)
|
2006-10-28 00:42:05 +02:00
|
|
|
error_message "ERROR: Reserved File Name: $RESTOREFILE"
|
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Clear descriptor 1 if it is a terminal
|
|
|
|
#
|
|
|
|
clear_term() {
|
|
|
|
[ -t 1 ] && clear
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Delay $timeout seconds -- if we're running on a recent bash2 then allow
|
|
|
|
# <enter> to terminate the delay
|
|
|
|
#
|
|
|
|
timed_read ()
|
|
|
|
{
|
|
|
|
read -t $timeout foo 2> /dev/null
|
|
|
|
|
|
|
|
test $? -eq 2 && sleep $timeout
|
|
|
|
}
|
|
|
|
|
2006-12-06 17:37:29 +01:00
|
|
|
#
|
|
|
|
# Determine if 'syslog -C' is running
|
|
|
|
#
|
|
|
|
syslog_circular_buffer() {
|
2008-03-14 03:07:28 +01:00
|
|
|
local pid
|
|
|
|
local tty
|
|
|
|
local flags
|
|
|
|
local cputime
|
|
|
|
local path
|
|
|
|
local args
|
|
|
|
local arg
|
2006-12-06 17:37:29 +01:00
|
|
|
|
|
|
|
ps ax 2> /dev/null | while read pid tty flags cputime path args; do
|
|
|
|
case $path in
|
|
|
|
syslogd|*/syslogd)
|
|
|
|
for arg in $args; do
|
|
|
|
if [ x$arg = x-C ]; then
|
|
|
|
echo Yes
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2006-10-28 00:42:05 +02:00
|
|
|
#
|
|
|
|
# Display the last $1 packets logged
|
|
|
|
#
|
|
|
|
packet_log() # $1 = number of messages
|
|
|
|
{
|
|
|
|
local options
|
|
|
|
|
|
|
|
if [ -n "$SHOWMACS" -o $VERBOSE -gt 2 ]; then
|
2007-08-26 17:09:27 +02:00
|
|
|
$LOGREAD | grep 'IN=.* OUT=' | head -n$1 | tac | sed 's/ kernel://; s/\[.*\] //' | sed s/" $host $LOGFORMAT"/" "/
|
2006-10-28 00:42:05 +02:00
|
|
|
else
|
2007-08-26 17:09:27 +02:00
|
|
|
$LOGREAD | grep 'IN=.* OUT=' | head -n$1 | tac | sed 's/ kernel://; s/MAC=.* SRC=/SRC=/; s/\[.*\] '// | sed s/" $host $LOGFORMAT"/" "/
|
2006-10-28 00:42:05 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Show traffic control information
|
|
|
|
#
|
|
|
|
show_tc() {
|
|
|
|
|
|
|
|
show_one_tc() {
|
2008-03-14 03:07:28 +01:00
|
|
|
local device
|
|
|
|
device=${1%@*}
|
2006-10-28 00:42:05 +02:00
|
|
|
qdisc=$(tc qdisc list dev $device)
|
|
|
|
|
|
|
|
if [ -n "$qdisc" ]; then
|
|
|
|
echo Device $device:
|
|
|
|
tc -s -d qdisc show dev $device
|
2008-03-16 21:31:50 +01:00
|
|
|
echo
|
2006-10-28 00:42:05 +02:00
|
|
|
tc -s -d class show dev $device
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2007-08-26 17:09:27 +02:00
|
|
|
ip -o link list | while read inx interface details; do
|
|
|
|
show_one_tc ${interface%:}
|
2006-10-28 00:42:05 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Show classifier information
|
|
|
|
#
|
|
|
|
show_classifiers() {
|
|
|
|
|
|
|
|
show_one_classifier() {
|
2008-03-14 03:07:28 +01:00
|
|
|
local device
|
|
|
|
device=${1%@*}
|
2006-10-28 00:42:05 +02:00
|
|
|
qdisc=$(tc qdisc list dev $device)
|
|
|
|
|
|
|
|
if [ -n "$qdisc" ]; then
|
|
|
|
echo Device $device:
|
|
|
|
tc -s filter ls dev $device
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2007-08-26 17:09:27 +02:00
|
|
|
ip -o link list | while read inx interface details; do
|
|
|
|
show_one_classifier ${interface%:}
|
2006-10-28 00:42:05 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Watch the Firewall Log
|
|
|
|
#
|
|
|
|
logwatch() # $1 = timeout -- if negative, prompt each time that
|
|
|
|
# an 'interesting' packet count changes
|
|
|
|
{
|
|
|
|
|
|
|
|
host=$(echo $HOSTNAME | sed 's/\..*$//')
|
|
|
|
oldrejects=$($IPTABLES -L -v -n | grep 'LOG')
|
|
|
|
|
|
|
|
if [ $1 -lt 0 ]; then
|
|
|
|
timeout=$((- $1))
|
|
|
|
pause="Yes"
|
|
|
|
else
|
|
|
|
pause="No"
|
|
|
|
timeout=$1
|
|
|
|
fi
|
|
|
|
|
|
|
|
qt mywhich awk && haveawk=Yes || haveawk=
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
clear_term
|
|
|
|
echo "$banner $(date)"
|
|
|
|
echo
|
|
|
|
|
|
|
|
echo "Dropped/Rejected Packet Log ($LOGFILE)"
|
|
|
|
echo
|
|
|
|
|
|
|
|
show_reset
|
|
|
|
|
|
|
|
rejects=$($IPTABLES -L -v -n | grep 'LOG')
|
|
|
|
|
|
|
|
if [ "$rejects" != "$oldrejects" ]; then
|
|
|
|
oldrejects="$rejects"
|
|
|
|
|
|
|
|
$RING_BELL
|
|
|
|
|
|
|
|
packet_log 40
|
|
|
|
|
|
|
|
if [ "$pause" = "Yes" ]; then
|
|
|
|
echo
|
|
|
|
echo $ECHO_N 'Enter any character to continue: '
|
|
|
|
read foo
|
|
|
|
else
|
|
|
|
timed_read
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo
|
|
|
|
packet_log 40
|
|
|
|
timed_read
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Save currently running configuration
|
|
|
|
#
|
|
|
|
save_config() {
|
2007-06-25 19:20:08 +02:00
|
|
|
|
2008-03-14 03:07:28 +01:00
|
|
|
local result
|
|
|
|
result=1
|
2007-06-25 19:20:08 +02:00
|
|
|
|
|
|
|
iptables_save=${IPTABLES}-save
|
|
|
|
|
|
|
|
[ -x $iptables_save ] || echo "$iptables-save does not exist or is not executable" >&2
|
|
|
|
|
2006-10-28 00:42:05 +02:00
|
|
|
if shorewall_is_started ; then
|
|
|
|
[ -d ${VARDIR} ] || mkdir -p ${VARDIR}
|
|
|
|
|
|
|
|
if [ -f $RESTOREPATH -a ! -x $RESTOREPATH ]; then
|
2007-06-25 19:20:08 +02:00
|
|
|
echo " ERROR: $RESTOREPATH exists and is not a saved $PRODUCT configuration" >&2
|
2006-10-28 00:42:05 +02:00
|
|
|
else
|
|
|
|
case $RESTOREFILE in
|
2006-11-30 01:23:33 +01:00
|
|
|
capabilities|chains|default_route|firewall|firewall.conf|nat|proxyarp|restarted|rt_tables|save|state|undo_routing|zones)
|
2007-06-25 19:20:08 +02:00
|
|
|
echo " ERROR: Reserved file name: $RESTOREFILE" >&2
|
2006-10-28 00:42:05 +02:00
|
|
|
;;
|
|
|
|
*)
|
2006-11-30 01:23:33 +01:00
|
|
|
validate_restorefile RESTOREFILE
|
|
|
|
|
2006-10-28 00:42:05 +02:00
|
|
|
if $IPTABLES -L dynamic -n > ${VARDIR}/save; then
|
|
|
|
echo " Dynamic Rules Saved"
|
|
|
|
if [ -f ${VARDIR}/.restore ]; then
|
|
|
|
if iptables-save | iptablesbug > ${VARDIR}/restore-$$; then
|
|
|
|
cp -f ${VARDIR}/.restore $RESTOREPATH
|
|
|
|
mv -f ${VARDIR}/restore-$$ ${RESTOREPATH}-iptables
|
|
|
|
chmod +x $RESTOREPATH
|
|
|
|
echo " Currently-running Configuration Saved to $RESTOREPATH"
|
|
|
|
|
|
|
|
rm -f ${RESTOREPATH}-ipsets
|
|
|
|
|
|
|
|
case ${SAVE_IPSETS:-No} in
|
|
|
|
[Yy][Ee][Ss])
|
|
|
|
RESTOREPATH=${RESTOREPATH}-ipsets
|
|
|
|
|
|
|
|
f=${VARDIR}/restore-$$
|
|
|
|
|
|
|
|
echo "#!/bin/sh" > $f
|
|
|
|
echo "#This ipset restore file generated $(date) by Shorewall $version" >> $f
|
|
|
|
echo >> $f
|
|
|
|
echo ". ${SHAREDIR}/lib.base" >> $f
|
|
|
|
echo >> $f
|
2006-11-15 05:16:59 +01:00
|
|
|
cat ${VARDIR}/.modulesdir >> $f
|
|
|
|
echo >> $f
|
2006-10-28 00:42:05 +02:00
|
|
|
echo "reload_kernel_modules << __EOF__" >> $f
|
2006-11-15 05:16:59 +01:00
|
|
|
grep 'loadmodule ip_set' ${VARDIR}/.modules >> $f
|
2006-10-28 00:42:05 +02:00
|
|
|
echo "__EOF__" >> $f
|
|
|
|
echo >> $f
|
|
|
|
echo "ipset -U :all: :all:" >> $f
|
2007-10-19 21:43:14 +02:00
|
|
|
echo "ipset -U :all: :default:" >> $f
|
2006-10-28 00:42:05 +02:00
|
|
|
echo "ipset -F" >> $f
|
|
|
|
echo "ipset -X" >> $f
|
|
|
|
echo "ipset -R << __EOF__" >> $f
|
|
|
|
ipset -S >> $f
|
|
|
|
echo "__EOF__" >> $f
|
|
|
|
mv -f $f $RESTOREPATH
|
|
|
|
chmod +x $RESTOREPATH
|
|
|
|
echo " Current Ipset Contents Saved to $RESTOREPATH"
|
2007-06-25 19:20:08 +02:00
|
|
|
result=0
|
2006-10-28 00:42:05 +02:00
|
|
|
;;
|
|
|
|
[Nn][Oo])
|
|
|
|
;;
|
|
|
|
*)
|
2007-06-25 19:20:08 +02:00
|
|
|
echo " WARNING: Invalid value ($SAVE_IPSETS) for SAVE_IPSETS. Ipset contents not saved" >&2
|
2006-10-28 00:42:05 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
rm -f ${VARDIR}/restore-$$
|
2007-06-25 19:20:08 +02:00
|
|
|
echo " ERROR: Currently-running Configuration Not Saved" >&2
|
2006-10-28 00:42:05 +02:00
|
|
|
fi
|
|
|
|
else
|
2007-06-25 19:20:08 +02:00
|
|
|
echo " ERROR: ${VARDIR}/.restore does not exist" >&2
|
2006-10-28 00:42:05 +02:00
|
|
|
fi
|
|
|
|
else
|
2007-06-25 19:20:08 +02:00
|
|
|
echo "Error Saving the Dynamic Rules" >&2
|
2006-10-28 00:42:05 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
else
|
2007-06-25 19:20:08 +02:00
|
|
|
echo "Shorewall isn't started" >&2
|
2006-10-28 00:42:05 +02:00
|
|
|
fi
|
|
|
|
|
2007-06-25 19:20:08 +02:00
|
|
|
return 0
|
|
|
|
|
2006-10-28 00:42:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Show routing configuration
|
|
|
|
#
|
|
|
|
show_routing() {
|
2007-07-22 15:44:06 +02:00
|
|
|
if [ -n "$(ip rule list)" ]; then
|
2006-10-28 00:42:05 +02:00
|
|
|
heading "Routing Rules"
|
2007-07-22 15:44:06 +02:00
|
|
|
ip rule list
|
|
|
|
ip rule list | while read rule; do
|
2006-10-28 00:42:05 +02:00
|
|
|
echo ${rule##* }
|
|
|
|
done | sort -u | while read table; do
|
|
|
|
heading "Table $table:"
|
2007-07-22 15:44:06 +02:00
|
|
|
ip route list table $table
|
2006-10-28 00:42:05 +02:00
|
|
|
done
|
|
|
|
else
|
|
|
|
heading "Routing Table"
|
2007-07-22 15:44:06 +02:00
|
|
|
ip route list
|
2006-10-28 00:42:05 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Show Command Executor
|
|
|
|
#
|
|
|
|
show_command() {
|
2008-03-14 03:07:28 +01:00
|
|
|
local finished
|
|
|
|
finished=0
|
|
|
|
local table
|
|
|
|
table=filter
|
|
|
|
local table_given
|
|
|
|
table_given=
|
2006-10-28 00:42:05 +02:00
|
|
|
|
2006-11-30 18:17:53 +01:00
|
|
|
show_macro() {
|
|
|
|
foo=`grep 'This macro' $macro | sed 's/This macro //'`
|
|
|
|
if [ -n "$foo" ]; then
|
|
|
|
macro=${macro#*.}
|
|
|
|
foo=${foo%.*}
|
2007-12-01 18:09:38 +01:00
|
|
|
if [ ${#macro} -gt 10 ]; then
|
|
|
|
echo " $macro ${foo#\#}"
|
|
|
|
else
|
|
|
|
$ECHO_E " $macro \t${foo#\#}"
|
|
|
|
fi
|
2006-11-30 18:17:53 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2006-10-28 00:42:05 +02:00
|
|
|
while [ $finished -eq 0 -a $# -gt 0 ]; do
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
|
|
|
v*)
|
|
|
|
VERBOSE=$(($VERBOSE + 1 ))
|
|
|
|
option=${option#v}
|
|
|
|
;;
|
|
|
|
x*)
|
|
|
|
IPT_OPTIONS="-xnv"
|
|
|
|
option=${option#x}
|
|
|
|
;;
|
|
|
|
m*)
|
|
|
|
SHOWMACS=Yes
|
|
|
|
option=${option#m}
|
|
|
|
;;
|
|
|
|
f*)
|
|
|
|
FILEMODE=Yes
|
|
|
|
option=${option#f}
|
|
|
|
;;
|
2006-11-21 23:52:07 +01:00
|
|
|
t)
|
|
|
|
[ $# -eq 1 ] && usage 1
|
|
|
|
|
|
|
|
case $2 in
|
2006-11-30 22:28:31 +01:00
|
|
|
mangle|nat|filter|raw)
|
2006-11-21 23:52:07 +01:00
|
|
|
table=$2
|
2007-06-28 20:21:28 +02:00
|
|
|
table_given=Yes
|
2006-11-21 23:52:07 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
fatal_error "Invalid table name ($s)"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
option=
|
|
|
|
shift
|
|
|
|
;;
|
2006-10-28 00:42:05 +02:00
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
[ -n "$debugging" ] && set -x
|
|
|
|
case "$1" in
|
|
|
|
connections)
|
|
|
|
[ $# -gt 1 ] && usage 1
|
|
|
|
echo "$PRODUCT $version Connections at $HOSTNAME - $(date)"
|
|
|
|
echo
|
2007-03-18 03:57:30 +01:00
|
|
|
[ -f /proc/net/ip_conntrack ] && cat /proc/net/ip_conntrack || cat /proc/net/nf_conntrack
|
2006-10-28 00:42:05 +02:00
|
|
|
;;
|
|
|
|
nat)
|
|
|
|
[ $# -gt 1 ] && usage 1
|
|
|
|
echo "$PRODUCT $version NAT Table at $HOSTNAME - $(date)"
|
|
|
|
echo
|
|
|
|
show_reset
|
|
|
|
$IPTABLES -t nat -L $IPT_OPTIONS
|
|
|
|
;;
|
|
|
|
tos|mangle)
|
|
|
|
[ $# -gt 1 ] && usage 1
|
|
|
|
echo "$PRODUCT $version Mangle Table at $HOSTNAME - $(date)"
|
|
|
|
echo
|
|
|
|
show_reset
|
|
|
|
$IPTABLES -t mangle -L $IPT_OPTIONS
|
|
|
|
;;
|
|
|
|
log)
|
|
|
|
[ $# -gt 1 ] && usage 1
|
|
|
|
echo "$PRODUCT $version Log ($LOGFILE) at $HOSTNAME - $(date)"
|
|
|
|
echo
|
|
|
|
show_reset
|
|
|
|
host=$(echo $HOSTNAME | sed 's/\..*$//')
|
|
|
|
packet_log 20
|
|
|
|
;;
|
|
|
|
tc)
|
|
|
|
[ $# -gt 1 ] && usage 1
|
|
|
|
echo "$PRODUCT $version Traffic Control at $HOSTNAME - $(date)"
|
|
|
|
echo
|
|
|
|
show_tc
|
|
|
|
;;
|
2008-03-19 20:29:56 +01:00
|
|
|
classifiers|filters)
|
2006-10-28 00:42:05 +02:00
|
|
|
[ $# -gt 1 ] && usage 1
|
|
|
|
echo "$PRODUCT $version Clasifiers at $HOSTNAME - $(date)"
|
|
|
|
echo
|
|
|
|
show_classifiers
|
|
|
|
;;
|
|
|
|
zones)
|
|
|
|
[ $# -gt 1 ] && usage 1
|
|
|
|
if [ -f ${VARDIR}/zones ]; then
|
|
|
|
echo "$PRODUCT $version Zones at $HOSTNAME - $(date)"
|
|
|
|
echo
|
|
|
|
while read zone type hosts; do
|
|
|
|
echo "$zone ($type)"
|
|
|
|
for host in $hosts; do
|
|
|
|
case $host in
|
|
|
|
exclude)
|
|
|
|
echo " exclude:"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo " $host"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
done < ${VARDIR}/zones
|
|
|
|
echo
|
|
|
|
else
|
|
|
|
echo " ERROR: ${VARDIR}/zones does not exist" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
capabilities)
|
|
|
|
[ $# -gt 1 ] && usage 1
|
|
|
|
determine_capabilities
|
|
|
|
VERBOSE=2
|
|
|
|
if [ -n "$FILEMODE" ]; then
|
|
|
|
report_capabilities1
|
|
|
|
else
|
|
|
|
report_capabilities
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
ip)
|
|
|
|
[ $# -gt 1 ] && usage 1
|
|
|
|
echo "$PRODUCT $version IP at $HOSTNAME - $(date)"
|
|
|
|
echo
|
2007-07-22 15:44:06 +02:00
|
|
|
ip addr list
|
2006-10-28 00:42:05 +02:00
|
|
|
;;
|
|
|
|
routing)
|
|
|
|
[ $# -gt 1 ] && usage 1
|
|
|
|
echo "$PRODUCT $version Routing at $HOSTNAME - $(date)"
|
|
|
|
echo
|
|
|
|
show_routing
|
|
|
|
;;
|
|
|
|
config)
|
|
|
|
. ${SHAREDIR}/configpath
|
|
|
|
echo "Default CONFIG_PATH is $CONFIG_PATH"
|
2007-07-08 19:46:38 +02:00
|
|
|
[ -n "$LITEDIR" ] && echo "LITEDIR is $LITEDIR"
|
2006-10-28 00:42:05 +02:00
|
|
|
;;
|
2007-06-28 20:21:28 +02:00
|
|
|
chain)
|
|
|
|
shift
|
|
|
|
echo "$PRODUCT $version $([ $# -gt 1 ] && echo "Chains " || [ $# -gt 0 ] && echo "Chain " || echo $table Table)$* at $HOSTNAME - $(date)"
|
|
|
|
echo
|
|
|
|
show_reset
|
|
|
|
if [ $# -gt 0 ]; then
|
|
|
|
for chain in $*; do
|
|
|
|
$IPTABLES -t $table -L $chain $IPT_OPTIONS
|
|
|
|
done
|
|
|
|
else
|
|
|
|
$IPTABLES -t $table -L $IPT_OPTIONS
|
|
|
|
fi
|
|
|
|
;;
|
2007-11-16 00:24:54 +01:00
|
|
|
vardir)
|
|
|
|
echo $VARDIR;
|
|
|
|
;;
|
2006-10-28 00:42:05 +02:00
|
|
|
*)
|
|
|
|
if [ "$PRODUCT" = Shorewall ]; then
|
|
|
|
case $1 in
|
|
|
|
actions)
|
|
|
|
[ $# -gt 1 ] && usage 1
|
|
|
|
echo "allowBcast # Silently Allow Broadcast/multicast"
|
|
|
|
echo "allowInvalid # Accept packets that are in the INVALID conntrack state."
|
|
|
|
echo "allowinUPnP # Allow UPnP inbound (to firewall) traffic"
|
2008-03-27 20:45:23 +01:00
|
|
|
echo "allowoutUPnP # Allow traffic from local command 'upnpd' (does not work with kernels after 2.6.13)"
|
|
|
|
echo "dropBcast # Silently Drop Broadcast/multicast"
|
|
|
|
echo "dropInvalid # Silently Drop packets that are in the INVALID conntrack state"
|
|
|
|
echo "dropNotSyn # Silently Drop Non-syn TCP packets"
|
|
|
|
echo "drop1918src # Drop packets with an RFC 1918 source address (Shorewall-perl only)"
|
|
|
|
echo "drop1918dst # Drop packets with an RFC 1918 original dest address (Shorewall-perl only)"
|
2006-10-28 00:42:05 +02:00
|
|
|
echo "forwardUPnP # Allow traffic that upnpd has redirected from"
|
2008-03-27 20:45:23 +01:00
|
|
|
echo "rejNotSyn # Silently Reject Non-syn TCP packets"
|
|
|
|
echo "rej1918src # Reject packets with an RFC 1918 source address (Shorewall-perl only)"
|
|
|
|
echo "rej1918dst # Reject packets with an RFC 1918 original dest address (Shorewall-perl only)"
|
2008-03-29 15:33:25 +01:00
|
|
|
|
|
|
|
if [ -f ${CONFDIR}/actions ]; then
|
|
|
|
cat ${SHAREDIR}/actions.std ${CONFDIR}/actions | grep -Ev '^\#|^$'
|
|
|
|
else
|
|
|
|
grep -Ev '^\#|^$' ${SHAREDIR}/actions.std
|
|
|
|
fi
|
|
|
|
|
2006-10-28 00:42:05 +02:00
|
|
|
return
|
|
|
|
;;
|
|
|
|
macros)
|
|
|
|
[ $# -gt 1 ] && usage 1
|
2006-11-30 18:17:53 +01:00
|
|
|
|
|
|
|
for directory in $(split $CONFIG_PATH); do
|
|
|
|
temp=
|
|
|
|
for macro in ${directory}/macro.*; do
|
|
|
|
case $macro in
|
|
|
|
*\*)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -z "$temp" ]; then
|
|
|
|
echo
|
|
|
|
echo "Macros in $directory:"
|
|
|
|
echo
|
|
|
|
temp=Yes
|
|
|
|
fi
|
|
|
|
show_macro
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2006-10-28 00:42:05 +02:00
|
|
|
done
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $# -gt 0 ]; then
|
2007-06-28 20:21:28 +02:00
|
|
|
[ -n "$table_given" ] || for chain in $*; do
|
|
|
|
if ! qt $IPTABLES -t $table -L $chain $IPT_OPTIONS; then
|
2008-03-26 16:36:23 +01:00
|
|
|
echo "usage $(basename $0) show [ -x ] [ -m ] [-f] [ -t {filter|mangle|nat} ] [ {chain [<chain> [ <chain> ... ]|actions|capabilities|classifiers|config|connections|filters|ip|log|macros|mangle|nat|routing|tc|zones} ] " >&2
|
2007-06-28 20:21:28 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "$PRODUCT $version $([ $# -gt 1 ] && echo "Chains " || echo "Chain ")$* at $HOSTNAME - $(date)"
|
|
|
|
echo
|
|
|
|
show_reset
|
2006-10-28 00:42:05 +02:00
|
|
|
for chain in $*; do
|
2006-11-21 23:52:07 +01:00
|
|
|
$IPTABLES -t $table -L $chain $IPT_OPTIONS
|
2006-10-28 00:42:05 +02:00
|
|
|
done
|
|
|
|
else
|
2007-06-28 20:21:28 +02:00
|
|
|
echo "$PRODUCT $version $table Table at $HOSTNAME - $(date)"
|
|
|
|
echo
|
|
|
|
show_reset
|
2006-11-21 23:52:07 +01:00
|
|
|
$IPTABLES -t $table -L $IPT_OPTIONS
|
2006-10-28 00:42:05 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Dump Command Executor
|
|
|
|
#
|
|
|
|
dump_command() {
|
2008-03-14 03:07:28 +01:00
|
|
|
local finished
|
|
|
|
finished=0
|
2006-10-28 00:42:05 +02:00
|
|
|
|
|
|
|
while [ $finished -eq 0 -a $# -gt 0 ]; do
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
|
|
|
x*)
|
|
|
|
IPT_OPTIONS="-xnv"
|
|
|
|
option=${option#x}
|
|
|
|
;;
|
2007-05-15 21:35:26 +02:00
|
|
|
m*)
|
|
|
|
SHOWMACS=Yes
|
|
|
|
option=${option#m}
|
|
|
|
;;
|
2006-10-28 00:42:05 +02:00
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
[ $VERBOSE -lt 2 ] && VERBOSE=2
|
|
|
|
|
|
|
|
[ -n "$debugging" ] && set -x
|
|
|
|
[ $# -eq 0 ] || usage 1
|
|
|
|
clear_term
|
|
|
|
echo "$PRODUCT $version Dump at $HOSTNAME - $(date)"
|
|
|
|
echo
|
2007-05-18 00:50:32 +02:00
|
|
|
if [ -f /usr/share/shorewall-shell/version ]; then
|
|
|
|
echo " Shorewall-shell $(cat /usr/share/shorewall-shell/version)"
|
|
|
|
if [ -f /usr/share/shorewall-perl/version ]; then
|
|
|
|
echo " Shorewall-perl $(cat /usr/share/shorewall-perl/version)"
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
elif [ -f /usr/share/shorewall-perl/version ]; then
|
|
|
|
echo " Shorewall-perl $(cat /usr/share/shorewall-perl/version)"
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
|
2006-10-28 00:42:05 +02:00
|
|
|
show_reset
|
|
|
|
host=$(echo $HOSTNAME | sed 's/\..*$//')
|
|
|
|
$IPTABLES -L $IPT_OPTIONS
|
|
|
|
|
|
|
|
heading "Log ($LOGFILE)"
|
|
|
|
packet_log 20
|
|
|
|
|
|
|
|
heading "NAT Table"
|
|
|
|
$IPTABLES -t nat -L $IPT_OPTIONS
|
|
|
|
|
|
|
|
heading "Mangle Table"
|
|
|
|
$IPTABLES -t mangle -L $IPT_OPTIONS
|
|
|
|
|
|
|
|
heading "Conntrack Table"
|
2007-03-18 03:57:30 +01:00
|
|
|
[ -f /proc/net/ip_conntrack ] && cat /proc/net/ip_conntrack || cat /proc/net/nf_conntrack
|
2006-10-28 00:42:05 +02:00
|
|
|
|
|
|
|
heading "IP Configuration"
|
2007-07-22 15:44:06 +02:00
|
|
|
ip addr list
|
2006-10-28 00:42:05 +02:00
|
|
|
|
|
|
|
heading "IP Stats"
|
2007-07-22 15:44:06 +02:00
|
|
|
ip -stat link list
|
2006-10-28 00:42:05 +02:00
|
|
|
|
|
|
|
if qt mywhich brctl; then
|
|
|
|
heading "Bridges"
|
|
|
|
brctl show
|
|
|
|
fi
|
|
|
|
|
2007-02-23 18:07:13 +01:00
|
|
|
if qt mywhich setkey; then
|
|
|
|
heading "PFKEY SPD"
|
|
|
|
setkey -DP
|
|
|
|
heading "PFKEY SAD"
|
|
|
|
setkey -D | grep -Ev '^[[:space:]](A:|E:)' # Don't divulge the keys
|
|
|
|
fi
|
|
|
|
|
2006-10-28 00:42:05 +02:00
|
|
|
heading "/proc"
|
|
|
|
show_proc /proc/version
|
|
|
|
show_proc /proc/sys/net/ipv4/ip_forward
|
|
|
|
show_proc /proc/sys/net/ipv4/icmp_echo_ignore_all
|
|
|
|
|
|
|
|
for directory in /proc/sys/net/ipv4/conf/*; do
|
|
|
|
for file in proxy_arp arp_filter arp_ignore rp_filter log_martians; do
|
|
|
|
show_proc $directory/$file
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
show_routing
|
|
|
|
|
|
|
|
heading "ARP"
|
|
|
|
arp -na
|
|
|
|
|
|
|
|
if qt mywhich lsmod; then
|
|
|
|
heading "Modules"
|
2007-05-26 23:09:10 +02:00
|
|
|
lsmod | grep -E '^(ip_|ipt_|iptable_|nf_|xt_)' | sort
|
2006-10-28 00:42:05 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
determine_capabilities
|
|
|
|
echo
|
|
|
|
report_capabilities
|
|
|
|
|
|
|
|
if [ -n "$TC_ENABLED" ]; then
|
|
|
|
heading "Traffic Control"
|
|
|
|
show_tc
|
|
|
|
heading "TC Filters"
|
|
|
|
show_classifiers
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Restore Comand Executor
|
|
|
|
#
|
|
|
|
restore_command() {
|
2008-03-14 03:07:28 +01:00
|
|
|
local finished
|
|
|
|
finished=0
|
2006-10-28 00:42:05 +02:00
|
|
|
|
|
|
|
while [ $finished -eq 0 -a $# -gt 0 ]; do
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
|
|
|
n*)
|
|
|
|
NOROUTES=Yes
|
|
|
|
option=${option#n}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $# in
|
|
|
|
0)
|
|
|
|
;;
|
|
|
|
1)
|
|
|
|
RESTOREFILE="$1"
|
|
|
|
validate_restorefile '<restore file>'
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ -z "$STARTUP_ENABLED" ]; then
|
|
|
|
error_message "ERROR: Startup is disabled"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
RESTOREPATH=${VARDIR}/$RESTOREFILE
|
|
|
|
|
|
|
|
export NOROUTES
|
|
|
|
|
|
|
|
[ -n "$nolock" ] || mutex_on
|
|
|
|
|
|
|
|
if [ -x $RESTOREPATH ]; then
|
|
|
|
if [ -x ${RESTOREPATH}-ipsets ] ; then
|
|
|
|
echo Restoring Ipsets...
|
|
|
|
iptables -F
|
|
|
|
iptables -X
|
|
|
|
$SHOREWALL_SHELL ${RESTOREPATH}-ipsets
|
|
|
|
fi
|
|
|
|
|
|
|
|
progress_message3 "Restoring Shorewall..."
|
2006-12-12 17:16:30 +01:00
|
|
|
|
2006-12-12 18:49:52 +01:00
|
|
|
$SHOREWALL_SHELL $RESTOREPATH restore && progress_message3 "$PRODUCT restored from ${VARDIR}/$RESTOREFILE"
|
2006-12-12 17:16:30 +01:00
|
|
|
|
2006-10-28 00:42:05 +02:00
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
else
|
|
|
|
echo "File ${VARDIR}/$RESTOREFILE: file not found"
|
|
|
|
[ -n "$nolock" ] || mutex_off
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Display the time that the counters were last reset
|
|
|
|
#
|
|
|
|
show_reset() {
|
|
|
|
[ -f ${VARDIR}/restarted ] && \
|
|
|
|
echo "Counters reset $(cat ${VARDIR}/restarted)" && \
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Display's the passed file name followed by "=" and the file's contents.
|
|
|
|
#
|
|
|
|
show_proc() # $1 = name of a file
|
|
|
|
{
|
|
|
|
[ -f $1 ] && echo " $1 = $(cat $1)"
|
|
|
|
}
|
|
|
|
|
|
|
|
read_yesno_with_timeout() {
|
|
|
|
read -t 60 yn 2> /dev/null
|
|
|
|
if [ $? -eq 2 ]
|
|
|
|
then
|
|
|
|
# read doesn't support timeout
|
|
|
|
test -x /bin/bash || return 2 # bash is not installed so the feature is not available
|
|
|
|
/bin/bash -c 'read -t 60 yn ; if [ "$yn" == "y" ] ; then exit 0 ; else exit 1 ; fi' # invoke bash and use its version of read
|
|
|
|
return $?
|
|
|
|
else
|
|
|
|
# read supports timeout
|
|
|
|
case "$yn" in
|
|
|
|
y|Y)
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Print a heading with leading and trailing black lines
|
|
|
|
#
|
|
|
|
heading() {
|
|
|
|
echo
|
|
|
|
echo "$@"
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Create the appropriate -q option to pass onward
|
|
|
|
#
|
|
|
|
make_verbose() {
|
2008-03-14 03:07:28 +01:00
|
|
|
local v
|
|
|
|
v=$VERBOSE_OFFSET
|
|
|
|
local option
|
|
|
|
option=-
|
2006-10-28 00:42:05 +02:00
|
|
|
|
2008-02-06 20:02:44 +01:00
|
|
|
if [ -n "$USE_VERBOSITY" ]; then
|
|
|
|
echo "-v$USE_VERBOSITY"
|
|
|
|
elif [ $VERBOSE_OFFSET -gt 0 ]; then
|
2006-10-28 00:42:05 +02:00
|
|
|
while [ $v -gt 0 ]; do
|
|
|
|
option="${option}v"
|
|
|
|
v=$(($v - 1))
|
|
|
|
done
|
|
|
|
|
|
|
|
echo $option
|
|
|
|
elif [ $VERBOSE_OFFSET -lt 0 ]; then
|
|
|
|
while [ $v -lt 0 ]; do
|
|
|
|
option="${option}q"
|
|
|
|
v=$(($v + 1))
|
|
|
|
done
|
|
|
|
|
|
|
|
echo $option
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Executor for drop,reject,... commands
|
|
|
|
#
|
2007-02-20 18:05:25 +01:00
|
|
|
block() # $1 = command, $2 = Finished, $3 - $n addresses
|
2006-10-28 00:42:05 +02:00
|
|
|
{
|
2008-03-14 03:07:28 +01:00
|
|
|
local chain
|
|
|
|
chain=$1
|
|
|
|
local finished
|
|
|
|
finished=$2
|
2006-10-28 00:42:05 +02:00
|
|
|
|
|
|
|
shift 3
|
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case $1 in
|
|
|
|
*-*)
|
|
|
|
qt $IPTABLES -D dynamic -m iprange --src-range $1 -j reject
|
|
|
|
qt $IPTABLES -D dynamic -m iprange --src-range $1 -j DROP
|
|
|
|
qt $IPTABLES -D dynamic -m iprange --src-range $1 -j logreject
|
|
|
|
qt $IPTABLES -D dynamic -m iprange --src-range $1 -j logdrop
|
|
|
|
$IPTABLES -A dynamic -m iprange --src-range $1 -j $chain || break 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
qt $IPTABLES -D dynamic -s $1 -j reject
|
|
|
|
qt $IPTABLES -D dynamic -s $1 -j DROP
|
|
|
|
qt $IPTABLES -D dynamic -s $1 -j logreject
|
|
|
|
qt $IPTABLES -D dynamic -s $1 -j logdrop
|
|
|
|
$IPTABLES -A dynamic -s $1 -j $chain || break 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
echo "$1 $finished"
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
}
|
2006-11-05 20:47:59 +01:00
|
|
|
|
2006-11-05 22:46:55 +01:00
|
|
|
#
|
|
|
|
# 'hits' commmand executor
|
|
|
|
#
|
2006-11-05 20:47:59 +01:00
|
|
|
hits_command() {
|
2008-03-14 03:07:28 +01:00
|
|
|
local finished
|
|
|
|
finished=0
|
|
|
|
local today
|
|
|
|
today=
|
2007-11-16 00:24:54 +01:00
|
|
|
|
|
|
|
while [ $finished -eq 0 -a $# -gt 0 ]; do
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
|
|
|
t*)
|
|
|
|
today=$(date +'^%b %_d.*')
|
|
|
|
option=${option#t}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
[ $# -eq 0 ] || usage 1
|
|
|
|
|
2006-11-05 20:47:59 +01:00
|
|
|
clear_term
|
2006-11-05 21:24:34 +01:00
|
|
|
echo "$PRODUCT $version Hits at $HOSTNAME - $(date)"
|
2006-11-05 20:47:59 +01:00
|
|
|
echo
|
|
|
|
|
|
|
|
timeout=30
|
|
|
|
|
2007-11-16 00:24:54 +01:00
|
|
|
if $LOGREAD | grep -q "${today}IN=.* OUT=" ; then
|
|
|
|
echo " HITS IP DATE"
|
2006-11-05 20:47:59 +01:00
|
|
|
echo " ---- --------------- ------"
|
2007-11-16 00:24:54 +01:00
|
|
|
$LOGREAD | grep "${today}IN=.* OUT=" | sed 's/\(.\{6\}\)\(.*SRC=\)\(.*\)\( DST=.*\)/\3 \1/' | sort | uniq -c | sort -rn | while read count address month day; do
|
2006-11-05 20:47:59 +01:00
|
|
|
printf '%7d %-15s %3s %2d\n' $count $address $month $day
|
|
|
|
done
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
2007-11-16 00:24:54 +01:00
|
|
|
echo " HITS IP PORT"
|
2006-11-05 20:47:59 +01:00
|
|
|
echo " ---- --------------- -----"
|
2007-11-16 00:24:54 +01:00
|
|
|
$LOGREAD | grep "${today}IN=.* OUT=" | sed 's/\(.*SRC=\)\(.*\)\( DST=.*DPT=\)\([0-9]\{1,5\}\)\(.*\)/\2 \4/
|
2006-11-05 20:47:59 +01:00
|
|
|
t
|
2007-11-16 00:24:54 +01:00
|
|
|
s/\(.*SRC=\)\(.*\)\( DST=.*\)/\2/' | sort | uniq -c | sort -rn | while read count address port; do
|
2006-11-05 20:47:59 +01:00
|
|
|
printf '%7d %-15s %d\n' $count $address $port
|
|
|
|
done
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
echo " HITS DATE"
|
|
|
|
echo " ---- ------"
|
2007-11-16 00:24:54 +01:00
|
|
|
$LOGREAD | grep "${today}IN=.* OUT=" | sed 's/\(.\{6\}\)\(.*\)/\1/' | sort | uniq -c | sort -rn | while read count month day; do
|
2006-11-05 20:47:59 +01:00
|
|
|
printf '%7d %3s %2d\n' $count $month $day
|
|
|
|
done
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
echo " HITS PORT SERVICE(S)"
|
|
|
|
echo " ---- ----- ----------"
|
2007-11-16 00:24:54 +01:00
|
|
|
$LOGREAD | grep "${today}IN=.* OUT=.*DPT" | sed 's/\(.*DPT=\)\([0-9]\{1,5\}\)\(.*\)/\2/' | sort | uniq -c | sort -rn | while read count port ; do
|
2006-11-05 20:47:59 +01:00
|
|
|
# List all services defined for the given port
|
|
|
|
srv=$(grep "^[^#].*\\b$port/" /etc/services | cut -f 1 | cut -f 1 -d' ' | sort -u)
|
|
|
|
srv=$(echo $srv | sed 's/ /,/g')
|
|
|
|
|
|
|
|
if [ -n "$srv" ] ; then
|
|
|
|
printf '%7d %5d %s\n' $count $port $srv
|
|
|
|
else
|
|
|
|
printf '%7d %5d\n' $count $port
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
2006-11-29 01:53:39 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# 'allow' command executor
|
|
|
|
#
|
|
|
|
allow_command() {
|
|
|
|
[ -n "$debugging" ] && set -x
|
|
|
|
[ $# -eq 1 ] && usage 1
|
|
|
|
if shorewall_is_started ; then
|
2007-06-16 17:43:14 +02:00
|
|
|
[ -n "$nolock" ] || mutex_on
|
2006-11-29 01:53:39 +01:00
|
|
|
while [ $# -gt 1 ]; do
|
|
|
|
shift
|
|
|
|
case $1 in
|
|
|
|
*-*)
|
|
|
|
if qt $IPTABLES -D dynamic -m iprange --src-range $1 -j reject ||\
|
|
|
|
qt $IPTABLES -D dynamic -m iprange --src-range $1 -j DROP ||\
|
|
|
|
qt $IPTABLES -D dynamic -m iprange --src-range $1 -j logdrop ||\
|
|
|
|
qt $IPTABLES -D dynamic -m iprange --src-range $1 -j logreject
|
|
|
|
then
|
|
|
|
echo "$1 Allowed"
|
|
|
|
else
|
|
|
|
echo "$1 Not Dropped or Rejected"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if qt $IPTABLES -D dynamic -s $1 -j reject ||\
|
|
|
|
qt $IPTABLES -D dynamic -s $1 -j DROP ||\
|
|
|
|
qt $IPTABLES -D dynamic -s $1 -j logdrop ||\
|
|
|
|
qt $IPTABLES -D dynamic -s $1 -j logreject
|
|
|
|
then
|
|
|
|
echo "$1 Allowed"
|
|
|
|
else
|
|
|
|
echo "$1 Not Dropped or Rejected"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2007-06-16 17:43:14 +02:00
|
|
|
[ -n "$nolock" ] || mutex_off
|
2006-11-29 01:53:39 +01:00
|
|
|
else
|
|
|
|
error_message "ERROR: $PRODUCT is not started"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
}
|
2007-05-18 00:50:32 +02:00
|
|
|
|
2006-11-29 02:11:29 +01:00
|
|
|
#
|
|
|
|
# 'logwatch' command executor
|
|
|
|
#
|
|
|
|
logwatch_command() {
|
|
|
|
shift
|
|
|
|
|
|
|
|
finished=0
|
|
|
|
|
|
|
|
while [ $finished -eq 0 -a $# -ne 0 ]; do
|
|
|
|
option=$1
|
|
|
|
case $option in
|
|
|
|
-*)
|
|
|
|
option=${option#-}
|
|
|
|
|
|
|
|
[ -z "$option" ] && usage 1
|
|
|
|
|
|
|
|
while [ -n "$option" ]; do
|
|
|
|
case $option in
|
|
|
|
v*)
|
|
|
|
VERBOSE=$(($VERBOSE + 1 ))
|
|
|
|
option=${option#v}
|
|
|
|
;;
|
|
|
|
q*)
|
|
|
|
VERBOSE=$(($VERBOSE - 1 ))
|
|
|
|
option=${option#q}
|
|
|
|
;;
|
|
|
|
m*)
|
|
|
|
SHOWMACS=Yes
|
|
|
|
option=${option#m}
|
|
|
|
;;
|
|
|
|
-)
|
|
|
|
finished=1
|
|
|
|
option=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
finished=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
[ -n "$debugging" ] && set -x
|
|
|
|
|
|
|
|
if [ $# -eq 1 ]; then
|
|
|
|
logwatch $1
|
|
|
|
elif [ $# -eq 0 ]; then
|
|
|
|
logwatch 30
|
|
|
|
else
|
|
|
|
usage 1
|
|
|
|
fi
|
|
|
|
}
|