Implement get-webpanel-api-token command
This commit is contained in:
@ -422,6 +422,15 @@ def get_web_panel_url():
|
|||||||
click.echo(f'Hysteria web panel is now running. The service is accessible on: {url}')
|
click.echo(f'Hysteria web panel is now running. The service is accessible on: {url}')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
click.echo(f'{e}', err=True)
|
click.echo(f'{e}', err=True)
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command('get-webpanel-api-token')
|
||||||
|
def get_web_panel_api_token():
|
||||||
|
try:
|
||||||
|
token = cli_api.get_webpanel_api_token()
|
||||||
|
click.echo(f'WebPanel API token: {token}')
|
||||||
|
except Exception as e:
|
||||||
|
click.echo(f'{e}', err=True)
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,8 @@ import subprocess
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import json
|
import json
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import traffic
|
import traffic
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
@ -172,7 +174,7 @@ def disable_hysteria2_masquerade():
|
|||||||
# region User
|
# region User
|
||||||
|
|
||||||
|
|
||||||
def list_users() -> dict | None:
|
def list_users() -> dict[str, dict[str, Any]] | None:
|
||||||
'''
|
'''
|
||||||
Lists all users.
|
Lists all users.
|
||||||
'''
|
'''
|
||||||
@ -180,7 +182,7 @@ def list_users() -> dict | None:
|
|||||||
return json.loads(res)
|
return json.loads(res)
|
||||||
|
|
||||||
|
|
||||||
def get_user(username: str) -> dict | None:
|
def get_user(username: str) -> dict[str, Any] | None:
|
||||||
'''
|
'''
|
||||||
Retrieves information about a specific user.
|
Retrieves information about a specific user.
|
||||||
'''
|
'''
|
||||||
@ -205,7 +207,7 @@ def edit_user(username: str, new_username: str | None, new_traffic_limit: int |
|
|||||||
'''
|
'''
|
||||||
if not username:
|
if not username:
|
||||||
raise InvalidInputError('Error: username is required')
|
raise InvalidInputError('Error: username is required')
|
||||||
if not any([new_username, new_traffic_limit, new_expiration_days, renew_password, renew_creation_date, blocked is not None]):
|
if not any([new_username, new_traffic_limit, new_expiration_days, renew_password, renew_creation_date, blocked is not None]): # type: ignore
|
||||||
raise InvalidInputError('Error: at least one option is required')
|
raise InvalidInputError('Error: at least one option is required')
|
||||||
if new_traffic_limit is not None and new_traffic_limit <= 0:
|
if new_traffic_limit is not None and new_traffic_limit <= 0:
|
||||||
raise InvalidInputError('Error: traffic limit must be greater than 0')
|
raise InvalidInputError('Error: traffic limit must be greater than 0')
|
||||||
@ -410,5 +412,9 @@ def stop_webpanel():
|
|||||||
|
|
||||||
def get_webpanel_url():
|
def get_webpanel_url():
|
||||||
return run_cmd(['bash', Command.SHELL_WEBPANEL.value, 'url'])
|
return run_cmd(['bash', Command.SHELL_WEBPANEL.value, 'url'])
|
||||||
|
|
||||||
|
|
||||||
|
def get_webpanel_api_token():
|
||||||
|
return run_cmd(['bash', Command.SHELL_WEBPANEL.value, 'api-token'])
|
||||||
# endregion
|
# endregion
|
||||||
# endregion
|
# endregion
|
||||||
|
|||||||
@ -169,6 +169,11 @@ show_webpanel_url() {
|
|||||||
echo "$webpanel_url"
|
echo "$webpanel_url"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
show_webpanel_api_token() {
|
||||||
|
source /etc/hysteria/core/scripts/webpanel/.env
|
||||||
|
echo "$API_TOKEN"
|
||||||
|
}
|
||||||
|
|
||||||
stop_service() {
|
stop_service() {
|
||||||
echo "Stopping Caddy..."
|
echo "Stopping Caddy..."
|
||||||
systemctl disable caddy.service
|
systemctl disable caddy.service
|
||||||
@ -195,6 +200,9 @@ case "$1" in
|
|||||||
url)
|
url)
|
||||||
show_webpanel_url
|
show_webpanel_url
|
||||||
;;
|
;;
|
||||||
|
api-token)
|
||||||
|
show_webpanel_api_token
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo -e "${red}Usage: $0 {start|stop} <DOMAIN> <PORT> ${NC}"
|
echo -e "${red}Usage: $0 {start|stop} <DOMAIN> <PORT> ${NC}"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user