i2p: Review and update views

- Update the description of the app. Remove link to web interface at it is now
  in clients list.

- Add showing running status of the service.

- Use the new style for showing subsubmenus under the description of the
  application.

- Don't use frames to show the interface. Let users launch that interface in a
  new window instead.

- Use class based views for I2P service views.

- Update description of the I2P service views.

- Minor styling updates.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Sunil Mohan Adapa 2019-04-01 16:42:51 -07:00
parent 6e5a45a9b3
commit fe03b4f34f
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
6 changed files with 159 additions and 95 deletions

View File

@ -29,9 +29,9 @@ from .manifest import backup, clients
version = 1
servicename = 'i2p'
service_name = 'i2p'
managed_services = [servicename]
managed_services = [service_name]
managed_packages = ['i2p']
@ -40,14 +40,14 @@ name = _('I2P')
short_description = _('Anonymity Network')
description = [
_('I2P is an anonymous overlay network - a network within a network. '
'It is intended to protect communication from dragnet surveillance '
'and monitoring by third parties such as ISPs.'),
_('When enabled, I2P\'s web interface will be available from '
'<a href="/i2p/">/i2p</a>.'),
_('The first visit will initiate the configuration process, which can also be skippped'),
_('You can find more information about I2P one can peruse their '
'<a href="https://geti2p.net" target="_blank">homepage</a>.')
_('The Invisible Internet Project is an anonymous network layer intended '
'to protect communication from censorship and surveillance. I2P '
'provides anonymity by sending encrypted traffic through a '
'volunteer-run network distributed around the world.'),
_('Find more information about I2P on their project '
'<a href="https://geti2p.net" target="_blank">homepage</a>.'),
_('The first visit to the provided web interface will initiate the '
'configuration process.')
]
clients = clients
@ -91,12 +91,14 @@ def setup(helper, old_version=None):
# Add favorites to the configuration
for fav_name, fav_url in additional_favorites:
helper.call('post', actions.superuser_run,
"i2p", ["add-favorite",
"--name='%s'" % fav_name,
"--url='%s'" % fav_url,
])
helper.call('post', action_utils.webserver_enable, "proxy_html", kind="module")
helper.call('post', actions.superuser_run, 'i2p', [
'add-favorite',
'--name',
fav_name,
'--url',
fav_url,
])
helper.call('post', enable)
global service
if service is None:
service = service_module.Service(managed_services[0], name, ports=[

View File

@ -0,0 +1,63 @@
{% extends "service-subsubmenu.html" %}
{% comment %}
#
# This file is part of FreedomBox.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
{% endcomment %}
{% load bootstrap %}
{% load i18n %}
{% block configuration %}
{% block status %}
{% if show_status_block %}
<h3>{% trans "Status" %}</h3>
<p class="running-status-parent">
{% with service_name=service.name %}
{% if service.is_running %}
<span class="running-status active"></span>
{% blocktrans trimmed %}
Service <em>{{ service_name }}</em> is running.
{% endblocktrans %}
{% else %}
<span class="running-status inactive"></span>
{% blocktrans trimmed %}
Service <em>{{ service_name }}</em> is not running.
{% endblocktrans %}
{% endif %}
{% endwith %}
</p>
{% endif %}
{% endblock %}
{% block diagnostics %}
{% if diagnostics_module_name %}
{% include "diagnostics_button.html" with module=diagnostics_module_name enabled=service.is_enabled %}
{% endif %}
{% endblock %}
<h3>{% trans "Configuration" %}</h3>
<form class="form form-configuration" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<input type="submit" class="btn btn-primary"
value="{% trans "Update setup" %}"/>
</form>
{% endblock %}

View File

@ -1,27 +0,0 @@
{% extends "base.html" %}
{% block page_head %}
<style>
.i2p-main-container {
display: flex;
flex-direction: column;
min-height: 500px;
height: 100%;
}
.i2p-main-container .i2p-main-container__frame {
flex-grow: 1;
}
</style>
{% endblock %}
{% block content %}
<div class="i2p-main-container">
<div class="i2p-main-container__header">
{% for line in description %}
<p>{{ line|safe }}</p>
{% endfor %}
</div>
<iframe name="i2p-frame" class="i2p-main-container__frame" src="{{ path }}" frameborder="0"></iframe>
</div>
{% endblock %}

View File

@ -0,0 +1,16 @@
{% extends "service-subsubmenu.html" %}
{% load i18n %}
{% block configuration %}
{% for line in service_description %}
<p>{{ line|safe }}</p>
{% endfor %}
<p>
<a class="btn btn-primary" target="_blank" role="button"
href="{{ service_path }}">
{% trans "Launch" %}
</a>
</p>
{% endblock %}

View File

@ -24,7 +24,6 @@ from plinth.modules.i2p import views
urlpatterns = [
url(r'^apps/i2p/$', views.I2PServiceView.as_view(), name='index'),
url(r'^apps/i2p/frame/tunnels/?$', views.i2p_frame_tunnels, name='frame_tunnels'),
url(r'^apps/i2p/frame/torrent/?$', views.i2p_frame_torrent, name='frame_torrent'),
url(r'^apps/i2p/tunnels/?$', views.TunnelsView.as_view(), name='tunnels'),
url(r'^apps/i2p/torrents/?$', views.TorrentsView.as_view(), name='torrents'),
]

View File

@ -14,10 +14,14 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from django.template.response import TemplateResponse
"""
Views for I2P application.
"""
from django.urls import reverse_lazy
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy
from django.views.generic import TemplateView
import plinth.modules.i2p as i2p
from plinth.views import ServiceView
@ -26,70 +30,77 @@ subsubmenu = [{
'url': reverse_lazy('i2p:index'),
'text': ugettext_lazy('Configure')
}, {
'url': reverse_lazy('i2p:frame_tunnels'),
'url': reverse_lazy('i2p:tunnels'),
'text': ugettext_lazy('Proxies')
}, {
'url': reverse_lazy('i2p:frame_torrent'),
'text': ugettext_lazy('Anonymous torrents')
}]
},
{
'url': reverse_lazy('i2p:torrents'),
'text': ugettext_lazy('Anonymous torrents')
}]
class I2PServiceView(ServiceView):
"""Serve configuration page."""
service_id = i2p.servicename
service_id = i2p.service_name
clients = i2p.clients
description = i2p.description
diagnostics_module_name = i2p.servicename
show_status_block = False
diagnostics_module_name = i2p.service_name
show_status_block = True
template_name = 'i2p.html'
def get_context_data(self, **kwargs):
"""Return the context data for rendering the template view."""
context = super().get_context_data(**kwargs)
context['subsubmenu'] = subsubmenu
context['title'] = i2p.name
context['description'] = i2p.description
context['clients'] = i2p.clients
context['manual_page'] = i2p.manual_page
context['subsubmenu'] = subsubmenu
return context
def _create_i2p_frame_view(title, rel_path, description):
"""
Creates a view with an iframe to the given path
class ServiceBaseView(TemplateView):
"""View to describe and launch a service."""
service_description = None
service_title = None
service_path = None
This is primarily used as a shortcut to pages under /i2p/
:param title: the page title that will have to be i18n
:type title: basestring
:param rel_path: the URL path after /i2p/<rel_path>
:type rel_path: basestring
:return: a django view
:rtype: callable
"""
path = "/i2p/" + rel_path
def i2p_frame_view(request):
return TemplateResponse(
request, 'i2p_frame.html', {
'title': _(title),
'subsubmenu': subsubmenu,
'path': path,
'description': description
})
return i2p_frame_view
def get_context_data(self, **kwargs):
"""Add context data for template."""
context = super().get_context_data(**kwargs)
context['title'] = i2p.name
context['description'] = i2p.description
context['clients'] = i2p.clients
context['manual_page'] = i2p.manual_page
context['subsubmenu'] = subsubmenu
context['service_title'] = self.service_title
context['service_path'] = self.service_path
context['service_description'] = self.service_description
return context
i2p_frame_tunnels = _create_i2p_frame_view(
"I2P Proxies and Tunnels", "i2ptunnel", [
_('I2P has the concept of tunnels. These enter an exit the network and are configured and (de)activated here.'),
_('HTTP/S SOCKS5 proxies are entry tunnels, so they are configured here.'),
_('In order to allow usage by other members of your network, '
'select the proxy then the interface you want your proxies to be bound to and save the settings.'
'The interface is in the "Reachable by" dropdown list.'),
_('You can find the IP addresses of your interfaces/connections <a href="/plinth/sys/networks/">here</a>'),
class TunnelsView(ServiceBaseView):
"""View to describe and launch tunnel configuration."""
template_name = 'i2p_service.html'
service_title = _('I2P Proxies and Tunnels')
service_path = '/i2p/i2ptunnel/'
service_description = [
_('I2P lets you browse the Internet and hidden services (eepsites) '
'anonymously. For this, your browser, preferably a Tor Browser, '
'needs to be configured for a proxy.'),
_('By default HTTP, HTTPS and SOCKS5 proxies are available. Additional '
'proxies and tunnels may be configured using the tunnel '
'configuration interface.'),
]
)
i2p_frame_torrent = _create_i2p_frame_view(
"Anonymous torrents", "i2psnark", [
_('Track the progress of your anonymous torrent downloads here.'),
_('You can find a list of trackers on the '
'<a href="/i2p/i2psnark/configure" target="i2p-frame" >Configuration page</a>'),
class TorrentsView(ServiceBaseView):
"""View to describe and launch I2P torrents application."""
template_name = 'i2p_service.html'
service_title = _('Anonymous Torrents')
service_path = '/i2p/i2psnark/'
service_description = [
_('I2P provides an application to download files anonymously in a '
'peer-to-peer network. Download files by adding torrents or create a '
'new torrent to share a file.'),
]
)