[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

(FWD) privoxy.tor: Script control privoxy's tor.



[Posted via gmane; I'm forwarding to the list. Let me know if you find
this useful or think we should put it somewhere more permanent. -RD]

----- Forwarded message from owner-or-talk@xxxxxxxxxxxxx -----

To: or-talk@xxxxxxxxxxxxx
From: JustFillBug <mozbugbox@xxxxxxxxxxxx>
Subject:  privoxy.tor: Script control privoxy's tor.
Date: Thu, 10 Mar 2005 04:13:25 +0000 (UTC)

Tor gates can be quite slow. Here is a script to turn privoxy's tor
on/off easily. Can be used with sudo.


>>>>>>>>>>>>>>>>>>-privoxy.tor-<<<<<<<<<<<<<<<<<<<<<<<
#!/bin/sh
# A script to turn tor sock4a in privoxy on or off.

CONFFILE=/etc/privoxy/config		# privoxy config file.
TOR_REG="forward.*localhost:9050"	# Regular expression open the tor in privoxy
PRIVOXY="/etc/init.d/privoxy restart"	# command to reload privoxy config file.
SED="/bin/sed"				# sed command, of course.
GREP="/bin/grep"			# grep command.

usage () {
echo "\
Usage: 
   privoxy.tor 			<-- No arguements. Switch the tor on or off.
   privoxy.tor [on|off]		<-- Set the tor on or off.
   privoxy.tor !.*xia		<-- Any arguement other than above shows
				    current status of the tor.
   privoxy.tor [-h|--help|-?]	<-- Print usage.
"
}

# Find out the current status of tor. Set $tor_status
get_status () {
   gret=`$GREP -l -e "^$TOR_REG"  $CONFFILE`
   if [ x$gret = x ] ; then
        tor_status=off;
   else
        tor_status=on;
   fi
   return
}

# Turn tor on/off according to $1
set_tor () {
   tor_gate=$1
   get_status
   if [ $tor_status = $tor_gate ] ; then
      echo "The tor is already $1."
      return
   elif [ $tor_gate = flip ] ; then
	if [ $tor_status = on ] ; then
		tor_gate=off
	elif [ $tor_status = off ] ; then
     		tor_gate=on
	fi
   fi
   echo "Turning the tor $tor_gate..."
   if [ $tor_gate = on ] ; then
   	reg=s/^#\($TOR_REG\)/\\1/
	$SED -i.bak -r "$reg"  $CONFFILE
   else
   	reg=s/^\($TOR_REG\)/#\\1/
	$SED -i.bak -r "$reg" $CONFFILE
   fi
   $PRIVOXY
   return 0;
}

if [ x$1 = x ] ; then
   set_tor flip
elif [ $1 = on ] ; then
   set_tor on
elif [ $1 = off ] ; then 
   set_tor off
elif [ $1 = --help ] || [ $1 = -h ] || [ $1 = "-?" ] ; then
   usage
   exit 0
else
   get_status
   echo "Currently, the tor is $tor_status."
fi

----- End forwarded message -----