transmission: Run from behind Apache

- Introduce Apache configuration for plinth.

- Remove Transmission service file for firewalld.

- Enable transmission on install.

- Enable/disable Apache configuration on Transmission on enable/disable.

- Remove IP address whilelisting as 127.0.0.1 is the default setting and
  is sufficient for Apache to reverse proxy.

- Update UI URL.
This commit is contained in:
Sunil Mohan Adapa 2015-04-12 19:30:19 +05:30
parent f94d0d5414
commit 69adf1cfc5
8 changed files with 31 additions and 32 deletions

View File

@ -79,10 +79,14 @@ def subcommand_enable(_):
"""Start Transmission service."""
set_service_enable(enable=True)
subprocess.call(['service', 'transmission-daemon', 'start'])
subprocess.call(['a2enconf', 'transmission-plinth'])
subprocess.call(['service', 'apache2', 'reload'])
def subcommand_disable(_):
"""Stop Transmission service."""
subprocess.call(['a2disconf', 'transmission-plinth'])
subprocess.call(['service', 'apache2', 'reload'])
subprocess.call(['service', 'transmission-daemon', 'stop'])
set_service_enable(enable=False)

View File

@ -0,0 +1,15 @@
##
## 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
## 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>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>Transmission Web Interface</short>
<description>Transmission is a client for BitTorrent, the peer-to-peer file sharing protocol. Transmission can run as a GUI client or as a daemon process running in the background. Both provide a web interface allowing themselves to be controlled using a web browser. Also, both can be controlled using a command line interface. Enable this if you wish to control Transmission BitTorrent GUI or daemon using its web interface or the command line utility.</description>
<port protocol="tcp" port="9091"/>
</service>

View File

@ -42,5 +42,5 @@ def init():
global service
service = service_module.Service(
'transmission-rpcplinth', _('Transmission BitTorrent'),
'transmission', _('Transmission BitTorrent'), ['http', 'https'],
is_external=True, enabled=enabled)

View File

@ -20,16 +20,7 @@ Plinth module for configuring Transmission.
"""
from django import forms
from django.core.validators import RegexValidator
from gettext import gettext as _
import re
ipv4_wildcard_re = r'(25[0-5]|2[0-4]\d|[0-1]?\d?\d)' \
r'(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d|\*)){3}'
multiple_ips_re = re.compile(r'^({ipv4})(\s*,\s*{ipv4})*$'.format(ipv4=ipv4_wildcard_re))
ip_validator = RegexValidator(multiple_ips_re)
class TransmissionForm(forms.Form): # pylint: disable=W0232
@ -53,10 +44,3 @@ default directory, ensure that the new directory exists and is writable by \
help_text=_('Password to login to the web interface. Current \
password is shown in a hashed format. To set a new password, enter the \
password in plain text.'))
rpc_whitelist = forms.CharField(
label=_('IP addresses to allow'),
validators=[ip_validator],
help_text=_('A comma separated list of IP addresses that will be \
allowed to connect to the web interface. IP addresses may use wild cards, \
such as 192.168.*.* .'))

View File

@ -28,9 +28,7 @@
daemon handles Bitorrent file sharing. Note that BitTorrent is not
anonymous.</p>
<p>Access the web interface at
<a href="http://{{ status.hostname }}:{{ status.rpc_port }}">
http://{{ status.hostname }}:{{ status.rpc_port }}</a>
<p>Access the web interface at <a href="/transmission">/transmission</a></p>
<h3>Status</h3>

View File

@ -37,8 +37,13 @@ logger = logging.getLogger(__name__)
TRANSMISSION_CONFIG = '/etc/transmission-daemon/settings.json'
def on_install():
"""Enable transmission as soon as it is installed."""
actions.superuser_run('transmission', ['enable'])
@login_required
@package.required(['transmission-daemon'])
@package.required(['transmission-daemon'], on_install=on_install)
def index(request):
"""Serve configuration page."""
status = get_status()
@ -92,13 +97,11 @@ def _apply_changes(request, old_status, new_status):
if old_status['download_dir'] != new_status['download_dir'] or \
old_status['rpc_username'] != new_status['rpc_username'] or \
old_status['rpc_password'] != new_status['rpc_password'] or \
old_status['rpc_whitelist'] != new_status['rpc_whitelist']:
old_status['rpc_password'] != new_status['rpc_password']:
new_configuration = {
'download-dir': new_status['download_dir'],
'rpc-username': new_status['rpc_username'],
'rpc-password': new_status['rpc_password'],
'rpc-whitelist': new_status['rpc_whitelist']
}
actions.superuser_run('transmission', ['merge-configuration',

View File

@ -129,9 +129,10 @@ setuptools.setup(
['data/usr/lib/freedombox/setup.d/86_plinth']),
('/usr/lib/freedombox/first-run.d',
['data/usr/lib/freedombox/first-run.d/90_firewall']),
('/etc/apache2/conf-available',
glob.glob('data/etc/apache2/conf-available/*.conf')),
('/etc/apache2/sites-available',
['data/etc/apache2/sites-available/plinth.conf',
'data/etc/apache2/sites-available/plinth-ssl.conf']),
glob.glob('data/etc/apache2/sites-available/*.conf')),
('/etc/sudoers.d', ['data/etc/sudoers.d/plinth']),
('/lib/systemd/system',
['data/lib/systemd/system/plinth.service']),