mirror of
https://github.com/cmehay/docker-tor-hidden-service.git
synced 2025-05-04 20:30:34 +00:00
Add onions tool in container
This commit is contained in:
parent
bebf1704ed
commit
8285c00f6e
7 changed files with 122 additions and 18 deletions
|
@ -7,12 +7,14 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
|
|||
tor \
|
||||
python3-pip
|
||||
|
||||
RUN pip3 install pyentrypoint==0.2.1
|
||||
RUN pip3 install pyentrypoint==0.2.2
|
||||
|
||||
ADD assets/entrypoint-config.yml /
|
||||
ADD assets/display_onions.py /
|
||||
ADD assets/onions /usr/local/src/onions
|
||||
ADD assets/torrc /etc/tor/torrc
|
||||
|
||||
RUN cd /usr/local/src/onions && python3 setup.py install
|
||||
|
||||
VOLUME ["/var/lib/tor/hidden_service/"]
|
||||
|
||||
ENTRYPOINT ["pyentrypoint"]
|
||||
|
|
20
README.md
20
README.md
|
@ -2,7 +2,7 @@
|
|||
|
||||
Create a tor hidden service with a link
|
||||
|
||||
```
|
||||
```sh
|
||||
# run a container with an network application
|
||||
$ docker run -d --name hello_world tutum/hello_world
|
||||
|
||||
|
@ -14,12 +14,28 @@ The .onion url is displayed to stdout at startup.
|
|||
|
||||
To keep onion keys, just mount volume `/var/lib/tor/hidden_service/`
|
||||
|
||||
```
|
||||
```sh
|
||||
$ docker run -ti --link something --volume /path/to/keys:/var/lib/tor/hidden_service/ goldy/tor-hidden-service
|
||||
```
|
||||
|
||||
Look at the `docker-compose.yml` file to see own to use it.
|
||||
|
||||
### Tools
|
||||
|
||||
A command line tool `onions` is available in container to get `.onion` url when container is running.
|
||||
|
||||
```sh
|
||||
# Get services
|
||||
$ docker exec -ti torhiddenproxy_tor_1 onions
|
||||
hello: vegm3d7q64gutl75.onion
|
||||
world: b2sflntvdne63amj.onion
|
||||
|
||||
# Get json
|
||||
$ docker exec -ti torhiddenproxy_tor_1 onions --json
|
||||
{"world": "b2sflntvdne63amj.onion", "hello": "vegm3d7q64gutl75.onion"}
|
||||
```
|
||||
|
||||
|
||||
### pyentrypoint
|
||||
|
||||
This container is using [`pyentrypoint`](https://github.com/cmehay/pyentrypoint) to generate its setup.
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
import os
|
||||
|
||||
for root, dirs, _ in os.walk("/var/lib/tor/hidden_service/", topdown=False):
|
||||
for service in dirs:
|
||||
filename = "{root}{service}/hostname".format(
|
||||
service=service,
|
||||
root=root
|
||||
)
|
||||
with open(filename, 'r') as hostfile:
|
||||
print('{service}: {onion}'.format(
|
||||
service=service,
|
||||
onion=hostfile.read()
|
||||
))
|
|
@ -8,7 +8,7 @@ config_files:
|
|||
|
||||
post_conf_commands:
|
||||
- timeout 3s tor > /dev/null || true
|
||||
- python3 /display_onions.py
|
||||
- onions
|
||||
- chown -R debian-tor:debian-tor $HOME
|
||||
|
||||
debug: false
|
||||
|
|
56
assets/onions/onions/Onions.py
Normal file
56
assets/onions/onions/Onions.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
from json import dumps
|
||||
|
||||
import argparse
|
||||
|
||||
|
||||
class Onions(object):
|
||||
"""Onions"""
|
||||
|
||||
hidden_service_dir = "/var/lib/tor/hidden_service/"
|
||||
|
||||
def __init__(self):
|
||||
self._get_onions()
|
||||
if 'HIDDEN_SERVICE_DIR' in os.environ:
|
||||
self.hidden_service_dir = os.environ['HIDDEN_SERVICE_DIR']
|
||||
|
||||
def _get_onions(self):
|
||||
self.onions = {}
|
||||
for root, dirs, _ in os.walk(self.hidden_service_dir,
|
||||
topdown=False):
|
||||
for service in dirs:
|
||||
filename = "{root}{service}/hostname".format(
|
||||
service=service,
|
||||
root=root
|
||||
)
|
||||
with open(filename, 'r') as hostfile:
|
||||
self.onions[service] = str(hostfile.read()).strip()
|
||||
|
||||
def __str__(self):
|
||||
if not self.onions:
|
||||
return 'No onion site'
|
||||
return '\n'.join(['%s: %s' % (service, onion)
|
||||
for (service, onion) in self.onions.items()])
|
||||
|
||||
def to_json(self):
|
||||
return dumps(self.onions)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Display onion sites',
|
||||
prog='onions')
|
||||
parser.add_argument('--json', dest='json', action='store_true',
|
||||
help='serialize to json')
|
||||
|
||||
args = parser.parse_args()
|
||||
onions = Onions()
|
||||
if args.json:
|
||||
print(onions.to_json())
|
||||
else:
|
||||
print(onions)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
1
assets/onions/onions/__init__.py
Normal file
1
assets/onions/onions/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
from .Onions import Onions, main
|
42
assets/onions/setup.py
Normal file
42
assets/onions/setup.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
from setuptools import find_packages
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='onions',
|
||||
|
||||
version='0.1',
|
||||
|
||||
packages=find_packages(),
|
||||
|
||||
author="Christophe Mehay",
|
||||
|
||||
author_email="cmehay@nospam.student.42.fr",
|
||||
|
||||
description="Display onion sites hosted",
|
||||
|
||||
include_package_data=True,
|
||||
|
||||
url='http://github.com/cmehay/docker-tor-hidden-service',
|
||||
|
||||
classifiers=[
|
||||
"Programming Language :: Python",
|
||||
"Development Status :: 1 - Planning",
|
||||
"License :: OSI Approved :: BSD License",
|
||||
"Natural Language :: English",
|
||||
"Operating System :: POSIX :: Linux",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.4",
|
||||
"Topic :: System :: Installation/Setup",
|
||||
],
|
||||
|
||||
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'onions = onions:main',
|
||||
],
|
||||
},
|
||||
|
||||
license="WTFPL",
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue