mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-11 09:04:54 +00:00
config: Move default-app configuration to a dedicated file
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
70cb3d46b4
commit
5ad22114ed
@ -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():
|
||||
|
||||
@ -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():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user