John Lines f978d2f0d0
zoph: Add new app to organize photos
- Identify Freedbombox admin who installed the app to be zoph admin.

- Implement backup and restore.

- Photos directory should remain at /var/lib/zoph, for proper operation of
backups.

- There remains an issue that the App is enabled before it is configured but
will not work correctly until configuration.

- OpenStreetMap mapping is enabled. These should be configurable before
installation.

- Add initial forms.py and views.py to Zoph app, however these are currently
unused as urls.py does not invoke the view. When the view is not invoked the
Zoph App installs, with single signon, currently as the first LDAP user, rather
than the plinth user.

- The first user's preferences are not set, and need to be manually set to avoid
other errors.

* Sunil's changes

- Squash commits and re-split them.

- Drop documentation as it will be auto populated from wiki later.

- Remove outdated validation code from manifest.

- Drop some dead code.

- Don't send MySQL password over command line for improved security. Instead
  rely on Unix authentication of root user similar to backup/restore process.

- Use JSON for exchanging configuration dump to avoid encoding errors.

- Add username validation to avoid a potential SQL injection.

- Update description for neural tone and brevity. Add information about how user
  accounts work in FreedomBox

- Fix functional tests.

- Drop all code related to changing photos path until it is ready.

- Update URL from /zoph to /zoph/ to avoid another redirect.

- Fix disabling the app.

- Use icon that Zoph uses for favicon as logo. Update copyright file.

- Fix spelling unzip.

- Minor refactors. Run yapf and isort.

- Use subprocess.run() instead of os.popen() everywhere for better security with
argument parsing.

- Enable OpenStreetMap by default. User have a choice to disable it before using
the app. Add label to explain privacy concerns.

- Fix dropping database by using --force argument.

- Cleanup enabling the app to not enable the app when updating configuration.

- Use AppView's default template instead of overriding.

- Update functional tests to just check if the app is enabled/disabled as
expected. Checking that Zoph site is available will require reliable handling of
admin user.

Signed-off-by: John Lines <john@paladyn.org>
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2021-02-10 01:13:29 -08:00

131 lines
4.5 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""
FreedomBox app to configure Zoph web application
"""
import json
import logging
from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import app as app_module
from plinth import cfg, frontpage, menu
from plinth.modules.apache.components import Webserver
from plinth.modules.backups.components import BackupRestore
from plinth.modules.firewall.components import Firewall
from plinth.utils import format_lazy
from . import manifest
logger = logging.getLogger(__name__)
version = 1
managed_packages = ['zoph']
_description = [
format_lazy(
_('Zoph manages your photo collection. Photos are stored on your '
'{box_name}, under your control. Instead of focusing on galleries '
'for public display, Zoph focuses on managing them for your own '
'use, organizing them by who took them, where they were taken, '
'and who is in them. Photos can be linked to multiple hierarchical '
'albums and categories. It is easy to find all photos containing a '
'person, or photos taken on a date, or photos taken at a location '
'using search, map and calendar views. Individual photos can be '
'shared with others by sending a direct link.'),
box_name=_(cfg.box_name)),
format_lazy(
_('The {box_name} user who setup Zoph will also become the '
'administrator in Zoph. For additional users, accounts must be '
'created both in {box_name} and in Zoph with the same user name.'),
box_name=_(cfg.box_name))
]
app = None
class ZophApp(app_module.App):
"""FreedomBox app for Zoph."""
app_id = 'zoph'
def __init__(self):
"""Create components for the app."""
super().__init__()
info = app_module.Info(app_id=self.app_id, version=version,
name=_('Zoph'), icon_filename='zoph',
short_description=_('Photo Organizer'),
description=_description, manual_page='Zoph',
clients=manifest.clients)
self.add(info)
menu_item = menu.Menu('menu-zoph', info.name, info.short_description,
info.icon_filename, 'zoph:index',
parent_url_name='apps')
self.add(menu_item)
shortcut = frontpage.Shortcut('shortcut-zoph', info.name,
short_description=info.short_description,
icon=info.icon_filename, url='/zoph/',
clients=info.clients,
login_required=True)
self.add(shortcut)
firewall = Firewall('firewall-zoph', info.name,
ports=['http', 'https'], is_external=True)
self.add(firewall)
webserver = Webserver('webserver-zoph', 'zoph',
urls=['https://{host}/zoph/'])
self.add(webserver)
backup_restore = ZophBackupRestore('backup-restore-zoph',
**manifest.backup)
self.add(backup_restore)
def setup(helper, old_version=None):
"""Install and configure the module."""
helper.call('pre', actions.superuser_run, 'zoph', ['pre-install'])
helper.install(managed_packages)
helper.call('post', actions.superuser_run, 'zoph', ['setup'])
helper.call('post', app.enable)
def set_configuration(admin_user=None, enable_osm=None):
"""Configure Zoph."""
args = []
if admin_user:
args += ['--admin-user', admin_user]
if enable_osm is not None:
args += ['--enable-osm', str(enable_osm)]
actions.superuser_run('zoph', ['set-configuration'] + args)
def is_configured():
"""Return whether the Zoph app is configured."""
output = actions.superuser_run('zoph', ['is-configured'])
return output.strip() == 'true'
def get_configuration():
"""Return full configuration of Zoph."""
configuration = actions.superuser_run('zoph', ['get-configuration'])
return json.loads(configuration)
class ZophBackupRestore(BackupRestore):
"""Component to backup/restore Zoph database"""
def backup_pre(self, packet):
"""Save database contents."""
actions.superuser_run('zoph', ['dump-database'])
def restore_post(self, packet):
"""Restore database contents."""
actions.superuser_run('zoph', ['restore-database'])