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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue