mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
Display Tor hidden service configuration on Tor page.
Currently assumes that there is no more than 1 hidden service.
This commit is contained in:
1 parent
bc08be681e
commit
cf52bf5029
3 files changed
+45
No files matched your search
+24
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user