mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
diaspora: Initial setup
Completed initial setup of diaspora on Plinth. Default configuration pending.
This commit is contained in:
1 parent
ee7cc98fee
commit
01e97e7369
9 files changed
+316
No files matched your search
@@ -0,0 +1,106 @@
|
||||
#
|
||||
# This file is part of Plinth.
|
||||
#
|
||||
# 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 import actions, action_utils, cfg, frontpage, service as service_module
|
||||
|
||||
version = 1
|
||||
|
||||
title_en = 'Federated Social Network (diaspora*)'
|
||||
|
||||
title = _(title_en)
|
||||
|
||||
depends = ['apps']
|
||||
|
||||
service = None
|
||||
|
||||
managed_services = ['diaspora']
|
||||
|
||||
managed_packages = ['diaspora']
|
||||
|
||||
description = [
|
||||
_('diaspora* is a decentralized social network where you can store and control your own data.'),
|
||||
|
||||
_('When enabled, the diaspora* pod will be available from '
|
||||
'<a href="/diaspora">/diaspora</a> path on the web server.')
|
||||
]
|
||||
|
||||
|
||||
def init():
|
||||
"""Initialize the Diaspora module."""
|
||||
menu = cfg.main_menu.get('apps:index')
|
||||
menu.add_urlname(title, 'glyphicon-thumbs-up', 'diaspora:index')
|
||||
|
||||
global service
|
||||
setup_helper = globals()['setup_helper']
|
||||
if setup_helper.get_state() != 'needs-setup':
|
||||
service = service_module.Service(
|
||||
managed_services[0], title, ports=['http', 'https'],
|
||||
is_external=True, is_enabled=is_enabled, enable=enable,
|
||||
disable=disable)
|
||||
|
||||
if is_enabled():
|
||||
add_shortcut()
|
||||
|
||||
|
||||
def setup(helper, old_version=None):
|
||||
"""Install and configure the module."""
|
||||
helper.install(managed_packages)
|
||||
helper.call('post', actions.superuser_run, 'diaspora', ['enable'])
|
||||
global service
|
||||
if service is None:
|
||||
service = service_module.Service(
|
||||
managed_services[0], title, ports=['http', 'https'],
|
||||
is_external=True, is_enabled=is_enabled, enable=enable,
|
||||
disable=disable)
|
||||
helper.call('post', service.notify_enabled, None, True)
|
||||
helper.call('post', add_shortcut)
|
||||
|
||||
|
||||
def add_shortcut():
|
||||
frontpage.add_shortcut('diaspora', title, url='/diaspora',
|
||||
login_required=True)
|
||||
|
||||
|
||||
def is_enabled():
|
||||
"""Return whether the module is enabled."""
|
||||
return action_utils.webserver_is_enabled('diaspora-plinth')
|
||||
|
||||
|
||||
def enable():
|
||||
"""Enable the module."""
|
||||
actions.superuser_run('diaspora', ['enable'])
|
||||
add_shortcut()
|
||||
|
||||
|
||||
def disable():
|
||||
"""Disable the module."""
|
||||
actions.superuser_run('diaspora', ['disable'])
|
||||
frontpage.remove_shortcut('diaspora')
|
||||
|
||||
|
||||
def diagnose():
|
||||
"""Run diagnostics and return the results."""
|
||||
results = []
|
||||
|
||||
results.append(action_utils.diagnose_port_listening(8112, 'tcp4'))
|
||||
results.append(action_utils.diagnose_port_listening(8112, 'tcp6'))
|
||||
results.extend(action_utils.diagnose_url_on_all(
|
||||
'https://{host}/diaspora', check_certificate=False))
|
||||
|
||||
return results
|
||||
@@ -0,0 +1,25 @@
|
||||
#
|
||||
# This file is part of Plinth.
|
||||
#
|
||||
# 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 import forms
|
||||
|
||||
class DiasporaForm(forms.Form):
|
||||
"""diaspora* configuration form."""
|
||||
enabled = forms.BooleanField(
|
||||
label='Enable diaspora',
|
||||
required=False)
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#
|
||||
# This file is part of Plinth.
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
@@ -0,0 +1,34 @@
|
||||
#
|
||||
# This file is part of Plinth.
|
||||
#
|
||||
# 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 Diaspora module.
|
||||
"""
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from plinth.modules import diaspora
|
||||
from plinth.views import ServiceView
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^apps/diaspora/$', ServiceView.as_view(
|
||||
description=diaspora.description,
|
||||
diagnostics_module_name="diaspora",
|
||||
service_id=diaspora.managed_services[0]
|
||||
), name='index'),
|
||||
]
|
||||
@@ -0,0 +1,71 @@
|
||||
#
|
||||
# This file is part of Plinth.
|
||||
#
|
||||
# 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 .forms import DiasporaForm
|
||||
from plinth.modules import diaspora
|
||||
from plinth import actions, package
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.template.response import TemplateResponse
|
||||
from django.contrib import messages
|
||||
|
||||
def get_status():
|
||||
"""Get the current status"""
|
||||
return {'enabled': diaspora.is_enabled()}
|
||||
|
||||
|
||||
def _apply_changes(request, old_status, new_status):
|
||||
"""Apply the changes."""
|
||||
modified = False
|
||||
|
||||
if old_status['enabled'] != new_status['enabled']:
|
||||
sub_command = 'enable' if new_status['enabled'] else 'disable'
|
||||
actions.superuser_run('diaspora', [sub_command])
|
||||
modified = True
|
||||
|
||||
if modified:
|
||||
messages.success(request, 'Configuration updated')
|
||||
else:
|
||||
messages.info(request, 'Setting unchanged')
|
||||
|
||||
|
||||
# TODO
|
||||
# If there are configuration tasks to be performed immediately before or after the package installation, Plinth provides hooks for it. The before_install= and
|
||||
# on_install= parameters to the @package.required decorator take a callback methods that are called before installation of packages and after installation of
|
||||
# packages respectively. See the reference section of this manual or the plinth.package module for details. Other modules in Plinth that use this feature provided
|
||||
# example usage.
|
||||
@package.required(['diaspora'])
|
||||
def index(request):
|
||||
"""Serve configuration page."""
|
||||
status = get_status()
|
||||
|
||||
form = None
|
||||
|
||||
if request.method == 'POST':
|
||||
form = DiasporaForm(request.POST, prefix='diaspora')
|
||||
if form.is_valid():
|
||||
_apply_changes(request, status, form.cleaned_data)
|
||||
status = get_status()
|
||||
form = DiasporaForm(initial=status, prefix='diaspora')
|
||||
else:
|
||||
form = DiasporaForm(initial=status, prefix='diaspora')
|
||||
|
||||
return TemplateResponse(request, 'diaspora.html',
|
||||
{'title': _(diaspora.title_en),
|
||||
'status': status,
|
||||
'form': form})
|
||||
|
||||
Reference in new issue
Block a user