Full Code

Transmission app is already included in FreedomBox. Here is the full source for the module for reference.

plinth/modules/transmission/__init__.py

# SPDX-License-Identifier: AGPL-3.0-or-later
"""
FreedomBox app to configure Transmission server.
"""

import json

from django.utils.translation import gettext_lazy as _

from plinth import actions
from plinth import app as app_module
from plinth import frontpage, menu
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.modules.users import add_user_to_share_group
from plinth.modules.users.components import UsersAndGroups
from plinth.package import Packages

from . import manifest

_description = [
    _('Transmission is a BitTorrent client with a web interface.'),
    _('BitTorrent is a peer-to-peer file sharing protocol. '
      'Note that BitTorrent is not anonymous.'),
    _('Please do not change the default port of the transmission daemon.'),
]

app = None

SYSTEM_USER = 'debian-transmission'


class TransmissionApp(app_module.App):
    """FreedomBox app for Transmission."""

    app_id = 'transmission'

    _version = 4

    DAEMON = 'transmission-daemon'

    def __init__(self):
        """Create components for the app."""
        super().__init__()

        groups = {
            'bit-torrent': _('Download files using BitTorrent applications')
        }

        info = app_module.Info(
            app_id=self.app_id, version=self._version, name=_('Transmission'),
            icon_filename='transmission',
            short_description=_('BitTorrent Web Client'),
            description=_description, manual_page='Transmission',
            clients=manifest.clients,
            donation_url='https://transmissionbt.com/donate/')
        self.add(info)

        menu_item = menu.Menu('menu-transmission', info.name,
                              info.short_description, info.icon_filename,
                              'transmission:index', parent_url_name='apps')
        self.add(menu_item)

        shortcut = frontpage.Shortcut(
            'shortcut-transmission', info.name,
            short_description=info.short_description, icon=info.icon_filename,
            url='/transmission', clients=info.clients, login_required=True,
            allowed_groups=list(groups))
        self.add(shortcut)

        packages = Packages('packages-transmission', ['transmission-daemon'])
        self.add(packages)

        firewall = Firewall('firewall-transmission', info.name,
                            ports=['http', 'https',
                                   'transmission-client'], is_external=True)
        self.add(firewall)

        webserver = Webserver('webserver-transmission', 'transmission-plinth',
                              urls=['https://{host}/transmission'])
        self.add(webserver)

        daemon = Daemon(
            'daemon-transmission', self.DAEMON, listen_ports=[
                (9091, 'tcp4'),
                (51413, 'tcp4'),
                (51413, 'tcp6'),
                (51413, 'udp4'),
            ])
        self.add(daemon)

        users_and_groups = UsersAndGroups('users-and-groups-transmission',
                                          reserved_usernames=[SYSTEM_USER],
                                          groups=groups)
        self.add(users_and_groups)

        backup_restore = BackupRestore('backup-restore-transmission',
                                       **manifest.backup)
        self.add(backup_restore)


def setup(helper, old_version=None):
    """Install and configure the module."""
    app.setup(old_version)

    if old_version and old_version <= 3 and app.is_enabled():
        app.get_component('firewall-transmission').enable()

    new_configuration = {
        'rpc-whitelist-enabled': False,
        'rpc-authentication-required': False
    }
    helper.call('post', actions.superuser_run, 'transmission',
                ['merge-configuration'],
                input=json.dumps(new_configuration).encode())
    add_user_to_share_group(SYSTEM_USER, TransmissionApp.DAEMON)
    helper.call('post', app.enable)

plinth/modules/transmission/forms.py

# SPDX-License-Identifier: AGPL-3.0-or-later
"""
FreedomBox app for configuring Transmission.
"""

from django.utils.translation import gettext_lazy as _

from plinth.modules.storage.forms import (DirectorySelectForm,
                                          DirectoryValidator)

from . import SYSTEM_USER


class TransmissionForm(DirectorySelectForm):
    """Transmission configuration form"""

    def __init__(self, *args, **kw):
        validator = DirectoryValidator(username=SYSTEM_USER,
                                       check_creatable=True)
        super(TransmissionForm,
              self).__init__(title=_('Download directory'),
                             default='/var/lib/transmission-daemon/downloads',
                             validator=validator, *args, **kw)

