Sunil Mohan Adapa fb0dd323ff
nextcloud: Populated and maintain a list of trusted domains
- Rename 'domain' to 'override domain'. See below.

- If override domain is not set and trusted domains list is properly maintained,
then Nextcloud can be accessed using a domain from list of trusted domains. This
is ideal as accessing from .onion domain and a regular domain will
simultaneously without forcing a single domain. However, non-localhost IP
addresses will not work with this approach and 'override domain' will be needed.

- When override domain is set to an IP address or a domain, then that domain
will forced. Also hostname are accepted on a request but after the first page
load, access will be forcefully redirected to the configured override domain.
Multiple domains, even trusted domains, will thus not work. This option should
be used as a last resort.

- All un-setting the override domain to an empty value so that trusted domains
can be used again.

- Update diagnostic checks to ensure that above logic is used with checking
domains.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2024-05-06 17:14:52 -04:00

45 lines
1.8 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""Nextcloud configuration form."""
from django import forms
from django.utils.translation import gettext_lazy as _
def _get_phone_regions():
"""Return choice field choices for phone regions."""
try:
from iso3166 import countries # type: ignore
phone_regions = [(country.alpha2, country.name)
for country in countries]
phone_regions = sorted(phone_regions)
except ImportError:
# Allow users to set a non-empty value
phone_regions = [('US', 'United States of America')]
return [('', _('Not set'))] + phone_regions
class NextcloudForm(forms.Form):
"""Nextcloud configuration form."""
override_domain = forms.CharField(
label=_('Override domain'), required=False, help_text=_(
'Set to the domain or IP address that Nextcloud should be forced '
'to generate URLs with. Should not be needed if a valid domain is '
'used to access Nextcloud. Examples: "myfreedombox.example.org" '
'or "example.onion".'))
admin_password = forms.CharField(
label=_('Administrator password'), help_text=_(
'Optional. Set a new password for Nextcloud\'s administrator '
'account (nextcloud-admin). The password cannot be a common one '
'and the minimum required length is <strong>10 characters'
'</strong>. Leave this field blank to keep the current password.'),
required=False, widget=forms.PasswordInput, min_length=10)
default_phone_region = forms.ChoiceField(
label=_('Default phone region'), required=False,
help_text=_('The default phone region is required to validate phone '
'numbers in the profile settings without a country code.'),
choices=_get_phone_regions)