From b96c89b0ab18f4896b6cf95f8729f1a387bb872d Mon Sep 17 00:00:00 2001 From: fonfon Date: Thu, 22 Jan 2015 13:32:19 +0000 Subject: [PATCH] make pagekite login-required; restart pagekite after adding/deleting a service so the changes take effect; improved warnings in the UI --- actions/pagekite | 37 ++++++++++--------- plinth/modules/pagekite/forms.py | 6 ++- .../templates/pagekite_custom_services.html | 5 +++ .../templates/pagekite_default_services.html | 7 +++- plinth/modules/pagekite/urls.py | 22 ++++++----- 5 files changed, 45 insertions(+), 32 deletions(-) diff --git a/actions/pagekite b/actions/pagekite index b2d27a381..c913857c5 100755 --- a/actions/pagekite +++ b/actions/pagekite @@ -49,15 +49,18 @@ def parse_arguments(): parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(dest='subcommand', help='Sub command') - # Start/Stop PageKite - subparsers.add_parser('start', help='Start PageKite service') - subparsers.add_parser('stop', help='Stop PageKite service') + # Start/Stop/Restart PageKite service daemon + # it's called daemon to avoid confusing it with pagekite services + daemon = subparsers.add_parser('daemon', + help='start/stop/restart PageKite') + daemon.add_argument('action', choices=['start', 'stop', 'restart']) - # Get/set status + # Enable/disable the pagekite service subparsers.add_parser('is-enabled', help='Get whether PakeKite is enabled') subparsers.add_parser('enable', help='Enable PageKite service') subparsers.add_parser('disable', help='Disable PageKite service') + # get/set using the default pagekite.net frontend subparsers.add_parser('get-pagekitenet-frontend-status', help='Get whether pagekite.net frontend is enabled') @@ -81,32 +84,28 @@ def parse_arguments(): help='Name of the kite (eg: mybox.pagekite.me)') set_kite.add_argument('--kite-secret', help='Secret for the kite') - # Services + # Add/remove pagekite services (service_on entries) subparsers.add_parser('get-services', help='Get list of enabled services') add_service = subparsers.add_parser('add-service', help='Add a pagekite service') - add_service.add_argument('--service', help='":"-separated service \ - parameters') + add_service.add_argument('--service', help='":"-separated service string') remove_service = subparsers.add_parser('remove-service', help='Remove a pagekite service') remove_service.add_argument('--service', help='":"-separated service \ - parameters') + string') return parser.parse_args() -def subcommand_start(_): - """Start PageKite service""" - status = subprocess.call(['service', 'pagekite', 'start']) - if status: - raise Exception('Unable to start PageKite server') +def subcommand_daemon(arguments): + """Start/stop/restart the pagekite daemon""" + _daemon(arguments.action) -def subcommand_stop(_): - """Stop PageKite service""" - status = subprocess.call(['service', 'pagekite', 'stop']) - if status: - raise Exception('Unable to stop PageKite server') +def _daemon(action): + error = subprocess.call(['service', 'pagekite', action]) + if error: + raise Exception('Unable to %s PageKite server' % action) def subcommand_is_enabled(_): @@ -206,6 +205,7 @@ def subcommand_remove_service(arguments): file.writelines(lines) # abort to only allow deleting one service break + _daemon('restart') def get_existing_service_paths(service): @@ -232,6 +232,7 @@ def subcommand_add_service(arguments): with open(path, 'a') as servicefile: line = "\nservice_on = %s\n" % convert_service_to_string(service) servicefile.write(line) + _daemon('restart') def convert_augeas_path_to_filepath(augpath, prefix='/files', diff --git a/plinth/modules/pagekite/forms.py b/plinth/modules/pagekite/forms.py index c4b8d54a9..2cd7ad7e9 100644 --- a/plinth/modules/pagekite/forms.py +++ b/plinth/modules/pagekite/forms.py @@ -69,7 +69,7 @@ for your account if no secret is set on the kite')) LOGGER.info('New status is - %s', new) if old != new: - _run(['stop']) + _run(['daemon', 'stop']) if old['enabled'] != new['enabled']: if new['enabled']: @@ -94,7 +94,7 @@ for your account if no secret is set on the kite')) messages.success(request, _('Pagekite server set')) if old != new: - _run(['start']) + _run(['daemon', 'start']) class DefaultServiceForm(forms.Form): @@ -167,7 +167,9 @@ class CustomServiceForm(forms.Form): def save(self, request): service = self.convert_form_data_to_service_string(self.cleaned_data) _run(['add-service', '--service', service]) + messages.success(request, _('Added custom service')) def delete(self, request): service = self.convert_form_data_to_service_string(self.cleaned_data) _run(['remove-service', '--service', service]) + messages.success(request, _('Deleted custom service')) diff --git a/plinth/modules/pagekite/templates/pagekite_custom_services.html b/plinth/modules/pagekite/templates/pagekite_custom_services.html index ee0ff9ca3..6f41e5f97 100644 --- a/plinth/modules/pagekite/templates/pagekite_custom_services.html +++ b/plinth/modules/pagekite/templates/pagekite_custom_services.html @@ -41,6 +41,11 @@ {% block content %}

Custom Services

+
diff --git a/plinth/modules/pagekite/templates/pagekite_default_services.html b/plinth/modules/pagekite/templates/pagekite_default_services.html index 906cfb4b6..0e0db1603 100644 --- a/plinth/modules/pagekite/templates/pagekite_default_services.html +++ b/plinth/modules/pagekite/templates/pagekite_default_services.html @@ -40,15 +40,18 @@

Default Services

+
{{ form.http|bootstrap_horizontal:'col-lg-0' }} {{ form.https|bootstrap_horizontal:'col-lg-0' }} {{ form.ssh|bootstrap_horizontal:'col-lg-0' }} {% csrf_token %} - +
{% endblock %} diff --git a/plinth/modules/pagekite/urls.py b/plinth/modules/pagekite/urls.py index ebc457c63..9f6a1921d 100644 --- a/plinth/modules/pagekite/urls.py +++ b/plinth/modules/pagekite/urls.py @@ -20,19 +20,21 @@ URLs for the PageKite module """ from django.conf.urls import patterns, url +from django.contrib.auth.decorators import login_required + from .views import DefaultServiceView, CustomServiceView, ConfigurationView, \ - DeleteServiceView + DeleteServiceView, index urlpatterns = patterns( # pylint: disable-msg=C0103 'plinth.modules.pagekite.views', - url(r'^apps/pagekite/$', 'index', name='index'), - url(r'^apps/pagekite/configure/$', ConfigurationView.as_view(), - name='configure'), - url(r'^apps/pagekite/services/default$', DefaultServiceView.as_view(), - name='default-services'), - url(r'^apps/pagekite/services/custom$', CustomServiceView.as_view(), - name='custom-services'), - url(r'^apps/pagekite/services/custom/delete$', DeleteServiceView.as_view(), - name='delete-custom-service'), + url(r'^apps/pagekite/$', login_required(index), name='index'), + url(r'^apps/pagekite/configure/$', + login_required(ConfigurationView.as_view()), name='configure'), + url(r'^apps/pagekite/services/default$', + login_required(DefaultServiceView.as_view()), name='default-services'), + url(r'^apps/pagekite/services/custom$', + login_required(CustomServiceView.as_view()), name='custom-services'), + url(r'^apps/pagekite/services/custom/delete$', + login_required(DeleteServiceView.as_view()), name='delete-custom-service'), )