diff --git a/core/cli.py b/core/cli.py index 3ba5e4a..f8fce50 100644 --- a/core/cli.py +++ b/core/cli.py @@ -11,7 +11,7 @@ import traffic import validator -SCRIPT_DIR = 'scripts' +SCRIPT_DIR = '/etc/hysteria/core/scripts' DEBUG = True class Command(Enum): @@ -39,7 +39,7 @@ def run_cmd(command:list[str]): Runs a command and returns the output. Could raise subprocess.CalledProcessError ''' - result = subprocess.check_output(command, shell=True) + result = subprocess.check_output(command, shell=False) if DEBUG: print(result.decode().strip()) @@ -48,7 +48,7 @@ def generate_password() -> str: Generates a random password using pwgen for user. Could raise subprocess.CalledProcessError ''' - return subprocess.check_output(['pwgen', '-s', '32', '1'], shell=True).decode().strip() + return subprocess.check_output(['pwgen', '-s', '32', '1'], shell=False).decode().strip() # endregion @@ -61,6 +61,7 @@ def cli(): @cli.command('install-hysteria2') @click.option('--port','-p', required=True, help='New port for Hysteria2',type=int,callback=validator.validate_port) def install_hysteria2(port:int): + print(f"bash {Command.INSTALL_HYSTERIA2.value} {str(port)}") run_cmd(['bash', Command.INSTALL_HYSTERIA2.value, str(port)]) diff --git a/core/validator.py b/core/validator.py index bd4f8b0..04c09a2 100644 --- a/core/validator.py +++ b/core/validator.py @@ -1,10 +1,10 @@ import os +import click - -def validate_port(ctx,param,value)-> bool: +def validate_port(ctx,param,value:int) -> int: if value < 1 or value > 65535: - return False + raise click.BadParameter('Port must be between 1 and 65535') # check if port is in use if os.system(f'lsof -i:{value}') == 0: - return False - return True \ No newline at end of file + raise click.BadParameter(f'Port {value} is in use') + return value \ No newline at end of file