mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
config: Rename Default App to Webserver Home Page
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
a87b0ff596
commit
8bc34f84c3
8 files changed
+60
-54
No files matched your search
@@ -39,9 +39,9 @@ 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)
|
||||
APACHE_HOMEPAGE_CONF_FILE_NAME = 'freedombox-apache-homepage.conf'
|
||||
APACHE_HOMEPAGE_CONFIG = os.path.join(APACHE_CONF_ENABLED_DIR,
|
||||
APACHE_HOMEPAGE_CONF_FILE_NAME)
|
||||
FREEDOMBOX_APACHE_CONFIG = os.path.join(APACHE_CONF_ENABLED_DIR,
|
||||
'freedombox.conf')
|
||||
|
||||
@@ -57,13 +57,13 @@ def get_hostname():
|
||||
return socket.gethostname()
|
||||
|
||||
|
||||
def get_default_app():
|
||||
def get_home_page():
|
||||
"""Get the default application for the domain."""
|
||||
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
|
||||
augeas.Augeas.NO_MODL_AUTOLOAD)
|
||||
aug.set('/augeas/load/Httpd/lens', 'Httpd.lns')
|
||||
conf_file = DEFAULT_APP_APACHE_CONFIG if os.path.exists(
|
||||
DEFAULT_APP_APACHE_CONFIG) else FREEDOMBOX_APACHE_CONFIG
|
||||
conf_file = APACHE_HOMEPAGE_CONFIG if os.path.exists(
|
||||
APACHE_HOMEPAGE_CONFIG) else FREEDOMBOX_APACHE_CONFIG
|
||||
aug.set('/augeas/load/Httpd/incl[last() + 1]', conf_file)
|
||||
aug.load()
|
||||
|
||||
@@ -106,18 +106,18 @@ def init():
|
||||
|
||||
def setup(helper, old_version=None):
|
||||
"""Install and configure the module."""
|
||||
_migrate_default_app_config()
|
||||
_migrate_home_page_config()
|
||||
|
||||
|
||||
def _migrate_default_app_config():
|
||||
def _migrate_home_page_config():
|
||||
"""Move the default app configuration to an external file."""
|
||||
|
||||
# Hold the current default app in a variable
|
||||
default_app_path = get_default_app().replace('_', '/')
|
||||
home_page_path = get_home_page().replace('_', '/')
|
||||
|
||||
# Reset the default app to plinth in freedombox.conf
|
||||
actions.superuser_run('config', ['reset-default-app'])
|
||||
actions.superuser_run('config', ['reset-home-page'])
|
||||
|
||||
# Write the default app setting into the new conf file
|
||||
# This step is run at the end because it reloads the Apache server
|
||||
actions.superuser_run('config', ['set-default-app', default_app_path])
|
||||
actions.superuser_run('config', ['set-home-page', home_page_path])
|
||||
@@ -42,11 +42,13 @@ def domain_label_validator(domainname):
|
||||
raise ValidationError(_('Invalid domain name'))
|
||||
|
||||
|
||||
def get_default_app_choices():
|
||||
def get_homepage_choices():
|
||||
shortcuts = frontpage.get_shortcuts(web_apps_only=True, sort_by='name')
|
||||
apps = [(shortcut['id'], shortcut['name']) for shortcut in shortcuts
|
||||
if shortcut['id']]
|
||||
return [('plinth', 'FreedomBox Service (Plinth)')] + apps
|
||||
apache_default = ('apache-default', _('Apache Default'))
|
||||
plinth = ('plinth', _('FreedomBox Service (Plinth)'))
|
||||
return [apache_default, plinth] + apps
|
||||
|
||||
|
||||
class ConfigurationForm(forms.Form):
|
||||
@@ -85,15 +87,15 @@ class ConfigurationForm(forms.Form):
|
||||
ugettext_lazy('Invalid domain name')), domain_label_validator
|
||||
], strip=True)
|
||||
|
||||
defaultapp = forms.ChoiceField(
|
||||
label=ugettext_lazy('Default App'), help_text=format_lazy(
|
||||
homepage = forms.ChoiceField(
|
||||
label=ugettext_lazy('Webserver Home Page'), help_text=format_lazy(
|
||||
ugettext_lazy(
|
||||
'Choose the default web application that must be served when '
|
||||
'Choose the default page that must be served when '
|
||||
'someone visits your {box_name} on the web. A typical use '
|
||||
'case is to set your blog or wiki as the landing page when '
|
||||
'someone visits the domain name. Note that once the default '
|
||||
'app is set to something other than {box_name} Service '
|
||||
'case is to set your blog or wiki as the home page when '
|
||||
'someone visits the domain name. Note that once the home '
|
||||
'page is set to something other than {box_name} Service '
|
||||
'(Plinth), your users must explicitly type /plinth or '
|
||||
'/freedombox to reach {box_name} Service (Plinth).'),
|
||||
box_name=ugettext_lazy(cfg.box_name)), required=False,
|
||||
choices=get_default_app_choices)
|
||||
choices=get_homepage_choices)
|
||||
@@ -63,7 +63,7 @@ def get_status():
|
||||
return {
|
||||
'hostname': config.get_hostname(),
|
||||
'domainname': config.get_domainname(),
|
||||
'defaultapp': config.get_default_app(),
|
||||
'homepage': config.get_home_page(),
|
||||
}
|
||||
|
||||
|
||||
@@ -91,16 +91,16 @@ def _apply_changes(request, old_status, new_status):
|
||||
else:
|
||||
messages.success(request, _('Domain name set'))
|
||||
|
||||
if old_status['defaultapp'] != new_status['defaultapp']:
|
||||
if old_status['homepage'] != new_status['homepage']:
|
||||
try:
|
||||
change_default_app(new_status['defaultapp'])
|
||||
change_home_page(new_status['homepage'])
|
||||
except Exception as exception:
|
||||
messages.error(
|
||||
request,
|
||||
_('Error setting default app: {exception}')
|
||||
_('Error setting webserver home page: {exception}')
|
||||
.format(exception=exception))
|
||||
else:
|
||||
messages.success(request, _('Default app set'))
|
||||
messages.success(request, _('Webserver home page set'))
|
||||
|
||||
|
||||
def change_default_app(app_id):
|
||||
@@ -114,7 +114,7 @@ def change_default_app(app_id):
|
||||
if shortcut['id'] == app_id
|
||||
][0]
|
||||
|
||||
actions.superuser_run('config', ['set-default-app', url.strip("/")])
|
||||
actions.superuser_run('config', ['set-home-page', url])
|
||||
|
||||
|
||||
def set_hostname(hostname):
|
||||
|
||||
Reference in new issue
Block a user