mirror of
https://github.com/cmehay/docker-tor-hidden-service.git
synced 2025-04-19 21:39:13 +00:00
Display port with .onion
This commit is contained in:
parent
7cb15100bd
commit
3081356fb1
4 changed files with 34 additions and 7 deletions
12
README.md
12
README.md
|
@ -20,6 +20,12 @@ $ docker run -ti --link something --volume /path/to/keys:/var/lib/tor/hidden_ser
|
|||
|
||||
Look at the `docker-compose.yml` file to see how to use it.
|
||||
|
||||
### Setup port
|
||||
|
||||
By default, ports are the same as linked containers, but a default port can be mapped using `PORT_MAP` environment variable.
|
||||
|
||||
__Caution__: Using `PORT_MAP` with multiple ports on single service will cause `tor` to fail.
|
||||
|
||||
### Tools
|
||||
|
||||
A command line tool `onions` is available in container to get `.onion` url when container is running.
|
||||
|
@ -27,12 +33,12 @@ A command line tool `onions` is available in container to get `.onion` url when
|
|||
```sh
|
||||
# Get services
|
||||
$ docker exec -ti torhiddenproxy_tor_1 onions
|
||||
hello: vegm3d7q64gutl75.onion
|
||||
world: b2sflntvdne63amj.onion
|
||||
hello: vegm3d7q64gutl75.onion:80
|
||||
world: b2sflntvdne63amj.onion:80
|
||||
|
||||
# Get json
|
||||
$ docker exec -ti torhiddenproxy_tor_1 onions --json
|
||||
{"world": "b2sflntvdne63amj.onion", "hello": "vegm3d7q64gutl75.onion"}
|
||||
{"hello": ["b2sflntvdne63amj.onion:80"], "world": ["vegm3d7q64gutl75.onion:80"]}
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -16,6 +16,23 @@ class Onions(object):
|
|||
if 'HIDDEN_SERVICE_DIR' in os.environ:
|
||||
self.hidden_service_dir = os.environ['HIDDEN_SERVICE_DIR']
|
||||
|
||||
def _get_port_from_service(self, service, filename):
|
||||
|
||||
with open(filename, 'r') as hostfile:
|
||||
onion = str(hostfile.read()).strip()
|
||||
|
||||
with open('/etc/tor/torrc', 'r') as torfile:
|
||||
self.onions[service] = []
|
||||
for line in torfile.readlines():
|
||||
find = '# PORT {name}'.format(name=service)
|
||||
if line.startswith(find):
|
||||
self.onions[service].append(
|
||||
'{onion}:{port}'.format(
|
||||
onion=onion,
|
||||
port=line[len(find):].strip()
|
||||
)
|
||||
)
|
||||
|
||||
def _get_onions(self):
|
||||
self.onions = {}
|
||||
for root, dirs, _ in os.walk(self.hidden_service_dir,
|
||||
|
@ -25,13 +42,12 @@ class Onions(object):
|
|||
service=service,
|
||||
root=root
|
||||
)
|
||||
with open(filename, 'r') as hostfile:
|
||||
self.onions[service] = str(hostfile.read()).strip()
|
||||
self._get_port_from_service(service, filename)
|
||||
|
||||
def __str__(self):
|
||||
if not self.onions:
|
||||
return 'No onion site'
|
||||
return '\n'.join(['%s: %s' % (service, onion)
|
||||
return '\n'.join(['%s: %s' % (service, ', '.join(onion))
|
||||
for (service, onion) in self.onions.items()])
|
||||
|
||||
def to_json(self):
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
{% for container in containers %}
|
||||
HiddenServiceDir /var/lib/tor/hidden_service/{{container.names[0]}}
|
||||
{% for link in container.links %}
|
||||
HiddenServicePort {{link.port}} {{link.ip}}:{{link.port}}
|
||||
{% set port = env['PORT_MAP'] if 'PORT_MAP' in env else link.port %}
|
||||
# PORT {{container.names[0]}} {{port}}
|
||||
HiddenServicePort {{port}} {{link.ip}}:{{link.port}}
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
|
|
|
@ -2,9 +2,12 @@
|
|||
|
||||
tor:
|
||||
image: goldy/tor-hidden-service
|
||||
# build: .
|
||||
links:
|
||||
- hello
|
||||
- world
|
||||
environment:
|
||||
PORT_MAP: 80 # Map port to detected service
|
||||
|
||||
hello:
|
||||
image: tutum/hello-world
|
||||
|
|
Loading…
Add table
Reference in a new issue