shadowsocks: Read configuration as root, update description

- Also use the service helper to start stop shadowsocks service.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Sunil Mohan Adapa 2017-11-29 16:13:47 +05:30
parent 9cfcc08434
commit aeae8c55a4
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
3 changed files with 27 additions and 25 deletions

View File

@ -27,7 +27,8 @@ import sys
from plinth import action_utils
from plinth.modules import shadowsocks
from plinth.modules.shadowsocks.views import SHADOWSOCKS_CONFIG
SHADOWSOCKS_CONFIG = '/etc/shadowsocks-libev/freedombox.json'
def parse_arguments():
@ -37,10 +38,8 @@ def parse_arguments():
subparsers.add_parser('setup',
help='Perform initial setup steps')
subparsers.add_parser('enable',
help='Enable Shadowsocks client socks5 proxy')
subparsers.add_parser('disable',
help='Disable Shadowsocks client socks5 proxy')
subparsers.add_parser(
'get-config', help='Read and print JSON config to stdout')
subparsers.add_parser(
'merge-config', help='Merge JSON config from stdin with existing')
@ -55,14 +54,12 @@ def subcommand_setup(_):
action_utils.service_disable('shadowsocks-libev')
def subcommand_enable(_):
"""Enable Shadowsocks client socks5 proxy."""
action_utils.service_enable(shadowsocks.managed_services[0])
def subcommand_disable(_):
"""Disable Shadowsocks client socks5 proxy."""
action_utils.service_disable(shadowsocks.managed_services[0])
def subcommand_get_config(arguments):
"""Read and print Shadowsocks configuration."""
try:
print(open(SHADOWSOCKS_CONFIG, 'r').read())
except Exception:
sys.exit(1)
def subcommand_merge_config(arguments):

View File

@ -24,9 +24,11 @@ from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import frontpage
from plinth import service as service_module
from plinth.menu import main_menu
from plinth.utils import format_lazy
version = 1
@ -42,14 +44,17 @@ managed_services = ['shadowsocks-libev-local@freedombox']
managed_packages = ['shadowsocks-libev']
description = [
_('Shadowsocks is a lightweight and secure socks5 proxy, designed to '
_('Shadowsocks is a lightweight and secure SOCKS5 proxy, designed to '
'protect your Internet traffic. It can be used to bypass Internet '
'filtering and censorship.'),
_('Your FreedomBox can run a Shadowsocks client, that can connect '
'to a Shadowsocks server. The FreedomBox will also run a socks5 '
'server. Local devices can connect to the socks5 server, and '
'their data will be encrypted and proxied through the Shadowsocks '
'server.'),
format_lazy(
_('Your {box_name} can run a Shadowsocks client, that can connect to '
'a Shadowsocks server. It will also run a SOCKS5 proxy. Local '
'devices can connect to this proxy, and their data will be '
'encrypted and proxied through the Shadowsocks server.'),
box_name=_(cfg.box_name)),
_('To use Shadowsocks after setup, set the SOCKS5 proxy URL in your '
'device, browser or application to http://freedombox_address:1080/')
]
@ -106,13 +111,13 @@ def is_running():
def enable():
"""Enable service."""
actions.superuser_run('shadowsocks', ['enable'])
actions.superuser_run('service', ['enable', managed_services[0]])
add_shortcut()
def disable():
"""Disable service."""
actions.superuser_run('shadowsocks', ['disable'])
actions.superuser_run('service', ['disable', managed_services[0]])
frontpage.remove_shortcut('shadowsocks')

View File

@ -26,10 +26,9 @@ from django.utils.translation import ugettext_lazy as _
from .forms import ShadowsocksForm
from plinth import actions
from plinth import views
from plinth.errors import ActionError
from plinth.modules import shadowsocks
SHADOWSOCKS_CONFIG = '/etc/shadowsocks-libev/freedombox.json'
class ShadowsocksServiceView(views.ServiceView):
"""Configuration view for Shadowsocks local socks5 proxy."""
@ -41,9 +40,10 @@ class ShadowsocksServiceView(views.ServiceView):
def get_initial(self, *args, **kwargs):
"""Get initial values for form."""
try:
configuration = open(SHADOWSOCKS_CONFIG, 'r').read()
configuration = actions.superuser_run('shadowsocks',
['get-config'])
status = json.loads(configuration)
except (OSError, json.JSONDecodeError):
except ActionError:
status = {
'server': '',
'server_port': 8388,