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.
This commit is contained in:
Sunil Mohan Adapa 2016-08-16 11:29:20 +05:30 committed by James Valleroy
parent 522db2ce4c
commit afdea208ec
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
4 changed files with 11 additions and 8 deletions

View File

@ -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

View File

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

View File

@ -47,8 +47,6 @@ description = [
service = None
TRANSMISSION_CONFIG = '/etc/transmission-daemon/settings.json'
def init():
"""Intialize the Transmission module."""

View File

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