mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-22 10:01:45 +00:00
config: Allow better Apache default home page
- Don't redirect to '/index.html' when Apache Default is set as the home page. This allows having other files such as 'index.php' as index file in /var/www/html/. - If the home page is currently set to 'Apache Default' upgrade the configuration. Tests: - With Home page set to 'Apache Default' apply the patches. Config setup is re-run. The configuration file becomes empty but is still present. Correctly value is shown in the UI. /var/www/html/index.html is still shown as the home page. - With Home page set to 'Bepasty' apply the patches. Config setup is re-reun. The configuration file is not modified. Bepasty is still shown as the home page. Correctly value is shown in the UI. - With Home page not modified apply the patches. Config setup is re-reun. The configuration file is created. FreedomBox is the home page. Correctly value is shown in the UI. - On fresh machine with patches applied, perform first run. The configuration file is not created. FreedomBox is the home page. Correctly value is shown in the UI. - Changing home page to Bepasty or 'Apache Default' works. Changing back to 'FreedomBox Service (Plinth)' also works. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
007d8de346
commit
298bb5ae58
@ -43,7 +43,9 @@
|
|||||||
## into FreedomBox server. Plinth then acts as a portal to reach all
|
## into FreedomBox server. Plinth then acts as a portal to reach all
|
||||||
## other services.
|
## other services.
|
||||||
##
|
##
|
||||||
RedirectMatch "^/$" "/plinth"
|
<IfFile !/etc/apache2/conf-enabled/freedombox-apache-homepage.conf>
|
||||||
|
RedirectMatch "^/$" "/plinth"
|
||||||
|
</IfFile>
|
||||||
|
|
||||||
##
|
##
|
||||||
## Disable sending Referer (sic) header from FreedomBox web interface to
|
## Disable sending Referer (sic) header from FreedomBox web interface to
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
"""FreedomBox app for basic system configuration."""
|
"""FreedomBox app for basic system configuration."""
|
||||||
|
|
||||||
|
import pathlib
|
||||||
|
|
||||||
import augeas
|
import augeas
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
@ -27,7 +29,7 @@ class ConfigApp(app_module.App):
|
|||||||
|
|
||||||
app_id = 'config'
|
app_id = 'config'
|
||||||
|
|
||||||
_version = 5
|
_version = 6
|
||||||
|
|
||||||
can_be_disabled = False
|
can_be_disabled = False
|
||||||
|
|
||||||
@ -65,6 +67,12 @@ class ConfigApp(app_module.App):
|
|||||||
elif old_version == 4:
|
elif old_version == 4:
|
||||||
privileged.set_logging_mode(privileged.get_logging_mode())
|
privileged.set_logging_mode(privileged.get_logging_mode())
|
||||||
|
|
||||||
|
if old_version <= 5:
|
||||||
|
# Update the style of Apache home page redirection.
|
||||||
|
home_page = get_home_page()
|
||||||
|
if home_page == 'apache-default':
|
||||||
|
change_home_page(home_page)
|
||||||
|
|
||||||
# systemd-journald is socket activated, it may not be running and it
|
# systemd-journald is socket activated, it may not be running and it
|
||||||
# does not support reload.
|
# does not support reload.
|
||||||
service_privileged.try_restart('systemd-journald')
|
service_privileged.try_restart('systemd-journald')
|
||||||
@ -77,20 +85,17 @@ class ConfigApp(app_module.App):
|
|||||||
service_privileged.mask('rsyslog')
|
service_privileged.mask('rsyslog')
|
||||||
|
|
||||||
|
|
||||||
def home_page_url2scid(url):
|
def home_page_url2scid(url: str | None):
|
||||||
"""Return the shortcut ID of the given home page url."""
|
"""Return the shortcut ID of the given home page url."""
|
||||||
# url is None when the freedombox-apache-homepage configuration file does
|
# url is None when the freedombox-apache-homepage configuration file exists
|
||||||
# not exist. In this case, the default redirect in /plinth from the shipped
|
# but is empty. In this case, no redirect is effective.
|
||||||
# configuration file is effective.
|
if url in ('/index.html', None):
|
||||||
if url is None:
|
|
||||||
return 'plinth'
|
|
||||||
|
|
||||||
if url in ('/plinth/', '/plinth', 'plinth'):
|
|
||||||
return 'plinth'
|
|
||||||
|
|
||||||
if url == '/index.html':
|
|
||||||
return 'apache-default'
|
return 'apache-default'
|
||||||
|
|
||||||
|
if url in ('/plinth/', '/plinth', 'plinth', '/freedombox/', '/freedombox',
|
||||||
|
'freedombox'):
|
||||||
|
return 'plinth'
|
||||||
|
|
||||||
if url and url.startswith('/~'):
|
if url and url.startswith('/~'):
|
||||||
return 'uws-{}'.format(user_of_uws_url(url))
|
return 'uws-{}'.format(user_of_uws_url(url))
|
||||||
|
|
||||||
@ -102,14 +107,12 @@ def home_page_url2scid(url):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _home_page_scid2url(shortcut_id):
|
def _home_page_scid2url(shortcut_id: str) -> str | None:
|
||||||
"""Return the url for the given home page shortcut ID."""
|
"""Return the url for the given home page shortcut ID."""
|
||||||
if shortcut_id is None:
|
if shortcut_id == 'plinth':
|
||||||
url = None
|
|
||||||
elif shortcut_id == 'plinth':
|
|
||||||
url = '/plinth/'
|
url = '/plinth/'
|
||||||
elif shortcut_id == 'apache-default':
|
elif shortcut_id == 'apache-default':
|
||||||
url = '/index.html'
|
url = None
|
||||||
elif shortcut_id.startswith('uws-'):
|
elif shortcut_id.startswith('uws-'):
|
||||||
user = shortcut_id[4:]
|
user = shortcut_id[4:]
|
||||||
if user in get_users_with_website():
|
if user in get_users_with_website():
|
||||||
@ -127,9 +130,12 @@ def _home_page_scid2url(shortcut_id):
|
|||||||
return url
|
return url
|
||||||
|
|
||||||
|
|
||||||
def _get_home_page_url():
|
def _get_home_page_url() -> str | None:
|
||||||
"""Get the default application for the domain."""
|
"""Get the default application for the domain."""
|
||||||
conf_file = privileged.APACHE_HOMEPAGE_CONFIG
|
conf_file = privileged.APACHE_HOMEPAGE_CONFIG
|
||||||
|
if not pathlib.Path(conf_file).exists():
|
||||||
|
return '/plinth/'
|
||||||
|
|
||||||
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
|
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
|
||||||
augeas.Augeas.NO_MODL_AUTOLOAD)
|
augeas.Augeas.NO_MODL_AUTOLOAD)
|
||||||
aug.set('/augeas/load/Httpd/lens', 'Httpd.lns')
|
aug.set('/augeas/load/Httpd/lens', 'Httpd.lns')
|
||||||
@ -152,14 +158,14 @@ def get_home_page():
|
|||||||
return home_page_url2scid(url)
|
return home_page_url2scid(url)
|
||||||
|
|
||||||
|
|
||||||
def change_home_page(shortcut_id):
|
def change_home_page(shortcut_id: str):
|
||||||
"""Change the FreedomBox's default redirect to URL of a shortcut."""
|
"""Change the FreedomBox's default redirect to URL of a shortcut."""
|
||||||
url = _home_page_scid2url(shortcut_id)
|
url = _home_page_scid2url(shortcut_id)
|
||||||
if url is None:
|
if url:
|
||||||
url = '/plinth/' # fall back to default url if scid is unknown.
|
url = str(url)
|
||||||
|
|
||||||
# URL may be a reverse_lazy() proxy
|
# URL may be a reverse_lazy() proxy
|
||||||
privileged.set_home_page(str(url))
|
privileged.set_home_page(url)
|
||||||
|
|
||||||
|
|
||||||
def get_advanced_mode():
|
def get_advanced_mode():
|
||||||
|
|||||||
@ -64,12 +64,14 @@ def set_logging_mode(mode: str):
|
|||||||
|
|
||||||
|
|
||||||
@privileged
|
@privileged
|
||||||
def set_home_page(homepage: str):
|
def set_home_page(homepage: str | None):
|
||||||
"""Set the default app for this FreedomBox."""
|
"""Set the default app for this FreedomBox."""
|
||||||
conf_file_path = os.path.join('/etc/apache2/conf-available',
|
conf_file_path = os.path.join('/etc/apache2/conf-available',
|
||||||
APACHE_HOMEPAGE_CONF_FILE_NAME)
|
APACHE_HOMEPAGE_CONF_FILE_NAME)
|
||||||
|
|
||||||
redirect_rule = 'RedirectMatch "^/$" "{}"\n'.format(homepage)
|
redirect_rule = ''
|
||||||
|
if homepage:
|
||||||
|
redirect_rule = 'RedirectMatch "^/$" "{}"\n'.format(homepage)
|
||||||
|
|
||||||
with open(conf_file_path, 'w', encoding='utf-8') as conf_file:
|
with open(conf_file_path, 'w', encoding='utf-8') as conf_file:
|
||||||
conf_file.write(redirect_rule)
|
conf_file.write(redirect_rule)
|
||||||
|
|||||||
@ -17,7 +17,7 @@ from plinth.modules.config import (_home_page_scid2url, change_home_page,
|
|||||||
def test_homepage_mapping():
|
def test_homepage_mapping():
|
||||||
"""Basic tests for homepage functions."""
|
"""Basic tests for homepage functions."""
|
||||||
func = home_page_url2scid
|
func = home_page_url2scid
|
||||||
assert func(None) == 'plinth'
|
assert func(None) == 'apache-default'
|
||||||
assert func('/unknown/url') is None
|
assert func('/unknown/url') is None
|
||||||
assert func('/plinth/') == 'plinth'
|
assert func('/plinth/') == 'plinth'
|
||||||
assert func('/plinth') == 'plinth'
|
assert func('/plinth') == 'plinth'
|
||||||
@ -27,9 +27,8 @@ def test_homepage_mapping():
|
|||||||
assert func('/~user/whatever/else') == 'uws-user'
|
assert func('/~user/whatever/else') == 'uws-user'
|
||||||
|
|
||||||
func = _home_page_scid2url
|
func = _home_page_scid2url
|
||||||
assert func(None) is None
|
|
||||||
assert func('plinth') == '/plinth/'
|
assert func('plinth') == '/plinth/'
|
||||||
assert func('apache-default') == '/index.html'
|
assert func('apache-default') is None
|
||||||
|
|
||||||
|
|
||||||
def test_homepage_mapping_skip_ci():
|
def test_homepage_mapping_skip_ci():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user