mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
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 <sunil@medhas.org>
This commit is contained in:
parent
de2c246dbd
commit
372ecdcda9
@ -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)
|
||||
|
||||
|
||||
|
||||
40
actions/privoxy → plinth/modules/privoxy/privileged.py
Executable file → Normal file
40
actions/privoxy → plinth/modules/privoxy/privileged.py
Executable file → Normal file
@ -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()
|
||||
Loading…
x
Reference in New Issue
Block a user