#!/bin/sh
#
# tircproxy     This shell script takes care of starting and stopping
#               the tircproxy (RedHat style init script).
#
# This example enables transparent proxying for all IRC servers on ports 
# 6666 and 6667 that aren't on the 12.34.56.0/24 network, for machines not 
# on that network (i.e. this is for a mixed legal/illegal IP address 
# environment, where the legal network is 12.34.56.0/24).
#
# In this case we assume the legal network should be allowed to connect to 
# IRC directly, which might not be a good idea as it bypasses both the DCC
# trojan manglers and the broadcasting code.
#
# This example also assumes there is a dedicated IRC server on the local 
# network, which the hidden network should have direct (unproxied) access to.
#

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -f /usr/sbin/tircproxy ] || exit 0

# See how we were called.
case "$1" in
  start)
        # Start daemons.
        echo -n "Starting transparent IRC proxy: "
        echo -n "redirection "
        ipfwadm -I -i accept -P tcp -S 12.34.56/24 -D 0.0.0.0/0 7000:7003
        ipfwadm -I -i accept -P tcp -S 12.34.56/24 -D 0.0.0.0/0 6660:6669
        ipfwadm -I -i accept -P tcp -S 0.0.0.0/0 -D local.irc.server 6660:6669
        ipfwadm -I -a accept -P tcp -S 0.0.0.0/0 -D 0.0.0.0/0 7000:7003 -r 8666
        ipfwadm -I -a accept -P tcp -S 0.0.0.0/0 -D 0.0.0.0/0 6660:6669 -r 8666
        daemon /usr/sbin/tircproxy -s 8666 -t 3 -I -o $HOSTNAME
        touch /var/lock/subsys/tircproxy
        echo
        ;;
  stop)
        # Stop daemons.
        echo -n "Shutting down transparent IRC proxy: "
        killproc tircproxy
        echo -n " redirection"
        ipfwadm -I -d accept -P tcp -S 12.34.56/24 -D 0.0.0.0/0 7000:7003
        ipfwadm -I -d accept -P tcp -S 12.34.56/24 -D 0.0.0.0/0 6660:6669
        ipfwadm -I -d accept -P tcp -S 0.0.0.0/0 -D local.irc.server 6660:6669
        ipfwadm -I -d accept -P tcp -S 0.0.0.0/0 -D 0.0.0.0/0 7000:7003 -r 8666
        ipfwadm -I -d accept -P tcp -S 0.0.0.0/0 -D 0.0.0.0/0 6660:6669 -r 8666
        echo
        rm -f /var/lock/subsys/tircproxy
        ;;
  *)
        echo "Usage: tircproxy {start|stop}"
        exit 1
esac

exit 0


syntax highlighted by Code2HTML, v. 0.9.1