diff --git a/modules/installed/router/pagekite.py b/modules/installed/router/pagekite.py index cc87fac2a..799a8860d 100644 --- a/modules/installed/router/pagekite.py +++ b/modules/installed/router/pagekite.py @@ -20,14 +20,14 @@ Plinth module for configuring PageKite service """ import cherrypy +from django import forms +from django.core import validators from gettext import gettext as _ import actions import cfg -from forms import Form from modules.auth import require -from plugin_mount import PagePlugin, FormPlugin -import re +from plugin_mount import PagePlugin import util @@ -39,7 +39,6 @@ class PageKite(PagePlugin): PagePlugin.__init__(self, *args, **kwargs) self.register_page("router.setup.pagekite") - self.register_page("router.setup.pagekite.configure") cfg.html_root.router.setup.menu.add_item( _("Public Visibility (PageKite)"), "icon-flag", "/router/setup/pagekite", 50) @@ -48,7 +47,7 @@ class PageKite(PagePlugin): @cherrypy.expose @require() def index(**kwargs): - """Serve introcution page""" + """Serve introdution page""" del kwargs # Unused menu = {'title': _('PageKite'), @@ -61,29 +60,82 @@ class PageKite(PagePlugin): sidebar_right=sidebar_right) -class configure(FormPlugin, PagePlugin): # pylint: disable-msg=C0103 +class TrimmedCharField(forms.CharField): + """Trim the contents of a CharField""" + def clean(self, value): + """Clean and validate the field value""" + if value: + value = value.strip() + + return super(TrimmedCharField, self).clean(value) + + +class ConfigureForm(forms.Form): # pylint: disable-msg=W0232 + """Form to configure PageKite""" + enabled = forms.BooleanField(label=_('Enable PageKite'), + required=False) + + server = forms.CharField( + label=_('Server'), required=False, + help_text=_('Currently only pagekite.net server is supported'), + widget=forms.TextInput(attrs={'placeholder': 'pagekite.net', + 'disabled': 'disabled'})) + + kite_name = TrimmedCharField( + label=_('Kite name'), + help_text=_('Example: mybox1-myacc.pagekite.me'), + validators=[ + validators.RegexValidator(r'^[\w-]{1,63}(\.[\w-]{1,63})*$', + _('Invalid kite name'))]) + + kite_secret = TrimmedCharField( + label=_('Kite secret'), + help_text=_('A secret associated with the kite or the default secret \ +for your account if no secret is set on the kite')) + + http_enabled = forms.BooleanField( + label=_('Web Server (HTTP)'), required=False, + help_text=_('Site will be available at \ +http://mybox1-myacc.pagekite.me \ +')) + + ssh_enabled = forms.BooleanField( + label=_('Secure Shell (SSH)'), required=False, + help_text=_('See SSH client setup instructions')) + + +class Configure(PagePlugin): # pylint: disable-msg=C0103 """Main configuration form""" order = 65 - url = ["/router/setup/pagekite/configure"] + def __init__(self, *args, **kwargs): + PagePlugin.__init__(self, *args, **kwargs) - js = """ - -""" + if kwargs: + form = ConfigureForm(kwargs, prefix='pagekite') + # pylint: disable-msg=E1101 + if form.is_valid(): + self._apply_changes(status, form.cleaned_data, messages) + status = self.get_status() + form = ConfigureForm(initial=status, prefix='pagekite') + else: + form = ConfigureForm(initial=status, prefix='pagekite') + + return util.render_template(template='pagekite_configure', + title=_('Configure PageKite'), form=form, + messages=messages) def get_status(self): """ @@ -112,99 +164,11 @@ $('#pagekite-enable').change(function() { status['service'] = {} for service in ('http', 'ssh'): output = self._run(['get-service-status', service]) - status['service'][service] = (output.split()[0] == 'enabled') + status[service + '_enabled'] = (output.split()[0] == 'enabled') return status - def main(self, *args, **kwargs): - """Build and return the main content area which is the form""" - del args # unused - - status = self.get_status() - - if not status: - return _(''' -
PageKite is not installed, please install it. PageKite comes -pre-installed with {box_name}. On any Debian based system (such as -{box_name}) you may install it using the command 'aptitude install -pagekite'
''').format(box_name=cfg.box_name) - - try: - message = kwargs['message'].text - except KeyError: - message = None - form = Form( - title="Configure PageKite", - action=cfg.server_dir + "/router/setup/pagekite/configure/", - name="configure_pagekite_form", message=message) - - form.checkbox(_("Enable PageKite"), name="pagekite_enable", - id="pagekite-enable", checked=status['enabled']) - - show_form = "block" if status['enabled'] else "none" - form.html(''' -PageKite is not installed, please install it. PageKite comes + pre-installed with {{ cfg.box_name }}. On any Debian based system + (such as {{ cfg.box_name }}) you may install it using the command + 'aptitude install pagekite'
+ +{% else %} + + {% for severity, message in messages %} +