mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +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('enable', help='Enable PageKite service')
|
||||||
subparsers.add_parser('disable', help='Disable 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
|
# Frontend
|
||||||
subparsers.add_parser('get-frontend', help='Get pagekite frontend')
|
subparsers.add_parser('get-frontend', help='Get pagekite frontend')
|
||||||
set_frontend = subparsers.add_parser('set-frontend',
|
set_frontend = subparsers.add_parser('set-frontend',
|
||||||
@ -130,23 +121,24 @@ def subcommand_disable(_):
|
|||||||
|
|
||||||
def subcommand_get_frontend(_):
|
def subcommand_get_frontend(_):
|
||||||
"""Get pagekite frontend url"""
|
"""Get pagekite frontend url"""
|
||||||
url = aug.get(PATHS['frontend'])
|
if aug.match(PATHS['defaults']):
|
||||||
print url if url else ""
|
print "pagekite.net"
|
||||||
|
else:
|
||||||
|
url = aug.get(PATHS['frontend'])
|
||||||
|
print url if url else ""
|
||||||
|
|
||||||
|
|
||||||
def subcommand_set_frontend(arguments):
|
def subcommand_set_frontend(arguments):
|
||||||
"""Set pagekite frontend url and disable default pagekite.net frontend"""
|
"""Set pagekite frontend url, taking care of defaults and pagekite.net"""
|
||||||
aug.remove(PATHS['defaults'])
|
if arguments.url in ('pagekite.net', 'defaults', 'default'):
|
||||||
aug.set(PATHS['frontend'], arguments.url)
|
enable_pagekitenet_frontend()
|
||||||
aug.save()
|
else:
|
||||||
|
aug.remove(PATHS['defaults'])
|
||||||
|
aug.set(PATHS['frontend'], arguments.url)
|
||||||
|
aug.save()
|
||||||
|
|
||||||
|
|
||||||
def subcommand_get_pagekitenet_frontend_status(_):
|
def enable_pagekitenet_frontend():
|
||||||
match = aug.match(PATHS['defaults'])
|
|
||||||
print "enabled" if match else "disabled"
|
|
||||||
|
|
||||||
|
|
||||||
def subcommand_enable_pagekitenet_frontend(_):
|
|
||||||
"""Enable using default pageket.net frontend
|
"""Enable using default pageket.net frontend
|
||||||
|
|
||||||
This disables any other frontends.
|
This disables any other frontends.
|
||||||
@ -157,12 +149,6 @@ def subcommand_enable_pagekitenet_frontend(_):
|
|||||||
print "enabled"
|
print "enabled"
|
||||||
|
|
||||||
|
|
||||||
def subcommand_disable_pagekitenet_frontend(_):
|
|
||||||
aug.remove(PATHS['defaults'])
|
|
||||||
aug.save()
|
|
||||||
print "disabled"
|
|
||||||
|
|
||||||
|
|
||||||
def pagekite_enable():
|
def pagekite_enable():
|
||||||
"""Enable the pagekite daemon"""
|
"""Enable the pagekite daemon"""
|
||||||
aug.remove(PATHS['abort_not_configured'])
|
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
|
The variables/functions defined here are used by both the action script
|
||||||
and the plinth pagekite module.
|
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
|
# 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):
|
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.
|
# The actions.py uses shlex.quote() to escape/quote malicious user input.
|
||||||
# That affects '*.@kitename', so the params string gets quoted.
|
# That affects '*.@kitename', so the params string gets quoted.
|
||||||
# If the string is escaped and contains '*.@kitename', look whether shlex
|
# 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):
|
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:
|
try:
|
||||||
service_string = ":".join([str(service[param]) for param in
|
service_string = ":".join([str(service[param]) for param in
|
||||||
SERVICE_PARAMS])
|
SERVICE_PARAMS])
|
||||||
|
|||||||
@ -86,11 +86,7 @@ for your account if no secret is set on the kite'))
|
|||||||
messages.success(request, _('Kite details set'))
|
messages.success(request, _('Kite details set'))
|
||||||
|
|
||||||
if old['server'] != new['server']:
|
if old['server'] != new['server']:
|
||||||
server = new['server']
|
_run(['set-frontend', new['server']])
|
||||||
if server in ('defaults', 'default', 'pagekite.net'):
|
|
||||||
_run(['enable-pagekitenet-frontend'])
|
|
||||||
else:
|
|
||||||
_run(['set-frontend', server])
|
|
||||||
messages.success(request, _('Pagekite server set'))
|
messages.success(request, _('Pagekite server set'))
|
||||||
|
|
||||||
if old != new:
|
if old != new:
|
||||||
|
|||||||
@ -84,14 +84,9 @@ def get_pagekite_config():
|
|||||||
# PageKite kite details
|
# PageKite kite details
|
||||||
status.update(get_kite_details())
|
status.update(get_kite_details())
|
||||||
|
|
||||||
# PageKite server: 'pagekite.net' if flag 'defaults' is set,
|
# PageKite frontend server
|
||||||
# the value of 'frontend' otherwise
|
server = _run(['get-frontend'])
|
||||||
use_pagekitenet_server = _run(['get-pagekitenet-frontend-status'])
|
status['server'] = server.replace('\n', '')
|
||||||
if "enabled" in use_pagekitenet_server:
|
|
||||||
value = 'pagekite.net'
|
|
||||||
elif "disabled" in use_pagekitenet_server:
|
|
||||||
value = _run(['get-frontend'])
|
|
||||||
status['server'] = value.replace('\n', '')
|
|
||||||
|
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,6 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
from django.contrib.auth.decorators import login_required
|
|
||||||
from django.core.urlresolvers import reverse, reverse_lazy
|
from django.core.urlresolvers import reverse, reverse_lazy
|
||||||
from django.http.response import HttpResponseRedirect
|
from django.http.response import HttpResponseRedirect
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
@ -39,7 +38,6 @@ subsubmenu = [{'url': reverse_lazy('pagekite:index'),
|
|||||||
'text': _('Custom Services')}]
|
'text': _('Custom Services')}]
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
|
||||||
def index(request):
|
def index(request):
|
||||||
"""Serve introduction page"""
|
"""Serve introduction page"""
|
||||||
return TemplateResponse(request, 'pagekite_introduction.html',
|
return TemplateResponse(request, 'pagekite_introduction.html',
|
||||||
@ -59,7 +57,8 @@ class ContextMixin(object):
|
|||||||
context['subsubmenu'] = subsubmenu
|
context['subsubmenu'] = subsubmenu
|
||||||
return context
|
return context
|
||||||
|
|
||||||
@method_decorator(package.required('pagekite'))
|
@method_decorator(package.required('pagekite', 'augeas-tools',
|
||||||
|
'python-augeas'))
|
||||||
def dispatch(self, *args, **kwargs):
|
def dispatch(self, *args, **kwargs):
|
||||||
return super(ContextMixin, self).dispatch(*args, **kwargs)
|
return super(ContextMixin, self).dispatch(*args, **kwargs)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user