From 372ecdcda993272cf8a6557c6c01f3015f45783f Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Wed, 13 Jul 2022 19:37:39 -0700 Subject: [PATCH] privoxy: Use privileged decorator for actions Tests: - App installation works. Proxying works when configured with Firefox. listen-address and permit-access directives are set as expected in the configuration file. Signed-off-by: Sunil Mohan Adapa --- plinth/modules/privoxy/__init__.py | 8 ++-- .../modules/privoxy/privileged.py | 40 +++---------------- 2 files changed, 10 insertions(+), 38 deletions(-) rename actions/privoxy => plinth/modules/privoxy/privileged.py (66%) mode change 100755 => 100644 diff --git a/plinth/modules/privoxy/__init__.py b/plinth/modules/privoxy/__init__.py index 432544723..2de23fc96 100644 --- a/plinth/modules/privoxy/__init__.py +++ b/plinth/modules/privoxy/__init__.py @@ -6,7 +6,7 @@ FreedomBox app to configure Privoxy. from django.urls import reverse_lazy from django.utils.translation import gettext_lazy as _ -from plinth import action_utils, actions +from plinth import action_utils from plinth import app as app_module from plinth import cfg, frontpage, menu from plinth.daemon import Daemon @@ -17,7 +17,7 @@ from plinth.modules.users.components import UsersAndGroups from plinth.package import Packages from plinth.utils import format_lazy -from . import manifest +from . import manifest, privileged _description = [ _('Privoxy is a non-caching web proxy with advanced filtering ' @@ -97,9 +97,9 @@ class PrivoxyApp(app_module.App): def setup(helper, old_version=None): """Install and configure the module.""" - helper.call('pre', actions.superuser_run, 'privoxy', ['pre-install']) + helper.call('pre', privileged.pre_install) app.setup(old_version) - helper.call('post', actions.superuser_run, 'privoxy', ['setup']) + helper.call('post', privileged.setup) helper.call('post', app.enable) diff --git a/actions/privoxy b/plinth/modules/privoxy/privileged.py old mode 100755 new mode 100644 similarity index 66% rename from actions/privoxy rename to plinth/modules/privoxy/privileged.py index 89b3fa29c..2c50cafb6 --- a/actions/privoxy +++ b/plinth/modules/privoxy/privileged.py @@ -1,40 +1,25 @@ -#!/usr/bin/python3 # SPDX-License-Identifier: AGPL-3.0-or-later -""" -Configuration helper for Privoxy server. -""" +"""Configure privoxy.""" -import argparse import pathlib import augeas from plinth import action_utils +from plinth.actions import privileged PRIVOXY_CONF_PATH = pathlib.Path('/etc/privoxy/config') -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( - 'pre-install', - help='Preseed debconf values before packages are installed') - subparsers.add_parser('setup', help='Perform post install steps') - - subparsers.required = True - return parser.parse_args() - - -def subcommand_pre_install(_): +@privileged +def pre_install(): """Preseed debconf values before packages are installed.""" action_utils.debconf_set_selections( ['privoxy privoxy/listen-address string [::]:8118']) -def subcommand_setup(_): +@privileged +def setup(): """Setup Privoxy configuration after installing it.""" _restrict_access() @@ -75,16 +60,3 @@ def _restrict_access(): aug.set('permit-access[last() + 1]', ip_range) aug.save() - - -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()