1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#!/bin/bash
##### v1.0.0
##### written by Daniel Roesen <droesen@entire-systems.com>
##### Configuration (change as needed) ######################
CONFIG=/usr/local/etc/redir-wrapper.conf # our configuration file
REDIR=redir # redir executable name
REDIR_PATH=/usr/local/sbin # path where redir resides
PING=ping
##### End of user configuration #############################
MYNAME=`basename $0` # name of this script
LOGCRITIC="logger -s -p daemon.crit -t ${MYNAME}[$$]"
LOGERROR="logger -s -p daemon.err -t ${MYNAME}[$$]"
LOGNOTICE="logger -s -p daemon.notice -t ${MYNAME}[$$]"
OPTTEMP=/tmp/${MYNAME}-options # name of the temporary option file
IFS=${IFS}: # append ":" to the IFS
RET=0 # return-code
#############################################################
killall -q redir # shutdown any running redirectors
rm -f $OPTTEMP # remove temporary file
###
### reading the config file
###
if [ ! -f $CONFIG ]; then
$LOGCRITIC "$CONFIG not found, no redirectors started!"
exit 1
fi
###
### get default options
###
grep "^option " $CONFIG | while read JUNK OPTNAME OPTPARAM
do
case $OPTNAME in
debug) echo -n " --debug" >>$OPTTEMP ;;
timeout) echo -n " --timeout="$OPTPARAM >>$OPTTEMP ;;
syslog) echo -n " --syslog" >>$OPTTEMP ;;
identity) echo -n " --bind_addr=$OPTPARAM" >>$OPTTEMP ;;
ftp) echo -n " --ftp" >>$OPTTEMP ;;
transproxy) echo -n " --transproxy" >>$OPTTEMP ;;
*) $LOGERROR "unknown option \"$OPTNAME\", ignored."
RET=1
;;
esac
done
###
### start redirectors
###
grep "^redir" $CONFIG | while read JUNK NAME FROMADDR FROMPORT TOADDR TOPORT OPTIONS
do
# build argument list
REDIR_ARGS="--laddr=${FROMADDR} --lport=${FROMPORT}"
REDIR_ARGS=$REDIR_ARGS" --caddr=${TOADDR} --cport=${TOPORT}"
REDIR_ARGS=$REDIR_ARGS"`cat ${OPTTEMP}` ${OPTIONS}"
REDIR_ARGS=$REDIR_ARGS" --name=${REDIR}-${NAME}"
# start the redirector
$LOGNOTICE "starting redirector \"${NAME}\"..."
$REDIR_PATH/$REDIR $REDIR_ARGS &
# MYPID=$!
#
# ps $! >/dev/null
#
# if [ $? = "0" ]
# then
# $LOGNOTICE "...succeeeded!"
# else
# $LOGCRITIC "redirector \"${NAME}\" failed!"
# RET=1
# fi
done
### remove temporary files
rm $OPTTEMP # remove temporary option file
exit $RET
|