From cf52bf5029a8066e7f2c327336edac43226ea575 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Sat, 11 Oct 2014 17:37:57 -0400 Subject: [PATCH] Display Tor hidden service configuration on Tor page. Currently assumes that there is no more than 1 hidden service. --- actions/tor | 24 ++++++++++++++++++++++++ plinth/modules/tor/templates/tor.html | 10 ++++++++++ plinth/modules/tor/tor.py | 11 +++++++++++ 3 files changed, 45 insertions(+) diff --git a/actions/tor b/actions/tor index 34d46f48a..72c39ebbb 100755 --- a/actions/tor +++ b/actions/tor @@ -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" diff --git a/plinth/modules/tor/templates/tor.html b/plinth/modules/tor/templates/tor.html index 916137773..7f24155c1 100644 --- a/plinth/modules/tor/templates/tor.html +++ b/plinth/modules/tor/templates/tor.html @@ -30,6 +30,16 @@ {% endif %}
+

Hidden Service

+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: + +

+

Bridge

Your FreedomBox is configured as a Tor bridge with obfsproxy, so it can help circumvent censorship. If your FreedomBox is behind a router diff --git a/plinth/modules/tor/tor.py b/plinth/modules/tor/tor.py index 0911e3122..a3825d715 100644 --- a/plinth/modules/tor/tor.py +++ b/plinth/modules/tor/tor.py @@ -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})