diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index d992b0f..0000000 --- a/.dockerignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -.git \ No newline at end of file diff --git a/.env b/.env deleted file mode 100644 index e69de29..0000000 diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 0733e05..0000000 --- a/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -FROM node:4.2.3 - -COPY . /app - -WORKDIR /app - -ENV DOCKER tcp://127.0.0.1:2375 - -ENV TORS 5 - -ENV DNS_PORT 9053 - -ENV PORT 9050 - -EXPOSE 9053 - -EXPOSE 9050 - -RUN npm install - -CMD /app/run.sh \ No newline at end of file diff --git a/bin/tor-router.js b/bin/tor-router.js old mode 100644 new mode 100755 index 108a018..4d6c16f --- a/bin/tor-router.js +++ b/bin/tor-router.js @@ -1,19 +1,39 @@ 'use strict'; -const TorPool = require('../lib/TorPool.js'); -const DockerPool = require('../lib/DockerPool'); -const SOCKS = require('../lib/SOCKSServer.js'); -const DNS = require('../lib/DNSServer.js'); +const dir = __dirname+'/../'; + +const TorPool = require(dir+'/lib/TorPool.js'); +const DockerPool = require(dir+'/lib/DockerPool'); +const SOCKS = require(dir+'/lib/SOCKSServer.js'); +const DNS = require(dir+'/lib/DNSServer.js'); const url = require('url'); +const program = require('commander'); -const program = { - docker: process.env.DOCKER || 'tcp://127.0.0.1:2375', - tors: parseInt(process.env.TORS) || 1, - port: parseInt(process.env.PORT) || 9050, - dns: parseInt(process.env.DNS_PORT) || 9053 -}; -var docker = new DockerPool({ host: (url.parse(program.docker).hostname), port: (url.parse(program.docker).port) }); +program + .version('0.0.1') + .option('-H, --docker [unix:///var/run/docker.sock]', 'Docker Host', (parseInt(process.env.DOCKER_HOST) || 'unix:///var/run/docker.sock')) + .option('-j, --tors [1]', 'Number of Tor Instances', (parseInt(process.env.TOR_INSTANCES) || 1)) + .option('-p, --port [9050]', 'SOCKS Port', (parseInt(process.env.PORT) || 9050)) + .option('-d, --dns [9053]', 'DNS Port', (parseInt(process.env.DNS_PORT) || 9053)) + .parse(process.argv); + +var docker_url = (url.parse(program.docker)); + +var docker_cfg = {}; +if (docker_url.protocol === 'unix:') { + docker_cfg.socketPath = docker_url.path; +} else if (docker_url.protocol === 'http:' || docker_url.protocol === 'tcp:') { + docker_cfg.host = docker_url.hostname; + docker_cfg.port = docker_url.port; + if (docker_url.protocol !== 'tcp:') { + docker_cfg.protocol = docker_url.protocol.replace(':', ''); + } +} else { + throw new Error('Invalid docker protocol: '+docker_url.protocol); +} + +var docker = new DockerPool(); var pool = new TorPool(program.tors, docker); process.stdin.resume(); @@ -30,7 +50,7 @@ pool.start(function () { }); } if (program.dns) { - let dns = new DNS(pool); + let dns = new DNS(pool, true); dns.server.serve(program.dns); } diff --git a/package.json b/package.json index e1b471c..ee07d67 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "tor-router", "version": "0.0.1", + "bin": "bin/tor-router.js", "author": [ { "name": "Zachary Boyd", diff --git a/run.sh b/run.sh deleted file mode 100755 index 7870b39..0000000 --- a/run.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -echo "using docker host $DOCKER" - -cd /app && node bin/tor-router.js - -exit 0 \ No newline at end of file