mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +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:
parent
a87b0ff596
commit
8bc34f84c3
@ -26,7 +26,7 @@ import os
|
||||
import augeas
|
||||
|
||||
from plinth import action_utils
|
||||
from plinth.modules.config import (DEFAULT_APP_CONF_FILE_NAME,
|
||||
from plinth.modules.config import (APACHE_HOMEPAGE_CONF_FILE_NAME,
|
||||
FREEDOMBOX_APACHE_CONFIG)
|
||||
|
||||
|
||||
@ -34,19 +34,20 @@ def parse_arguments():
|
||||
"""Return parsed command line arguments as dictionary."""
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
set_default_app = subparsers.add_parser(
|
||||
'set-default-app',
|
||||
help='Set the default app for this FreedomBox instance.')
|
||||
set_default_app.add_argument('app', help='name of the default app')
|
||||
set_home_page = subparsers.add_parser(
|
||||
'set-home-page',
|
||||
help='Set the home page for this FreedomBox instance.')
|
||||
set_home_page.add_argument('homepage',
|
||||
help='path to the webserver home page')
|
||||
subparsers.add_parser(
|
||||
'reset-default-app',
|
||||
'reset-home-page',
|
||||
help='Reset the default app configuraton in freedombox.conf')
|
||||
|
||||
subparsers.required = True
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def subcommand_reset_default_app(_):
|
||||
def subcommand_reset_home_page(_):
|
||||
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
|
||||
augeas.Augeas.NO_MODL_AUTOLOAD)
|
||||
aug.set('/augeas/load/Httpd/lens', 'Httpd.lns')
|
||||
@ -63,17 +64,17 @@ def subcommand_reset_default_app(_):
|
||||
aug.save()
|
||||
|
||||
|
||||
def subcommand_set_default_app(arguments):
|
||||
def subcommand_set_home_page(arguments):
|
||||
"""Set the default app for this FreedomBox."""
|
||||
conf_file_path = os.path.join('/etc/apache2/conf-available',
|
||||
DEFAULT_APP_CONF_FILE_NAME)
|
||||
APACHE_HOMEPAGE_CONF_FILE_NAME)
|
||||
|
||||
redirect_rule = 'RedirectMatch "^/$" "/{}"\n'.format(arguments.app)
|
||||
redirect_rule = 'RedirectMatch "^/$" "/{}"\n'.format(arguments.homepage)
|
||||
|
||||
with open(conf_file_path, 'w') as conf_file:
|
||||
conf_file.write(redirect_rule)
|
||||
|
||||
action_utils.webserver_enable('default-app')
|
||||
action_utils.webserver_enable('freedombox-apache-homepage')
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@ -8,6 +8,8 @@ Header set Strict-Transport-Security "max-age=31536000; includeSubDomains" env=H
|
||||
## into FreedomBox server. Plinth then acts as a portal to reach all
|
||||
## other services.
|
||||
##
|
||||
## TODO Deprecation: The homepage for Apache server is being set in
|
||||
## freedombox-apache-homepage.conf. This line will be removed.
|
||||
RedirectMatch "^/$" "/plinth"
|
||||
RedirectMatch "^/freedombox" "/plinth"
|
||||
|
||||
|
||||
@ -30,10 +30,10 @@ Scenario: Change domain name
|
||||
When I change the domain name to mydomain.example
|
||||
Then the domain name should be mydomain.example
|
||||
|
||||
Scenario: Change default app
|
||||
Scenario: Change webserver home page
|
||||
Given the syncthing application is installed
|
||||
And the syncthing application is enabled
|
||||
And the default app is syncthing
|
||||
When I change the default app to plinth
|
||||
Then the default app should be plinth
|
||||
And the home page is syncthing
|
||||
When I change the home page to plinth
|
||||
Then the home page should be plinth
|
||||
|
||||
|
||||
@ -45,9 +45,9 @@ def downloaded_file_info():
|
||||
return dict()
|
||||
|
||||
|
||||
@given(parsers.parse('the default app is {app_name:w}'))
|
||||
def set_default_app(browser, app_name):
|
||||
system.set_default_app(browser, app_name)
|
||||
@given(parsers.parse('the home page is {app_name:w}'))
|
||||
def set_home_page(browser, app_name):
|
||||
system.set_home_page(browser, app_name)
|
||||
|
||||
|
||||
@given(parsers.parse('the domain name is set to {domain:S}'))
|
||||
@ -65,9 +65,9 @@ def change_domain_name_to(browser, domain):
|
||||
system.set_domain_name(browser, domain)
|
||||
|
||||
|
||||
@when(parsers.parse('I change the default app to {app_name:w}'))
|
||||
def change_default_app_to(browser, app_name):
|
||||
system.set_default_app(browser, app_name)
|
||||
@when(parsers.parse('I change the home page to {app_name:w}'))
|
||||
def change_home_page_to(browser, app_name):
|
||||
system.set_home_page(browser, app_name)
|
||||
|
||||
|
||||
@when('I change the language to <language>')
|
||||
@ -157,8 +157,8 @@ def snapshot_assert_configuration(browser, free_space, timeline_enabled,
|
||||
yearly) == system.snapshot_get_configuration(browser)
|
||||
|
||||
|
||||
@then(parsers.parse('the default app should be {app_name:w}'))
|
||||
def default_app_should_be(browser, app_name):
|
||||
@then(parsers.parse('the home page should be {app_name:w}'))
|
||||
def home_page_should_be(browser, app_name):
|
||||
assert system.check_home_page_redirect(browser, app_name)
|
||||
|
||||
|
||||
|
||||
@ -15,9 +15,10 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
from urllib.parse import urlparse
|
||||
import requests
|
||||
import tempfile
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import requests
|
||||
|
||||
from . import application, config
|
||||
from .interface import default_url, nav_to_module, submit
|
||||
@ -62,10 +63,10 @@ def set_domain_name(browser, domain_name):
|
||||
submit(browser)
|
||||
|
||||
|
||||
def set_default_app(browser, app_name):
|
||||
def set_home_page(browser, home_page):
|
||||
nav_to_module(browser, 'config')
|
||||
drop_down = browser.find_by_id('id_configuration-defaultapp')
|
||||
drop_down.select(app_name)
|
||||
drop_down = browser.find_by_id('id_configuration-homepage')
|
||||
drop_down.select(home_page)
|
||||
submit(browser)
|
||||
|
||||
|
||||
|
||||
@ -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):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user