# /bin/sh

SSHHOST=${1:-mitel}

PROCDIRS=$(cd /proc; grep -l ENVHACK=esmith-fwds */environ 2>/dev/null)

if [ "$PROCDIRS" ]
then
    for proc in $PROCDIRS
	do
	   otherpid=$(dirname $proc)
	   echo killing process $otherpid
       kill $otherpid
    done
fi

ENVHACK="esmith-fwds"
export ENVHACK

SSH='/usr/bin/ssh'

# Options for both SSH sessions
SSHOPTS=
SSHOPTS="$SSHOPTS -n"  # input from /dev/null
SSHOPTS="$SSHOPTS -a"  # no auth-agent forwarding
SSHOPTS="$SSHOPTS -x"  # no X forwarding
SSHOPTS="$SSHOPTS -T"  # no tty
SSHOPTS="$SSHOPTS -f"  # fork into background
SSHOPTS="$SSHOPTS -N"  # don't execute a shell
#SSHOPTS="$SSHOPTS -g"  # allow connections to forwarded ports from elsewhere
SSHOPTS="$SSHOPTS -l richl" # me
#SSHOPTS="$SSHOPTS -C"  # compress???
SSHOPTS="$SSHOPTS -D 5191" # socks4
SSHOPTS="$SSHOPTS -v"

SSHFWD=
SSHFWD="$SSHFWD -L5222:allspice:5222"   # jabber -- requires 'nssg.mitel.com'
                                        #           mapped to localhost
SSHFWD="$SSHFWD -L3129:allspice:3128"   # web
SSHFWD="$SSHFWD -L25000:smtp:25"		# smtp
SSHFWD="$SSHFWD -L25144:allspice:144"	# imap
SSHFWD="$SSHFWD -L25143:kandb02:143"	# imap
SSHFWD="$SSHFWD -L25993:allspice:993"	# imaps
SSHFWD="$SSHFWD -L3389:ottadc01:3389"   # rdp

exec ${SSH} ${SSHOPTS} ${SSHFWD} ${SSHHOST} || echo "ssh failed"
