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 ugettext_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.firewall.components import Firewall
from plinth.modules.users import add_user_to_share_group, register_group

from .manifest import backup, clients  # noqa, pylint: disable=unused-import

version = 3

managed_services = ['transmission-daemon']

managed_packages = ['transmission-daemon']

_description = [
    _('BitTorrent is a peer-to-peer file sharing protocol. '
      'Transmission daemon handles Bitorrent file sharing.  Note that '
      'BitTorrent is not anonymous.'),
]

reserved_usernames = ['debian-transmission']

group = ('bit-torrent', _('Download files using BitTorrent applications'))

app = None


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

    app_id = 'transmission'

    def __init__(self):
        """Create components for the app."""
        super().__init__()
        info = app_module.Info(app_id=self.app_id, version=version,
                               name=_('Transmission'),
                               icon_filename='transmission',
                               short_description=_('BitTorrent Web Client'),
                               description=_description,
                               manual_page='Transmission', clients=clients)
        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=[group[0]])
        self.add(shortcut)

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

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

        daemon = Daemon('daemon-transmission', managed_services[0],
                        listen_ports=[(9091, 'tcp4')])
        self.add(daemon)


def init():
    """Initialize the Transmission module."""
    global app
    app = TransmissionApp()
    register_group(group)

    setup_helper = globals()['setup_helper']
    if setup_helper.get_state() != 'needs-setup' and app.is_enabled():
        app.set_enabled(True)


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

    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(reserved_usernames[0], managed_services[0])
    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 ugettext_lazy as _

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


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

    def __init__(self, *args, **kw):
        validator = DirectoryValidator(
            username=reserved_usernames[0], check_writable=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 ugettext_lazy as _

from plinth.clients import validate
from plinth.modules.backups.api import validate as validate_backup

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

backup = validate_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.conf.urls import url

from .views import TransmissionAppView

urlpatterns = [
    url(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 os
import socket

from django.contrib import messages
from django.utils.translation import ugettext 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'] = os.path.normpath(
            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 new_status['is_enabled'] or not old_status['is_enabled']:
            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()