Add decoy status API

This commit is contained in:
Whispering Wind
2025-04-26 13:31:19 +03:30
committed by GitHub
parent fa7090a88b
commit c1d8c422af
3 changed files with 36 additions and 4 deletions

View File

@ -1,6 +1,6 @@
from fastapi import APIRouter, BackgroundTasks, HTTPException, UploadFile, File
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
import shutil
import zipfile
@ -373,4 +373,15 @@ async def stop_decoy_api(background_tasks: BackgroundTasks):
"""
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)}')

View File

@ -11,4 +11,8 @@ class IPLimitConfig(BaseModel):
class SetupDecoyRequest(BaseModel):
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")