tor: Fix various issues related to plinth instance

- Remove extra newlines added to torrc.
- Remove comments added in random places to torrc.
- Enable tor instance during setup.
- Fix restarts to use tor instance.
- Revert change to augeas lens to attempt handling +.
- Add support for hyphens in values to augeas lens.
- Increment module version so setup can run again.
This commit is contained in:
James Valleroy committed 2017-01-08 15:36:59 -05:00
1 parent 658e52f6cd
commit 85b87268b4
5 files changed
+15 -12

No files matched your search

+10 -7
View File
@@ -70,21 +70,24 @@ def parse_arguments():
def subcommand_setup(_):
"""Setup Tor configuration after installing it."""
# Disable default tor service. We will use tor@plinth instance
# instead.
_disable_apt_transport_tor()
action_utils.service_disable('tor')
subprocess.run(['tor-instance-create', 'plinth'], check=True)
# Remove line starting with +SocksPort, since our augeas lens
# doesn't handle it correctly.
with open('/etc/tor/instances/plinth/torrc', 'r') as torrc:
torrc_lines = torrc.readlines()
with open('/etc/tor/instances/plinth/torrc', 'w') as torrc:
for line in torrc_lines:
if not line.startswith('+'):
torrc.write(line + '\n')
torrc.write(line)
aug = augeas_load()
aug.set(TOR_CONFIG + '/#comment[last() + 1]',
'Run as non-exit bridge relay')
aug.set(TOR_CONFIG + '/SocksPort[1]', '[::]:9050')
aug.set(TOR_CONFIG + '/SocksPort[2]', '0.0.0.0:9050')
aug.set(TOR_CONFIG + '/ControlPort', '9051')
@@ -92,7 +95,6 @@ def subcommand_setup(_):
aug.set(TOR_CONFIG + '/ExitPolicy[1]', 'reject *:*')
aug.set(TOR_CONFIG + '/ExitPolicy[2]', 'reject6 *:*')
aug.set(TOR_CONFIG + '/#comment[last() + 1]', 'Enable transparent proxy')
aug.set(TOR_CONFIG + '/VirtualAddrNetworkIPv4', '10.192.0.0/10')
aug.set(TOR_CONFIG + '/AutomapHostsOnResolve', '1')
aug.set(TOR_CONFIG + '/TransPort[1]', '127.0.0.1:9040')
@@ -111,6 +113,7 @@ def subcommand_setup(_):
aug.save()
action_utils.service_enable('tor@plinth')
action_utils.service_restart('tor@plinth')
_update_ports()
@@ -286,7 +289,7 @@ def _enable_relay(relay=None, bridge=None, restart=True, aug=None):
if restart:
if is_enabled() and is_running():
action_utils.service_restart('tor')
action_utils.service_restart('tor@plinth')
def _enable_hs(restart=True):
@@ -308,7 +311,7 @@ def _enable_hs(restart=True):
if restart:
if is_enabled() and is_running():
action_utils.service_restart('tor')
action_utils.service_restart('tor@plinth')
# wait until hidden service information is available
tries = 0
@@ -333,7 +336,7 @@ def _disable_hs(restart=True):
if restart:
if is_enabled() and is_running():
action_utils.service_restart('tor')
action_utils.service_restart('tor@plinth')
def _enable_apt_transport_tor():