mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +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 json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from shutil import move
|
||||
import random
|
||||
import string
|
||||
|
||||
from plinth import action_utils
|
||||
from plinth.modules import shadowsocks
|
||||
@ -29,11 +31,6 @@ def parse_arguments():
|
||||
subparsers.add_parser('merge-config',
|
||||
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
|
||||
return parser.parse_args()
|
||||
|
||||
@ -43,6 +40,33 @@ def subcommand_setup(_):
|
||||
# Only client socks5 proxy is supported for now. Disable the
|
||||
# server component.
|
||||
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):
|
||||
os.symlink(SHADOWSOCKS_CONFIG_ACTUAL, SHADOWSOCKS_CONFIG_SYMLINK)
|
||||
|
||||
@ -74,18 +98,6 @@ def subcommand_merge_config(_):
|
||||
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():
|
||||
"""Parse arguments and perform all duties."""
|
||||
arguments = parse_arguments()
|
||||
|
||||
@ -89,11 +89,6 @@ def init():
|
||||
|
||||
def setup(helper, old_version=None):
|
||||
"""Install and configure the module."""
|
||||
|
||||
if old_version == 1:
|
||||
helper.call('migration', actions.superuser_run, 'shadowsocks',
|
||||
['migrate-1-2'])
|
||||
|
||||
helper.install(managed_packages)
|
||||
helper.call('post', actions.superuser_run, 'shadowsocks', ['setup'])
|
||||
helper.call('post', app.enable)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user