mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
pagekite: Remove first wizard step for danube edition
- The code was never used by end users. - The code was expected to be used long back but the plans didn't materialize. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
fa35d6d59a
commit
cff9a61f09
@ -34,12 +34,3 @@ secure_proxy_ssl_header = HTTP_X_FORWARDED_PROTO
|
|||||||
|
|
||||||
[Misc]
|
[Misc]
|
||||||
box_name = FreedomBox
|
box_name = FreedomBox
|
||||||
# The danube_edition changes the firstboot process and offers entering a
|
|
||||||
# voucher for a freedombox.me sub-domain. This functionality requires
|
|
||||||
# additional debian packages to be installed:
|
|
||||||
#
|
|
||||||
# pagekite, python3-requests
|
|
||||||
#
|
|
||||||
# They are not added as dependencies to keep the normal installation images
|
|
||||||
# lean, but make sure to add them if you want to build danube-edition images.
|
|
||||||
danube_edition = False
|
|
||||||
|
|||||||
@ -34,12 +34,3 @@ secure_proxy_ssl_header = HTTP_X_FORWARDED_PROTO
|
|||||||
|
|
||||||
[Misc]
|
[Misc]
|
||||||
box_name = FreedomBox
|
box_name = FreedomBox
|
||||||
# The danube_edition changes the firstboot process and offers entering a
|
|
||||||
# voucher for a freedombox.me sub-domain. This functionality requires
|
|
||||||
# additional debian packages to be installed:
|
|
||||||
#
|
|
||||||
# pagekite, python3-requests
|
|
||||||
#
|
|
||||||
# They are not added as dependencies to keep the normal installation images
|
|
||||||
# lean, but make sure to add them if you want to build danube-edition images.
|
|
||||||
danube_edition = False
|
|
||||||
|
|||||||
@ -37,7 +37,6 @@ use_x_forwarded_host = False
|
|||||||
secure_proxy_ssl_header = None
|
secure_proxy_ssl_header = None
|
||||||
develop = False
|
develop = False
|
||||||
server_dir = '/'
|
server_dir = '/'
|
||||||
danube_edition = False
|
|
||||||
|
|
||||||
config_file = None
|
config_file = None
|
||||||
|
|
||||||
@ -102,7 +101,6 @@ def read(config_path=None, root_directory=None):
|
|||||||
('Network', 'use_x_forwarded_for', 'bool'),
|
('Network', 'use_x_forwarded_for', 'bool'),
|
||||||
('Network', 'use_x_forwarded_host', 'bool'),
|
('Network', 'use_x_forwarded_host', 'bool'),
|
||||||
('Misc', 'box_name', 'string'),
|
('Misc', 'box_name', 'string'),
|
||||||
('Misc', 'danube_edition', 'bool'),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for section, name, datatype in config_items:
|
for section, name, datatype in config_items:
|
||||||
|
|||||||
@ -14,7 +14,6 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Project specific errors
|
Project specific errors
|
||||||
"""
|
"""
|
||||||
@ -30,11 +29,6 @@ class ActionError(PlinthError):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DomainRegistrationError(PlinthError):
|
|
||||||
"""Domain registration failed"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class PackageNotInstalledError(PlinthError):
|
class PackageNotInstalledError(PlinthError):
|
||||||
"""Could not complete module setup due to missing package."""
|
"""Could not complete module setup due to missing package."""
|
||||||
pass
|
pass
|
||||||
|
|||||||
@ -36,14 +36,6 @@ managed_services = ['pagekite']
|
|||||||
|
|
||||||
managed_packages = ['pagekite']
|
managed_packages = ['pagekite']
|
||||||
|
|
||||||
first_boot_steps = [
|
|
||||||
{
|
|
||||||
'id': 'pagekite_firstboot',
|
|
||||||
'url': 'pagekite:firstboot',
|
|
||||||
'order': 5,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
name = _('PageKite')
|
name = _('PageKite')
|
||||||
|
|
||||||
short_description = _('Public Visibility')
|
short_description = _('Public Visibility')
|
||||||
|
|||||||
@ -23,13 +23,9 @@ from django.core.exceptions import ValidationError
|
|||||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import requests
|
|
||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
from plinth import cfg
|
from plinth.errors import ActionError
|
||||||
from plinth.errors import ActionError, DomainRegistrationError
|
|
||||||
from plinth.modules.pagekite.utils import PREDEFINED_SERVICES, run
|
|
||||||
from plinth.utils import format_lazy
|
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -261,101 +257,3 @@ class AddCustomServiceForm(BaseCustomServiceForm):
|
|||||||
messages.error(request, _('This service already exists'))
|
messages.error(request, _('This service already exists'))
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
class FirstBootForm(forms.Form):
|
|
||||||
"""Set up freedombox.me pagekite subdomain"""
|
|
||||||
DOMAIN_APPENDIX = '.freedombox.me'
|
|
||||||
# Webservice url for domain validation and registration
|
|
||||||
service_url = 'http://freedombox.me/cgi-bin/freedomkite.pl'
|
|
||||||
|
|
||||||
code_help_text = format_lazy(
|
|
||||||
ugettext_lazy('The voucher you received with your {box_name} Danube '
|
|
||||||
'Edition'), box_name=ugettext_lazy(cfg.box_name))
|
|
||||||
|
|
||||||
code = forms.CharField(help_text=code_help_text)
|
|
||||||
|
|
||||||
domain = forms.SlugField(label=_('Subdomain'),
|
|
||||||
widget=SubdomainWidget(domain=DOMAIN_APPENDIX),
|
|
||||||
help_text=_('The subdomain you want to register'))
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
"""Initialize the form."""
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
self.fields['code'].widget.attrs.update({'autofocus': 'autofocus'})
|
|
||||||
|
|
||||||
def clean_domain(self):
|
|
||||||
"""Append the domain to the users' subdomain"""
|
|
||||||
return self.cleaned_data['domain'] + self.DOMAIN_APPENDIX
|
|
||||||
|
|
||||||
def clean(self):
|
|
||||||
"""Validate user input (subdomain and code)"""
|
|
||||||
cleaned_data = super().clean()
|
|
||||||
|
|
||||||
# If the subdomain is wrong, don't look if the domain is
|
|
||||||
# available
|
|
||||||
if self.errors:
|
|
||||||
return cleaned_data
|
|
||||||
|
|
||||||
self.domain_already_registered = False
|
|
||||||
code = cleaned_data.get('code')
|
|
||||||
domain = cleaned_data.get('domain')
|
|
||||||
|
|
||||||
response = requests.get(self.service_url, params={'code': code}).json()
|
|
||||||
|
|
||||||
# 1. Code is invalid: {}
|
|
||||||
if 'domain' not in response:
|
|
||||||
raise ValidationError(_('This code is not valid'), code='invalid')
|
|
||||||
# 2. Code is valid, domain registered: {'domain': 'xx.freedombox.me'}
|
|
||||||
elif response['domain']:
|
|
||||||
if response['domain'] == domain:
|
|
||||||
self.domain_already_registered = True
|
|
||||||
else:
|
|
||||||
message = _('This code is bound to the domain {domain}.') \
|
|
||||||
.format(domain=response['domain'])
|
|
||||||
raise ValidationError(message, code='invalid')
|
|
||||||
# 3. Code is valid, no domain registered: {'domain': None}
|
|
||||||
elif response['domain'] is None:
|
|
||||||
# Make sure that the desired domain is available
|
|
||||||
data = {'domain': domain}
|
|
||||||
domain_response = requests.get(self.service_url, params=data)
|
|
||||||
registered_domain = domain_response.json()['domain']
|
|
||||||
if registered_domain is not None:
|
|
||||||
message = _('The requested domain is already registered.')
|
|
||||||
raise ValidationError(message, code='invalid')
|
|
||||||
|
|
||||||
return cleaned_data
|
|
||||||
|
|
||||||
def register_domain(self):
|
|
||||||
"""Register a domain (only if it's not already registered)"""
|
|
||||||
if self.domain_already_registered:
|
|
||||||
return
|
|
||||||
|
|
||||||
data = {'domain': self.cleaned_data['domain'],
|
|
||||||
'code': self.cleaned_data['code']}
|
|
||||||
response = requests.post(self.service_url, data)
|
|
||||||
if not response.ok:
|
|
||||||
message = _('Domain registration failed: {response}.').format(
|
|
||||||
response=response.text)
|
|
||||||
LOGGER.error(message)
|
|
||||||
raise DomainRegistrationError(message)
|
|
||||||
|
|
||||||
def setup_pagekite(self):
|
|
||||||
"""Configure and enable PageKite service."""
|
|
||||||
# Set kite name and secret
|
|
||||||
run(['set-kite', '--kite-name', self.cleaned_data['domain']],
|
|
||||||
input=self.cleaned_data['code'].encode())
|
|
||||||
|
|
||||||
# Set frontend
|
|
||||||
run(['set-frontend', '%s:80' % self.cleaned_data['domain']])
|
|
||||||
|
|
||||||
# Enable PageKite HTTP + HTTPS service
|
|
||||||
for service_name in ['http', 'https']:
|
|
||||||
service = PREDEFINED_SERVICES[service_name]['params']
|
|
||||||
try:
|
|
||||||
run(['add-service', '--service', json.dumps(service)])
|
|
||||||
except ActionError as err:
|
|
||||||
if 'already exists' not in str(err):
|
|
||||||
raise
|
|
||||||
|
|
||||||
run(['start-and-enable'])
|
|
||||||
|
|||||||
@ -20,8 +20,8 @@ URLs for the PageKite module
|
|||||||
|
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
|
|
||||||
from .views import StandardServiceView, CustomServiceView, ConfigurationView, \
|
from .views import (ConfigurationView, CustomServiceView, DeleteServiceView,
|
||||||
DeleteServiceView, FirstBootView, first_boot_skip
|
StandardServiceView)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^sys/pagekite/$', ConfigurationView.as_view(), name='index'),
|
url(r'^sys/pagekite/$', ConfigurationView.as_view(), name='index'),
|
||||||
@ -31,8 +31,4 @@ urlpatterns = [
|
|||||||
name='custom-services'),
|
name='custom-services'),
|
||||||
url(r'^sys/pagekite/services/custom/delete/$', DeleteServiceView.as_view(),
|
url(r'^sys/pagekite/services/custom/delete/$', DeleteServiceView.as_view(),
|
||||||
name='delete-custom-service'),
|
name='delete-custom-service'),
|
||||||
url(r'^sys/pagekite/firstboot/$', FirstBootView.as_view(),
|
|
||||||
name='firstboot'),
|
|
||||||
url(r'^sys/pagekite/firstboot/skip/$', first_boot_skip,
|
|
||||||
name='firstboot-skip'),
|
|
||||||
]
|
]
|
||||||
|
|||||||
@ -15,21 +15,17 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
from django.contrib import messages
|
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.urls import reverse, reverse_lazy
|
from django.urls import reverse, reverse_lazy
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.views.generic import TemplateView, View
|
from django.views.generic import TemplateView, View
|
||||||
from django.views.generic.edit import FormView
|
from django.views.generic.edit import FormView
|
||||||
|
|
||||||
from plinth import cfg
|
from plinth.modules import pagekite
|
||||||
from plinth.errors import DomainRegistrationError
|
|
||||||
from plinth.modules import first_boot, pagekite
|
|
||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
from .forms import (AddCustomServiceForm, ConfigurationForm,
|
from .forms import (AddCustomServiceForm, ConfigurationForm,
|
||||||
DeleteCustomServiceForm, FirstBootForm,
|
DeleteCustomServiceForm, StandardServiceForm)
|
||||||
StandardServiceForm)
|
|
||||||
|
|
||||||
subsubmenu = [{
|
subsubmenu = [{
|
||||||
'url': reverse_lazy('pagekite:index'),
|
'url': reverse_lazy('pagekite:index'),
|
||||||
@ -131,37 +127,3 @@ class ConfigurationView(ContextMixin, FormView):
|
|||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
form.save(self.request)
|
form.save(self.request)
|
||||||
return super(ConfigurationView, self).form_valid(form)
|
return super(ConfigurationView, self).form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
class FirstBootView(FormView):
|
|
||||||
"""First boot (optional) setup of the Pagekite subdomain."""
|
|
||||||
template_name = 'pagekite_firstboot.html'
|
|
||||||
form_class = FirstBootForm
|
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
|
||||||
"""Skip this first boot step if it is not relevant."""
|
|
||||||
if not cfg.danube_edition:
|
|
||||||
return first_boot_skip(request)
|
|
||||||
|
|
||||||
return super().get(request, *args, **kwargs)
|
|
||||||
|
|
||||||
def form_valid(self, form):
|
|
||||||
"""Act on valid form submission."""
|
|
||||||
try:
|
|
||||||
form.register_domain()
|
|
||||||
except DomainRegistrationError as error:
|
|
||||||
messages.error(self.request, error)
|
|
||||||
return self.form_invalid(form)
|
|
||||||
|
|
||||||
form.setup_pagekite()
|
|
||||||
first_boot.mark_step_done('pagekite_firstboot')
|
|
||||||
message = _('Pagekite setup finished. The HTTP and HTTPS services '
|
|
||||||
'are activated now.')
|
|
||||||
messages.success(self.request, message)
|
|
||||||
return HttpResponseRedirect(reverse(first_boot.next_step()))
|
|
||||||
|
|
||||||
|
|
||||||
def first_boot_skip(request):
|
|
||||||
"""Skip the first boot step."""
|
|
||||||
first_boot.mark_step_done('pagekite_firstboot')
|
|
||||||
return HttpResponseRedirect(reverse(first_boot.next_step()))
|
|
||||||
|
|||||||
@ -34,12 +34,3 @@ secure_proxy_ssl_header = HTTP_X_FORWARDED_PROTO
|
|||||||
|
|
||||||
[Misc]
|
[Misc]
|
||||||
box_name = FreedomBox
|
box_name = FreedomBox
|
||||||
# The danube_edition changes the firstboot process and offers entering a
|
|
||||||
# voucher for a freedombox.me sub-domain. This functionality requires
|
|
||||||
# additional debian packages to be installed:
|
|
||||||
#
|
|
||||||
# pagekite, python3-requests
|
|
||||||
#
|
|
||||||
# They are not added as dependencies to keep the normal installation images
|
|
||||||
# lean, but make sure to add them if you want to build danube-edition images.
|
|
||||||
danube_edition = False
|
|
||||||
|
|||||||
@ -1,3 +1,2 @@
|
|||||||
[Misc]
|
[Misc]
|
||||||
box_name = FreedomBox
|
box_name = FreedomBox
|
||||||
danube_edition = False
|
|
||||||
|
|||||||
@ -141,6 +141,5 @@ def compare_configurations(parser):
|
|||||||
assert isinstance(cfg.use_x_forwarded_host, bool)
|
assert isinstance(cfg.use_x_forwarded_host, bool)
|
||||||
assert parser.get('Network', 'use_x_forwarded_host') == \
|
assert parser.get('Network', 'use_x_forwarded_host') == \
|
||||||
str(cfg.use_x_forwarded_host)
|
str(cfg.use_x_forwarded_host)
|
||||||
assert len(parser.items('Misc')) == 3
|
assert len(parser.items('Misc')) == 2
|
||||||
assert parser.get('Misc', 'danube_edition') == str(cfg.danube_edition)
|
|
||||||
assert parser.get('Misc', 'box_name') == cfg.box_name
|
assert parser.get('Misc', 'box_name') == cfg.box_name
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user