mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
When this option is enabled, it would make the interface easy to work with. This is likely what most users would want. Don't break things for users who have already installed roundcube and ensure that local only is disable for them. Tests: - Install roundcube without the patch. Disable the app. Apply patch. Restart service. Notice that roundcube is not re-enabled. - Install roundcube without the patch. Apply patch. Restart service. Notice that roundcube configuration /etc/roundcube/config.inc.php file has been updated and include_once() at the end has been added. The file /etc/roundcube/freedombox-config.php has been added. Local only option is disabled. - Install roundcube freshly with the patch. Local only option is enabled. Open interface. Notice that server option is not presented. - Disable local only option and notice that server field is shown in the interface. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> [jvalleroy: Fix comment] Signed-off-by: James Valleroy <jvalleroy@mailbox.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
98 lines
2.9 KiB
Python
Executable File
98 lines
2.9 KiB
Python
Executable File
#!/usr/bin/python3
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""
|
|
Configuration helper for Roundcube server.
|
|
"""
|
|
|
|
import argparse
|
|
import json
|
|
import pathlib
|
|
import re
|
|
|
|
from plinth import action_utils
|
|
|
|
_config_file = pathlib.Path('/etc/roundcube/freedombox-config.php')
|
|
|
|
|
|
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='Perform Roundcube pre-install configuration')
|
|
subparsers.add_parser('setup', help='Setup basic configuration')
|
|
subparsers.add_parser('get-config', help='Print current configuration')
|
|
subparser = subparsers.add_parser('set-config', help='Set configuration')
|
|
subparser.add_argument('--local-only', choices=['True', 'False'],
|
|
help='Set current configuration')
|
|
|
|
subparsers.required = True
|
|
return parser.parse_args()
|
|
|
|
|
|
def subcommand_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'
|
|
])
|
|
|
|
|
|
def subcommand_setup(_):
|
|
"""Add FreedomBox configuration and include from main configuration."""
|
|
if not _config_file.exists():
|
|
_config_file.write_text('<?php\n')
|
|
|
|
base_config = pathlib.Path('/etc/roundcube/config.inc.php')
|
|
lines = base_config.read_text().splitlines()
|
|
exists = any((str(_config_file) in line for line in lines))
|
|
if not exists:
|
|
lines.append(f'include_once("{_config_file}");\n')
|
|
base_config.write_text('\n'.join(lines))
|
|
|
|
|
|
def subcommand_get_config(_):
|
|
"""Print the current configuration as JSON."""
|
|
pattern = r'\s*\$config\[\s*\'([^\']*)\'\s*\]\s*=\s*\'([^\']*)\'\s*;'
|
|
_config = {}
|
|
try:
|
|
for line in _config_file.read_text().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'
|
|
print(json.dumps({'local_only': local_only}))
|
|
|
|
|
|
def subcommand_set_config(arguments):
|
|
"""Set the configuration."""
|
|
config = '<?php\n'
|
|
if arguments.local_only == 'True':
|
|
config = '''<?php
|
|
$config['default_host'] = 'localhost';
|
|
$config['mail_domain'] = '%n';
|
|
|
|
$config['smtp_server'] = 'localhost';
|
|
$config['smtp_port'] = 25;
|
|
$config['smtp_helo_host'] = 'localhost';
|
|
'''
|
|
|
|
_config_file.write_text(config)
|
|
|
|
|
|
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()
|