From afdea208ec3649f8ce3b7d82af39d8a66086f877 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 16 Aug 2016 11:29:20 +0530 Subject: [PATCH] transmission: Read configuration as super user Due to permission restrictions on the configuration file (due to stored password), it is not possible to read it as plinth user. Read it using sudo instead. --- CHANGELOG.md | 1 + actions/transmission | 13 ++++++++----- plinth/modules/transmission/__init__.py | 2 -- plinth/modules/transmission/views.py | 3 ++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 577ff3afa..e560a660b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. ### Changed - dynamicdns: Allowed Plinth to run as non-root. +- transmission: Read configuration as super user. ## [0.10.0] - 2016-08-12 ### Added diff --git a/actions/transmission b/actions/transmission index a21f0e14e..85f1751d1 100755 --- a/actions/transmission +++ b/actions/transmission @@ -37,13 +37,10 @@ def parse_arguments(): parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(dest='subcommand', help='Sub command') - # Enable service subparsers.add_parser('enable', help='Enable Transmission service') - - # Disable service subparsers.add_parser('disable', help='Disable Transmission service') - - # Merge given JSON configration with existing + subparsers.add_parser( + 'get-configuration', help='Return the current configuration') subparsers.add_parser( 'merge-configuration', help='Merge JSON configuration from stdin with existing') @@ -63,6 +60,12 @@ def subcommand_disable(_): action_utils.service_disable('transmission-daemon') +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() diff --git a/plinth/modules/transmission/__init__.py b/plinth/modules/transmission/__init__.py index 6af0e7b19..3a5a02a0c 100644 --- a/plinth/modules/transmission/__init__.py +++ b/plinth/modules/transmission/__init__.py @@ -47,8 +47,6 @@ description = [ service = None -TRANSMISSION_CONFIG = '/etc/transmission-daemon/settings.json' - def init(): """Intialize the Transmission module.""" diff --git a/plinth/modules/transmission/views.py b/plinth/modules/transmission/views.py index 781c87e97..54e3d6d5e 100644 --- a/plinth/modules/transmission/views.py +++ b/plinth/modules/transmission/views.py @@ -42,7 +42,8 @@ class TransmissionServiceView(views.ServiceView): def get_initial(self): """Get the current settings from Transmission server.""" - configuration = open(transmission.TRANSMISSION_CONFIG, 'r').read() + configuration = actions.superuser_run( + 'transmission', ['get-configuration']) status = json.loads(configuration) status = {key.translate(str.maketrans({'-': '_'})): value for key, value in status.items()}