Adds readme. fully working

This commit is contained in:
zachary 2015-07-06 14:26:31 -04:00
parent 133b4820d7
commit 4f3d19a71a
9 changed files with 74 additions and 67 deletions

View file

@ -3,4 +3,5 @@ Dockerfile
.git
.gitignore
.drone.yml
Makefile
Makefile
run.sh

View file

@ -1,7 +1,9 @@
FROM ubuntu:15.04
FROM php:5.4.42-cli
VOLUME /var/lib/docker
VOLUME /tmp
COPY ./install_docker.sh /usr/local/bin/install_docker
RUN chmod +x /usr/local/bin/install_docker
@ -10,7 +12,7 @@ RUN bash /usr/local/bin/install_docker
COPY docker /usr/bin/docker
ADD ./dind/wrapdocker /usr/local/bin/wrapdocker
COPY ./dind/wrapdocker /usr/local/bin/wrapdocker
RUN chmod +x /usr/local/bin/wrapdocker
@ -22,6 +24,8 @@ COPY ./tor-router.sh /usr/local/bin/tor-router
COPY ./new_ip.sh /usr/local/bin/new-ip
COPY ./haproxy-config.php /opt/haproxy-config.php
RUN chmod -v +x /usr/local/bin/stop-tor-router
RUN chmod -v +x /usr/local/bin/start-tor-router

View file

@ -12,8 +12,5 @@ dind:
docker:
cp -aruv /usr/bin/docker docker
build: docker all
docker build -t znetstar/tor-router:0.0.1 .
install:
bash install.sh
docker build -t znetstar/tor-router:0.0.1 .

11
README.md Normal file
View file

@ -0,0 +1,11 @@
Creates multiple instances of Tor and switches between them in a round-robin fashion.
Based on Docker, HAProxy and of course Tor
Run using
./run.sh
Use the enviornment variable TOR_INSTANCES to set how many instances of Tor you'd like to run
Use the enviornment variable TOR_PORT to set the port you'd like to connect to. The TOR_PORT variable can also be an ip address and port (TOR_PORT=127.0.0.1:9050)
By default TOR_INSTANCES is set to 5 and TOR_PORT is set to 0.0.0.0:9050

28
haproxy-config.php Normal file
View file

@ -0,0 +1,28 @@
global
user root
group root
defaults
log global
mode http
option dontlognull
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
errorfile 400 /usr/local/etc/haproxy/errors/400.http
errorfile 403 /usr/local/etc/haproxy/errors/403.http
errorfile 408 /usr/local/etc/haproxy/errors/408.http
errorfile 500 /usr/local/etc/haproxy/errors/500.http
errorfile 502 /usr/local/etc/haproxy/errors/502.http
errorfile 503 /usr/local/etc/haproxy/errors/503.http
errorfile 504 /usr/local/etc/haproxy/errors/504.http
listen socks *:<?php echo getenv('TOR_PORT').PHP_EOL; ?>
<?php
$instances = intval(getenv("TOR_INSTANCES"));
$current_instance = 0;
while( $current_instance < $instances )
{ ?> server <?php echo $current_instance; ?> <?php echo getenv('INSTANCE_PREFIX').$current_instance; ?>:9050 check <?php $current_instance++; echo PHP_EOL; } ?>
mode tcp
balance roundrobin

View file

@ -1,7 +1,10 @@
#!/bin/bash
export TOR_INSTANCES=${TOR_INSTANCES:-5}
export TOR_PORT=${TOR_PORT:-9050}
apt-get update -y
apt-get install -yqq curl git tar
apt-get install -yqq curl git tar btrfs-tools
echo 'installing docker...'
@ -27,7 +30,7 @@ apt-get install -y lxc-docker-1.5.0
# END: docker installer
echo 'running tor-router...'
/usr/bin/docker run --privileged -v /var/run/docker.sock:/var/run/docker.sock -p 9050:9050 --rm -it znetstar/tor-router:0.0.1
echo 'starting up tor-router...'
/usr/bin/docker run --rm -it -e TOR_INSTANCES=$TOR_INSTANCES -e TOR_PORT=$TOR_PORT --name tor-router --privileged -v /tmp:/tmp -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker:/var/lib/docker znetstar/tor-router:0.0.1
exit 0

View file

