pagekite: Use the new app toggle button

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
This commit is contained in:
Joseph Nuthalapati committed 2019-11-20 06:26:54 +05:30
1 parent 71ccb5882b
commit 5b2df956e8
7 files changed
+31 -73

No files matched your search

+4 -5
View File
@@ -47,9 +47,8 @@ description = [
'need this if your {box_name} services are unreachable from '
'the rest of the Internet. This includes the following '
'situations:'), box_name=_(cfg.box_name)),
format_lazy(
_('{box_name} is behind a restricted firewall.'),
box_name=_(cfg.box_name)),
format_lazy(_('{box_name} is behind a restricted firewall.'),
box_name=_(cfg.box_name)),
format_lazy(
_('{box_name} is connected to a (wireless) router which you '
'don\'t control.'), box_name=_(cfg.box_name)),
@@ -59,10 +58,10 @@ description = [
'address changes every time you connect to Internet.'),
_('Your ISP limits incoming connections.'),
format_lazy(
_('PageKite works around NAT, firewalls and IP-address limitations '
_('PageKite works around NAT, firewalls and IP address limitations '
'by using a combination of tunnels and reverse proxies. You can '
'use any pagekite service provider, for example '
'<a href="https://pagekite.net">pagekite.net</a>. In future it '
'<a href="https://pagekite.net">pagekite.net</a>. In the future it '
'might be possible to use your buddy\'s {box_name} for this.'),
box_name=_(cfg.box_name))
]
+11 -17
View File
@@ -26,6 +26,7 @@ from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy
from plinth.errors import ActionError
from plinth.forms import AppForm
from . import utils
@@ -34,7 +35,6 @@ LOGGER = logging.getLogger(__name__)
class TrimmedCharField(forms.CharField):
"""Trim the contents of a CharField"""
def clean(self, value):
"""Clean and validate the field value"""
if value:
@@ -45,7 +45,6 @@ class TrimmedCharField(forms.CharField):
class SubdomainWidget(forms.widgets.TextInput):
"""Append the domain to the subdomain bootstrap input field"""
def __init__(self, domain, *args, **kwargs):
"""Initialize the widget by storing the domain value."""
super().__init__(*args, **kwargs)
@@ -60,12 +59,9 @@ class SubdomainWidget(forms.widgets.TextInput):
</div>""".format(inputfield, self.domain)
class ConfigurationForm(forms.Form):
class ConfigurationForm(AppForm):
"""Configure PageKite credentials and frontend"""
enabled = forms.BooleanField(
label=ugettext_lazy('Enable PageKite'), required=False)
server_domain = forms.CharField(
label=ugettext_lazy('Server domain'), required=False,
help_text=ugettext_lazy(
@@ -109,8 +105,8 @@ class ConfigurationForm(forms.Form):
messages.success(request, _('Pagekite server set'))
config_changed = True
if old['enabled'] != new['enabled']:
if new['enabled']:
if old['is_enabled'] != new['is_enabled']:
if new['is_enabled']:
utils.run(['start-and-enable'])
# Ensure all standard/predefined services are enabled
for service_name in utils.PREDEFINED_SERVICES.keys():
@@ -119,9 +115,9 @@ class ConfigurationForm(forms.Form):
service = json.dumps(service)
# Probably should keep track of which services
# are enabled since adding the service produces
# an error if it is already added. But this works
# too.
# are enabled since adding the service produces
# an error if it is already added. But this works
# too.
try:
utils.run(['add-service', '--service', service])
@@ -137,11 +133,11 @@ class ConfigurationForm(forms.Form):
# Restart the service if the config was changed while the service
# was running, so changes take effect immediately.
elif config_changed and new['enabled']:
elif config_changed and new['is_enabled']:
utils.run(['restart'])
# Update kite name registered with Name Services module.
utils.update_names_module(enabled=new['enabled'],
utils.update_names_module(enabled=new['is_enabled'],
kite_name=new['kite_name'])
@@ -156,8 +152,8 @@ class BaseCustomServiceForm(forms.Form):
backend_port = forms.IntegerField(
min_value=0, max_value=65535,
label=ugettext_lazy('internal (freedombox) port'))
subdomains = forms.BooleanField(
label=ugettext_lazy('Enable Subdomains'), required=False)
subdomains = forms.BooleanField(label=ugettext_lazy('Enable Subdomains'),
required=False)
def convert_formdata_to_service(self, formdata):
"""Add information to make a service out of the form data"""
@@ -187,7 +183,6 @@ class BaseCustomServiceForm(forms.Form):
class DeleteCustomServiceForm(BaseCustomServiceForm):
"""Form to remove custom service."""
def delete(self, request):
service = self.convert_formdata_to_service(self.cleaned_data)
utils.run(['remove-service', '--service', json.dumps(service)])
@@ -196,7 +191,6 @@ class DeleteCustomServiceForm(BaseCustomServiceForm):
class AddCustomServiceForm(BaseCustomServiceForm):
"""Adds the save() method and validation to not add predefined services"""
def matches_predefined_service(self, formdata):
"""Returns whether the user input matches a predefined service"""
service = self.convert_formdata_to_service(formdata)
+2 -2
View File
@@ -109,7 +109,7 @@ def get_pagekite_config():
# 2) the pagekite service running
is_disabled = (run(['is-disabled']).strip() == 'true')
service_running = action_utils.service_is_running('pagekite')
status['enabled'] = service_running and not is_disabled
status['is_enabled'] = service_running and not is_disabled
# PageKite kite details
status.update(get_kite_details())
@@ -265,7 +265,7 @@ def update_names_module(initial_registration=False, enabled=None,
if enabled is None:
try:
enabled = get_pagekite_config()['enabled']
enabled = get_pagekite_config()['is_enabled']
except IndexError:
enabled = False
+5 -5
View File
@@ -32,7 +32,6 @@ class ContextMixin(object):
Also adds the requirement of all necessary packages to be installed
"""
def get_context_data(self, **kwargs):
"""Use self.title and the module-level subsubmenu"""
context = super(ContextMixin, self).get_context_data(**kwargs)
@@ -40,6 +39,7 @@ class ContextMixin(object):
context['name'] = pagekite.name
context['description'] = pagekite.description
context['manual_page'] = pagekite.manual_page
context['is_enabled'] = pagekite.app.is_enabled()
return context
def dispatch(self, *args, **kwargs):
@@ -58,8 +58,8 @@ class AddCustomServiceView(ContextMixin, TemplateView):
template_name = 'pagekite_custom_services.html'
def get_context_data(self, *args, **kwargs):
context = super(AddCustomServiceView, self).get_context_data(
*args, **kwargs)
context = super(AddCustomServiceView,
self).get_context_data(*args, **kwargs)
unused, custom_services = utils.get_pagekite_services()
for service in custom_services:
service['form'] = AddCustomServiceForm(initial=service)
@@ -94,8 +94,8 @@ class ConfigurationView(ContextMixin, FormView):
success_url = reverse_lazy('pagekite:index')
def get_context_data(self, *args, **kwargs):
context = super(ConfigurationView, self).get_context_data(
*args, **kwargs)
context = super(ConfigurationView,
self).get_context_data(*args, **kwargs)
unused, custom_services = utils.get_pagekite_services()
for service in custom_services:
service['form'] = AddCustomServiceForm(initial=service)