plinth/modules/transmission/manifest.py

# SPDX-License-Identifier: AGPL-3.0-or-later

from django.utils.translation import gettext_lazy as _

clients = [{
    'name': _('Transmission'),
    'platforms': [{
        'type': 'web',
        'url': '/transmission'
    }]
}]

backup = {
    'data': {
        'directories': ['/var/lib/transmission-daemon/.config']
    },
    'secrets': {
        'files': ['/etc/transmission-daemon/settings.json']
    },
    'services': ['transmission-daemon']
}

plinth/modules/transmission/urls.py

# SPDX-License-Identifier: AGPL-3.0-or-later
"""
URLs for the Transmission module.
"""

from django.urls import re_path

from .views import TransmissionAppView

urlpatterns = [
    re_path(r'^apps/transmission/$', TransmissionAppView.as_view(),
            name='index'),
]

plinth/modules/transmission/views.py

# SPDX-License-Identifier: AGPL-3.0-or-later
"""
FreedomBox app for configuring Transmission Server.
"""

import json
import logging
import socket

from django.contrib import messages
from django.utils.translation import gettext as _

from plinth import actions, views

from .forms import TransmissionForm

logger = logging.getLogger(__name__)


class TransmissionAppView(views.AppView):
    """Serve configuration page."""
    form_class = TransmissionForm
    app_id = 'transmission'

    def get_initial(self):
        """Get the current settings from Transmission server."""
        status = super().get_initial()
        configuration = actions.superuser_run('transmission',
                                              ['get-configuration'])
        configuration = json.loads(configuration)
        status['storage_path'] = configuration['download-dir']
        status['hostname'] = socket.gethostname()

        return status

    def form_valid(self, form):
        """Apply the changes submitted in the form."""
        old_status = form.initial
        new_status = form.cleaned_data
        if old_status['storage_path'] != new_status['storage_path']:
            new_configuration = {
                'download-dir': new_status['storage_path'],
            }

            actions.superuser_run('transmission', ['merge-configuration'],
                                  input=json.dumps(new_configuration).encode())
            messages.success(self.request, _('Configuration updated'))

        return super().form_valid(form)

plinth/modules/transmission/data/etc/plinth/modules-enabled/transmission

plinth.modules.transmission

plinth/modules/transmission/data/etc/apache2/conf-available/transmission-plinth.conf

##
## On all sites, provide Transmission on a default path: /transmission
##
## Requires the following Apache modules to be enabled:
##   mod_headers
##   mod_proxy
##   mod_proxy_http
##
<Location /transmission>
    ProxyPass        http://localhost:9091/transmission
    Include          includes/freedombox-single-sign-on.conf
    <IfModule mod_auth_pubtkt.c>
        TKTAuthToken "admin" "bit-torrent"
    </IfModule>
    ## Send the scheme from user's request to enable Transmission to
    ## redirect URLs, set cookies, set absolute URLs (if any)
    ## properly.
    RequestHeader    set X-Forwarded-Proto 'https' env=HTTPS
</Location>

plinth/modules/transmission/tests/__init__.py


actions/transmission

#!/usr/bin/python3
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Configuration helper for Transmission daemon.
"""

import argparse
import json
import sys

from plinth import action_utils

TRANSMISSION_CONFIG = '/etc/transmission-daemon/settings.json'


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('get-configuration',
                          help='Return the current configuration')
    subparsers.add_parser(
        'merge-configuration',
        help='Merge JSON configuration from stdin with existing')

    subparsers.required = True
    return parser.parse_args()


def subcommand_get_configuration(_):
    """Return the current configuration in JSON format."""
    configuration = open(TRANSMISSION_CONFIG, 'r').read()
    print(configuration)


def subcommand_merge_configuration(arguments):
    """Merge given JSON configuration with existing configuration."""
    configuration = sys.stdin.read()
    configuration = json.loads(configuration)

    current_configuration = open(TRANSMISSION_CONFIG, 'r').read()
    current_configuration = json.loads(current_configuration)

    new_configuration = current_configuration
    new_configuration.update(configuration)
    new_configuration = json.dumps(new_configuration, indent=4, sort_keys=True)

    open(TRANSMISSION_CONFIG, 'w').write(new_configuration)
    action_utils.service_reload('transmission-daemon')


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