mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
Name Services module
This commit is contained in:
1 parent
5dfa2d0626
commit
e0bfd1401f
14 files changed
+524
-15
No files matched your search
@@ -28,7 +28,7 @@ from plinth import action_utils
|
||||
|
||||
__all__ = ['tor', 'init']
|
||||
|
||||
depends = ['plinth.modules.apps']
|
||||
depends = ['plinth.modules.apps', 'plinth.modules.names']
|
||||
|
||||
|
||||
def diagnose():
|
||||
|
||||
+58
-12
@@ -32,6 +32,8 @@ from plinth import action_utils
|
||||
from plinth import cfg
|
||||
from plinth import package
|
||||
from plinth.errors import ActionError
|
||||
from plinth.modules.names import SERVICES
|
||||
from plinth.signals import domain_added, domain_removed
|
||||
|
||||
APT_SOURCES_URI_PATHS = ('/files/etc/apt/sources.list/*/uri',
|
||||
'/files/etc/apt/sources.list.d/*/*/uri')
|
||||
@@ -64,6 +66,25 @@ def init():
|
||||
menu.add_urlname(_('Anonymity Network (Tor)'), 'glyphicon-eye-close',
|
||||
'tor:index', 100)
|
||||
|
||||
# Register hidden service name with Name Services module.
|
||||
enabled = action_utils.service_is_enabled('tor')
|
||||
is_running = action_utils.service_is_running('tor')
|
||||
(hs_enabled, hs_hostname, hs_ports) = get_hs()
|
||||
|
||||
if enabled and is_running and hs_enabled and hs_hostname:
|
||||
hs_services = []
|
||||
for service in SERVICES:
|
||||
if str(service[2]) in hs_ports:
|
||||
hs_services.append(service[0])
|
||||
else:
|
||||
hs_hostname = None
|
||||
hs_services = None
|
||||
|
||||
domain_added.send_robust(
|
||||
sender='tor', domain_type='hiddenservice',
|
||||
name=hs_hostname, description=_('Tor Hidden Service'),
|
||||
services=hs_services)
|
||||
|
||||
|
||||
def on_install():
|
||||
"""Setup Tor configuration as soon as it is installed."""
|
||||
@@ -167,18 +188,7 @@ def is_apt_transport_tor_enabled():
|
||||
return True
|
||||
|
||||
|
||||
def get_status():
|
||||
"""Return the current status"""
|
||||
output = actions.superuser_run('tor', ['get-ports'])
|
||||
port_info = output.split('\n')
|
||||
ports = {}
|
||||
for line in port_info:
|
||||
try:
|
||||
(key, val) = line.split()
|
||||
ports[key] = val
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
def get_hs():
|
||||
output = actions.superuser_run('tor', ['get-hs'])
|
||||
output = output.strip()
|
||||
if output == '':
|
||||
@@ -195,6 +205,23 @@ def get_status():
|
||||
hs_hostname = hs_info[0]
|
||||
hs_ports = hs_info[1]
|
||||
|
||||
return (hs_enabled, hs_hostname, hs_ports)
|
||||
|
||||
|
||||
def get_status():
|
||||
"""Return the current status"""
|
||||
output = actions.superuser_run('tor', ['get-ports'])
|
||||
port_info = output.split('\n')
|
||||
ports = {}
|
||||
for line in port_info:
|
||||
try:
|
||||
(key, val) = line.split()
|
||||
ports[key] = val
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
(hs_enabled, hs_hostname, hs_ports) = get_hs()
|
||||
|
||||
return {'enabled': action_utils.service_is_enabled('tor'),
|
||||
'is_running': action_utils.service_is_running('tor'),
|
||||
'ports': ports,
|
||||
@@ -238,6 +265,25 @@ def __apply_changes(request, old_status, new_status):
|
||||
actions.superuser_run('tor', ['disable-hs'])
|
||||
messages.success(request, _('Tor hidden service disabled'))
|
||||
|
||||
# Update hidden service name registered with Name Services module.
|
||||
domain_removed.send_robust(
|
||||
sender='tor', domain_type='hiddenservice')
|
||||
|
||||
enabled = action_utils.service_is_enabled('tor')
|
||||
is_running = action_utils.service_is_running('tor')
|
||||
(hs_enabled, hs_hostname, hs_ports) = get_hs()
|
||||
|
||||
if enabled and is_running and hs_enabled and hs_hostname:
|
||||
hs_services = []
|
||||
for service in SERVICES:
|
||||
if str(service[2]) in hs_ports:
|
||||
hs_services.append(service[0])
|
||||
|
||||
domain_added.send_robust(
|
||||
sender='tor', domain_type='hiddenservice',
|
||||
name=hs_hostname, description=_('Tor Hidden Service'),
|
||||
services=hs_services)
|
||||
|
||||
if old_status['apt_transport_tor_enabled'] != \
|
||||
new_status['apt_transport_tor_enabled']:
|
||||
if new_status['apt_transport_tor_enabled']:
|
||||
|
||||
Reference in new issue
Block a user