mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +00:00
names: Make all apps use new api to retrieve domain names
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
ab42b9b241
commit
b684b07d11
@ -30,7 +30,6 @@ from django.utils.translation import get_language_info
|
|||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
import plinth
|
import plinth
|
||||||
from plinth import utils
|
|
||||||
|
|
||||||
|
|
||||||
class AppForm(forms.Form):
|
class AppForm(forms.Form):
|
||||||
@ -46,7 +45,10 @@ class DomainSelectionForm(forms.Form):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.fields['domain_name'].choices = utils.get_domain_names()
|
|
||||||
|
from plinth.modules.names.components import DomainName
|
||||||
|
domains = list(DomainName.list_names())
|
||||||
|
self.fields['domain_name'].choices = zip(domains, domains)
|
||||||
|
|
||||||
domain_name = forms.ChoiceField(
|
domain_name = forms.ChoiceField(
|
||||||
label=_('Select a domain name to be used with this application'),
|
label=_('Select a domain name to be used with this application'),
|
||||||
|
|||||||
@ -32,9 +32,9 @@ from plinth.modules import names
|
|||||||
def access_info(request, **kwargs):
|
def access_info(request, **kwargs):
|
||||||
"""API view to return a list of domains and types."""
|
"""API view to return a list of domains and types."""
|
||||||
domains = [{
|
domains = [{
|
||||||
'domain': domain,
|
'domain': domain.name,
|
||||||
'type': domain_type
|
'type': domain.domain_type.component_id
|
||||||
} for domain_type, domains in names.domains.items() for domain in domains]
|
} for domain in names.components.DomainName.list()]
|
||||||
response = {'domains': domains}
|
response = {'domains': domains}
|
||||||
|
|
||||||
return HttpResponse(json.dumps(response), content_type='application/json')
|
return HttpResponse(json.dumps(response), content_type='application/json')
|
||||||
|
|||||||
@ -110,11 +110,9 @@ def init():
|
|||||||
def setup(helper, old_version=None):
|
def setup(helper, old_version=None):
|
||||||
"""Install and configure the module."""
|
"""Install and configure the module."""
|
||||||
helper.install(managed_packages)
|
helper.install(managed_packages)
|
||||||
domains = [
|
domains = names.components.DomainName.list_names('https')
|
||||||
domain for domains_of_a_type in names.domains.values()
|
helper.call('post', actions.superuser_run, 'cockpit',
|
||||||
for domain in domains_of_a_type
|
['setup'] + list(domains))
|
||||||
]
|
|
||||||
helper.call('post', actions.superuser_run, 'cockpit', ['setup'] + domains)
|
|
||||||
helper.call('post', app.enable)
|
helper.call('post', app.enable)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -25,8 +25,7 @@ from django.utils.translation import ugettext as _
|
|||||||
from django.views.generic import FormView
|
from django.views.generic import FormView
|
||||||
|
|
||||||
from plinth.forms import DomainSelectionForm
|
from plinth.forms import DomainSelectionForm
|
||||||
from plinth.modules import diaspora
|
from plinth.modules import diaspora, names
|
||||||
from plinth.utils import get_domain_names
|
|
||||||
from plinth.views import AppView
|
from plinth.views import AppView
|
||||||
|
|
||||||
from .forms import DiasporaAppForm
|
from .forms import DiasporaAppForm
|
||||||
@ -50,7 +49,8 @@ class DiasporaSetupView(FormView):
|
|||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context['description'] = self.description
|
context['description'] = self.description
|
||||||
context['title'] = self.title
|
context['title'] = self.title
|
||||||
context['domain_names'] = get_domain_names()
|
context['domain_names'] = names.components.DomainName.list_names(
|
||||||
|
'https')
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|||||||
@ -111,12 +111,9 @@ def diagnose():
|
|||||||
"""Run diagnostics and return the results."""
|
"""Run diagnostics and return the results."""
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
for domain_type, domains in names.domains.items():
|
for domain in names.components.DomainName.list():
|
||||||
if domain_type == 'hiddenservice':
|
if domain.domain_type.can_have_certificate:
|
||||||
continue
|
results.append(action_utils.diagnose_url('https://' + domain.name))
|
||||||
|
|
||||||
for domain in domains:
|
|
||||||
results.append(action_utils.diagnose_url('https://' + domain))
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
@ -203,13 +200,9 @@ def get_status():
|
|||||||
status = actions.superuser_run('letsencrypt', ['get-status'])
|
status = actions.superuser_run('letsencrypt', ['get-status'])
|
||||||
status = json.loads(status)
|
status = json.loads(status)
|
||||||
|
|
||||||
for domain_type, domains in names.domains.items():
|
for domain in names.components.DomainName.list():
|
||||||
# XXX: Remove when Let's Encrypt supports .onion addresses
|
if domain.domain_type.can_have_certificate:
|
||||||
if domain_type == 'hiddenservice':
|
status['domains'].setdefault(domain.name, {})
|
||||||
continue
|
|
||||||
|
|
||||||
for domain in domains:
|
|
||||||
status['domains'].setdefault(domain, {})
|
|
||||||
|
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
|||||||
@ -26,8 +26,7 @@ from django.views.generic import FormView
|
|||||||
|
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
from plinth.forms import DomainSelectionForm
|
from plinth.forms import DomainSelectionForm
|
||||||
from plinth.modules import matrixsynapse
|
from plinth.modules import matrixsynapse, names
|
||||||
from plinth.utils import get_domain_names
|
|
||||||
from plinth.views import AppView
|
from plinth.views import AppView
|
||||||
|
|
||||||
from . import get_public_registration_status
|
from . import get_public_registration_status
|
||||||
@ -51,7 +50,8 @@ class SetupView(FormView):
|
|||||||
|
|
||||||
context['title'] = matrixsynapse.name
|
context['title'] = matrixsynapse.name
|
||||||
context['description'] = matrixsynapse.description
|
context['description'] = matrixsynapse.description
|
||||||
context['domain_names'] = get_domain_names()
|
context['domain_names'] = names.components.DomainName.list_names(
|
||||||
|
'matrix-synapse-plinth')
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|||||||
@ -51,10 +51,8 @@ class MinetestAppView(AppView): # pylint: disable=too-many-ancestors
|
|||||||
def get_context_data(self, *args, **kwargs):
|
def get_context_data(self, *args, **kwargs):
|
||||||
"""Add service to the context data."""
|
"""Add service to the context data."""
|
||||||
context = super().get_context_data(*args, **kwargs)
|
context = super().get_context_data(*args, **kwargs)
|
||||||
# Filter out onion addresses and get a unique list of domains
|
context['domains'] = names.components.DomainName.list_names(
|
||||||
domains = set(domain for domains in names.domains.values()
|
'minetest-plinth')
|
||||||
for domain in domains if not domain.endswith('.onion'))
|
|
||||||
context['domains'] = domains
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
|
|||||||
@ -109,10 +109,7 @@ def get_keys(fingerprint=None):
|
|||||||
['host-show-keys'] + fingerprint)
|
['host-show-keys'] + fingerprint)
|
||||||
keys = json.loads(output)['keys']
|
keys = json.loads(output)['keys']
|
||||||
|
|
||||||
domains = [
|
domains = names.components.DomainName.list_names()
|
||||||
domain for domains_of_a_type in names.domains.values()
|
|
||||||
for domain in domains_of_a_type
|
|
||||||
]
|
|
||||||
for key in keys.values():
|
for key in keys.values():
|
||||||
key['imported_domains'] = set(key.get('imported_domains', []))
|
key['imported_domains'] = set(key.get('imported_domains', []))
|
||||||
key['available_domains'] = set(key.get('available_domains', []))
|
key['available_domains'] = set(key.get('available_domains', []))
|
||||||
|
|||||||
@ -22,8 +22,7 @@ from django.urls import reverse_lazy
|
|||||||
from django.views.generic import FormView
|
from django.views.generic import FormView
|
||||||
|
|
||||||
from plinth.forms import DomainSelectionForm
|
from plinth.forms import DomainSelectionForm
|
||||||
from plinth.modules import tahoe
|
from plinth.modules import names, tahoe
|
||||||
from plinth.utils import get_domain_names
|
|
||||||
from plinth.views import AppView
|
from plinth.views import AppView
|
||||||
|
|
||||||
|
|
||||||
@ -44,7 +43,8 @@ class TahoeSetupView(FormView):
|
|||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context['description'] = self.description
|
context['description'] = self.description
|
||||||
context['title'] = self.title
|
context['title'] = self.title
|
||||||
context['domain_names'] = get_domain_names()
|
context['domain_names'] = names.components.DomainName.list_names(
|
||||||
|
'tahoe-plinth')
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|||||||
@ -74,21 +74,6 @@ def is_user_admin(request, cached=False):
|
|||||||
return user_is_admin
|
return user_is_admin
|
||||||
|
|
||||||
|
|
||||||
def get_domain_names():
|
|
||||||
"""Return the domain name(s)"""
|
|
||||||
from plinth.modules import names
|
|
||||||
|
|
||||||
domain_names = []
|
|
||||||
|
|
||||||
for domain_type, domains in names.domains.items():
|
|
||||||
if domain_type == 'hiddenservice':
|
|
||||||
continue
|
|
||||||
for domain in domains:
|
|
||||||
domain_names.append((domain, domain))
|
|
||||||
|
|
||||||
return domain_names
|
|
||||||
|
|
||||||
|
|
||||||
class YAMLFile(object):
|
class YAMLFile(object):
|
||||||
"""A context management class for updating YAML files"""
|
"""A context management class for updating YAML files"""
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user