mirror of
https://github.com/cmehay/docker-tor-hidden-service.git
synced 2025-05-31 20:02:15 +00:00
Display port with .onion
This commit is contained in:
parent
7cb15100bd
commit
3081356fb1
4 changed files with 34 additions and 7 deletions
|
@ -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 %}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue