Merge remote-tracking branch 'freedombox-team/master'

This commit is contained in:
James Valleroy committed 2019-04-01 21:23:13 -04:00
commit 5c2a8c0b40
15 files changed
+800 -2

No files matched your search

+1 -1
View File
@@ -20,7 +20,7 @@ FreedomBox app for Apache server.
from plinth import actions
version = 6
version = 7
is_essential = True
+1 -1
View File
@@ -26,6 +26,6 @@ from . import diagnostics as views
urlpatterns = [
url(r'^sys/diagnostics/$', views.index, name='index'),
url(r'^sys/diagnostics/(?P<module_name>[a-z\-]+)/$', views.module,
url(r'^sys/diagnostics/(?P<module_name>[1-9a-z\-]+)/$', views.module,
name='module'),
]
+153
View File
@@ -0,0 +1,153 @@
#
# 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/>.
#
"""
FreedomBox app to configure I2P.
"""
from django.utils.translation import ugettext_lazy as _
from plinth import action_utils, actions, frontpage
from plinth import service as service_module
from plinth.menu import main_menu
from plinth.modules.users import register_group
from .manifest import backup, clients
version = 1
service_name = 'i2p'
managed_services = [service_name]
managed_packages = ['i2p']
name = _('I2P')
short_description = _('Anonymity Network')
description = [
_('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
group = ('i2p', _('Manage I2P application'))
service = None
manual_page = 'I2P'
additional_favorites = [
('Searx instance', 'http://ransack.i2p'),
('Torrent tracker', 'http://tracker2.postman.i2p'),
('YaCy Legwork', 'http://legwork.i2p'),
('YaCy Seeker', 'http://seeker.i2p'),
]
def init():
"""Intialize the module."""
menu = main_menu.get('apps')
menu.add_urlname(name, 'i2p', 'i2p:index', short_description)
register_group(group)
global service
setup_helper = globals()['setup_helper']
if setup_helper.get_state() != 'needs-setup':
service = service_module.Service(managed_services[0], name, ports=[
'http', 'https'
], is_external=True, is_enabled=is_enabled, enable=enable,
disable=disable,
is_running=is_running)
if is_enabled():
add_shortcut()
def setup(helper, old_version=None):
"""Install and configure the module."""
helper.install(managed_packages)
# Add favorites to the configuration
for fav_name, fav_url in additional_favorites:
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=[
'http', 'https'
], is_external=True, is_enabled=is_enabled, enable=enable,
disable=disable,
is_running=is_running)
helper.call('post', service.notify_enabled, None, True)
helper.call('post', add_shortcut)
def add_shortcut():
"""Helper method to add a shortcut to the frontpage."""
frontpage.add_shortcut('i2p', name, short_description=short_description,
url='/i2p/', login_required=True,
allowed_groups=[group[0]])
def is_running():
"""Return whether the service is running."""
return action_utils.service_is_running('i2p')
def is_enabled():
"""Return whether the module is enabled."""
return action_utils.service_is_enabled('i2p') and \
action_utils.webserver_is_enabled('i2p-freedombox')
def enable():
"""Enable the module."""
actions.superuser_run('i2p', ['enable'])
add_shortcut()
def disable():
"""Enable the module."""
actions.superuser_run('i2p', ['disable'])
frontpage.remove_shortcut('i2p')
def diagnose():
"""Run diagnostics and return the results."""
results = []
results.append(action_utils.diagnose_port_listening(7657, 'tcp6'))
results.extend(
action_utils.diagnose_url_on_all('https://{host}/i2p/',
check_certificate=False))
return results
@@ -0,0 +1,30 @@
##
## On all sites, provide I2P on a default path: /i2p
##
## Requires the following Apache modules to be enabled:
## mod_headers
## mod_proxy
## mod_proxy_http
## mod_proxy_html
##
<Location /i2p>
# Disable compression
# As soon as it has to be chunked, it doesn't work
RequestHeader unset Accept-Encoding
ProxyPass http://localhost:7657
ProxyPassReverse http://localhost:7657
# Rewrite absolute urls from i2p to pass through apache
ProxyHTMLEnable On
ProxyHTMLURLMap / /i2p/
Include includes/freedombox-single-sign-on.conf
<IfModule mod_auth_pubtkt.c>
TKTAuthToken "admin" "i2p"
</IfModule>
</Location>
# Catch some other root i2p addresses
# These are most likely generated by javascript
RedirectMatch "^/(i2p[^/]+.*)" "/i2p/$1"
@@ -0,0 +1 @@
#plinth.modules.i2p
+56
View File
@@ -0,0 +1,56 @@
#
# 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/>.
#
from django.utils.translation import ugettext_lazy as _
from plinth.clients import validate
from plinth.modules.backups.api import validate as validate_backup
_package_id = 'net.geti2p.i2p'
_download_url = 'https://geti2p.net/download'
clients = validate([{
'name':
_('I2P'),
'platforms': [{
'type': 'web',
'url': '/i2p/'
}, {
'type': 'package',
'format': 'deb',
'name': 'i2p',
}, {
'type': 'download',
'os': 'gnu-linux',
'url': _download_url,
}, {
'type': 'download',
'os': 'macos',
'url': _download_url,
}, {
'type': 'download',
'os': 'windows',
'url': _download_url,
}]
}])
backup = validate_backup({
'secrets': {
'directories': ['/var/lib/i2p/i2p-config']
},
'services': ['i2p']
})
+63
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 %}
@@ -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 %}
+29
View File
@@ -0,0 +1,29 @@
#
# 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/>.
#
"""
URLs for the I2P module.
"""
from django.conf.urls import url
from plinth.modules.i2p import views
urlpatterns = [
url(r'^apps/i2p/$', views.I2PServiceView.as_view(), name='index'),
url(r'^apps/i2p/tunnels/?$', views.TunnelsView.as_view(), name='tunnels'),
url(r'^apps/i2p/torrents/?$', views.TorrentsView.as_view(), name='torrents'),
]
+106
View File
@@ -0,0 +1,106 @@
#
# 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/>.
#
"""
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
subsubmenu = [{
'url': reverse_lazy('i2p:index'),
'text': ugettext_lazy('Configure')
}, {
'url': reverse_lazy('i2p:tunnels'),
'text': ugettext_lazy('Proxies')
},
{
'url': reverse_lazy('i2p:torrents'),
'text': ugettext_lazy('Anonymous torrents')
}]
class I2PServiceView(ServiceView):
"""Serve configuration page."""
service_id = i2p.service_name
clients = i2p.clients
description = i2p.description
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['title'] = i2p.name
context['description'] = i2p.description
context['clients'] = i2p.clients
context['manual_page'] = i2p.manual_page
context['subsubmenu'] = subsubmenu
return context
class ServiceBaseView(TemplateView):
"""View to describe and launch a service."""
service_description = None
service_title = None
service_path = None
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
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.'),
]
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.'),
]