mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +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>
|
||||
|
||||
<p>
|
||||
{% if is_running %}
|
||||
{% if status.is_running %}
|
||||
<div class='running-status active'></div> Tor is running
|
||||
{% else %}
|
||||
<div class='running-status inactive'></div> Tor is not running
|
||||
{% endif %}
|
||||
</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
|
||||
services (such as OwnCloud or Chat) without revealing its location.
|
||||
Here is the current configuration:</p>
|
||||
<h3>Configuration</h3>
|
||||
|
||||
<ul>
|
||||
<li>Hostname: {{ tor_hs_hostname }}</li>
|
||||
<li>Ports: {{ tor_hs_ports }}</li>
|
||||
</ul>
|
||||
|
||||
<form class="form form-inline" method="post">
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
{{ 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>
|
||||
|
||||
<h3>Bridge</h3>
|
||||
@ -77,7 +89,7 @@ port-forwarded, if necessary:</p>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for name, port in tor_ports.items %}
|
||||
{% for name, port in status.ports.items %}
|
||||
<tr>
|
||||
<td>{{ name }}</td>
|
||||
<td>{{ port }}</td>
|
||||
|
||||
@ -32,9 +32,15 @@ from plinth import package
|
||||
|
||||
class TorForm(forms.Form): # pylint: disable=W0232
|
||||
"""Tor configuration form"""
|
||||
hs_enabled = forms.BooleanField(
|
||||
label=_('Enable Hidden Service'),
|
||||
enabled = forms.BooleanField(
|
||||
label=_('Enable Tor'),
|
||||
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():
|
||||
@ -63,11 +69,7 @@ def index(request):
|
||||
|
||||
return TemplateResponse(request, 'tor.html',
|
||||
{'title': _('Tor Control Panel'),
|
||||
'is_running': status['is_running'],
|
||||
'tor_ports': status['ports'],
|
||||
'tor_hs_enabled': status['hs_enabled'],
|
||||
'tor_hs_hostname': status['hs_hostname'],
|
||||
'tor_hs_ports': status['hs_ports'],
|
||||
'status': status,
|
||||
'form': form})
|
||||
|
||||
|
||||
@ -99,7 +101,8 @@ def get_status():
|
||||
hs_hostname = hs_info[0]
|
||||
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,
|
||||
'hs_enabled': hs_enabled,
|
||||
'hs_hostname': hs_hostname,
|
||||
@ -107,16 +110,24 @@ def get_status():
|
||||
|
||||
|
||||
def _apply_changes(request, old_status, new_status):
|
||||
"""Apply the changes"""
|
||||
if old_status['hs_enabled'] == new_status['hs_enabled']:
|
||||
"""Apply the changes."""
|
||||
if old_status['enabled'] == new_status['enabled'] and \
|
||||
old_status['hs_enabled'] == new_status['hs_enabled']:
|
||||
messages.info(request, _('Setting unchanged'))
|
||||
return
|
||||
|
||||
if new_status['hs_enabled']:
|
||||
messages.success(request, _('Tor hidden service enabled'))
|
||||
command = 'enable-hs'
|
||||
else:
|
||||
messages.success(request, _('Tor hidden service disabled'))
|
||||
command = 'disable-hs'
|
||||
if old_status['enabled'] != new_status['enabled']:
|
||||
if new_status['enabled']:
|
||||
messages.success(request, _('Tor enabled'))
|
||||
actions.superuser_run('tor', ['enable'])
|
||||
else:
|
||||
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