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 authored and Sunil Mohan Adapa committed 2014-10-20 00:19:42 +05:30
1 parent bc08be681e
commit cf52bf5029
3 files changed
+45

No files matched your search

+24
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"