diff --git a/actions/tor b/actions/tor index 3b8f48fb7..1964d318f 100755 --- a/actions/tor +++ b/actions/tor @@ -31,9 +31,9 @@ import socket import time from plinth import action_utils -from plinth.modules.tor import is_enabled, is_running, APT_TOR_PREFIX from plinth.modules.tor.utils import get_real_apt_uri_path, iter_apt_uris, \ - get_augeas + get_augeas, is_running, is_enabled, \ + APT_TOR_PREFIX SERVICE_FILE = '/etc/firewalld/services/tor-{0}.xml' TOR_CONFIG = '/files/etc/tor/torrc' diff --git a/plinth/modules/tor/__init__.py b/plinth/modules/tor/__init__.py index 78fcd7b68..259288edc 100644 --- a/plinth/modules/tor/__init__.py +++ b/plinth/modules/tor/__init__.py @@ -29,7 +29,7 @@ from plinth import service as service_module from plinth.modules.names import SERVICES from plinth.signals import domain_added, domain_removed -from . import utils as tor_utils +from . import utils version = 1 @@ -50,10 +50,6 @@ description = [ socks_service = None bridge_service = None -APT_SOURCES_URI_PATHS = ('/files/etc/apt/sources.list/*/uri', - '/files/etc/apt/sources.list.d/*/*/uri') -APT_TOR_PREFIX = 'tor+' - def init(): """Initialize the module.""" @@ -63,20 +59,22 @@ def init(): global socks_service socks_service = service_module.Service( 'tor-socks', _('Tor Anonymity Network'), - is_external=False, is_enabled=is_enabled, is_running=is_running) + is_external=False, is_enabled=utils.is_enabled, + is_running=utils.is_running) global bridge_service bridge_service = service_module.Service( 'tor-bridge', _('Tor Bridge Relay'), ports=['tor-orport', 'tor-obfs3', 'tor-obfs4'], - is_external=True, is_enabled=is_enabled, is_running=is_running) + is_external=True, is_enabled=utils.is_enabled, + is_running=utils.is_running) # Register hidden service name with Name Services module. - hs_info = tor_utils.get_hs() + hs_info = utils.get_hs() hostname = hs_info['hostname'] hs_virtports = [port['virtport'] for port in hs_info['ports']] - if is_enabled() and is_running() and \ + if utils.is_enabled() and utils.is_running() and \ hs_info['enabled'] and hs_info['hostname']: hs_services = [] for service_type in SERVICES: @@ -107,7 +105,7 @@ def setup(helper, old_version=None): def update_hidden_service_domain(status=None): """Update HS domain with Name Services module.""" if not status: - status = tor_utils.get_status() + status = utils.get_status() domain_removed.send_robust( sender='tor', domain_type='hiddenservice') @@ -120,15 +118,6 @@ def update_hidden_service_domain(status=None): services=status['hs_services']) -def is_enabled(): - """Return whether the module is enabled.""" - return action_utils.service_is_enabled('tor') - - -def is_running(): - """Return whether the service is running.""" - return action_utils.service_is_running('tor') - def diagnose(): """Run diagnostics and return the results.""" diff --git a/plinth/modules/tor/utils.py b/plinth/modules/tor/utils.py index 7f7e649b1..76b41b048 100644 --- a/plinth/modules/tor/utils.py +++ b/plinth/modules/tor/utils.py @@ -25,10 +25,25 @@ import itertools import json from plinth import actions -from plinth.modules import tor +from plinth import action_utils from plinth.modules.names import SERVICES +APT_SOURCES_URI_PATHS = ('/files/etc/apt/sources.list/*/uri', + '/files/etc/apt/sources.list.d/*/*/uri') +APT_TOR_PREFIX = 'tor+' + + +def is_enabled(): + """Return whether the module is enabled.""" + return action_utils.service_is_enabled('tor') + + +def is_running(): + """Return whether the service is running.""" + return action_utils.service_is_running('tor') + + def get_hs(): """Return hidden service status.""" output = actions.superuser_run('tor', ['get-hs']) @@ -47,8 +62,8 @@ def get_status(): if str(service_type[2]) in hs_virtports: hs_services.append(service_type[0]) - return {'enabled': tor.is_enabled(), - 'is_running': tor.is_running(), + return {'enabled': is_enabled(), + 'is_running': is_running(), 'ports': ports, 'hs_enabled': hs_info['enabled'], 'hs_status': hs_info['status'], @@ -63,7 +78,7 @@ def get_status(): def iter_apt_uris(aug): """Iterate over all the APT source URIs.""" return itertools.chain.from_iterable([aug.match(path) for \ - path in tor.APT_SOURCES_URI_PATHS]) + path in APT_SOURCES_URI_PATHS]) def get_real_apt_uri_path(aug, path): @@ -125,7 +140,7 @@ def _is_apt_transport_tor_enabled(): for uri_path in iter_apt_uris(aug): uri_path = get_real_apt_uri_path(aug, uri_path) uri = aug.get(uri_path) - if not uri.startswith(tor.APT_TOR_PREFIX) and \ + if not uri.startswith(APT_TOR_PREFIX) and \ (uri.startswith('http://') or uri.startswith('https://')): return False