Fix cli validator and scripts path
This commit is contained in:
@ -11,7 +11,7 @@ import traffic
|
|||||||
import validator
|
import validator
|
||||||
|
|
||||||
|
|
||||||
SCRIPT_DIR = 'scripts'
|
SCRIPT_DIR = '/etc/hysteria/core/scripts'
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|
||||||
class Command(Enum):
|
class Command(Enum):
|
||||||
@ -39,7 +39,7 @@ def run_cmd(command:list[str]):
|
|||||||
Runs a command and returns the output.
|
Runs a command and returns the output.
|
||||||
Could raise subprocess.CalledProcessError
|
Could raise subprocess.CalledProcessError
|
||||||
'''
|
'''
|
||||||
result = subprocess.check_output(command, shell=True)
|
result = subprocess.check_output(command, shell=False)
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print(result.decode().strip())
|
print(result.decode().strip())
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ def generate_password() -> str:
|
|||||||
Generates a random password using pwgen for user.
|
Generates a random password using pwgen for user.
|
||||||
Could raise subprocess.CalledProcessError
|
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
|
# endregion
|
||||||
|
|
||||||
@ -61,6 +61,7 @@ def cli():
|
|||||||
@cli.command('install-hysteria2')
|
@cli.command('install-hysteria2')
|
||||||
@click.option('--port','-p', required=True, help='New port for Hysteria2',type=int,callback=validator.validate_port)
|
@click.option('--port','-p', required=True, help='New port for Hysteria2',type=int,callback=validator.validate_port)
|
||||||
def install_hysteria2(port:int):
|
def install_hysteria2(port:int):
|
||||||
|
print(f"bash {Command.INSTALL_HYSTERIA2.value} {str(port)}")
|
||||||
run_cmd(['bash', Command.INSTALL_HYSTERIA2.value, str(port)])
|
run_cmd(['bash', Command.INSTALL_HYSTERIA2.value, str(port)])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import os
|
import os
|
||||||
|
import click
|
||||||
|
|
||||||
|
def validate_port(ctx,param,value:int) -> int:
|
||||||
def validate_port(ctx,param,value)-> bool:
|
|
||||||
if value < 1 or value > 65535:
|
if value < 1 or value > 65535:
|
||||||
return False
|
raise click.BadParameter('Port must be between 1 and 65535')
|
||||||
# check if port is in use
|
# check if port is in use
|
||||||
if os.system(f'lsof -i:{value}') == 0:
|
if os.system(f'lsof -i:{value}') == 0:
|
||||||
return False
|
raise click.BadParameter(f'Port {value} is in use')
|
||||||
return True
|
return value
|
||||||
Reference in New Issue
Block a user