mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
pagekite: Use the new app toggle button
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
This commit is contained in:
parent
71ccb5882b
commit
5b2df956e8
@ -24,17 +24,17 @@ Background:
|
||||
Given the pagekite application is installed
|
||||
|
||||
Scenario: Enable pagekite application
|
||||
Given pagekite is disabled
|
||||
When I enable pagekite
|
||||
Given the pagekite application is disabled
|
||||
When I enable the pagekite application
|
||||
Then pagekite should be enabled
|
||||
|
||||
Scenario: Configure pagekite application
|
||||
Given pagekite is enabled
|
||||
Given the pagekite application is enabled
|
||||
When I configure pagekite with host pagekite.example.com, port 8080, kite name mykite.example.com and kite secret mysecret
|
||||
Then pagekite should be configured with host pagekite.example.com, port 8080, kite name mykite.example.com and kite secret mysecret
|
||||
|
||||
Scenario: Backup and restore pagekite
|
||||
Given pagekite is enabled
|
||||
Given the pagekite application is enabled
|
||||
When I configure pagekite with host beforebackup.example.com, port 8081, kite name beforebackup.example.com and kite secret beforebackupsecret
|
||||
And I create a backup of the pagekite app data
|
||||
And I configure pagekite with host afterbackup.example.com, port 8082, kite name afterbackup.example.com and kite secret afterbackupsecret
|
||||
@ -43,6 +43,6 @@ Scenario: Backup and restore pagekite
|
||||
And pagekite should be configured with host beforebackup.example.com, port 8081, kite name beforebackup.example.com and kite secret beforebackupsecret
|
||||
|
||||
Scenario: Disable pagekite application
|
||||
Given pagekite is enabled
|
||||
When I disable pagekite
|
||||
Given the pagekite application is enabled
|
||||
When I disable the pagekite application
|
||||
Then pagekite should be disabled
|
||||
|
||||
@ -211,26 +211,6 @@ def backup_restore_from_upload(browser, app_name, downloaded_file_info):
|
||||
os.remove(path)
|
||||
|
||||
|
||||
@given('pagekite is enabled')
|
||||
def pagekite_is_enabled(browser):
|
||||
system.pagekite_enable(browser, True)
|
||||
|
||||
|
||||
@given('pagekite is disabled')
|
||||
def pagekite_is_disabled(browser):
|
||||
system.pagekite_enable(browser, False)
|
||||
|
||||
|
||||
@when('I enable pagekite')
|
||||
def pagekite_enable(browser):
|
||||
system.pagekite_enable(browser, True)
|
||||
|
||||
|
||||
@when('I disable pagekite')
|
||||
def pagekite_disable(browser):
|
||||
system.pagekite_enable(browser, False)
|
||||
|
||||
|
||||
@then('pagekite should be enabled')
|
||||
def pagekite_assert_enabled(browser):
|
||||
assert system.pagekite_is_enabled(browser)
|
||||
@ -333,8 +313,8 @@ def monkeysphere_given_import_key(browser, key_type, domain):
|
||||
system.monkeysphere_import_key(browser, key_type.lower(), domain)
|
||||
|
||||
|
||||
@when(
|
||||
parsers.parse('I import {key_type:w} key for {domain:S} in monkeysphere'))
|
||||
@when(parsers.parse('I import {key_type:w} key for {domain:S} in monkeysphere')
|
||||
)
|
||||
def monkeysphere_import_key(browser, key_type, domain):
|
||||
system.monkeysphere_import_key(browser, key_type.lower(), domain)
|
||||
|
||||
|
||||
@ -275,25 +275,10 @@ def download_file_logged_in(browser, url, suffix=''):
|
||||
return temp_file.name
|
||||
|
||||
|
||||
def pagekite_enable(browser, should_enable):
|
||||
"""Enable/disable pagekite service."""
|
||||
nav_to_module(browser, 'pagekite')
|
||||
checkbox = browser.find_by_id('id_pagekite-enabled').first
|
||||
if checkbox.checked == should_enable:
|
||||
return
|
||||
|
||||
if should_enable:
|
||||
checkbox.check()
|
||||
else:
|
||||
checkbox.uncheck()
|
||||
|
||||
submit(browser)
|
||||
|
||||
|
||||
def pagekite_is_enabled(browser):
|
||||
"""Return whether pagekite is enabled."""
|
||||
nav_to_module(browser, 'pagekite')
|
||||
return browser.find_by_id('id_pagekite-enabled').checked
|
||||
return browser.find_by_id('app-toggle-input').checked
|
||||
|
||||
|
||||
def pagekite_configure(browser, host, port, kite_name, kite_secret):
|
||||
|
||||
@ -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))
|
||||
]
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user