mirror of
https://github.com/cmehay/docker-tor-hidden-service.git
synced 2025-05-31 20:02:15 +00:00
initial commit
This commit is contained in:
commit
45219ce52f
5 changed files with 166 additions and 0 deletions
51
assets/tor_config.py
Normal file
51
assets/tor_config.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
from docker import docker
|
||||
from subprocess import call
|
||||
|
||||
# Generate conf for tor hidden service
|
||||
def set_conf():
|
||||
rtn = []
|
||||
links = docker.get_links()
|
||||
with open("/etc/tor/torrc", "a") as conf:
|
||||
for link in links:
|
||||
path = "/var/lib/tor/hidden_service/{service}".format(service=link)
|
||||
# Test if link has ports
|
||||
if len(links[link]['ports']) == 0:
|
||||
print("{link} has no port")
|
||||
continue
|
||||
conf.write('HiddenServiceDir {path}\n'.format(path=path))
|
||||
rtn.append(link)
|
||||
for port in links[link]['ports']:
|
||||
if links[link]['ports'][port]['protocol'] == 'UDP':
|
||||
continue
|
||||
service = '{port} {ip}:{port}'.format(
|
||||
port=port, ip=links[link]['ip']
|
||||
)
|
||||
conf.write('HiddenServicePort {service}\n'.format(
|
||||
service=service
|
||||
))
|
||||
# set relay if enabled in env (not so secure)
|
||||
if 'RELAY' in os.environ:
|
||||
conf.write("ORPort 9001\n")
|
||||
# Disable local socket
|
||||
conf.write("SocksPort 0\n")
|
||||
return rtn
|
||||
|
||||
def gen_host(services):
|
||||
# Run tor to generate keys if they doesn't exist
|
||||
call(["sh", "-c", "timeout 3s tor > /dev/null"])
|
||||
for service in services:
|
||||
filename = "/var/lib/tor/hidden_service/{service}/hostname".format(
|
||||
service=service
|
||||
)
|
||||
with open(filename, 'r') as hostfile:
|
||||
print('{service}: {onion}'.format(
|
||||
service=service,
|
||||
onion=hostfile.read()
|
||||
))
|
||||
|
||||
if __name__ == '__main__':
|
||||
services = set_conf()
|
||||
gen_host(services)
|
Loading…
Add table
Add a link
Reference in a new issue