From 97ade9e4eb2f112ac0eef57d9a13c468f384a3df Mon Sep 17 00:00:00 2001 From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com> Date: Mon, 2 Jun 2025 00:19:25 +0330 Subject: [PATCH] feat: Add OBFS status API endpoint --- .../routers/api/v1/config/hysteria.py | 19 ++++++++++++++++++- .../routers/api/v1/schema/config/hysteria.py | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/core/scripts/webpanel/routers/api/v1/config/hysteria.py b/core/scripts/webpanel/routers/api/v1/config/hysteria.py index 2f08f59..7c676df 100644 --- a/core/scripts/webpanel/routers/api/v1/config/hysteria.py +++ b/core/scripts/webpanel/routers/api/v1/config/hysteria.py @@ -1,5 +1,5 @@ from fastapi import APIRouter, BackgroundTasks, HTTPException, UploadFile, File -from ..schema.config.hysteria import ConfigFile, GetPortResponse, GetSniResponse +from ..schema.config.hysteria import ConfigFile, GetPortResponse, GetSniResponse, GetObfsResponse from ..schema.response import DetailResponse, IPLimitConfig, SetupDecoyRequest, DecoyStatusResponse, IPLimitConfigResponse from fastapi.responses import FileResponse import shutil @@ -223,6 +223,23 @@ async def disable_obfs(): raise HTTPException(status_code=400, detail=f'Error: {str(e)}') +@router.get('/check-obfs', response_model=GetObfsResponse, summary='Check Hysteria2 OBFS Status') +async def check_obfs(): + """ + Checks the current status of Hysteria2 OBFS. + + Returns: + A GetObfsResponse containing the Hysteria2 OBFS status message (e.g., 'OBFS is active.'). + + Raises: + HTTPException: if an error occurs while checking the Hysteria2 OBFS status. + """ + try: + obfs_status_message = cli_api.check_hysteria2_obfs() + return GetObfsResponse(obfs=obfs_status_message) + except Exception as e: + raise HTTPException(status_code=400, detail=f'Error checking OBFS status: {str(e)}') + @router.get('/enable-masquerade/{domain}', response_model=DetailResponse, summary='Enable Hysteria2 masquerade') async def enable_masquerade(domain: str): """ diff --git a/core/scripts/webpanel/routers/api/v1/schema/config/hysteria.py b/core/scripts/webpanel/routers/api/v1/schema/config/hysteria.py index 82e51a4..444db27 100644 --- a/core/scripts/webpanel/routers/api/v1/schema/config/hysteria.py +++ b/core/scripts/webpanel/routers/api/v1/schema/config/hysteria.py @@ -18,3 +18,6 @@ class GetPortResponse(BaseModel): class GetSniResponse(BaseModel): sni: str + +class GetObfsResponse(BaseModel): + obfs: str \ No newline at end of file