Fix cli.py install-hysteria2
This commit is contained in:
@ -6,9 +6,9 @@ import io
|
|||||||
import click
|
import click
|
||||||
import subprocess
|
import subprocess
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
from contextlib import redirect_stdout
|
|
||||||
|
|
||||||
import traffic
|
import traffic
|
||||||
|
import validator
|
||||||
|
|
||||||
SCRIPT_DIR = 'scripts'
|
SCRIPT_DIR = 'scripts'
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
@ -58,8 +58,9 @@ def cli():
|
|||||||
|
|
||||||
# region hysteria2 menu options
|
# region hysteria2 menu options
|
||||||
@cli.command('install-hysteria2')
|
@cli.command('install-hysteria2')
|
||||||
def install_hysteria2():
|
@click.option('--port','-p', required=True, help='New port for Hysteria2',type=int,validate=validator.validate_port)
|
||||||
run_cmd(['bash', Command.INSTALL_HYSTERIA2])
|
def install_hysteria2(port:int):
|
||||||
|
run_cmd(['bash', Command.INSTALL_HYSTERIA2, str(port)])
|
||||||
|
|
||||||
|
|
||||||
@cli.command('uninstall-hysteria2')
|
@cli.command('uninstall-hysteria2')
|
||||||
@ -76,7 +77,7 @@ def restart_hysteria2():
|
|||||||
|
|
||||||
|
|
||||||
@cli.command('change-hysteria2-port')
|
@cli.command('change-hysteria2-port')
|
||||||
@click.option('--port','-p', required=True, help='New port for Hysteria2',type=int)
|
@click.option('--port','-p', required=True, help='New port for Hysteria2',type=int,validate=validator.validate_port)
|
||||||
def change_hysteria2_port(port:int):
|
def change_hysteria2_port(port:int):
|
||||||
run_cmd(['bash', Command.CHANGE_PORT_HYSTERIA2, str(port)])
|
run_cmd(['bash', Command.CHANGE_PORT_HYSTERIA2, str(port)])
|
||||||
|
|
||||||
|
|||||||
10
core/validator.py
Normal file
10
core/validator.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def validate_port(p:int)-> bool:
|
||||||
|
if p < 1 or p > 65535:
|
||||||
|
return False
|
||||||
|
# check if port is in use
|
||||||
|
if os.system(f'lsof -i:{p}') == 0:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
Reference in New Issue
Block a user