@ -10,12 +10,15 @@ do
index=$[index+1]
done
echo "stop haproxy"
echo "shutting down haproxy..."
docker rm -f haproxy
echo "closing port"
iptables -A INPUT -p tcp --dport 9050 -j REJECT
echo 'removing files...'
rm -rf /tmp/haproxy.cfg
rm -rf /tmp/tor
#sleep 5
echo 'tor router has shut down'
exit 0

View file

@ -1,10 +1,9 @@
#!/bin/bash
export TEMP_HA_CONFIG=$(mktemp)
export TOR_CMD='tor --MaxCircuitDirtiness 60 --RunAsDaemon 0 --CookieAuthentication 0 --controlport 0.0.0.0:9051 --HashedControlPassword 16:4E9480609FC7089F604C83E788481164C25C205288E17D9E5E73EB050B --PidFile tor.pid --SocksPort 0.0.0.0:9150 --DataDirectory /data/tor --ExcludeSingleHopRelays 0 --NewCircuitPeriod 30 --EnforceDistinctSubnets 0 --AllowDotExit 1'
index="0"
export TOR_CMD='tor --MaxCircuitDirtiness 60 --RunAsDaemon 0 --CookieAuthentication 0 --controlport 0.0.0.0:9051 --HashedControlPassword 16:4E9480609FC7089F604C83E788481164C25C205288E17D9E5E73EB050B --PidFile tor.pid --SocksPort 0.0.0.0:9050 --DataDirectory /data/tor --ExcludeSingleHopRelays 0 --NewCircuitPeriod 30 --EnforceDistinctSubnets 0 --AllowDotExit 1'
index=0
instances=''
#docker -d &
while [ $index -lt $TOR_INSTANCES ]
@ -15,61 +14,22 @@ do
docker rm -f $current_instance
echo "instance $current_instance removed"
# control_port=$(cat $2/$current_instance)
echo "instnce $current_instance will be assigned control port control port $control_port"
echo "creating instance $current_instance..."
docker run --name $current_instance -d -v /data --restart="on-failure" znetstar/tor $TOR_CMD
echo "instance $current_instance created"
docker run -d -v /tmp/tor/$current_instance:/data --name $current_instance --restart="on-failure" znetstar/tor $TOR_CMD
echo 'created $current_instance'
instances="$instances --link $current_instance:$current_instance"
index=$[$index+1]
done
echo "removing haproxy..."
docker kill haproxy
docker rm -f haproxy
echo "writing config..."
cat << EOF > $TEMP_HA_CONFIG
global
user root
group root
php /opt/haproxy-config.php > /tmp/haproxy.cfg
defaults
log global
mode http
option dontlognull
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
errorfile 400 /usr/local/etc/haproxy/errors/400.http
errorfile 403 /usr/local/etc/haproxy/errors/403.http
errorfile 408 /usr/local/etc/haproxy/errors/408.http
errorfile 500 /usr/local/etc/haproxy/errors/500.http
errorfile 502 /usr/local/etc/haproxy/errors/502.http
errorfile 503 /usr/local/etc/haproxy/errors/503.http
errorfile 504 /usr/local/etc/haproxy/errors/504.http
EOF
echo "listen socks :$TOR_PORT" > $TEMP_HA_CONFIG
cat <<-EOF >> $TEMP_HA_CONFIG
mode tcp
balance roundrobin
EOF
index="0"
instances=""
while [ $index -lt $TOR_INSTANCES ]
do
current_instance=$INSTANCE_PREFIX$index
instances=$instances" --link $current_instance:$current_instance"
cat <<-EOF >> $TEMP_HA_CONFIG
server $current_instance $current_instance:9050 check
EOF
index=$[$index+1]
done
echo "starting haproxy..."
docker run -d -p 9050:9050 --name haproxy $instances -v $TEMP_HA_CONFIG:/usr/local/etc/haproxy/haproxy.cfg:ro haproxy:1.5.9
echo "tor server setup is complete"
echo "started tor-router"
clear;
docker run --name haproxy -d -p $TOR_PORT:9050 $instances -v /tmp/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro haproxy:1.5.9
exit 0

View file

@ -6,8 +6,8 @@ sleep 5
echo 'starting tor router...'
/usr/local/bin/start-tor-router
docker kill haproxy
docker start -a -i haproxy
docker logs -f haproxy &
docker wait haproxy
echo 'stopping tor router...'
/usr/local/bin/stop-tor-router