diff --git a/actions/config b/actions/config index 5be59881a..45d79e7c1 100755 --- a/actions/config +++ b/actions/config @@ -21,12 +21,10 @@ Configuration helper for FreedomBox general configuration. """ import argparse - -import augeas +import os from plinth import action_utils - -APACHE_CONFIGURATION = '/etc/apache2/conf-available/freedombox.conf' +from plinth.modules.config import DEFAULT_APP_CONF_FILE_NAME def parse_arguments(): @@ -44,24 +42,15 @@ def parse_arguments(): def subcommand_set_default_app(arguments): """Set the default app for this FreedomBox.""" - app = arguments.app + conf_file_path = os.path.join('/etc/apache2/conf-available', + DEFAULT_APP_CONF_FILE_NAME) - aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD + - augeas.Augeas.NO_MODL_AUTOLOAD) - aug.set('/augeas/load/Httpd/lens', 'Httpd.lns') - aug.set('/augeas/load/Httpd/incl[last() + 1]', APACHE_CONFIGURATION) - aug.load() + redirect_rule = 'RedirectMatch "^/$" "/{}"\n'.format(arguments.app) - aug.defvar('conf', '/files' + APACHE_CONFIGURATION) + with open(conf_file_path, 'w') as conf_file: + conf_file.write(redirect_rule) - for match in aug.match('/files' + APACHE_CONFIGURATION + - '/directive["RedirectMatch"]'): - if aug.get(match + "/arg[1]") == '''"^/$"''': - aug.set(match + "/arg[2]", '"/{}/"'.format(app)) - - aug.save() - - action_utils.service_reload('apache2') + action_utils.webserver_enable('default-app') def main(): diff --git a/plinth/modules/config/__init__.py b/plinth/modules/config/__init__.py index d525a337c..95dee6e9d 100644 --- a/plinth/modules/config/__init__.py +++ b/plinth/modules/config/__init__.py @@ -18,6 +18,7 @@ FreedomBox app for basic system configuration. """ +import os import socket import augeas @@ -37,6 +38,13 @@ depends = ['firewall', 'names'] manual_page = 'Configure' +APACHE_CONF_ENABLED_DIR = '/etc/apache2/conf-enabled' +DEFAULT_APP_CONF_FILE_NAME = 'default-app.conf' +DEFAULT_APP_APACHE_CONFIG = os.path.join(APACHE_CONF_ENABLED_DIR, + DEFAULT_APP_CONF_FILE_NAME) +FREEDOMBOX_APACHE_CONFIG = os.path.join(APACHE_CONF_ENABLED_DIR, + 'freedombox.conf') + def get_domainname(): """Return the domainname""" @@ -51,22 +59,22 @@ def get_hostname(): def get_default_app(): """Get the default application for the domain.""" - APACHE_CONFIGURATION = '/etc/apache2/conf-available/freedombox.conf' - aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD + augeas.Augeas.NO_MODL_AUTOLOAD) aug.set('/augeas/load/Httpd/lens', 'Httpd.lns') - aug.set('/augeas/load/Httpd/incl[last() + 1]', APACHE_CONFIGURATION) + conf_file = DEFAULT_APP_APACHE_CONFIG if os.path.exists( + DEFAULT_APP_APACHE_CONFIG) else FREEDOMBOX_APACHE_CONFIG + aug.set('/augeas/load/Httpd/incl[last() + 1]', conf_file) aug.load() - aug.defvar('conf', '/files' + APACHE_CONFIGURATION) + aug.defvar('conf', '/files' + conf_file) - for match in aug.match('/files' + APACHE_CONFIGURATION + + for match in aug.match('/files' + conf_file + '/directive["RedirectMatch"]'): if aug.get(match + "/arg[1]") == '''"^/$"''': app_path = aug.get(match + "/arg[2]") - return app_path.strip('"').strip('/') + return app_path.strip('/"') def init():