tor: remove circular import

This commit is contained in:
fonfon 2016-05-09 20:12:05 +00:00 committed by James Valleroy
parent f867ecfb16
commit bc2cba0cbf
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
3 changed files with 30 additions and 26 deletions

View File

@ -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'

View File

@ -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."""

View File

@ -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