diaspora: Initial setup

Completed initial setup of diaspora on Plinth. Default configuration pending.
This commit is contained in:
Joseph Nuthalpati 2017-02-14 17:47:43 +05:30 committed by James Valleroy
parent ee7cc98fee
commit 01e97e7369
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
9 changed files with 316 additions and 0 deletions

View File

@ -43,6 +43,7 @@ otherwise.
- static/themes/default/img/network-internet.svg :: [[http://tango.freedesktop.org/][Public Domain]]
- static/themes/default/img/network-wireless.svg :: [[http://tango.freedesktop.org/][Public Domain]]
- static/themes/default/icons/deluge.png :: [[https://upload.wikimedia.org/wikipedia/commons/thumb/8/85//Deluge-Logo.svg/2000px-Deluge-Logo.svg.png][GPL]]
- static/themes/default/icons/diaspora.png :: [[https://upload.wikimedia.org/wikipedia/commons/thumb/8/85//Deluge-Logo.svg/2000px-Deluge-Logo.svg.png][Publc Domain]]
- static/themes/default/icons/infinoted.png :: [[https://github.com/gobby/gobby/blob/master/COPYING][ISC]]
- static/themes/default/icons/ikiwiki.png :: [[https://ikiwiki.info/][GPL-2+]]
- static/themes/default/icons/jsxc.png :: -

61
actions/diaspora Normal file
View File

@ -0,0 +1,61 @@
#!/usr/bin/python3
# -*- mode: python -*-
#
# 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/>.
#
"""
Configuration helper for diaspora* web client.
"""
import argparse
from plinth import action_utils
def parse_arguments():
"""Return parsed command line arguments as dictionary."""
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
subparsers.add_parser('enable', help='Enable diaspora*')
subparsers.add_parser('disable', help='Disable diaspora*')
return parser.parse_args()
def subcommand_enable(_):
"""Enable web configuration and reload."""
action_utils.webserver_enable('diaspora')
def subcommand_disable(_):
"""Disable web configuration and reload."""
action_utils.webserver_disable('diaspora')
def main():
"""Parse arguments and perform all duties."""
arguments = parse_arguments()
subcommand = arguments.subcommand.replace('-', '_')
subcommand_method = globals()['subcommand_' + subcommand]
subcommand_method(arguments)
if __name__ == '__main__':
main()

View File

@ -0,0 +1,2 @@
plinth.modules.diaspora

View File

@ -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

View File

@ -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)

View File

@ -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/>.
#

View File

@ -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'),
]

View File

@ -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})

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB