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:
Sunil Mohan Adapa authored and James Valleroy committed 2019-10-02 17:21:39 -04:00
1 parent fa35d6d59a
commit cff9a61f09
11 files changed
+6 -195

No files matched your search

-8
View File
@@ -36,14 +36,6 @@ managed_services = ['pagekite']
managed_packages = ['pagekite']
first_boot_steps = [
{
'id': 'pagekite_firstboot',
'url': 'pagekite:firstboot',
'order': 5,
},
]
name = _('PageKite')
short_description = _('Public Visibility')
+1 -103
View File
@@ -23,13 +23,9 @@ from django.core.exceptions import ValidationError
from django.utils.translation import ugettext as _, ugettext_lazy
import json
import logging
import requests
from . import utils
from plinth import cfg
from plinth.errors import ActionError, DomainRegistrationError
from plinth.modules.pagekite.utils import PREDEFINED_SERVICES, run
from plinth.utils import format_lazy
from plinth.errors import ActionError
LOGGER = logging.getLogger(__name__)
@@ -261,101 +257,3 @@ class AddCustomServiceForm(BaseCustomServiceForm):
messages.error(request, _('This service already exists'))
else:
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'])
+2 -6
View File
@@ -20,8 +20,8 @@ URLs for the PageKite module
from django.conf.urls import url
from .views import StandardServiceView, CustomServiceView, ConfigurationView, \
DeleteServiceView, FirstBootView, first_boot_skip
from .views import (ConfigurationView, CustomServiceView, DeleteServiceView,
StandardServiceView)
urlpatterns = [
url(r'^sys/pagekite/$', ConfigurationView.as_view(), name='index'),
@@ -31,8 +31,4 @@ urlpatterns = [
name='custom-services'),
url(r'^sys/pagekite/services/custom/delete/$', DeleteServiceView.as_view(),
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'),
]
+2 -40
View File
@@ -15,21 +15,17 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from django.contrib import messages
from django.http import HttpResponseRedirect
from django.urls import reverse, reverse_lazy
from django.utils.translation import ugettext_lazy as _
from django.views.generic import TemplateView, View
from django.views.generic.edit import FormView
from plinth import cfg
from plinth.errors import DomainRegistrationError
from plinth.modules import first_boot, pagekite
from plinth.modules import pagekite
from . import utils
from .forms import (AddCustomServiceForm, ConfigurationForm,
DeleteCustomServiceForm, FirstBootForm,
StandardServiceForm)
DeleteCustomServiceForm, StandardServiceForm)
subsubmenu = [{
'url': reverse_lazy('pagekite:index'),
@@ -131,37 +127,3 @@ class ConfigurationView(ContextMixin, FormView):
def form_valid(self, form):
form.save(self.request)
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()))