Display Tor hidden service configuration on Tor page.

Currently assumes that there is no more than 1 hidden service.
This commit is contained in:
James Valleroy 2014-10-11 17:37:57 -04:00 committed by Sunil Mohan Adapa
parent bc08be681e
commit cf52bf5029
3 changed files with 45 additions and 0 deletions

View File

@ -25,6 +25,7 @@ import argparse
import subprocess
SERVICE_CONFIG = '/etc/default/tor'
TOR_CONFIG = '/etc/tor/torrc'
def parse_arguments():
@ -41,6 +42,9 @@ def parse_arguments():
# Stop Tor and disable service
subparsers.add_parser('stop', help='Stop Tor service')
# Get currently configured Tor hidden service
subparsers.add_parser('get-hs', help='Get hidden service')
return parser.parse_args()
@ -73,6 +77,26 @@ def subcommand_stop(_):
subprocess.call(['service', 'tor', 'stop'])
def subcommand_get_hs(_):
"""Get currently configured Tor hidden service"""
hs_dir = ""
hs_ports = []
with open(TOR_CONFIG, 'r') as file:
lines = file.readlines()
for line in lines:
if line.startswith('HiddenServiceDir'):
hs_dir = line.split()[1]
elif line.startswith('HiddenServicePort'):
hs_ports.append(line.split()[1])
if hs_dir != "":
with open(hs_dir + 'hostname', 'r') as file:
hs_hostname = file.read().strip()
print hs_hostname + ' ' + ','.join(hs_ports)
def set_tor_service(enable):
"""Enable/disable tor service; enable: boolean"""
newline = "RUN_DAEMON=\"yes\"\n" if enable else "RUN_DAEMON=\"no\"\n"

View File

@ -30,6 +30,16 @@
{% endif %}
<br style='clear:both'>
<p><h3>Hidden Service</h3>
A hidden service will allow your FreedomBox to provide selected
services (such as OwnCloud or Chat) without revealing its location.
Here is the current configuration:
<ul>
<li>Hostname: {{ tor_hs_hostname }}</li>
<li>Ports: {{ tor_hs_ports }}</li>
</ul>
</p>
<p><h3>Bridge</h3>
Your FreedomBox is configured as a Tor bridge with obfsproxy, so it
can help circumvent censorship. If your FreedomBox is behind a router

View File

@ -47,8 +47,19 @@ def index(request):
except ValueError:
continue
output = actions.superuser_run("tor", ["get-hs"])
if output == "":
tor_hs_hostname = "Not Configured"
tor_hs_ports = ""
else:
hs_info = output.split()
tor_hs_hostname = hs_info[0]
tor_hs_ports = hs_info[1]
is_running = actions.superuser_run("tor", ["is-running"]).strip() == "yes"
return TemplateResponse(request, 'tor.html',
{'title': _('Tor Control Panel'),
'tor_hs_hostname': tor_hs_hostname,
'tor_hs_ports': tor_hs_ports,
'tor_ports': tor_ports,
'is_running': is_running})