James Valleroy e719b1ed49
shadowsocksserver: Add separate app for Shadowsocks server
Closes: #729.

Tests:

- Install Shadowsocks Server. Install Shadowsocks Client, and set the
  server to localhost, and set the same password as the server. Use
  curl to connect to local SOCKS proxy on port 1080 and fetch a
  website.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
[sunil: Update some docstring comments for shadowsocks clients]
[sunil: Use the term Censorship instead of network filters]
[sunil: Prevent enabling both apps when setup is re-run]
[sunil: Update typehint for a privileged method to be minimal]
[sunil: Accept connections from external IPs too]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2023-05-23 13:58:39 -07:00

44 lines
1.6 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""FreedomBox app for configuring Shadowsocks Server."""
from django import forms
from django.utils.translation import gettext_lazy as _
from plinth.utils import format_lazy
METHODS = [('chacha20-ietf-poly1305',
format_lazy('chacha20-ietf-poly1305 ({})', _('Recommended'))),
('aes-256-gcm', format_lazy('aes-256-gcm ({})', _('Recommended'))),
('aes-192-gcm', 'aes-192-gcm'), ('aes-128-gcm', 'aes-128-gcm'),
('aes-128-ctr', 'aes-128-ctr'), ('aes-192-ctr', 'aes-192-ctr'),
('aes-256-ctr', 'aes-256-ctr'), ('aes-128-cfb', 'aes-128-cfb'),
('aes-192-cfb', 'aes-192-cfb'), ('aes-256-cfb', 'aes-256-cfb'),
('camellia-128-cfb', 'camellia-128-cfb'),
('camellia-192-cfb', 'camellia-192-cfb'),
('camellia-256-cfb', 'camellia-256-cfb'),
('chacha20-ietf', 'chacha20-ietf')]
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 ShadowsocksServerForm(forms.Form):
"""Shadowsocks Server configuration form."""
password = forms.CharField(
label=_('Password'),
help_text=_('Password used to encrypt data. Clients must use the '
'same password.'))
method = forms.ChoiceField(
label=_('Method'), choices=METHODS,
help_text=_('Encryption method. Clients must use the same setting.'))