mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
tor: Implement enabling/disabling
- Reorganize hidden service information
This commit is contained in:
parent
05ef2921db
commit
09e8a75930
@ -34,30 +34,42 @@ Tor Browser</a>.</p>
|
|||||||
<h3>Status</h3>
|
<h3>Status</h3>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
{% if is_running %}
|
{% if status.is_running %}
|
||||||
<div class='running-status active'></div> Tor is running
|
<div class='running-status active'></div> Tor is running
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class='running-status inactive'></div> Tor is not running
|
<div class='running-status inactive'></div> Tor is not running
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h3>Hidden Service</h3>
|
{% if status.hs_enabled %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-3">
|
||||||
|
<table class="table table-bordered table-condensed table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Hidden Service</th>
|
||||||
|
<th>Port</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>{{ status.hs_hostname }}</td>
|
||||||
|
<td>{{ status.hs_ports }}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<p>A hidden service will allow your {{ cfg.box_name }} to provide selected
|
<h3>Configuration</h3>
|
||||||
services (such as OwnCloud or Chat) without revealing its location.
|
|
||||||
Here is the current configuration:</p>
|
|
||||||
|
|
||||||
<ul>
|
<form class="form" method="post">
|
||||||
<li>Hostname: {{ tor_hs_hostname }}</li>
|
|
||||||
<li>Ports: {{ tor_hs_ports }}</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<form class="form form-inline" method="post">
|
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
||||||
{{ form|bootstrap }}
|
{{ form|bootstrap }}
|
||||||
|
|
||||||
<input type="submit" class="btn btn-primary btn-sm" value="Update setup"/>
|
<input type="submit" class="btn btn-primary btn-md" value="Update setup"/>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<h3>Bridge</h3>
|
<h3>Bridge</h3>
|
||||||
@ -77,7 +89,7 @@ port-forwarded, if necessary:</p>
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for name, port in tor_ports.items %}
|
{% for name, port in status.ports.items %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ name }}</td>
|
<td>{{ name }}</td>
|
||||||
<td>{{ port }}</td>
|
<td>{{ port }}</td>
|
||||||
|
|||||||
@ -32,9 +32,15 @@ from plinth import package
|
|||||||
|
|
||||||
class TorForm(forms.Form): # pylint: disable=W0232
|
class TorForm(forms.Form): # pylint: disable=W0232
|
||||||
"""Tor configuration form"""
|
"""Tor configuration form"""
|
||||||
hs_enabled = forms.BooleanField(
|
enabled = forms.BooleanField(
|
||||||
label=_('Enable Hidden Service'),
|
label=_('Enable Tor'),
|
||||||
required=False)
|
required=False)
|
||||||
|
hs_enabled = forms.BooleanField(
|
||||||
|
label=_('Enable Tor Hidden Service'),
|
||||||
|
required=False,
|
||||||
|
help_text=_('A hidden service will allow FreedomBox to provide '
|
||||||
|
'selected services (such as ownCloud or Chat) without '
|
||||||
|
'revealing its location.'))
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
@ -63,11 +69,7 @@ def index(request):
|
|||||||
|
|
||||||
return TemplateResponse(request, 'tor.html',
|
return TemplateResponse(request, 'tor.html',
|
||||||
{'title': _('Tor Control Panel'),
|
{'title': _('Tor Control Panel'),
|
||||||
'is_running': status['is_running'],
|
'status': status,
|
||||||
'tor_ports': status['ports'],
|
|
||||||
'tor_hs_enabled': status['hs_enabled'],
|
|
||||||
'tor_hs_hostname': status['hs_hostname'],
|
|
||||||
'tor_hs_ports': status['hs_ports'],
|
|
||||||
'form': form})
|
'form': form})
|
||||||
|
|
||||||
|
|
||||||
@ -99,7 +101,8 @@ def get_status():
|
|||||||
hs_hostname = hs_info[0]
|
hs_hostname = hs_info[0]
|
||||||
hs_ports = hs_info[1]
|
hs_ports = hs_info[1]
|
||||||
|
|
||||||
return {'is_running': action_utils.service_is_running('tor'),
|
return {'enabled': action_utils.service_is_enabled('tor'),
|
||||||
|
'is_running': action_utils.service_is_running('tor'),
|
||||||
'ports': ports,
|
'ports': ports,
|
||||||
'hs_enabled': hs_enabled,
|
'hs_enabled': hs_enabled,
|
||||||
'hs_hostname': hs_hostname,
|
'hs_hostname': hs_hostname,
|
||||||
@ -107,16 +110,24 @@ def get_status():
|
|||||||
|
|
||||||
|
|
||||||
def _apply_changes(request, old_status, new_status):
|
def _apply_changes(request, old_status, new_status):
|
||||||
"""Apply the changes"""
|
"""Apply the changes."""
|
||||||
if old_status['hs_enabled'] == new_status['hs_enabled']:
|
if old_status['enabled'] == new_status['enabled'] and \
|
||||||
|
old_status['hs_enabled'] == new_status['hs_enabled']:
|
||||||
messages.info(request, _('Setting unchanged'))
|
messages.info(request, _('Setting unchanged'))
|
||||||
return
|
return
|
||||||
|
|
||||||
if new_status['hs_enabled']:
|
if old_status['enabled'] != new_status['enabled']:
|
||||||
messages.success(request, _('Tor hidden service enabled'))
|
if new_status['enabled']:
|
||||||
command = 'enable-hs'
|
messages.success(request, _('Tor enabled'))
|
||||||
else:
|
actions.superuser_run('tor', ['enable'])
|
||||||
messages.success(request, _('Tor hidden service disabled'))
|
else:
|
||||||
command = 'disable-hs'
|
messages.success(request, _('Tor disabled'))
|
||||||
|
actions.superuser_run('tor', ['disable'])
|
||||||
|
|
||||||
actions.superuser_run('tor', [command])
|
if old_status['hs_enabled'] != new_status['hs_enabled']:
|
||||||
|
if new_status['hs_enabled']:
|
||||||
|
messages.success(request, _('Tor hidden service enabled'))
|
||||||
|
actions.superuser_run('tor', ['enable-hs'])
|
||||||
|
else:
|
||||||
|
messages.success(request, _('Tor hidden service disabled'))
|
||||||
|
actions.superuser_run('tor', ['disable-hs'])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user