make pagekite login-required;

restart pagekite after adding/deleting a service so the changes take
effect;
improved warnings in the UI
This commit is contained in:
fonfon 2015-01-22 13:32:19 +00:00
parent 0b2b8ba51a
commit b96c89b0ab
5 changed files with 45 additions and 32 deletions

View File

@ -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',

View File

@ -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'))

View File

@ -41,6 +41,11 @@
{% block content %}
<h3>Custom Services</h3>
<div class="alert alert-warning" role="alert">
Warning: Your PageKite frontend server may not support all the
protocol/port combinations that you are able to define here. For example,
HTTPS on ports other than 443 is known to cause problems.
</div>
<div class="row custom-services">

View File

@ -40,15 +40,18 @@
<h3>Default Services</h3>
<div class="alert alert-warning" role="alert">
<p>Exposing services makes them accessible and attackable from the evil
internet. Be cautious!</p>
internet.<p>
<p><b>Exposing SSH with the default password for 'fbx' is a very bad idea.</b></p>
</div>
<form class="form predefined" method="post">
{{ form.http|bootstrap_horizontal:'col-lg-0' }}
{{ form.https|bootstrap_horizontal:'col-lg-0' }}
{{ form.ssh|bootstrap_horizontal:'col-lg-0' }}
{% csrf_token %}
<input type="submit" class="btn btn-primary" value="Save settings"/>
<input type="submit" class="btn btn-primary" value="Save Services"/>
</form>
{% endblock %}

View File

@ -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'),
)