mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +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
|
Given the pagekite application is installed
|
||||||
|
|
||||||
Scenario: Enable pagekite application
|
Scenario: Enable pagekite application
|
||||||
Given pagekite is disabled
|
Given the pagekite application is disabled
|
||||||
When I enable pagekite
|
When I enable the pagekite application
|
||||||
Then pagekite should be enabled
|
Then pagekite should be enabled
|
||||||
|
|
||||||
Scenario: Configure pagekite application
|
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
|
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
|
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
|
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
|
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 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
|
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
|
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
|
Scenario: Disable pagekite application
|
||||||
Given pagekite is enabled
|
Given the pagekite application is enabled
|
||||||
When I disable pagekite
|
When I disable the pagekite application
|
||||||
Then pagekite should be disabled
|
Then pagekite should be disabled
|
||||||
|
|||||||
@ -211,26 +211,6 @@ def backup_restore_from_upload(browser, app_name, downloaded_file_info):
|
|||||||
os.remove(path)
|
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')
|
@then('pagekite should be enabled')
|
||||||
def pagekite_assert_enabled(browser):
|
def pagekite_assert_enabled(browser):
|
||||||
assert system.pagekite_is_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)
|
system.monkeysphere_import_key(browser, key_type.lower(), domain)
|
||||||
|
|
||||||
|
|
||||||
@when(
|
@when(parsers.parse('I import {key_type:w} key for {domain:S} in monkeysphere')
|
||||||
parsers.parse('I import {key_type:w} key for {domain:S} in monkeysphere'))
|
)
|
||||||
def monkeysphere_import_key(browser, key_type, domain):
|
def monkeysphere_import_key(browser, key_type, domain):
|
||||||
system.monkeysphere_import_key(browser, key_type.lower(), 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
|
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):
|
def pagekite_is_enabled(browser):
|
||||||
"""Return whether pagekite is enabled."""
|
"""Return whether pagekite is enabled."""
|
||||||
nav_to_module(browser, 'pagekite')
|
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):
|
def pagekite_configure(browser, host, port, kite_name, kite_secret):
|
||||||
|
|||||||
@ -47,8 +47,7 @@ description = [
|
|||||||
'need this if your {box_name} services are unreachable from '
|
'need this if your {box_name} services are unreachable from '
|
||||||
'the rest of the Internet. This includes the following '
|
'the rest of the Internet. This includes the following '
|
||||||
'situations:'), box_name=_(cfg.box_name)),
|
'situations:'), box_name=_(cfg.box_name)),
|
||||||
format_lazy(
|
format_lazy(_('{box_name} is behind a restricted firewall.'),
|
||||||
_('{box_name} is behind a restricted firewall.'),
|
|
||||||
box_name=_(cfg.box_name)),
|
box_name=_(cfg.box_name)),
|
||||||
format_lazy(
|
format_lazy(
|
||||||
_('{box_name} is connected to a (wireless) router which you '
|
_('{box_name} is connected to a (wireless) router which you '
|
||||||
@ -59,10 +58,10 @@ description = [
|
|||||||
'address changes every time you connect to Internet.'),
|
'address changes every time you connect to Internet.'),
|
||||||
_('Your ISP limits incoming connections.'),
|
_('Your ISP limits incoming connections.'),
|
||||||
format_lazy(
|
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 '
|
'by using a combination of tunnels and reverse proxies. You can '
|
||||||
'use any pagekite service provider, for example '
|
'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.'),
|
'might be possible to use your buddy\'s {box_name} for this.'),
|
||||||
box_name=_(cfg.box_name))
|
box_name=_(cfg.box_name))
|
||||||
]
|
]
|
||||||
|
|||||||
@ -26,6 +26,7 @@ from django.utils.translation import ugettext as _
|
|||||||
from django.utils.translation import ugettext_lazy
|
from django.utils.translation import ugettext_lazy
|
||||||
|
|
||||||
from plinth.errors import ActionError
|
from plinth.errors import ActionError
|
||||||
|
from plinth.forms import AppForm
|
||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
|
|
||||||
@ -34,7 +35,6 @@ LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class TrimmedCharField(forms.CharField):
|
class TrimmedCharField(forms.CharField):
|
||||||
"""Trim the contents of a CharField"""
|
"""Trim the contents of a CharField"""
|
||||||
|
|
||||||
def clean(self, value):
|
def clean(self, value):
|
||||||
"""Clean and validate the field value"""
|
"""Clean and validate the field value"""
|
||||||
if value:
|
if value:
|
||||||
@ -45,7 +45,6 @@ class TrimmedCharField(forms.CharField):
|
|||||||
|
|
||||||
class SubdomainWidget(forms.widgets.TextInput):
|
class SubdomainWidget(forms.widgets.TextInput):
|
||||||
"""Append the domain to the subdomain bootstrap input field"""
|
"""Append the domain to the subdomain bootstrap input field"""
|
||||||
|
|
||||||
def __init__(self, domain, *args, **kwargs):
|
def __init__(self, domain, *args, **kwargs):
|
||||||
"""Initialize the widget by storing the domain value."""
|
"""Initialize the widget by storing the domain value."""
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
@ -60,12 +59,9 @@ class SubdomainWidget(forms.widgets.TextInput):
|
|||||||
</div>""".format(inputfield, self.domain)
|
</div>""".format(inputfield, self.domain)
|
||||||
|
|
||||||
|
|
||||||
class ConfigurationForm(forms.Form):
|
class ConfigurationForm(AppForm):
|
||||||
"""Configure PageKite credentials and frontend"""
|
"""Configure PageKite credentials and frontend"""
|
||||||
|
|
||||||
enabled = forms.BooleanField(
|
|
||||||
label=ugettext_lazy('Enable PageKite'), required=False)
|
|
||||||
|
|
||||||
server_domain = forms.CharField(
|
server_domain = forms.CharField(
|
||||||
label=ugettext_lazy('Server domain'), required=False,
|
label=ugettext_lazy('Server domain'), required=False,
|
||||||
help_text=ugettext_lazy(
|
help_text=ugettext_lazy(
|
||||||
@ -109,8 +105,8 @@ class ConfigurationForm(forms.Form):
|
|||||||
messages.success(request, _('Pagekite server set'))
|
messages.success(request, _('Pagekite server set'))
|
||||||
config_changed = True
|
config_changed = True
|
||||||
|
|
||||||
if old['enabled'] != new['enabled']:
|
if old['is_enabled'] != new['is_enabled']:
|
||||||
if new['enabled']:
|
if new['is_enabled']:
|
||||||
utils.run(['start-and-enable'])
|
utils.run(['start-and-enable'])
|
||||||
# Ensure all standard/predefined services are enabled
|
# Ensure all standard/predefined services are enabled
|
||||||
for service_name in utils.PREDEFINED_SERVICES.keys():
|
for service_name in utils.PREDEFINED_SERVICES.keys():
|
||||||
@ -137,11 +133,11 @@ class ConfigurationForm(forms.Form):
|
|||||||
|
|
||||||
# Restart the service if the config was changed while the service
|
# Restart the service if the config was changed while the service
|
||||||
# was running, so changes take effect immediately.
|
# was running, so changes take effect immediately.
|
||||||
elif config_changed and new['enabled']:
|
elif config_changed and new['is_enabled']:
|
||||||
utils.run(['restart'])
|
utils.run(['restart'])
|
||||||
|
|
||||||
# Update kite name registered with Name Services module.
|
# 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'])
|
kite_name=new['kite_name'])
|
||||||
|
|
||||||
|
|
||||||
@ -156,8 +152,8 @@ class BaseCustomServiceForm(forms.Form):
|
|||||||
backend_port = forms.IntegerField(
|
backend_port = forms.IntegerField(
|
||||||
min_value=0, max_value=65535,
|
min_value=0, max_value=65535,
|
||||||
label=ugettext_lazy('internal (freedombox) port'))
|
label=ugettext_lazy('internal (freedombox) port'))
|
||||||
subdomains = forms.BooleanField(
|
subdomains = forms.BooleanField(label=ugettext_lazy('Enable Subdomains'),
|
||||||
label=ugettext_lazy('Enable Subdomains'), required=False)
|
required=False)
|
||||||
|
|
||||||
def convert_formdata_to_service(self, formdata):
|
def convert_formdata_to_service(self, formdata):
|
||||||
"""Add information to make a service out of the form data"""
|
"""Add information to make a service out of the form data"""
|
||||||
@ -187,7 +183,6 @@ class BaseCustomServiceForm(forms.Form):
|
|||||||
|
|
||||||
class DeleteCustomServiceForm(BaseCustomServiceForm):
|
class DeleteCustomServiceForm(BaseCustomServiceForm):
|
||||||
"""Form to remove custom service."""
|
"""Form to remove custom service."""
|
||||||
|
|
||||||
def delete(self, request):
|
def delete(self, request):
|
||||||
service = self.convert_formdata_to_service(self.cleaned_data)
|
service = self.convert_formdata_to_service(self.cleaned_data)
|
||||||
utils.run(['remove-service', '--service', json.dumps(service)])
|
utils.run(['remove-service', '--service', json.dumps(service)])
|
||||||
@ -196,7 +191,6 @@ class DeleteCustomServiceForm(BaseCustomServiceForm):
|
|||||||
|
|
||||||
class AddCustomServiceForm(BaseCustomServiceForm):
|
class AddCustomServiceForm(BaseCustomServiceForm):
|
||||||
"""Adds the save() method and validation to not add predefined services"""
|
"""Adds the save() method and validation to not add predefined services"""
|
||||||
|
|
||||||
def matches_predefined_service(self, formdata):
|
def matches_predefined_service(self, formdata):
|
||||||
"""Returns whether the user input matches a predefined service"""
|
"""Returns whether the user input matches a predefined service"""
|
||||||
service = self.convert_formdata_to_service(formdata)
|
service = self.convert_formdata_to_service(formdata)
|
||||||
|
|||||||
@ -109,7 +109,7 @@ def get_pagekite_config():
|
|||||||
# 2) the pagekite service running
|
# 2) the pagekite service running
|
||||||
is_disabled = (run(['is-disabled']).strip() == 'true')
|
is_disabled = (run(['is-disabled']).strip() == 'true')
|
||||||
service_running = action_utils.service_is_running('pagekite')
|
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
|
# PageKite kite details
|
||||||
status.update(get_kite_details())
|
status.update(get_kite_details())
|
||||||
@ -265,7 +265,7 @@ def update_names_module(initial_registration=False, enabled=None,
|
|||||||
|
|
||||||
if enabled is None:
|
if enabled is None:
|
||||||
try:
|
try:
|
||||||
enabled = get_pagekite_config()['enabled']
|
enabled = get_pagekite_config()['is_enabled']
|
||||||
except IndexError:
|
except IndexError:
|
||||||
enabled = False
|
enabled = False
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,6 @@ class ContextMixin(object):
|
|||||||
|
|
||||||
Also adds the requirement of all necessary packages to be installed
|
Also adds the requirement of all necessary packages to be installed
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
"""Use self.title and the module-level subsubmenu"""
|
"""Use self.title and the module-level subsubmenu"""
|
||||||
context = super(ContextMixin, self).get_context_data(**kwargs)
|
context = super(ContextMixin, self).get_context_data(**kwargs)
|
||||||
@ -40,6 +39,7 @@ class ContextMixin(object):
|
|||||||
context['name'] = pagekite.name
|
context['name'] = pagekite.name
|
||||||
context['description'] = pagekite.description
|
context['description'] = pagekite.description
|
||||||
context['manual_page'] = pagekite.manual_page
|
context['manual_page'] = pagekite.manual_page
|
||||||
|
context['is_enabled'] = pagekite.app.is_enabled()
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def dispatch(self, *args, **kwargs):
|
def dispatch(self, *args, **kwargs):
|
||||||
@ -58,8 +58,8 @@ class AddCustomServiceView(ContextMixin, TemplateView):
|
|||||||
template_name = 'pagekite_custom_services.html'
|
template_name = 'pagekite_custom_services.html'
|
||||||
|
|
||||||
def get_context_data(self, *args, **kwargs):
|
def get_context_data(self, *args, **kwargs):
|
||||||
context = super(AddCustomServiceView, self).get_context_data(
|
context = super(AddCustomServiceView,
|
||||||
*args, **kwargs)
|
self).get_context_data(*args, **kwargs)
|
||||||
unused, custom_services = utils.get_pagekite_services()
|
unused, custom_services = utils.get_pagekite_services()
|
||||||
for service in custom_services:
|
for service in custom_services:
|
||||||
service['form'] = AddCustomServiceForm(initial=service)
|
service['form'] = AddCustomServiceForm(initial=service)
|
||||||
@ -94,8 +94,8 @@ class ConfigurationView(ContextMixin, FormView):
|
|||||||
success_url = reverse_lazy('pagekite:index')
|
success_url = reverse_lazy('pagekite:index')
|
||||||
|
|
||||||
def get_context_data(self, *args, **kwargs):
|
def get_context_data(self, *args, **kwargs):
|
||||||
context = super(ConfigurationView, self).get_context_data(
|
context = super(ConfigurationView,
|
||||||
*args, **kwargs)
|
self).get_context_data(*args, **kwargs)
|
||||||
unused, custom_services = utils.get_pagekite_services()
|
unused, custom_services = utils.get_pagekite_services()
|
||||||
for service in custom_services:
|
for service in custom_services:
|
||||||
service['form'] = AddCustomServiceForm(initial=service)
|
service['form'] = AddCustomServiceForm(initial=service)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user