mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +00:00
shadowshocks: Fix setting configuration on Buster
- Ensure that /var/lib/private/shadowsocks-libev/freedombox always exists. This fixes not being able to save configuration after setup on fresh Buster installs. - Merge migration path from version 1 to 2 into setup process in an idempotent way. - Always creating an initial configuration file so that daemon starts soon after install. Set a default random password. Localhost as default server. Closes: #1792 Signed-off-by: Nektarios Katakis <iam@nektarioskatakis.xyz> [sunil: Minor indentation, update commit message] Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
50186eea6a
commit
af713d23fd
@ -7,8 +7,10 @@ Helper script for configuring Shadowsocks.
|
|||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import subprocess
|
|
||||||
import sys
|
import sys
|
||||||
|
from shutil import move
|
||||||
|
import random
|
||||||
|
import string
|
||||||
|
|
||||||
from plinth import action_utils
|
from plinth import action_utils
|
||||||
from plinth.modules import shadowsocks
|
from plinth.modules import shadowsocks
|
||||||
@ -29,11 +31,6 @@ def parse_arguments():
|
|||||||
subparsers.add_parser('merge-config',
|
subparsers.add_parser('merge-config',
|
||||||
help='Merge JSON config from stdin with existing')
|
help='Merge JSON config from stdin with existing')
|
||||||
|
|
||||||
# Migrations
|
|
||||||
subparsers.add_parser(
|
|
||||||
'migrate-1-2',
|
|
||||||
help='Move shadowsocks config file to a secure location')
|
|
||||||
|
|
||||||
subparsers.required = True
|
subparsers.required = True
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
@ -43,6 +40,33 @@ def subcommand_setup(_):
|
|||||||
# Only client socks5 proxy is supported for now. Disable the
|
# Only client socks5 proxy is supported for now. Disable the
|
||||||
# server component.
|
# server component.
|
||||||
action_utils.service_disable('shadowsocks-libev')
|
action_utils.service_disable('shadowsocks-libev')
|
||||||
|
|
||||||
|
os.makedirs('/var/lib/private/shadowsocks-libev/freedombox/',
|
||||||
|
exist_ok=True)
|
||||||
|
|
||||||
|
# if existing configuration from version 1 which is normal file
|
||||||
|
# move it to new location.
|
||||||
|
if (
|
||||||
|
not os.path.islink(SHADOWSOCKS_CONFIG_SYMLINK) and
|
||||||
|
os.path.isfile(SHADOWSOCKS_CONFIG_SYMLINK)
|
||||||
|
):
|
||||||
|
move(SHADOWSOCKS_CONFIG_SYMLINK, SHADOWSOCKS_CONFIG_ACTUAL)
|
||||||
|
else:
|
||||||
|
# new install
|
||||||
|
if not os.path.isfile(SHADOWSOCKS_CONFIG_ACTUAL):
|
||||||
|
initial_config = {
|
||||||
|
"server": "127.0.0.1",
|
||||||
|
"mode": "tcp_and_udp",
|
||||||
|
"server_port": 8388,
|
||||||
|
"local_port": 1080,
|
||||||
|
"password": ''.join(
|
||||||
|
random.choice(string.ascii_letters) for i in range(20)),
|
||||||
|
"timeout": 60,
|
||||||
|
"method": "chacha20-ietf-poly1305"
|
||||||
|
}
|
||||||
|
open(SHADOWSOCKS_CONFIG_ACTUAL, 'w').write(
|
||||||
|
json.dumps(initial_config))
|
||||||
|
|
||||||
if not os.path.islink(SHADOWSOCKS_CONFIG_SYMLINK):
|
if not os.path.islink(SHADOWSOCKS_CONFIG_SYMLINK):
|
||||||
os.symlink(SHADOWSOCKS_CONFIG_ACTUAL, SHADOWSOCKS_CONFIG_SYMLINK)
|
os.symlink(SHADOWSOCKS_CONFIG_ACTUAL, SHADOWSOCKS_CONFIG_SYMLINK)
|
||||||
|
|
||||||
@ -74,18 +98,6 @@ def subcommand_merge_config(_):
|
|||||||
action_utils.service_restart(shadowsocks.managed_services[0])
|
action_utils.service_restart(shadowsocks.managed_services[0])
|
||||||
|
|
||||||
|
|
||||||
def subcommand_migrate_1_2(_):
|
|
||||||
"""Move shadowsocks config file to a secure location."""
|
|
||||||
if os.path.isfile(SHADOWSOCKS_CONFIG_SYMLINK): # ignoring symlinks
|
|
||||||
os.makedirs('/var/lib/private/shadowsocks-libev/freedombox/',
|
|
||||||
exist_ok=True)
|
|
||||||
os.replace(SHADOWSOCKS_CONFIG_SYMLINK, SHADOWSOCKS_CONFIG_ACTUAL)
|
|
||||||
os.symlink(SHADOWSOCKS_CONFIG_ACTUAL, SHADOWSOCKS_CONFIG_SYMLINK)
|
|
||||||
|
|
||||||
subprocess.check_call(['systemctl', 'daemon-reload'])
|
|
||||||
action_utils.service_restart(shadowsocks.managed_services[0])
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Parse arguments and perform all duties."""
|
"""Parse arguments and perform all duties."""
|
||||||
arguments = parse_arguments()
|
arguments = parse_arguments()
|
||||||
|
|||||||
@ -89,11 +89,6 @@ def init():
|
|||||||
|
|
||||||
def setup(helper, old_version=None):
|
def setup(helper, old_version=None):
|
||||||
"""Install and configure the module."""
|
"""Install and configure the module."""
|
||||||
|
|
||||||
if old_version == 1:
|
|
||||||
helper.call('migration', actions.superuser_run, 'shadowsocks',
|
|
||||||
['migrate-1-2'])
|
|
||||||
|
|
||||||
helper.install(managed_packages)
|
helper.install(managed_packages)
|
||||||
helper.call('post', actions.superuser_run, 'shadowsocks', ['setup'])
|
helper.call('post', actions.superuser_run, 'shadowsocks', ['setup'])
|
||||||
helper.call('post', app.enable)
|
helper.call('post', app.enable)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user