add init_paths to handle sys.path setup for importing shared modules like paths.py
This commit is contained in:
7
core/scripts/hysteria2/init_paths.py
Normal file
7
core/scripts/hysteria2/init_paths.py
Normal file
@ -0,0 +1,7 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
core_scripts_dir = Path(__file__).resolve().parents[1]
|
||||
|
||||
if str(core_scripts_dir) not in sys.path:
|
||||
sys.path.append(str(core_scripts_dir))
|
||||
@ -6,8 +6,9 @@ import sys
|
||||
import os
|
||||
from hysteria2_api import Hysteria2Client, Hysteria2Error
|
||||
|
||||
CONFIG_FILE = '/etc/hysteria/config.json'
|
||||
API_BASE_URL = 'http://127.0.0.1:25413'
|
||||
from init_paths import *
|
||||
from paths import *
|
||||
|
||||
|
||||
def get_api_secret(config_path: str) -> str:
|
||||
if not os.path.exists(config_path):
|
||||
|
||||
@ -7,13 +7,8 @@ import subprocess
|
||||
import argparse
|
||||
import re
|
||||
from typing import Tuple, Optional, Dict, List, Any
|
||||
|
||||
CORE_DIR = "/etc/hysteria"
|
||||
CONFIG_FILE = f"{CORE_DIR}/config.json"
|
||||
USERS_FILE = f"{CORE_DIR}/users.json"
|
||||
HYSTERIA2_ENV = f"{CORE_DIR}/.configs.env"
|
||||
SINGBOX_ENV = f"{CORE_DIR}/core/scripts/singbox/.env"
|
||||
NORMALSUB_ENV = f"{CORE_DIR}/core/scripts/normalsub/.env"
|
||||
from init_paths import *
|
||||
from paths import *
|
||||
|
||||
def load_env_file(env_file: str) -> Dict[str, str]:
|
||||
"""Load environment variables from a file into a dictionary."""
|
||||
@ -29,7 +24,7 @@ def load_env_file(env_file: str) -> Dict[str, str]:
|
||||
|
||||
def load_hysteria2_env() -> Dict[str, str]:
|
||||
"""Load Hysteria2 environment variables."""
|
||||
return load_env_file(HYSTERIA2_ENV)
|
||||
return load_env_file(CONFIG_ENV)
|
||||
|
||||
def load_hysteria2_ips() -> Tuple[str, str, str]:
|
||||
"""Load Hysteria2 IPv4 and IPv6 addresses from environment."""
|
||||
|
||||
@ -4,10 +4,8 @@ import os
|
||||
import sys
|
||||
import requests
|
||||
from pathlib import Path
|
||||
|
||||
LOCALVERSION = "/etc/hysteria/VERSION"
|
||||
LATESTVERSION = "https://raw.githubusercontent.com/ReturnFI/Blitz/main/VERSION"
|
||||
LASTESTCHANGE = "https://raw.githubusercontent.com/ReturnFI/Blitz/main/changelog"
|
||||
from init_paths import *
|
||||
from paths import *
|
||||
|
||||
def version_greater_equal(version1, version2):
|
||||
version1_parts = [int(part) for part in version1.strip().split('.')]
|
||||
|
||||
@ -4,12 +4,14 @@ import re
|
||||
import json
|
||||
import sys
|
||||
|
||||
SHOW_URI_SCRIPT = "/etc/hysteria/core/scripts/hysteria2/show_user_uri.py"
|
||||
from init_paths import *
|
||||
from paths import *
|
||||
|
||||
DEFAULT_ARGS = ["-a", "-n", "-s"]
|
||||
|
||||
def run_show_uri(username):
|
||||
try:
|
||||
cmd = ["python3", SHOW_URI_SCRIPT, "-u", username] + DEFAULT_ARGS
|
||||
cmd = ["python3", CLI_PATH, "show-user-uri", "-u", username] + DEFAULT_ARGS
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
||||
output = result.stdout
|
||||
if "Invalid username" in output:
|
||||
|
||||
Reference in New Issue
Block a user