Image

Image

Search This Blog

Tuesday, September 16, 2008

redir init script
Posted by rain on August 29th, 2008

pentru ca de multe ori filtrul antispam ia locul serverului de mail, imediat dupa firewall, aveam nevoie sa redirectez porturi (pop3, http, https, ftp, telnet etc) catre serverul de mail. am facut un script de init pentru redir ( http://sammy.net/~sammy/hacks/redir-2.2.1.tar.gz ). da, puteam face asta si din iptables, stiu.

fisierul de configurare contine linii de forma:

# port_sursa ip_destinatie port_destinatie optiune1 optiune2

110 10.0.0.1 110 --transproxy

80 10.0.0.1 80

21 10.0.0.1 21 --transproxy --ftp

# ===============================================

scriptul:

#!/bin/bash
#
# /etc/rc.d/init.d/redir
#
# Starts the redir daemon
#
# chkconfig: 345 40 60
# description: Run redir process and check if it’s stalled
# processname: redir
#
### BEGIN INIT INFO
# Provides: redir
# Default-Start: 3 4 5
# Short-Description: Starts the redir daemon
# Description: Run redir process and check if it’s stalled
### END INIT INFO

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

prog=”/usr/sbin/redir”
conf=”/etc/sysconfig/redir.conf”

test -x $prog || echo “No binary file” || exit 0
test -f $conf || echo “No config” || exit 0

RETVAL=0

# Define main functions

start() {
gprintf “Starting %s: ” “$prog”
sed ‘/^ *#/d;s/#.*//’ $conf | while read a b c d e
do
$prog –lport=$a –caddr=$b –cport=$c $d $e &
done
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/redir
echo
return $RETVAL
}

stop() {
gprintf “Stopping %s: ” “$prog”
killproc $prog
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/redir
echo
return $RETVAL
}

check() {
sed ‘/^ *#/d;s/#.*//’ $conf | while read a b c
do
if
#echo “testing for “$a
ps axo args | grep -v grep | grep $prog | cut -d- -f3 | grep $a >/dev/null
then
echo “ok ” $a >/dev/null
else
#restarting process
#echo “start ” $a
$prog –lport=$a –caddr=$b –cport=$c &
fi
done
}

restart() {
stop
sleep 5
start
}

reload() {
restart
}

status_rd() {
status $prog
}

# See how we were called.

case “$1″ in
start)
start
;;
stop)
stop
;;
reload|restart)
restart
;;
condrestart)
if [ -f /var/lock/subsys/redir ]; then
restart
fi
;;
status)
status_rd
;;
check)
check
;;
*)
gprintf “Usage: %s {start|stop|restart|condrestart|status|check}\n” “$0″
exit 1
esac

exit $?
exit $RETVAL

No comments:

Post a Comment

Blog Archive