File: forms.py

package info (click to toggle)
freedombox 26.2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 82,976 kB
  • sloc: python: 48,504; javascript: 1,736; xml: 481; makefile: 290; sh: 167; php: 32
file content (37 lines) | stat: -rw-r--r-- 1,242 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# SPDX-License-Identifier: AGPL-3.0-or-later
"""FreedomBox app for configuring Shadowsocks Client."""

from django import forms
from django.utils.translation import gettext_lazy as _

from plinth.modules.shadowsocksserver.forms import METHODS


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().clean(value)


class ShadowsocksForm(forms.Form):
    """Shadowsocks Client configuration form."""

    server = TrimmedCharField(label=_('Server'),
                              help_text=_('Server hostname or IP address'))

    server_port = forms.IntegerField(label=_('Server port'), min_value=0,
                                     max_value=65535,
                                     help_text=_('Server port number'))

    password = forms.CharField(
        label=_('Password'), help_text=_('Password used to encrypt data. '
                                         'Must match server password.'))

    method = forms.ChoiceField(
        label=_('Method'), choices=METHODS,
        help_text=_('Encryption method. Must match setting on server.'))