James Valleroy 0e698eb4b4
apache: Use a Uwsgi native socket systemd unit for each app
[Sunil]:

- Drop Uwsgi component entirely. After the changes, it mostly looks like Daemon
component minus some features. One change that Uwsgi component does is when
component is disabled, it also stops and disables the .service unit. Stopping
the service is useful and we can add this to Daemon component.

- Use /run instead of /var/run/ as 1) /var/run is a symlink to /run 2) /run/
path is what is listed in uwsgi-app@.socket unit file.

- Implement upgrade for apps from older version. Disable and mask uwsgi init.d
script. Enable the daemon component if the webserver component is enabled.

- Update manifest files to deal with .socket units instead of 'uwsgi' service.
Backup the /var/lib/private directories as that is actual directory to backup
with DynamicUser=yes.

- For bepasty load the configuration as a systemd provided credential since
DynamicUser=yes.

- Remove the /var/lib/private directories during uninstall.

- Don't create user/group for bepasty as it is not needed with DynamicUser=yes.

Tests:

- Radicale

  - Functional tests pass

  - Freshly install radicale.

  - Web interface works.

  - Create and edit calendars

  - Path of the storage directory is in /var/lib/private/radicale (after
  accessing web interface)

  - Permissions on the storage folder and files inside are set to nobody:nobody.

  - Uninstall removes the /var/lib/private/radicale directory.

  - Create a calender and backup the app. Uninstall the app. Re-install the app.
  The calendar is not available. After restoring the backup, the calendar is
  available.

  - Install radicale without patch and create a calendar. Apply patches and
  start plinth.service. Setup is run. UWSGI is disabled and masked. Service is
  running. Old calender is visible.

  - Install radicale without patch. Disable and apply patches and start
  plinth.service. Setup is run. UWSGI is disabled and masked. Service is not
  running. Enabling the service works.

  - After upgrade, data storage path got migrated to /var/lib/private/radicale.
  Old data is accessible.

  - After upgrade the directory is still owned by radicale:radicale.

  - Freshly install radicale with patch and restore an old backup. The data is
  available in the web interface and data was migrated to
  /var/lib/private/radicale.

- Bepasty

  - Functional tests pass

  - Freshly install bepasy.

  - Enabling and disabling rapidly works.

  - Uploading files works.

  - Path of the storage directory is /var/lib/private/bepasty.

  - Permissions on the storage folder are as expect 755 but on the parent are
  700.

  - Permissions on the stored files are 644 and owned by nobody:nobody.

  - Uninstall removes the /var/lib/private/bepasty directory.

  - Upload a picture and backup the app. Uninstall the app. Re-install the app.
  The uploaded file is not available. After restoring the backup, the uploaded
  file is available.

  - Install bepasty without patch and upload a file. Apply patches and start
  plinth.service. Setup is run. UWSGI is disabled and masked. Service is
  running. Old uploaded picture is visible.

  - Install bepasty without patch. Disable app. Apply patches and start
  plinth.service. Setup is run. UWSGI is disabled and masked. Service is not
  running. Enabling the service works.

  - After upgrade, data storage path got migrated to /var/lib/private/bepasty.
  Old data is accessible.

  - After upgrade the directory is still owned by bepasty:bepasty.

  - Freshly install bepasty with patch and restore an old backup. The uploaded
  file is available in the web interface and data was migrated to
  /var/lib/private/bepasty.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2026-03-21 07:45:51 -07:00

127 lines
4.7 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""FreedomBox app for bepasty."""
from django.utils.translation import gettext_lazy as _
from plinth import app as app_module
from plinth import frontpage, menu
from plinth.config import DropinConfigs
from plinth.daemon import Daemon
from plinth.modules.apache.components import Webserver
from plinth.modules.backups.components import BackupRestore
from plinth.modules.firewall.components import Firewall
from plinth.package import Packages
from plinth.privileged import service as service_privileged
from . import manifest, privileged
_description = [
_('bepasty is a web application that allows large files to be uploaded '
'and shared. Text and code snippets can also be pasted and shared. '
'Text, image, audio, video and PDF documents can be previewed in the '
'browser. Shared files can be set to expire after a time period.'),
_('bepasty does not use usernames for login. It only uses passwords. For '
'each password, a set of permissions can be selected. Once you have '
'created a password, you can share it with the users who should have the'
' associated permissions.'),
_('You can also create multiple passwords with the same set of privileges,'
' and distribute them to different people or groups. This will allow '
'you to later revoke access for a single person or group, by removing '
'their password from the list.'),
]
PERMISSIONS = {
'read': _('Read a file, if a web link to the file is available'),
'create': _('Create or upload files'),
'list': _('List all files and their web links'),
'delete': _('Delete files'),
'admin': _('Administer files: lock/unlock files'),
}
DEFAULT_PERMISSIONS = {
'': _('None, password is always required'),
'read': _('Read a file, if a web link to the file is available'),
'read list': _('List and read all files'),
}
class BepastyApp(app_module.App):
"""FreedomBox app for bepasty."""
app_id = 'bepasty'
_version = 4
def __init__(self) -> None:
"""Create components for the app."""
super().__init__()
info = app_module.Info(self.app_id, self._version, name=_('bepasty'),
icon_filename='bepasty',
description=_description, manual_page='bepasty',
clients=manifest.clients, tags=manifest.tags)
self.add(info)
menu_item = menu.Menu('menu-bepasty', info.name, info.icon_filename,
info.tags, 'bepasty:index',
parent_url_name='apps')
self.add(menu_item)
shortcut = frontpage.Shortcut('shortcut-bepasty', info.name,
info.icon_filename, '/bepasty',
clients=manifest.clients, tags=info.tags)
self.add(shortcut)
packages = Packages('packages-bepasty', ['bepasty'])
self.add(packages)
dropin_configs = DropinConfigs('dropin-configs-bepasty', [
'/etc/apache2/conf-available/bepasty-freedombox.conf',
'/etc/uwsgi/apps-available/bepasty-freedombox.ini'
])
self.add(dropin_configs)
firewall = Firewall('firewall-bepasty', info.name,
ports=['http', 'https'], is_external=True)
self.add(firewall)
daemon = Daemon('daemon-bepasty',
'uwsgi-app@bepasty-freedombox.socket')
self.add(daemon)
webserver = Webserver('webserver-bepasty', 'bepasty-freedombox',
urls=['https://{host}/bepasty/'])
self.add(webserver)
backup_restore = BackupRestore('backup-restore-bepasty',
**manifest.backup)
self.add(backup_restore)
def setup(self, old_version):
"""Install and configure the app."""
super().setup(old_version)
privileged.setup('freedombox.local')
if not old_version:
self.enable()
if old_version == 1 and not privileged.get_configuration().get(
'DEFAULT_PERMISSIONS'):
# Upgrade to a better default only if user hasn't changed the
# value.
privileged.set_default(['read'])
if old_version and old_version <= 3:
webserver = self.get_component('webserver-bepasty')
daemon = self.get_component('daemon-bepasty')
if webserver.is_enabled():
daemon.enable()
# Vanquish the old uwsgi init.d script.
service_privileged.disable('uwsgi')
service_privileged.mask('uwsgi')
def uninstall(self):
"""De-configure and uninstall the app."""
super().uninstall()
privileged.uninstall()