Add file-sharing application Coquelicot to FreedomBox

- Add settings in Service View
- Fixes for maximum file setting
- Don't allow negative values for max. file size in UI
- Minor text changes to django messages
- Minor correction to maximum file size calculation
- Rename apache conf file to coquelicot-freedombox.conf
- Remove all hacks to adjust file size.
- Fix permissions issues for settings file
- Show status block in UI
- try-restart on settings change instead of restart

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Joseph Nuthalapati authored and James Valleroy committed 2018-02-14 07:11:25 -05:00
1 parent 5b37d0df8d
commit ff9d061e98
10 files changed
+455 -20

No files matched your search

+15 -20
View File
@@ -99,41 +99,36 @@ def service_unmask(service_name):
def service_start(service_name):
"""Start a service with systemd or sysvinit."""
if is_systemd_running():
subprocess.run(['systemctl', 'start', service_name],
stdout=subprocess.DEVNULL)
else:
subprocess.run(['service', service_name, 'start'],
stdout=subprocess.DEVNULL)
service_action(service_name, 'start')
def service_stop(service_name):
"""Stop a service with systemd or sysvinit."""
if is_systemd_running():
subprocess.run(['systemctl', 'stop', service_name],
stdout=subprocess.DEVNULL)
else:
subprocess.run(['service', service_name, 'stop'],
stdout=subprocess.DEVNULL)
service_action(service_name, 'stop')
def service_restart(service_name):
"""Restart a service with systemd or sysvinit."""
if is_systemd_running():
subprocess.run(['systemctl', 'restart', service_name],
stdout=subprocess.DEVNULL)
else:
subprocess.run(['service', service_name, 'restart'],
stdout=subprocess.DEVNULL)
service_action(service_name, 'restart')
def service_try_restart(service_name):
"""Try to restart a service with systemd or sysvinit."""
service_action(service_name, 'try-restart')
def service_reload(service_name):
"""Reload a service with systemd or sysvinit."""
service_action(service_name, 'reload')
def service_action(service_name, action):
"""Preform the given action on the service_name."""
if is_systemd_running():
subprocess.run(['systemctl', 'reload', service_name],
subprocess.run(['systemctl', action, service_name],
stdout=subprocess.DEVNULL)
else:
subprocess.run(['service', service_name, 'reload'],
subprocess.run(['service', service_name, action],
stdout=subprocess.DEVNULL)
+133
View File
@@ -0,0 +1,133 @@
#
# 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/>.
#
"""
Plinth module to configure coquelicot.
"""
from django.utils.translation import ugettext_lazy as _
from plinth import service as service_module
from plinth import action_utils, actions, frontpage
from plinth.menu import main_menu
from .manifest import clients
clients = clients
version = 1
managed_services = ['coquelicot']
managed_packages = ['coquelicot']
name = _('Coquelicot')
short_description = _('File Sharing')
description = [
_('Coquelicot is a “one-click” file sharing web application with a focus '
'on protecting users’ privacy. It is best used for quickly sharing a '
'single file. '),
_('This Coquelicot instance is exposed to the public but requires an '
'upload password to prevent unauthorized access. You can set a new '
'upload password in the form that will appear below after installation. '
'The default upload password is "test".')
]
service = None
def init():
"""Intialize the module."""
menu = main_menu.get('apps')
menu.add_urlname(name, 'glyphicon-open-file', 'coquelicot:index',
short_description)
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)
helper.call('post', actions.superuser_run, 'coquelicot', ['setup'])
helper.call('post', actions.superuser_run, 'coquelicot', ['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('coquelicot', name,
short_description=short_description,
url='/coquelicot', login_required=True)
def is_running():
"""Return whether the service is running."""
return action_utils.service_is_running('coquelicot')
def is_enabled():
"""Return whether the module is enabled."""
return (action_utils.service_is_enabled('coquelicot')
and action_utils.webserver_is_enabled('coquelicot-freedombox'))
def enable():
"""Enable the module."""
actions.superuser_run('coquelicot', ['enable'])
add_shortcut()
def disable():
"""Disable the module."""
actions.superuser_run('coquelicot', ['disable'])
frontpage.remove_shortcut('coquelicot')
def get_current_max_file_size():
"""Get the current value of maximum file size."""
size = actions.superuser_run('coquelicot', ['get-max-file-size'])
return int(size.strip())
def diagnose():
"""Run diagnostics and return the results."""
results = []
results.extend(
action_utils.diagnose_url_on_all('https://{host}/coquelicot',
check_certificate=False))
return results
+37
View File
@@ -0,0 +1,37 @@
#
# 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/>.
#
"""
Plinth form for configuring Coquelicot.
"""
from django import forms
from django.utils.translation import ugettext_lazy as _
from plinth.forms import ServiceForm
class CoquelicotForm(ServiceForm): # pylint: disable=W0232
"""Coquelicot configuration form."""
upload_password = forms.CharField(
label=_('Upload Password'),
help_text=_('Set a new upload password for Coquelicot. '
'Leave this field blank to keep the current password.'),
required=False, widget=forms.PasswordInput)
max_file_size = forms.IntegerField(
label=_("Maximum File Size (in MiB)"), help_text=_(
'Set the maximum size of the files that can be uploaded to '
'Coquelicot.'), required=False, min_value=0)
+28
View File
@@ -0,0 +1,28 @@
#
# 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.clients import validate
clients = validate([{
'name': _('coquelicot'),
'platforms': [{
'type': 'web',
'url': '/coquelicot'
}]
}])
+27
View File
@@ -0,0 +1,27 @@
#
# 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 coquelicot module.
"""
from django.conf.urls import url
from .views import CoquelicotServiceView
urlpatterns = [
url(r'^apps/coquelicot/$', CoquelicotServiceView.as_view(), name='index'),
]
+72
View File
@@ -0,0 +1,72 @@
#
# 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/>.
#
"""
Plinth views for Coquelicot.
"""
from django.contrib import messages
from django.utils.translation import ugettext as _
from plinth import actions, views
from plinth.errors import ActionError
from plinth.modules.coquelicot import (clients, description,
get_current_max_file_size)
from .forms import CoquelicotForm
class CoquelicotServiceView(views.ServiceView):
"""Serve configuration page."""
clients = clients
description = description
diagnostics_module_name = 'coquelicot'
service_id = 'coquelicot'
form_class = CoquelicotForm
show_status_block = True
def get_initial(self):
"""Return the status of the service to fill in the form."""
initial = super().get_initial()
initial['max_file_size'] = get_current_max_file_size()
return initial
def form_valid(self, form):
"""Apply the changes submitted in the form."""
form_data = form.cleaned_data
if form_data['upload_password']:
try:
actions.superuser_run(
'coquelicot', ['set-upload-password'],
input=form_data['upload_password'].encode())
messages.success(self.request, _('Upload password updated'))
except ActionError as e:
messages.error(self.request,
_('Failed to update upload password'))
max_file_size = form_data['max_file_size']
if max_file_size and max_file_size != get_current_max_file_size():
try:
actions.superuser_run(
'coquelicot', ['set-max-file-size',
str(max_file_size)])
messages.success(self.request, _('Maximum file size updated'))
except ActionError as e:
messages.error(self.request,
_('Failed to update maximum file size'))
return super().form_valid(form)