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 %}
+