tor: Use new setup mechanism

This commit is contained in:
Sunil Mohan Adapa 2016-02-12 18:31:59 +05:30
parent ecad252653
commit ac558568ba
No known key found for this signature in database
GPG Key ID: 36C361440C9BC971
3 changed files with 30 additions and 32 deletions

View File

@ -20,7 +20,7 @@ Plinth module to configure Tor.
""" """
import augeas import augeas
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext_lazy as _
import glob import glob
import itertools import itertools
@ -32,8 +32,21 @@ from plinth.modules.names import SERVICES
from plinth.signals import domain_added from plinth.signals import domain_added
version = 1
depends = ['apps', 'names'] depends = ['apps', 'names']
title = _('Anonymity Network (Tor)')
description = [
_('Tor is an anonymous communication system. You can learn more '
'about it from the <a href="https://www.torproject.org/">Tor '
'Project</a> website. For best protection when web surfing, the '
'Tor Project recommends that you use the '
'<a href="https://www.torproject.org/download/download-easy.html.en">'
'Tor Browser</a>.')
]
socks_service = None socks_service = None
bridge_service = None bridge_service = None
@ -45,8 +58,7 @@ APT_TOR_PREFIX = 'tor+'
def init(): def init():
"""Initialize the module.""" """Initialize the module."""
menu = cfg.main_menu.get('apps:index') menu = cfg.main_menu.get('apps:index')
menu.add_urlname(_('Anonymity Network (Tor)'), 'glyphicon-eye-close', menu.add_urlname(title, 'glyphicon-eye-close', 'tor:index', 100)
'tor:index', 100)
global socks_service global socks_service
socks_service = service_module.Service( socks_service = service_module.Service(
@ -77,6 +89,17 @@ def init():
services=hs_services) services=hs_services)
def setup(helper, old_version=None):
"""Install and configure the module."""
helper.install(['tor', 'tor-geoipdb', 'torsocks', 'obfs4proxy',
'apt-transport-tor'])
helper.call('post', actions.superuser_run, 'tor', ['setup'])
helper.call('post', actions.superuser_run, 'tor',
['configure', '--apt-transport-tor', 'enable'])
helper.call('post', socks_service.notify_enabled, None, True)
helper.call('post', bridge_service.notify_enabled, None, True)
def is_enabled(): def is_enabled():
"""Return whether the module is enabled.""" """Return whether the module is enabled."""
return action_utils.service_is_enabled('tor') return action_utils.service_is_enabled('tor')

View File

@ -1,4 +1,4 @@
{% extends "base.html" %} {% extends "app.html" %}
{% comment %} {% comment %}
# #
# This file is part of Plinth. # This file is part of Plinth.
@ -30,20 +30,7 @@
{% endblock %} {% endblock %}
{% block content %} {% block configuration %}
<h2>{% trans "Anonymity Network (Tor)" %}</h2>
<p>
{% blocktrans trimmed %}
Tor is an anonymous communication system. You can learn more
about it from the <a href="https://www.torproject.org/">Tor
Project</a> website. For best protection when web surfing, the
Tor Project recommends that you use the
<a href="https://www.torproject.org/download/download-easy.html.en">
Tor Browser</a>.
{% endblocktrans %}
</p>
<h3>{% trans "Status" %}</h3> <h3>{% trans "Status" %}</h3>

View File

@ -25,7 +25,6 @@ from django.utils.translation import ugettext_lazy as _
from .forms import TorForm from .forms import TorForm
from plinth import actions from plinth import actions
from plinth import package
from plinth.errors import ActionError from plinth.errors import ActionError
from plinth.modules import tor from plinth.modules import tor
from plinth.modules.names import SERVICES from plinth.modules.names import SERVICES
@ -34,18 +33,6 @@ from plinth.signals import domain_added, domain_removed
config_process = None config_process = None
def on_install():
"""Setup Tor configuration as soon as it is installed."""
actions.superuser_run('tor', ['setup'])
actions.superuser_run('tor',
['configure', '--apt-transport-tor', 'enable'])
tor.socks_service.notify_enabled(None, True)
tor.bridge_service.notify_enabled(None, True)
@package.required(['tor', 'tor-geoipdb', 'torsocks', 'obfs4proxy',
'apt-transport-tor'],
on_install=on_install)
def index(request): def index(request):
"""Serve configuration page.""" """Serve configuration page."""
if config_process: if config_process:
@ -65,7 +52,8 @@ def index(request):
form = TorForm(initial=status, prefix='tor') form = TorForm(initial=status, prefix='tor')
return TemplateResponse(request, 'tor.html', return TemplateResponse(request, 'tor.html',
{'title': _('Tor Control Panel'), {'title': tor.title,
'description': tor.description,
'status': status, 'status': status,
'config_running': bool(config_process), 'config_running': bool(config_process),
'form': form}) 'form': form})