# SPDX-License-Identifier: AGPL-3.0-or-later """Configure roundcube.""" import pathlib import re from plinth import action_utils from plinth.actions import privileged _config_file = pathlib.Path('/etc/roundcube/freedombox-config.php') _rc_db_file = pathlib.Path('/var/lib/dbconfig-common/sqlite3/' 'roundcube/roundcube') @privileged def pre_install(): """Preseed debconf values before packages are installed.""" action_utils.debconf_set_selections([ 'roundcube-core roundcube/dbconfig-install boolean true', 'roundcube-core roundcube/database-type string sqlite3' ]) @privileged def setup(): """Add FreedomBox configuration and include from main configuration.""" if not _config_file.exists(): _config_file.write_text(' dict[str, bool]: """Return the current configuration as a dictionary.""" pattern = r'\s*\$config\[\s*\'([^\']*)\'\s*\]\s*=\s*\'([^\']*)\'\s*;' _config = {} try: for line in _config_file.read_text(encoding='utf-8').splitlines(): match = re.match(pattern, line) if match: _config[match.group(1)] = match.group(2) except FileNotFoundError: pass local_only = _config.get('default_host') == 'localhost' return {'local_only': local_only} @privileged def set_config(local_only: bool): """Set the configuration.""" config = '''