mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
roundcube: Add setting for local connection only
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>
This commit is contained in:
1 parent
9a2d66c62f
commit
affffddf36
5 files changed
+130
-5
No files matched your search
@@ -5,9 +5,14 @@ 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."""
|
||||
@@ -16,6 +21,11 @@ def parse_arguments():
|
||||
|
||||
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()
|
||||
@@ -29,6 +39,51 @@ def subcommand_pre_install(_):
|
||||
])
|
||||
|
||||
|
||||
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()
|
||||
|
||||
Reference in new issue
Block a user