3 # Wrapper script for use of the tsocks(8) transparent socksification library
4 # See the tsocks(1) manpages.
6 # Copyright (c) 2004, 2006 Peter Palfrader
7 # Modified by Jacob Appelbaum <jacob@appelbaum.net> April 16th 2006
8 # Modified by Felix Bechstein <f@ub0r.de> Dec 23th 2007
11 # Define and ensure we have tsocks
12 # XXX: what if we don't have which?
13 TSOCKS
="`which tsocks`"
16 echo "$0: Can't find tsocks in PATH. Perhaps you haven't installed it?" >&2
23 # Check for any argument list
26 echo "Usage: $0 <port/dev> <command> [<options>...]" >&2
30 if [ "$#" = 1 ] && ( [ "$1" = "-h" ] ||
[ "$1" = "--help" ] )
32 echo "Usage: $0 <port/dev> <command> [<options>...]"
41 echo "Usage: $0 <port/dev> <command> [<options>...]" >&2
44 if [ "$#" = 1 ] && ( [ "$1" = "-h" ] ||
[ "$1" = "--help" ] )
46 echo "Usage: $0 <port/dev> <command> [<options>...]"
50 # generate config file for port/dev $TSOCKS_PORT
51 if [ -r "${TMPDIR}routify.${TSOCKS_PORT}" ] ; then
52 #conf file already generated. we should use that conf
53 TSOCKS_CONF_FILE
="${TMPDIR}routify.${TSOCKS_PORT}"
56 if echo test | nc localhost
${TSOCKS_PORT} > /dev
/null
2> /dev
/null
; then
57 if [ -z "$TSOCKS_CONF_FILE" ] ; then
58 echo "server = 127.0.0.1" > ${TMPDIR}routify.
${TSOCKS_PORT}
59 echo "server_port = ${TSOCKS_PORT}" >> ${TMPDIR}routify.${TSOCKS_PORT}
62 /sbin/ifconfig | grep -o "^
[a-zA-Z
][^
]*" | grep -v ^lo$ > "${TMPDIR}devlist
"
63 if echo ${TSOCKS_PORT} | grep -f "${TMPDIR}devlist
" > /dev/null ; then
64 TSOCKS_DEV=${TSOCKS_PORT}
66 # but no proxy started for this device
67 if [ -z "$TSOCKS_CONF_FILE" ] ; then
70 if echo test | nc localhost ${TSOCKS_PORT} > /dev/null 2> /dev/null ; then
71 TSOCKS_PORT=$(expr ${TSOCKS_PORT} + 1) # search for free port
73 if fgrep "server_port
= $TSOCKS_PORT" ${TMPDIR}routify.* > /dev/null 2> /dev/null ; then
74 TSOCKS_PORT=$(expr ${TSOCKS_PORT} + 1) # search for free port
81 echo "server
= 127.0.0.1" > ${TMPDIR}routify.${TSOCKS_DEV}
82 echo "server_port
= ${TSOCKS_PORT}" >> ${TMPDIR}routify.${TSOCKS_DEV}
84 # read port from conf file
85 TSOCKS_PORT
=$
(grep server_port
${TMPDIR}routify.
${TSOCKS_PORT} |
tr -d 'a-zA-Z =#;_')
87 # start nylon on $TSOCKS_DEV to listen on $TSOCKS_PORT
88 echo test | nc localhost
${TSOCKS_PORT} 2> /dev
/null
> /dev
/null || \
89 nylon
-p $TSOCKS_PORT -I $TSOCKS_DEV -P ${TMPDIR}routify.
${TSOCKS_DEV}.nylon
90 TSOCKS_CONF_FILE
="${TMPDIR}routify.${TSOCKS_DEV}"
92 echo "socket-proxy is down!"
101 # Define our tsocks config file
102 [ -z "$TSOCKS_CONF_FILE" ] && TSOCKS_CONF_FILE
="${TMPDIR}routify.${TSOCKS_PORT}"
103 export TSOCKS_CONF_FILE
105 # Check that we've got a tsocks config file
106 if [ -r "$TSOCKS_CONF_FILE" ]
109 echo "$0: Failed to exec tsocks $@" >&2
112 echo "$0: Missing tsocks configuration file \"$TSOCKS_CONF_FILE\"." >&2