diff --git a/plinth/modules/tor/__init__.py b/plinth/modules/tor/__init__.py index c64feb83a..7429269c8 100644 --- a/plinth/modules/tor/__init__.py +++ b/plinth/modules/tor/__init__.py @@ -1,16 +1,18 @@ # SPDX-License-Identifier: AGPL-3.0-or-later """FreedomBox app to configure Tor.""" +import json import logging from django.utils.translation import gettext_lazy as _ from plinth import action_utils from plinth import app as app_module -from plinth import cfg, menu +from plinth import cfg, kvstore, menu from plinth import setup as setup_module from plinth.daemon import (Daemon, app_is_running, diagnose_netcat, diagnose_port_listening) +from plinth.modules import torproxy from plinth.modules.apache.components import Webserver from plinth.modules.backups.components import BackupRestore from plinth.modules.firewall.components import Firewall @@ -173,7 +175,8 @@ class TorApp(app_module.App): """Install and configure the app.""" super().setup(old_version) privileged.setup(old_version) - update_hidden_service_domain(utils.get_status()) + status = utils.get_status() + update_hidden_service_domain(status) # Enable/disable Onion-Location component based on app status. # Component was introduced in version 6. @@ -188,16 +191,20 @@ class TorApp(app_module.App): component.disable() # The SOCKS proxy and "Download software packages using Tor" features - # were moved into a new app, Tor Proxy, in version 7. If the "Download - # software packages using Tor" option was enabled, then install and - # enable Tor Proxy, to avoid any issues for apt. - if old_version and old_version < 7: - if self.is_enabled() and is_apt_transport_tor_enabled(): - logger.info( - 'Tor Proxy app will be installed for apt-transport-tor') - # This creates the operation, which will run after the current - # operation (Tor setup) is completed. - setup_module.run_setup_on_app('torproxy') + # were moved into a new app, Tor Proxy, in version 7. If Tor is + # enabled, then store the relevant configuration, and install Tor + # Proxy. + if old_version and old_version < 7 and self.is_enabled(): + logger.info('Tor Proxy app will be installed') + config = { + 'use_upstream_bridges': status['use_upstream_bridges'], + 'upstream_bridges': status['upstream_bridges'], + 'apt_transport_tor': is_apt_transport_tor_enabled() + } + kvstore.set(torproxy.PREINSTALL_CONFIG_KEY, json.dumps(config)) + # This creates the operation, which will run after the current + # operation (Tor setup) is completed. + setup_module.run_setup_on_app('torproxy') if not old_version: logger.info('Enabling Tor app') diff --git a/plinth/modules/torproxy/__init__.py b/plinth/modules/torproxy/__init__.py index e9a24d992..80e4a580a 100644 --- a/plinth/modules/torproxy/__init__.py +++ b/plinth/modules/torproxy/__init__.py @@ -1,13 +1,14 @@ # SPDX-License-Identifier: AGPL-3.0-or-later """FreedomBox app to configure Tor Proxy.""" +import json import logging from django.urls import reverse_lazy from django.utils.translation import gettext_lazy as _ from plinth import app as app_module -from plinth import cfg, frontpage, menu +from plinth import cfg, frontpage, kvstore, menu from plinth.daemon import Daemon from plinth.modules.apache.components import diagnose_url from plinth.modules.backups.components import BackupRestore @@ -20,6 +21,8 @@ from . import manifest, privileged logger = logging.getLogger(__name__) +PREINSTALL_CONFIG_KEY = 'torproxy_preinstall_config' + _description = [ _('Tor is an anonymous communication system. You can learn more ' 'about it from the Tor ' @@ -111,9 +114,17 @@ class TorProxyApp(app_module.App): privileged.setup(old_version) if not old_version: logger.info('Enabling apt-transport-tor') - privileged.configure(apt_transport_tor=True) + config = kvstore.get_default(PREINSTALL_CONFIG_KEY, '{}') + config = json.loads(config) + config = { + 'use_upstream_bridges': config.get('use_upstream_bridges'), + 'upstream_bridges': config.get('upstream_bridges'), + 'apt_transport_tor': config.get('apt_transport_tor', True), + } + privileged.configure(**config) logger.info('Enabling Tor Proxy app') self.enable() + kvstore.delete(PREINSTALL_CONFIG_KEY, ignore_missing=True) def uninstall(self): """De-configure and uninstall the app."""