mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
tor: remove circular import
This commit is contained in:
parent
f867ecfb16
commit
bc2cba0cbf
@ -31,9 +31,9 @@ import socket
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from plinth import action_utils
|
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, \
|
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'
|
SERVICE_FILE = '/etc/firewalld/services/tor-{0}.xml'
|
||||||
TOR_CONFIG = '/files/etc/tor/torrc'
|
TOR_CONFIG = '/files/etc/tor/torrc'
|
||||||
|
|||||||
@ -29,7 +29,7 @@ from plinth import service as service_module
|
|||||||
from plinth.modules.names import SERVICES
|
from plinth.modules.names import SERVICES
|
||||||
from plinth.signals import domain_added, domain_removed
|
from plinth.signals import domain_added, domain_removed
|
||||||
|
|
||||||
from . import utils as tor_utils
|
from . import utils
|
||||||
|
|
||||||
|
|
||||||
version = 1
|
version = 1
|
||||||
@ -50,10 +50,6 @@ description = [
|
|||||||
socks_service = None
|
socks_service = None
|
||||||
bridge_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():
|
def init():
|
||||||
"""Initialize the module."""
|
"""Initialize the module."""
|
||||||
@ -63,20 +59,22 @@ def init():
|
|||||||
global socks_service
|
global socks_service
|
||||||
socks_service = service_module.Service(
|
socks_service = service_module.Service(
|
||||||
'tor-socks', _('Tor Anonymity Network'),
|
'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
|
global bridge_service
|
||||||
bridge_service = service_module.Service(
|
bridge_service = service_module.Service(
|
||||||
'tor-bridge', _('Tor Bridge Relay'),
|
'tor-bridge', _('Tor Bridge Relay'),
|
||||||
ports=['tor-orport', 'tor-obfs3', 'tor-obfs4'],
|
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.
|
# Register hidden service name with Name Services module.
|
||||||
hs_info = tor_utils.get_hs()
|
hs_info = utils.get_hs()
|
||||||
hostname = hs_info['hostname']
|
hostname = hs_info['hostname']
|
||||||
hs_virtports = [port['virtport'] for port in hs_info['ports']]
|
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_info['enabled'] and hs_info['hostname']:
|
||||||
hs_services = []
|
hs_services = []
|
||||||
for service_type in SERVICES:
|
for service_type in SERVICES:
|
||||||
@ -107,7 +105,7 @@ def setup(helper, old_version=None):
|
|||||||
def update_hidden_service_domain(status=None):
|
def update_hidden_service_domain(status=None):
|
||||||
"""Update HS domain with Name Services module."""
|
"""Update HS domain with Name Services module."""
|
||||||
if not status:
|
if not status:
|
||||||
status = tor_utils.get_status()
|
status = utils.get_status()
|
||||||
|
|
||||||
domain_removed.send_robust(
|
domain_removed.send_robust(
|
||||||
sender='tor', domain_type='hiddenservice')
|
sender='tor', domain_type='hiddenservice')
|
||||||
@ -120,15 +118,6 @@ def update_hidden_service_domain(status=None):
|
|||||||
services=status['hs_services'])
|
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():
|
def diagnose():
|
||||||
"""Run diagnostics and return the results."""
|
"""Run diagnostics and return the results."""
|
||||||
|
|||||||
@ -25,10 +25,25 @@ import itertools
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
from plinth.modules import tor
|
from plinth import action_utils
|
||||||
from plinth.modules.names import SERVICES
|
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():
|
def get_hs():
|
||||||
"""Return hidden service status."""
|
"""Return hidden service status."""
|
||||||
output = actions.superuser_run('tor', ['get-hs'])
|
output = actions.superuser_run('tor', ['get-hs'])
|
||||||
@ -47,8 +62,8 @@ def get_status():
|
|||||||
if str(service_type[2]) in hs_virtports:
|
if str(service_type[2]) in hs_virtports:
|
||||||
hs_services.append(service_type[0])
|
hs_services.append(service_type[0])
|
||||||
|
|
||||||
return {'enabled': tor.is_enabled(),
|
return {'enabled': is_enabled(),
|
||||||
'is_running': tor.is_running(),
|
'is_running': is_running(),
|
||||||
'ports': ports,
|
'ports': ports,
|
||||||
'hs_enabled': hs_info['enabled'],
|
'hs_enabled': hs_info['enabled'],
|
||||||
'hs_status': hs_info['status'],
|
'hs_status': hs_info['status'],
|
||||||
@ -63,7 +78,7 @@ def get_status():
|
|||||||
def iter_apt_uris(aug):
|
def iter_apt_uris(aug):
|
||||||
"""Iterate over all the APT source URIs."""
|
"""Iterate over all the APT source URIs."""
|
||||||
return itertools.chain.from_iterable([aug.match(path) for \
|
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):
|
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):
|
for uri_path in iter_apt_uris(aug):
|
||||||
uri_path = get_real_apt_uri_path(aug, uri_path)
|
uri_path = get_real_apt_uri_path(aug, uri_path)
|
||||||
uri = aug.get(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://')):
|
(uri.startswith('http://') or uri.startswith('https://')):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user