Add decoy status API
This commit is contained in:
@ -12,7 +12,7 @@ DEBUG = False
|
|||||||
SCRIPT_DIR = '/etc/hysteria/core/scripts'
|
SCRIPT_DIR = '/etc/hysteria/core/scripts'
|
||||||
CONFIG_FILE = '/etc/hysteria/config.json'
|
CONFIG_FILE = '/etc/hysteria/config.json'
|
||||||
CONFIG_ENV_FILE = '/etc/hysteria/.configs.env'
|
CONFIG_ENV_FILE = '/etc/hysteria/.configs.env'
|
||||||
|
WEBPANEL_ENV_FILE = '/etc/hysteria/core/scripts/webpanel/.env'
|
||||||
|
|
||||||
class Command(Enum):
|
class Command(Enum):
|
||||||
'''Contains path to command's script'''
|
'''Contains path to command's script'''
|
||||||
@ -531,6 +531,23 @@ def stop_webpanel_decoy():
|
|||||||
'''Stops and removes the decoy site configuration for the web panel.'''
|
'''Stops and removes the decoy site configuration for the web panel.'''
|
||||||
run_cmd(['bash', Command.SHELL_WEBPANEL.value, 'stopdecoy'])
|
run_cmd(['bash', Command.SHELL_WEBPANEL.value, 'stopdecoy'])
|
||||||
|
|
||||||
|
def get_webpanel_decoy_status() -> Dict[str, Any]:
|
||||||
|
"""Checks the status of the webpanel decoy site configuration."""
|
||||||
|
try:
|
||||||
|
if not os.path.exists(WEBPANEL_ENV_FILE):
|
||||||
|
return {"active": False, "path": None}
|
||||||
|
|
||||||
|
env_vars = dotenv_values(WEBPANEL_ENV_FILE)
|
||||||
|
decoy_path = env_vars.get('DECOY_PATH')
|
||||||
|
|
||||||
|
if decoy_path and decoy_path.strip():
|
||||||
|
return {"active": True, "path": decoy_path.strip()}
|
||||||
|
else:
|
||||||
|
return {"active": False, "path": None}
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error checking decoy status: {e}")
|
||||||
|
return {"active": False, "path": None}
|
||||||
|
|
||||||
def get_webpanel_url() -> str | None:
|
def get_webpanel_url() -> str | None:
|
||||||
'''Gets the URL of WebPanel.'''
|
'''Gets the URL of WebPanel.'''
|
||||||
return run_cmd(['bash', Command.SHELL_WEBPANEL.value, 'url'])
|
return run_cmd(['bash', Command.SHELL_WEBPANEL.value, 'url'])
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
from fastapi import APIRouter, BackgroundTasks, HTTPException, UploadFile, File
|
from fastapi import APIRouter, BackgroundTasks, HTTPException, UploadFile, File
|
||||||
from ..schema.config.hysteria import ConfigFile, GetPortResponse, GetSniResponse
|
from ..schema.config.hysteria import ConfigFile, GetPortResponse, GetSniResponse
|
||||||
from ..schema.response import DetailResponse, IPLimitConfig, SetupDecoyRequest
|
from ..schema.response import DetailResponse, IPLimitConfig, SetupDecoyRequest, DecoyStatusResponse
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
import shutil
|
import shutil
|
||||||
import zipfile
|
import zipfile
|
||||||
@ -374,3 +374,14 @@ async def stop_decoy_api(background_tasks: BackgroundTasks):
|
|||||||
background_tasks.add_task(run_stop_decoy_background)
|
background_tasks.add_task(run_stop_decoy_background)
|
||||||
|
|
||||||
return DetailResponse(detail='Web Panel decoy site stop initiated. Caddy will restart in the background.')
|
return DetailResponse(detail='Web Panel decoy site stop initiated. Caddy will restart in the background.')
|
||||||
|
|
||||||
|
@router.get('/webpanel/decoy/status', response_model=DecoyStatusResponse, summary='Get WebPanel Decoy Site Status')
|
||||||
|
async def get_decoy_status_api():
|
||||||
|
"""
|
||||||
|
Checks if the decoy site is currently configured and active.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
status = cli_api.get_webpanel_decoy_status()
|
||||||
|
return DecoyStatusResponse(**status)
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(status_code=500, detail=f'Error retrieving decoy status: {str(e)}')
|
||||||
@ -12,3 +12,7 @@ class IPLimitConfig(BaseModel):
|
|||||||
class SetupDecoyRequest(BaseModel):
|
class SetupDecoyRequest(BaseModel):
|
||||||
domain: str = Field(..., description="Domain name associated with the web panel")
|
domain: str = Field(..., description="Domain name associated with the web panel")
|
||||||
decoy_path: str = Field(..., description="Absolute path to the directory containing the decoy website files")
|
decoy_path: str = Field(..., description="Absolute path to the directory containing the decoy website files")
|
||||||
|
|
||||||
|
class DecoyStatusResponse(BaseModel):
|
||||||
|
active: bool = Field(..., description="Whether the decoy site is currently configured and active")
|
||||||
|
path: Optional[str] = Field(None, description="The configured path for the decoy site, if active")
|
||||||
|
|||||||
Reference in New Issue
Block a user