mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-02-04 08:13:38 +00:00
removed default frontend stuff from actions
it's all handled via get-frontend and set-frontend now. and there are now some doctests in actions/pagekite_util.py
This commit is contained in:
parent
e0fa113a9c
commit
99bfda3b69
@ -60,15 +60,6 @@ def parse_arguments():
|
||||
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')
|
||||
subparsers.add_parser('enable-pagekitenet-frontend',
|
||||
help='Enable using default pagekite.net frontend')
|
||||
subparsers.add_parser('disable-pagekitenet-frontend',
|
||||
help='Disable default pagekite.net frontend')
|
||||
|
||||
# Frontend
|
||||
subparsers.add_parser('get-frontend', help='Get pagekite frontend')
|
||||
set_frontend = subparsers.add_parser('set-frontend',
|
||||
@ -130,23 +121,24 @@ def subcommand_disable(_):
|
||||
|
||||
def subcommand_get_frontend(_):
|
||||
"""Get pagekite frontend url"""
|
||||
url = aug.get(PATHS['frontend'])
|
||||
print url if url else ""
|
||||
if aug.match(PATHS['defaults']):
|
||||
print "pagekite.net"
|
||||
else:
|
||||
url = aug.get(PATHS['frontend'])
|
||||
print url if url else ""
|
||||
|
||||
|
||||
def subcommand_set_frontend(arguments):
|
||||
"""Set pagekite frontend url and disable default pagekite.net frontend"""
|
||||
aug.remove(PATHS['defaults'])
|
||||
aug.set(PATHS['frontend'], arguments.url)
|
||||
aug.save()
|
||||
"""Set pagekite frontend url, taking care of defaults and pagekite.net"""
|
||||
if arguments.url in ('pagekite.net', 'defaults', 'default'):
|
||||
enable_pagekitenet_frontend()
|
||||
else:
|
||||
aug.remove(PATHS['defaults'])
|
||||
aug.set(PATHS['frontend'], arguments.url)
|
||||
aug.save()
|
||||
|
||||
|
||||
def subcommand_get_pagekitenet_frontend_status(_):
|
||||
match = aug.match(PATHS['defaults'])
|
||||
print "enabled" if match else "disabled"
|
||||
|
||||
|
||||
def subcommand_enable_pagekitenet_frontend(_):
|
||||
def enable_pagekitenet_frontend():
|
||||
"""Enable using default pageket.net frontend
|
||||
|
||||
This disables any other frontends.
|
||||
@ -157,12 +149,6 @@ def subcommand_enable_pagekitenet_frontend(_):
|
||||
print "enabled"
|
||||
|
||||
|
||||
def subcommand_disable_pagekitenet_frontend(_):
|
||||
aug.remove(PATHS['defaults'])
|
||||
aug.save()
|
||||
print "disabled"
|
||||
|
||||
|
||||
def pagekite_enable():
|
||||
"""Enable the pagekite daemon"""
|
||||
aug.remove(PATHS['abort_not_configured'])
|
||||
|
||||
@ -18,13 +18,10 @@
|
||||
#
|
||||
|
||||
"""
|
||||
Utilities for configuring PageKite.
|
||||
|
||||
The variables/functions defined here are used by both the action script
|
||||
and the plinth pagekite module.
|
||||
|
||||
For example the functionality to convert pagekite service_on strings like
|
||||
"http:@kitename:localhost:80:@kitestring"
|
||||
into parameter dictionaries and the other way round. And functions that we want
|
||||
to be covered by tests.
|
||||
"""
|
||||
# ATTENTION: This file has to be both python2 and python3 compatible
|
||||
|
||||
@ -37,7 +34,11 @@ SERVICE_PARAMS = ['protocol', 'kitename', 'backend_host', 'backend_port',
|
||||
|
||||
|
||||
def convert_to_service(service_string):
|
||||
""" Convert a service string into a service parameter dictionary"""
|
||||
""" Convert a service string into a service parameter dictionary
|
||||
>>> convert_to_service('https/443:@kitename:localhost:443:@kitesecret')
|
||||
{'kitename': '@kitename', 'backend_host': 'localhost', \
|
||||
'secret': '@kitesecret', 'protocol': 'https/443', 'backend_port': '443'}
|
||||
"""
|
||||
# The actions.py uses shlex.quote() to escape/quote malicious user input.
|
||||
# That affects '*.@kitename', so the params string gets quoted.
|
||||
# If the string is escaped and contains '*.@kitename', look whether shlex
|
||||
@ -75,7 +76,13 @@ def convert_to_service(service_string):
|
||||
|
||||
|
||||
def convert_service_to_string(service):
|
||||
""" Convert service dict into a ":"-separated parameter string """
|
||||
""" Convert service dict into a ":"-separated parameter string
|
||||
|
||||
>>> convert_service_to_string({'kitename': '@kitename', \
|
||||
'backend_host': 'localhost', 'secret': '@kitesecret', \
|
||||
'protocol': 'https/443', 'backend_port': '443'})
|
||||
'https/443:@kitename:localhost:443:@kitesecret'
|
||||
"""
|
||||
try:
|
||||
service_string = ":".join([str(service[param]) for param in
|
||||
SERVICE_PARAMS])
|
||||
|
||||
@ -86,11 +86,7 @@ for your account if no secret is set on the kite'))
|
||||
messages.success(request, _('Kite details set'))
|
||||
|
||||
if old['server'] != new['server']:
|
||||
server = new['server']
|
||||
if server in ('defaults', 'default', 'pagekite.net'):
|
||||
_run(['enable-pagekitenet-frontend'])
|
||||
else:
|
||||
_run(['set-frontend', server])
|
||||
_run(['set-frontend', new['server']])
|
||||
messages.success(request, _('Pagekite server set'))
|
||||
|
||||
if old != new:
|
||||
|
||||
@ -84,14 +84,9 @@ def get_pagekite_config():
|
||||
# PageKite kite details
|
||||
status.update(get_kite_details())
|
||||
|
||||
# PageKite server: 'pagekite.net' if flag 'defaults' is set,
|
||||
# the value of 'frontend' otherwise
|
||||
use_pagekitenet_server = _run(['get-pagekitenet-frontend-status'])
|
||||
if "enabled" in use_pagekitenet_server:
|
||||
value = 'pagekite.net'
|
||||
elif "disabled" in use_pagekitenet_server:
|
||||
value = _run(['get-frontend'])
|
||||
status['server'] = value.replace('\n', '')
|
||||
# PageKite frontend server
|
||||
server = _run(['get-frontend'])
|
||||
status['server'] = server.replace('\n', '')
|
||||
|
||||
return status
|
||||
|
||||
|
||||
@ -16,7 +16,6 @@
|
||||
#
|
||||
|
||||
from gettext import gettext as _
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.urlresolvers import reverse, reverse_lazy
|
||||
from django.http.response import HttpResponseRedirect
|
||||
from django.template.response import TemplateResponse
|
||||
@ -39,7 +38,6 @@ subsubmenu = [{'url': reverse_lazy('pagekite:index'),
|
||||
'text': _('Custom Services')}]
|
||||
|
||||
|
||||
@login_required
|
||||
def index(request):
|
||||
"""Serve introduction page"""
|
||||
return TemplateResponse(request, 'pagekite_introduction.html',
|
||||
@ -59,7 +57,8 @@ class ContextMixin(object):
|
||||
context['subsubmenu'] = subsubmenu
|
||||
return context
|
||||
|
||||
@method_decorator(package.required('pagekite'))
|
||||
@method_decorator(package.required('pagekite', 'augeas-tools',
|
||||
'python-augeas'))
|
||||
def dispatch(self, *args, **kwargs):
|
||||
return super(ContextMixin, self).dispatch(*args, **kwargs)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user