diff --git a/plinth/module_loader.py b/plinth/module_loader.py index 8d019eec2..dd4edaff4 100644 --- a/plinth/module_loader.py +++ b/plinth/module_loader.py @@ -5,13 +5,14 @@ Discover, load and manage FreedomBox applications. import collections import importlib +import inspect import logging import pathlib import re import django -from plinth import cfg, setup +from plinth import app, cfg, setup from plinth.signals import post_module_loading, pre_module_loading logger = logging.getLogger(__name__) @@ -109,18 +110,24 @@ def _include_module_urls(module_import_path, module_name): def _initialize_module(module_name, module): - """Call initialization method in the module if it exists""" + """Perform module initialization""" + # Perform setup related initialization on the module setup.init(module_name, module) try: - init = module.init - except AttributeError: - logger.debug('No init() for module - %s', module.__name__) - return + module_classes = inspect.getmembers(module, inspect.isclass) + app_class = [ + cls for cls in module_classes if issubclass(cls[1], app.App) + ] + if module_classes and app_class: + module.app = app_class[0][1]() - try: - init() + if module.setup_helper.get_state( + ) != 'needs-setup' and module.app.is_enabled(): + module.app.set_enabled(True) + + logger.debug("Initialized %s", module.__name__) except Exception as exception: logger.exception('Exception while running init for %s: %s', module, exception) diff --git a/plinth/modules/apache/__init__.py b/plinth/modules/apache/__init__.py index c598a6930..2826ed558 100644 --- a/plinth/modules/apache/__init__.py +++ b/plinth/modules/apache/__init__.py @@ -56,13 +56,6 @@ class ApacheApp(app_module.App): self.add(daemon) -def init(): - """Initailze firewall module""" - global app - app = ApacheApp() - app.set_enabled(True) - - def setup(helper, old_version=None): """Configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/avahi/__init__.py b/plinth/modules/avahi/__init__.py index 7c44b2e75..ab16e2f95 100644 --- a/plinth/modules/avahi/__init__.py +++ b/plinth/modules/avahi/__init__.py @@ -76,19 +76,13 @@ class AvahiApp(app_module.App): daemon = Daemon('daemon-avahi', managed_services[0]) self.add(daemon) + if self.is_enabled(): + domain_added.send_robust(sender='avahi', + domain_type='domain-type-local', + name=get_hostname() + '.local', + services='__all__') -def init(): - """Initialize the service discovery module.""" - global app - app = AvahiApp() - if app.is_enabled(): - domain_added.send_robust(sender='avahi', - domain_type='domain-type-local', - name=get_hostname() + '.local', - services='__all__') - app.set_enabled(True) - - post_hostname_change.connect(on_post_hostname_change) + post_hostname_change.connect(on_post_hostname_change) def setup(helper, old_version=None): diff --git a/plinth/modules/backups/__init__.py b/plinth/modules/backups/__init__.py index eb4615cbe..ed7991451 100644 --- a/plinth/modules/backups/__init__.py +++ b/plinth/modules/backups/__init__.py @@ -56,16 +56,6 @@ class BackupsApp(app_module.App): self.add(menu_item) -def init(): - """Initialize the module.""" - global app - app = BackupsApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/bind/__init__.py b/plinth/modules/bind/__init__.py index 80f0dc70e..963222fc9 100644 --- a/plinth/modules/bind/__init__.py +++ b/plinth/modules/bind/__init__.py @@ -102,16 +102,6 @@ class BindApp(app_module.App): self.add(daemon) -def init(): - """Initialize the BIND module.""" - global app - app = BindApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/cockpit/__init__.py b/plinth/modules/cockpit/__init__.py index 2d001fe4a..c1cf08767 100644 --- a/plinth/modules/cockpit/__init__.py +++ b/plinth/modules/cockpit/__init__.py @@ -91,18 +91,8 @@ class CockpitApp(app_module.App): daemon = Daemon('daemon-cockpit', managed_services[0]) self.add(daemon) - -def init(): - """Initialize the module.""" - global app - app = CockpitApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - domain_added.connect(on_domain_added) - domain_removed.connect(on_domain_removed) + domain_added.connect(on_domain_added) + domain_removed.connect(on_domain_removed) def setup(helper, old_version=None): diff --git a/plinth/modules/config/__init__.py b/plinth/modules/config/__init__.py index 0ad1bbf06..a0c60f932 100644 --- a/plinth/modules/config/__init__.py +++ b/plinth/modules/config/__init__.py @@ -62,6 +62,13 @@ class ConfigApp(app_module.App): 'config:index', can_have_certificate=True) self.add(domain_type) + # Register domain with Name Services module. + domainname = get_domainname() + if domainname: + domain_added.send_robust(sender='config', + domain_type='domain-type-static', + name=domainname, services='__all__') + def get_domainname(): """Return the domainname""" @@ -142,20 +149,6 @@ def set_advanced_mode(advanced_mode): kvstore.set(ADVANCED_MODE_KEY, advanced_mode) -def init(): - """Initialize the module""" - global app - app = ConfigApp() - app.set_enabled(True) - - # Register domain with Name Services module. - domainname = get_domainname() - if domainname: - domain_added.send_robust(sender='config', - domain_type='domain-type-static', - name=domainname, services='__all__') - - def setup(helper, old_version=None): """Install and configure the module.""" _migrate_home_page_config() diff --git a/plinth/modules/coquelicot/__init__.py b/plinth/modules/coquelicot/__init__.py index 1501cde6a..291e0bf95 100644 --- a/plinth/modules/coquelicot/__init__.py +++ b/plinth/modules/coquelicot/__init__.py @@ -73,16 +73,6 @@ class CoquelicotApp(app_module.App): self.add(daemon) -def init(): - """Initialize the module.""" - global app - app = CoquelicotApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/coturn/__init__.py b/plinth/modules/coturn/__init__.py index 2f80bea4a..ba3ae9338 100644 --- a/plinth/modules/coturn/__init__.py +++ b/plinth/modules/coturn/__init__.py @@ -99,16 +99,6 @@ class CoturnApp(app_module.App): self.add(users_and_groups) -def init(): - """Initialize the Coturn module.""" - global app - app = CoturnApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/datetime/__init__.py b/plinth/modules/datetime/__init__.py index 218ad486e..a45e410a2 100644 --- a/plinth/modules/datetime/__init__.py +++ b/plinth/modules/datetime/__init__.py @@ -92,15 +92,6 @@ class DateTimeApp(app_module.App): return self._is_time_managed() -def init(): - """Initialize the date/time module.""" - global app - app = DateTimeApp() - - if app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.call('post', app.enable) diff --git a/plinth/modules/deluge/__init__.py b/plinth/modules/deluge/__init__.py index b70bc8fb7..bb6137161 100644 --- a/plinth/modules/deluge/__init__.py +++ b/plinth/modules/deluge/__init__.py @@ -88,16 +88,6 @@ class DelugeApp(app_module.App): self.add(users_and_groups) -def init(): - """Initialize the Deluge module.""" - global app - app = DelugeApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/diagnostics/__init__.py b/plinth/modules/diagnostics/__init__.py index 3afb3303b..80e4aec18 100644 --- a/plinth/modules/diagnostics/__init__.py +++ b/plinth/modules/diagnostics/__init__.py @@ -65,13 +65,6 @@ class DiagnosticsApp(app_module.App): return results -def init(): - """Initialize the module""" - global app - app = DiagnosticsApp() - app.set_enabled(True) - - def start_task(): """Start the run task in a separate thread.""" global running_task diff --git a/plinth/modules/diaspora/__init__.py b/plinth/modules/diaspora/__init__.py index 660e89f29..2be66b871 100644 --- a/plinth/modules/diaspora/__init__.py +++ b/plinth/modules/diaspora/__init__.py @@ -112,22 +112,13 @@ class DiasporaApp(app_module.App): class Shortcut(frontpage.Shortcut): """Frontpage shortcut to use configured domain name for URL.""" + def enable(self): """Set the proper shortcut URL when enabled.""" super().enable() self.url = 'https://diaspora.{}'.format(get_configured_domain_name()) -def init(): - """Initialize the Diaspora module.""" - global app - app = DiasporaApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.call('pre', actions.superuser_run, 'diaspora', ['pre-install']) diff --git a/plinth/modules/dynamicdns/__init__.py b/plinth/modules/dynamicdns/__init__.py index 77a0d5823..bcf20774f 100644 --- a/plinth/modules/dynamicdns/__init__.py +++ b/plinth/modules/dynamicdns/__init__.py @@ -70,18 +70,21 @@ class DynamicDNSApp(app_module.App): reserved_usernames=['ez-ipupd']) self.add(users_and_groups) + current_status = get_status() + if current_status['enabled']: + domain_added.send_robust(sender='dynamicdns', + domain_type='domain-type-dynamic', + name=current_status['dynamicdns_domain'], + services='__all__') + self.set_enabled(True) -def init(): - """Initialize the module.""" - global app - app = DynamicDNSApp() - current_status = get_status() - if current_status['enabled']: - domain_added.send_robust(sender='dynamicdns', - domain_type='domain-type-dynamic', - name=current_status['dynamicdns_domain'], - services='__all__') - app.set_enabled(True) + def is_enabled(self): + """Return whether all the leader components are enabled. + + Return True when there are no leader components and DynamicDNS setup + is done. + """ + return super().is_enabled() and get_status()['enabled'] def setup(helper, old_version=None): diff --git a/plinth/modules/ejabberd/__init__.py b/plinth/modules/ejabberd/__init__.py index 76e44f533..a85bda1c8 100644 --- a/plinth/modules/ejabberd/__init__.py +++ b/plinth/modules/ejabberd/__init__.py @@ -113,19 +113,9 @@ class EjabberdApp(app_module.App): reserved_usernames=['ejabberd']) self.add(users_and_groups) - -def init(): - """Initialize the ejabberd module""" - global app - app = EjabberdApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - pre_hostname_change.connect(on_pre_hostname_change) - post_hostname_change.connect(on_post_hostname_change) - domain_added.connect(on_domain_added) + pre_hostname_change.connect(on_pre_hostname_change) + post_hostname_change.connect(on_post_hostname_change) + domain_added.connect(on_domain_added) def setup(helper, old_version=None): diff --git a/plinth/modules/firewall/__init__.py b/plinth/modules/firewall/__init__.py index 5ab04d8d7..178ed409c 100644 --- a/plinth/modules/firewall/__init__.py +++ b/plinth/modules/firewall/__init__.py @@ -75,13 +75,6 @@ class FirewallApp(app_module.App): self.add(daemon) -def init(): - """Initailze firewall module""" - global app - app = FirewallApp() - app.set_enabled(True) - - def _run_setup(): """Run firewalld setup.""" _run(['setup'], superuser=True) diff --git a/plinth/modules/first_boot/__init__.py b/plinth/modules/first_boot/__init__.py index fc6476b14..e90729193 100644 --- a/plinth/modules/first_boot/__init__.py +++ b/plinth/modules/first_boot/__init__.py @@ -8,7 +8,7 @@ import os from django.urls import reverse -from plinth import cfg, module_loader +from plinth import app, cfg, module_loader from plinth.signals import post_setup version = 1 @@ -34,9 +34,15 @@ _all_first_boot_steps = None _is_completed = None -def init(): - """Initialize the first boot module.""" - post_setup.connect(_clear_first_boot_steps) +class FirstBootApp(app.App): + """FreedomBox app for First Boot.""" + + app_id = 'first_boot' + + def __init__(self): + """Create components for the app.""" + super().__init__() + post_setup.connect(_clear_first_boot_steps) def _clear_first_boot_steps(sender, module_name, **kwargs): diff --git a/plinth/modules/gitweb/__init__.py b/plinth/modules/gitweb/__init__.py index 983a617b7..1395b4bac 100644 --- a/plinth/modules/gitweb/__init__.py +++ b/plinth/modules/gitweb/__init__.py @@ -18,7 +18,7 @@ from plinth.modules.users.components import UsersAndGroups from .forms import is_repo_url from .manifest import (GIT_REPO_PATH, # noqa, pylint: disable=unused-import - backup, clients) + backup, clients) version = 1 @@ -88,6 +88,10 @@ class GitwebApp(app_module.App): groups=groups) self.add(users_and_groups) + setup_helper = globals()['setup_helper'] + if setup_helper.get_state() != 'needs-setup': + self.update_service_access() + def set_shortcut_login_required(self, login_required): """Change the login_required property of shortcut.""" shortcut = self.remove('shortcut-gitweb') @@ -164,18 +168,6 @@ class GitwebWebserverAuth(Webserver): super().enable() -def init(): - """Initialize the module.""" - global app - app = GitwebApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup': - app.update_service_access() - if app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/help/__init__.py b/plinth/modules/help/__init__.py index b062bdeb1..4addcb579 100644 --- a/plinth/modules/help/__init__.py +++ b/plinth/modules/help/__init__.py @@ -63,10 +63,3 @@ class HelpApp(app_module.App): static_files = web_server.StaticFiles('static-files-help', directory_map) self.add(static_files) - - -def init(): - """Initialize the Help module""" - global app - app = HelpApp() - app.set_enabled(True) diff --git a/plinth/modules/i2p/__init__.py b/plinth/modules/i2p/__init__.py index cbdf49d14..f46b1ee2b 100644 --- a/plinth/modules/i2p/__init__.py +++ b/plinth/modules/i2p/__init__.py @@ -103,16 +103,6 @@ class I2PApp(app_module.App): self.add(users_and_groups) -def init(): - """Initialize the module.""" - global app - app = I2PApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/ikiwiki/__init__.py b/plinth/modules/ikiwiki/__init__.py index 4e8e738c3..1d5cfacf8 100644 --- a/plinth/modules/ikiwiki/__init__.py +++ b/plinth/modules/ikiwiki/__init__.py @@ -101,16 +101,6 @@ class IkiwikiApp(app_module.App): return sites -def init(): - """Initialize the ikiwiki module.""" - global app - app = IkiwikiApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/infinoted/__init__.py b/plinth/modules/infinoted/__init__.py index 64c42cf5d..2624942b6 100644 --- a/plinth/modules/infinoted/__init__.py +++ b/plinth/modules/infinoted/__init__.py @@ -72,16 +72,6 @@ class InfinotedApp(app_module.App): self.add(daemon) -def init(): - """Initialize the infinoted module.""" - global app - app = InfinotedApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/jsxc/__init__.py b/plinth/modules/jsxc/__init__.py index a8f15102c..7ef583f7f 100644 --- a/plinth/modules/jsxc/__init__.py +++ b/plinth/modules/jsxc/__init__.py @@ -72,16 +72,6 @@ class JSXCApp(app_module.App): self.add(static_files) -def init(): - """Initialize the JSXC module""" - global app - app = JSXCApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/letsencrypt/__init__.py b/plinth/modules/letsencrypt/__init__.py index 981e42430..d0ae503b8 100644 --- a/plinth/modules/letsencrypt/__init__.py +++ b/plinth/modules/letsencrypt/__init__.py @@ -73,6 +73,11 @@ class LetsEncryptApp(app_module.App): 'letsencrypt:index', parent_url_name='system') self.add(menu_item) + domain_added.connect(on_domain_added) + domain_removed.connect(on_domain_removed) + + post_module_loading.connect(_certificate_handle_modified) + def diagnose(self): """Run diagnostics and return the results.""" results = super().diagnose() @@ -84,18 +89,6 @@ class LetsEncryptApp(app_module.App): return results -def init(): - """Initialize the module.""" - global app - app = LetsEncryptApp() - app.set_enabled(True) - - domain_added.connect(on_domain_added) - domain_removed.connect(on_domain_removed) - - post_module_loading.connect(_certificate_handle_modified) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/matrixsynapse/__init__.py b/plinth/modules/matrixsynapse/__init__.py index fcc388e89..ac2d6c268 100644 --- a/plinth/modules/matrixsynapse/__init__.py +++ b/plinth/modules/matrixsynapse/__init__.py @@ -106,16 +106,6 @@ class MatrixSynapseApp(app_module.App): self.add(daemon) -def init(): - """Initialize the matrix-synapse module.""" - global app - app = MatrixSynapseApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/mediawiki/__init__.py b/plinth/modules/mediawiki/__init__.py index e8a057f9e..a588f9834 100644 --- a/plinth/modules/mediawiki/__init__.py +++ b/plinth/modules/mediawiki/__init__.py @@ -86,22 +86,13 @@ class MediaWikiApp(app_module.App): class Shortcut(frontpage.Shortcut): """Frontpage shortcut for only logged users when in private mode.""" + def enable(self): """When enabled, check if MediaWiki is in private mode.""" super().enable() self.login_required = is_private_mode_enabled() -def init(): - """Initialize the module.""" - global app - app = MediaWikiApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) @@ -125,6 +116,7 @@ def is_private_mode_enabled(): def get_default_skin(): """Return the value of the default skin""" + def _find_skin(config_file): with open(config_file, 'r') as config: for line in config: diff --git a/plinth/modules/minetest/__init__.py b/plinth/modules/minetest/__init__.py index c8d7d373a..9b8dfb435 100644 --- a/plinth/modules/minetest/__init__.py +++ b/plinth/modules/minetest/__init__.py @@ -92,16 +92,6 @@ class MinetestApp(app_module.App): self.add(users_and_groups) -def init(): - """Initialize the module.""" - global app - app = MinetestApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/minidlna/__init__.py b/plinth/modules/minidlna/__init__.py index 755bd28cf..2bc18cebd 100644 --- a/plinth/modules/minidlna/__init__.py +++ b/plinth/modules/minidlna/__init__.py @@ -81,16 +81,6 @@ class MiniDLNAApp(app_module.App): self.add(users_and_groups) -def init(): - """Initialize the module.""" - global app - app = MiniDLNAApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the package""" helper.install(managed_packages) diff --git a/plinth/modules/mldonkey/__init__.py b/plinth/modules/mldonkey/__init__.py index 06221335e..d282a03c0 100644 --- a/plinth/modules/mldonkey/__init__.py +++ b/plinth/modules/mldonkey/__init__.py @@ -89,16 +89,6 @@ class MLDonkeyApp(app_module.App): self.add(users_and_groups) -def init(): - """Initialize the MLDonkey module.""" - global app - app = MLDonkeyApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.call('pre', actions.superuser_run, 'mldonkey', ['pre-install']) diff --git a/plinth/modules/monkeysphere/__init__.py b/plinth/modules/monkeysphere/__init__.py index 5a16a383e..b125a56b6 100644 --- a/plinth/modules/monkeysphere/__init__.py +++ b/plinth/modules/monkeysphere/__init__.py @@ -61,13 +61,6 @@ class MonkeysphereApp(app_module.App): self.add(users_and_groups) -def init(): - """Initialize the monkeysphere module.""" - global app - app = MonkeysphereApp() - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/mumble/__init__.py b/plinth/modules/mumble/__init__.py index 94c4896b7..31f347ffd 100644 --- a/plinth/modules/mumble/__init__.py +++ b/plinth/modules/mumble/__init__.py @@ -77,16 +77,6 @@ class MumbleApp(app_module.App): self.add(users_and_groups) -def init(): - """Initialize the Mumble module.""" - global app - app = MumbleApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/names/__init__.py b/plinth/modules/names/__init__.py index 9f5297cf8..b06316fbc 100644 --- a/plinth/modules/names/__init__.py +++ b/plinth/modules/names/__init__.py @@ -52,15 +52,8 @@ class NamesApp(app_module.App): 'names:index', parent_url_name='system') self.add(menu_item) - -def init(): - """Initialize the names module.""" - global app - app = NamesApp() - app.set_enabled(True) - - domain_added.connect(on_domain_added) - domain_removed.connect(on_domain_removed) + domain_added.connect(on_domain_added) + domain_removed.connect(on_domain_removed) def on_domain_added(sender, domain_type, name='', description='', diff --git a/plinth/modules/networks/__init__.py b/plinth/modules/networks/__init__.py index 36409eea4..8504dfcf3 100644 --- a/plinth/modules/networks/__init__.py +++ b/plinth/modules/networks/__init__.py @@ -87,13 +87,6 @@ class NetworksApp(app_module.App): return results -def init(): - """Initialize the Networks module.""" - global app - app = NetworksApp() - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/openvpn/__init__.py b/plinth/modules/openvpn/__init__.py index 29d612c94..978239d91 100644 --- a/plinth/modules/openvpn/__init__.py +++ b/plinth/modules/openvpn/__init__.py @@ -83,16 +83,13 @@ class OpenVPNApp(app_module.App): listen_ports=[(1194, 'udp4'), (1194, 'udp6')]) self.add(daemon) + def is_enabled(self): + """Return whether all the leader components are enabled. -def init(): - """Initialize the OpenVPN module.""" - global app - app = OpenVPNApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled() \ - and is_setup(): - app.set_enabled(True) + Return True when there are no leader components and OpenVPN setup + is done. + """ + return super().is_enabled() and is_setup() def setup(helper, old_version=None): diff --git a/plinth/modules/pagekite/__init__.py b/plinth/modules/pagekite/__init__.py index 429b0469d..eff0ab899 100644 --- a/plinth/modules/pagekite/__init__.py +++ b/plinth/modules/pagekite/__init__.py @@ -80,6 +80,9 @@ class PagekiteApp(app_module.App): daemon = Daemon('daemon-pagekite', managed_services[0]) self.add(daemon) + # Register kite name with Name Services module. + utils.update_names_module(is_enabled=self.is_enabled()) + def enable(self): """Send domain signals after enabling the app.""" super().enable() @@ -91,19 +94,6 @@ class PagekiteApp(app_module.App): super().disable() -def init(): - """Initialize the PageKite module""" - global app - app = PagekiteApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - # Register kite name with Name Services module. - utils.update_names_module(is_enabled=True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/performance/__init__.py b/plinth/modules/performance/__init__.py index 260171084..61c813e8c 100644 --- a/plinth/modules/performance/__init__.py +++ b/plinth/modules/performance/__init__.py @@ -70,16 +70,6 @@ class PerformanceApp(app_module.App): self.add(daemon_3) -def init(): - """Initialize the Performance module.""" - global app - app = PerformanceApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/power/__init__.py b/plinth/modules/power/__init__.py index ba2e4052e..936e86fac 100644 --- a/plinth/modules/power/__init__.py +++ b/plinth/modules/power/__init__.py @@ -33,10 +33,3 @@ class PowerApp(app_module.App): self.add(info) # not in menu, see issue #834 - - -def init(): - """Initialize the power module.""" - global app - app = PowerApp() - app.set_enabled(True) diff --git a/plinth/modules/privoxy/__init__.py b/plinth/modules/privoxy/__init__.py index 2848ad32b..047f5f3f3 100644 --- a/plinth/modules/privoxy/__init__.py +++ b/plinth/modules/privoxy/__init__.py @@ -89,16 +89,6 @@ class PrivoxyApp(app_module.App): return results -def init(): - """Initialize the module.""" - global app - app = PrivoxyApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.call('pre', actions.superuser_run, 'privoxy', ['pre-install']) diff --git a/plinth/modules/quassel/__init__.py b/plinth/modules/quassel/__init__.py index 90f1f4cfc..b883fe925 100644 --- a/plinth/modules/quassel/__init__.py +++ b/plinth/modules/quassel/__init__.py @@ -99,16 +99,6 @@ class QuasselApp(app_module.App): self.add(users_and_groups) -def init(): - """Initialize the quassel module.""" - global app - app = QuasselApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/radicale/__init__.py b/plinth/modules/radicale/__init__.py index 37de29ab7..d94838a3a 100644 --- a/plinth/modules/radicale/__init__.py +++ b/plinth/modules/radicale/__init__.py @@ -174,16 +174,6 @@ class RadicaleDaemon(Daemon): return True -def init(): - """Initialize the radicale module.""" - global app - app = RadicaleApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" if old_version == 1: diff --git a/plinth/modules/roundcube/__init__.py b/plinth/modules/roundcube/__init__.py index 25a055d09..9452140b2 100644 --- a/plinth/modules/roundcube/__init__.py +++ b/plinth/modules/roundcube/__init__.py @@ -77,16 +77,6 @@ class RoundcubeApp(app_module.App): self.add(webserver) -def init(): - """Initialize the module.""" - global app - app = RoundcubeApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.call('pre', actions.superuser_run, 'roundcube', ['pre-install']) diff --git a/plinth/modules/samba/__init__.py b/plinth/modules/samba/__init__.py index 33f474e42..bc59a274e 100644 --- a/plinth/modules/samba/__init__.py +++ b/plinth/modules/samba/__init__.py @@ -98,16 +98,6 @@ class SambaApp(app_module.App): self.add(users_and_groups) -def init(): - """Initialize the module.""" - global app - app = SambaApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/searx/__init__.py b/plinth/modules/searx/__init__.py index 162865d45..a1beef45b 100644 --- a/plinth/modules/searx/__init__.py +++ b/plinth/modules/searx/__init__.py @@ -15,7 +15,7 @@ from plinth.modules.firewall.components import Firewall from plinth.modules.users.components import UsersAndGroups from .manifest import (PUBLIC_ACCESS_SETTING_FILE, # noqa, pylint: disable=unused-import - backup, clients) + backup, clients) version = 4 @@ -103,16 +103,6 @@ class SearxWebserverAuth(Webserver): super().enable() -def init(): - """Initialize the module.""" - global app - app = SearxApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/security/__init__.py b/plinth/modules/security/__init__.py index 1e5446f08..4d78bbd9b 100644 --- a/plinth/modules/security/__init__.py +++ b/plinth/modules/security/__init__.py @@ -51,13 +51,6 @@ class SecurityApp(app_module.App): self.add(menu_item) -def init(): - """Initialize the module""" - global app - app = SecurityApp() - app.set_enabled(True) - - def setup(helper, old_version=None): """Install the required packages""" helper.install(managed_packages) diff --git a/plinth/modules/shaarli/__init__.py b/plinth/modules/shaarli/__init__.py index bcdbb3698..3433f10d1 100644 --- a/plinth/modules/shaarli/__init__.py +++ b/plinth/modules/shaarli/__init__.py @@ -60,16 +60,6 @@ class ShaarliApp(app_module.App): self.add(webserver) -def init(): - """Initialize the module.""" - global app - app = ShaarliApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/shadowsocks/__init__.py b/plinth/modules/shadowsocks/__init__.py index 705c65447..66ffa53a4 100644 --- a/plinth/modules/shadowsocks/__init__.py +++ b/plinth/modules/shadowsocks/__init__.py @@ -77,16 +77,6 @@ class ShadowsocksApp(app_module.App): self.add(daemon) -def init(): - """Initialize the module.""" - global app - app = ShadowsocksApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/sharing/__init__.py b/plinth/modules/sharing/__init__.py index da9c86793..bf6644cfb 100644 --- a/plinth/modules/sharing/__init__.py +++ b/plinth/modules/sharing/__init__.py @@ -45,13 +45,6 @@ class SharingApp(app_module.App): self.add(menu_item) -def init(): - """Initialize the module.""" - global app - app = SharingApp() - app.set_enabled(True) - - def list_shares(): """Return a list of shares.""" output = actions.superuser_run('sharing', ['list']) diff --git a/plinth/modules/snapshot/__init__.py b/plinth/modules/snapshot/__init__.py index 13faf8d48..b126ab888 100644 --- a/plinth/modules/snapshot/__init__.py +++ b/plinth/modules/snapshot/__init__.py @@ -61,16 +61,6 @@ class SnapshotApp(app_module.App): self.add(menu_item) -def init(): - """Initialize the module.""" - global app - app = SnapshotApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def is_supported(): """Return whether snapshots are support on current setup.""" fs_type = storage.get_filesystem_type() diff --git a/plinth/modules/ssh/__init__.py b/plinth/modules/ssh/__init__.py index a100059bf..d66fb6f78 100644 --- a/plinth/modules/ssh/__init__.py +++ b/plinth/modules/ssh/__init__.py @@ -63,14 +63,6 @@ class SSHApp(app_module.App): self.add(daemon) -def init(): - """Initialize the ssh module.""" - global app - app = SSHApp() - if app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Configure the module.""" actions.superuser_run('ssh', ['setup']) diff --git a/plinth/modules/sso/__init__.py b/plinth/modules/sso/__init__.py index 2a6912adf..0d2197472 100644 --- a/plinth/modules/sso/__init__.py +++ b/plinth/modules/sso/__init__.py @@ -28,6 +28,7 @@ class SSOApp(app_module.App): def __init__(self): """Create components for the app.""" + super().__init__() info = app_module.Info(app_id=self.app_id, version=version, is_essential=is_essential, depends=depends, name=_('Single Sign On')) diff --git a/plinth/modules/storage/__init__.py b/plinth/modules/storage/__init__.py index facb5d0b9..471c55dcc 100644 --- a/plinth/modules/storage/__init__.py +++ b/plinth/modules/storage/__init__.py @@ -67,13 +67,6 @@ class StorageApp(app_module.App): glib.schedule(3, udisks2.init, repeat=False) -def init(): - """Initialize the module.""" - global app - app = StorageApp() - app.set_enabled(True) - - def get_disks(): """Returns list of disks and their free space. diff --git a/plinth/modules/syncthing/__init__.py b/plinth/modules/syncthing/__init__.py index a3190ce24..c8fdaf2b0 100644 --- a/plinth/modules/syncthing/__init__.py +++ b/plinth/modules/syncthing/__init__.py @@ -90,21 +90,11 @@ class SyncthingApp(app_module.App): daemon = Daemon('daemon-syncthing', managed_services[0]) self.add(daemon) - users_and_groups = UsersAndGroups( - 'users-and-groups-syncthing', [SYSTEM_USER], self.groups) + users_and_groups = UsersAndGroups('users-and-groups-syncthing', + [SYSTEM_USER], self.groups) self.add(users_and_groups) -def init(): - """Initialize the module.""" - global app - app = SyncthingApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/tahoe/__init__.py b/plinth/modules/tahoe/__init__.py index 2c5fedcab..e8cec9501 100644 --- a/plinth/modules/tahoe/__init__.py +++ b/plinth/modules/tahoe/__init__.py @@ -92,6 +92,14 @@ class TahoeApp(app_module.App): daemon = Daemon('daemon-tahoe', managed_services[0]) self.add(daemon) + def is_enabled(self): + """Return whether all the leader components are enabled. + + Return True when there are no leader components and + domain name is setup. + """ + return super().is_enabled() and is_setup() + def diagnose(self): """Run diagnostics and return the results.""" results = super().diagnose() @@ -108,6 +116,7 @@ class TahoeApp(app_module.App): class Shortcut(frontpage.Shortcut): """Frontpage shortcut to use configured domain name for URL.""" + def enable(self): """Set the proper shortcut URL when enabled.""" super().enable() @@ -130,17 +139,6 @@ def get_configured_domain_name(): return dnf.read().rstrip() -def init(): - """Initialize the module.""" - global app - app = TahoeApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and is_setup() \ - and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/tor/__init__.py b/plinth/modules/tor/__init__.py index f074526f1..7cd98bfc9 100644 --- a/plinth/modules/tor/__init__.py +++ b/plinth/modules/tor/__init__.py @@ -10,7 +10,8 @@ from django.utils.translation import ugettext_lazy as _ from plinth import action_utils, actions from plinth import app as app_module from plinth import menu -from plinth.daemon import Daemon, diagnose_netcat, diagnose_port_listening +from plinth.daemon import (Daemon, app_is_running, diagnose_netcat, + diagnose_port_listening) from plinth.modules.apache.components import diagnose_url from plinth.modules.firewall.components import Firewall from plinth.modules.names.components import DomainType @@ -85,6 +86,17 @@ class TorApp(app_module.App): reserved_usernames=['debian-tor']) self.add(users_and_groups) + # Register hidden service name with Name Services module. + if self.is_enabled() and app_is_running(self): + status = utils.get_status(initialized=False) + hostname = status['hs_hostname'] + services = [int(port['virtport']) for port in status['hs_ports']] + + if status['hs_enabled'] and status['hs_hostname']: + domain_added.send_robust(sender='tor', + domain_type='domain-type-tor', + name=hostname, services=services) + def diagnose(self): """Run diagnostics and return the results.""" results = super().diagnose() @@ -133,30 +145,6 @@ class TorApp(app_module.App): return results -def init(): - """Initialize the module.""" - global app - app = TorApp() - - setup_helper = globals()['setup_helper'] - needs_setup = setup_helper.get_state() == 'needs-setup' - - if not needs_setup: - if app.is_enabled(): - app.set_enabled(True) - - # Register hidden service name with Name Services module. - status = utils.get_status() - hostname = status['hs_hostname'] - services = [int(port['virtport']) for port in status['hs_ports']] - - if status['enabled'] and status['is_running'] and \ - status['hs_enabled'] and status['hs_hostname']: - domain_added.send_robust(sender='tor', - domain_type='domain-type-tor', - name=hostname, services=services) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/tor/utils.py b/plinth/modules/tor/utils.py index 27387a058..292d2925c 100644 --- a/plinth/modules/tor/utils.py +++ b/plinth/modules/tor/utils.py @@ -19,7 +19,7 @@ APT_SOURCES_URI_PATHS = ('/files/etc/apt/sources.list/*/uri', APT_TOR_PREFIX = 'tor+' -def get_status(): +def get_status(initialized=True): """Return current Tor status.""" output = actions.superuser_run('tor', ['get-status']) status = json.loads(output) @@ -43,8 +43,8 @@ def get_status(): } return { - 'enabled': tor.app.is_enabled(), - 'is_running': app_is_running(tor.app), + 'enabled': tor.app.is_enabled() if initialized else False, + 'is_running': app_is_running(tor.app) if initialized else False, 'use_upstream_bridges': status['use_upstream_bridges'], 'upstream_bridges': status['upstream_bridges'], 'relay_enabled': status['relay_enabled'], diff --git a/plinth/modules/transmission/__init__.py b/plinth/modules/transmission/__init__.py index 29bf1367c..055b52bd9 100644 --- a/plinth/modules/transmission/__init__.py +++ b/plinth/modules/transmission/__init__.py @@ -85,16 +85,6 @@ class TransmissionApp(app_module.App): self.add(users_and_groups) -def init(): - """Initialize the Transmission module.""" - global app - app = TransmissionApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/ttrss/__init__.py b/plinth/modules/ttrss/__init__.py index 18784bdaf..69f070de5 100644 --- a/plinth/modules/ttrss/__init__.py +++ b/plinth/modules/ttrss/__init__.py @@ -93,16 +93,6 @@ class TTRSSApp(app_module.App): actions.superuser_run('ttrss', ['enable-api-access']) -def init(): - """Initialize the module.""" - global app - app = TTRSSApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.call('pre', actions.superuser_run, 'ttrss', ['pre-setup']) diff --git a/plinth/modules/upgrades/__init__.py b/plinth/modules/upgrades/__init__.py index 0edf17e7b..259efb011 100644 --- a/plinth/modules/upgrades/__init__.py +++ b/plinth/modules/upgrades/__init__.py @@ -94,13 +94,6 @@ class UpgradesApp(app_module.App): note.dismiss(should_dismiss=dismiss) -def init(): - """Initialize the module.""" - global app - app = UpgradesApp() - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/users/__init__.py b/plinth/modules/users/__init__.py index 987b51dec..fdb1e8f03 100644 --- a/plinth/modules/users/__init__.py +++ b/plinth/modules/users/__init__.py @@ -91,13 +91,6 @@ class UsersApp(app_module.App): return results -def init(): - """Initialize the user module.""" - global app - app = UsersApp() - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages) diff --git a/plinth/modules/wireguard/__init__.py b/plinth/modules/wireguard/__init__.py index 5a0afa023..d4a0c00e7 100644 --- a/plinth/modules/wireguard/__init__.py +++ b/plinth/modules/wireguard/__init__.py @@ -92,16 +92,6 @@ class WireguardApp(app_module.App): return enabled and kvstore.get_default('wireguard-enabled', False) -def init(): - """Initialize the module.""" - global app - app = WireguardApp() - - setup_helper = globals()['setup_helper'] - if setup_helper.get_state() != 'needs-setup' and app.is_enabled(): - app.set_enabled(True) - - def setup(helper, old_version=None): """Install and configure the module.""" helper.install(managed_packages)