|
@@ -1,22 +1,29 @@
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -43,8 +50,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
VERSION=v1
|
|
|
TORCTLIP=127.0.0.1
|
|
@@ -58,40 +66,41 @@ usage()
|
|
|
cat <<EOF
|
|
|
|
|
|
tor-ctrl $VERSION by Stefan Behte (http://ge.mine.nu)
|
|
|
-You should have a look at http://tor.eff.org/svn/trunk/doc/spec/control-spec.txt
|
|
|
+You should have a look at
|
|
|
+ http://tor.eff.org/svn/trunk/doc/spec/control-spec.txt
|
|
|
|
|
|
usage: tor-ctrl [-switch] [variable]
|
|
|
|
|
|
- [-c] [command] = command to execute
|
|
|
- notice: always "quote" your command
|
|
|
+ [-c] [command] = command to execute
|
|
|
+ notice: always "quote" your command
|
|
|
|
|
|
- [-f] [file] = file to execute commands from
|
|
|
- notice: only one command per line
|
|
|
+ [-f] [file] = file to execute commands from
|
|
|
+ notice: only one command per line
|
|
|
|
|
|
- [-a] [path] = path to tor's control_auth_cookie
|
|
|
- default: /var/lib/tor/data/control_auth_cookie
|
|
|
- notice: do not forget to adjust your torrc
|
|
|
+ [-a] [path] = path to tor's control_auth_cookie
|
|
|
+ default: /var/lib/tor/data/control_auth_cookie
|
|
|
+ notice: do not forget to adjust your torrc
|
|
|
|
|
|
- [-s] [time] = sleep [var] seconds after each command sent
|
|
|
- default: 1 second
|
|
|
- notice: for GETCONF, you can use smaller pause times than for SETCONF
|
|
|
- this is due to telnet's behaviour.
|
|
|
+ [-s] [time] = sleep [var] seconds after each command sent
|
|
|
+ default: 1 second
|
|
|
+ notice: for GETCONF, you can use smaller pause times
|
|
|
+ than for SETCONF; this is due to telnet's behaviour.
|
|
|
|
|
|
- [-p] [pwd] = Use password [var] instead of tor's control_auth_cookie
|
|
|
- default: not used
|
|
|
- notice: do not forget to adjust your torrc
|
|
|
-
|
|
|
- [-P] [port] = Tor ControlPort
|
|
|
- default: 9051
|
|
|
+ [-p] [pwd] = Use password [var] instead of tor's control_auth_cookie
|
|
|
+ default: not used
|
|
|
+ notice: do not forget to adjust your torrc
|
|
|
+
|
|
|
+ [-P] [port] = Tor ControlPort
|
|
|
+ default: 9051
|
|
|
|
|
|
- [-v] = verbose
|
|
|
- default: not set
|
|
|
- notice: the default output is the return code ;)
|
|
|
- You propably want to set -v when running manually
|
|
|
+ [-v] = verbose
|
|
|
+ default: not set
|
|
|
+ notice: the default output is the return code ;)
|
|
|
+ You propably want to set -v when running manually
|
|
|
|
|
|
- Examples: $0 -c "SETCONF bandwidthrate=1mb"
|
|
|
- $0 -v -c "GETINFO version"
|
|
|
- $0 -v -s 0 -P 9051 -p foobar -c "GETCONF bandwidthrate"
|
|
|
+ Examples: $0 -c "SETCONF bandwidthrate=1mb"
|
|
|
+ $0 -v -c "GETINFO version"
|
|
|
+ $0 -v -s 0 -P 9051 -p foobar -c "GETCONF bandwidthrate"
|
|
|
|
|
|
EOF
|
|
|
exit 2
|
|
@@ -99,103 +108,104 @@ exit 2
|
|
|
|
|
|
checkprogs()
|
|
|
{
|
|
|
- programs="telnet"
|
|
|
- if [ "$PASSWORD" = "" ]
|
|
|
- then
|
|
|
- programs="$programs xxd"
|
|
|
- fi
|
|
|
-
|
|
|
- for p in $programs
|
|
|
- do
|
|
|
- which $p &>/dev/null
|
|
|
- if [ "$?" != "0" ]
|
|
|
- then
|
|
|
- echo "$p is missing."
|
|
|
- exit 2
|
|
|
- fi
|
|
|
- done
|
|
|
+ programs="telnet"
|
|
|
+ if [ "$PASSWORD" = "" ]
|
|
|
+ then
|
|
|
+
|
|
|
+ programs="$programs xxd"
|
|
|
+ fi
|
|
|
+
|
|
|
+ for p in $programs
|
|
|
+ do
|
|
|
+ which $p &>/dev/null
|
|
|
+ if [ "$?" != "0" ]
|
|
|
+ then
|
|
|
+ echo "$p is missing."
|
|
|
+ exit 2
|
|
|
+ fi
|
|
|
+ done
|
|
|
}
|
|
|
|
|
|
sendcmd()
|
|
|
{
|
|
|
- echo "$@"
|
|
|
- sleep ${SLEEP_AFTER_CMD}
|
|
|
+ echo "$@"
|
|
|
+ sleep ${SLEEP_AFTER_CMD}
|
|
|
}
|
|
|
|
|
|
login()
|
|
|
{
|
|
|
- if [ "$PASSWORD" = "" ]
|
|
|
- then
|
|
|
- sendcmd "AUTHENTICATE $(xxd -c 32 -g 0 ${TOR_COOKIE} | awk '{print $2}')"
|
|
|
- else
|
|
|
- sendcmd "AUTHENTICATE \"${PASSWORD}\""
|
|
|
- fi
|
|
|
+ if [ "$PASSWORD" = "" ]
|
|
|
+ then
|
|
|
+ sendcmd "AUTHENTICATE $(xxd -c 32 -g 0 ${TOR_COOKIE} | awk '{print $2}')"
|
|
|
+ else
|
|
|
+ sendcmd "AUTHENTICATE \"${PASSWORD}\""
|
|
|
+ fi
|
|
|
}
|
|
|
|
|
|
cmdpipe()
|
|
|
{
|
|
|
- login
|
|
|
- sendcmd "$@"
|
|
|
- sendcmd "QUIT"
|
|
|
+ login
|
|
|
+ sendcmd "$@"
|
|
|
+ sendcmd "QUIT"
|
|
|
}
|
|
|
|
|
|
vecho()
|
|
|
{
|
|
|
- if [ $VERBOSE -ge 1 ]
|
|
|
- then
|
|
|
- echo "$@"
|
|
|
- fi
|
|
|
+ if [ $VERBOSE -ge 1 ]
|
|
|
+ then
|
|
|
+ echo "$@"
|
|
|
+ fi
|
|
|
}
|
|
|
|
|
|
myecho()
|
|
|
{
|
|
|
- STR=$(cat)
|
|
|
- vecho "$STR"
|
|
|
-
|
|
|
- echo "$STR" | if [ "$(grep -c ^"250 ")" = 3 ]
|
|
|
- then
|
|
|
- exit 0
|
|
|
- else
|
|
|
- exit 1
|
|
|
- fi
|
|
|
+ STR=$(cat)
|
|
|
+ vecho "$STR"
|
|
|
+
|
|
|
+ echo "$STR" | if [ "$(grep -c ^"250 ")" = 3 ]
|
|
|
+ then
|
|
|
+ exit 0
|
|
|
+ else
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
}
|
|
|
|
|
|
filepipe()
|
|
|
{
|
|
|
- login
|
|
|
- cat "$1" | while read line
|
|
|
- do
|
|
|
- sendcmd "$line"
|
|
|
- done
|
|
|
- sendcmd "QUIT"
|
|
|
+ login
|
|
|
+ cat "$1" | while read line
|
|
|
+ do
|
|
|
+ sendcmd "$line"
|
|
|
+ done
|
|
|
+ sendcmd "QUIT"
|
|
|
}
|
|
|
|
|
|
while getopts ":a:c:s:p:P:f:vh" Option
|
|
|
do
|
|
|
- case $Option in
|
|
|
- a) TOR_COOKIE="${OPTARG}";;
|
|
|
- c) CMD="${OPTARG}";;
|
|
|
- s) SLEEP_AFTER_CMD="${OPTARG}";;
|
|
|
- p) PASSWORD="${OPTARG}";;
|
|
|
- P) TORCTLPORT="${OPTARG}";;
|
|
|
- f) FILE="${OPTARG}";;
|
|
|
- v) VERBOSE=1;;
|
|
|
- h) usage;;
|
|
|
- *) usage;;
|
|
|
- esac
|
|
|
+ case $Option in
|
|
|
+ a) TOR_COOKIE="${OPTARG}";;
|
|
|
+ c) CMD="${OPTARG}";;
|
|
|
+ s) SLEEP_AFTER_CMD="${OPTARG}";;
|
|
|
+ p) PASSWORD="${OPTARG}";;
|
|
|
+ P) TORCTLPORT="${OPTARG}";;
|
|
|
+ f) FILE="${OPTARG}";;
|
|
|
+ v) VERBOSE=1;;
|
|
|
+ h) usage;;
|
|
|
+ *) usage;;
|
|
|
+ esac
|
|
|
done
|
|
|
|
|
|
if [ -e "$FILE" ]
|
|
|
then
|
|
|
- checkprogs
|
|
|
- filepipe "$FILE" | telnet $TORCTLIP $TORCTLPORT 2>/dev/null | myecho
|
|
|
- exit 4
|
|
|
+ checkprogs
|
|
|
+ filepipe "$FILE" | telnet $TORCTLIP $TORCTLPORT 2>/dev/null | myecho
|
|
|
+ exit 4
|
|
|
fi
|
|
|
|
|
|
if [ "$CMD" != "" ]
|
|
|
then
|
|
|
- checkprogs
|
|
|
- cmdpipe $CMD | telnet $TORCTLIP $TORCTLPORT 2>/dev/null | myecho
|
|
|
+ checkprogs
|
|
|
+ cmdpipe $CMD | telnet $TORCTLIP $TORCTLPORT 2>/dev/null | myecho
|
|
|
else
|
|
|
- usage
|
|
|
+ usage
|
|
|
fi
|