Implement ip APIs
This commit is contained in:
@ -4,6 +4,7 @@ from . import warp
|
||||
from . import telegram
|
||||
from . import normalsub
|
||||
from . import singbox
|
||||
from . import ip
|
||||
from . import misc
|
||||
|
||||
router = APIRouter()
|
||||
@ -14,4 +15,5 @@ router.include_router(warp.router, prefix='/warp')
|
||||
router.include_router(telegram.router, prefix='/telegram')
|
||||
router.include_router(normalsub.router, prefix='/normalsub')
|
||||
router.include_router(singbox.router, prefix='/singbox')
|
||||
router.include_router(ip.router, prefix='/ip')
|
||||
router.include_router(misc.router)
|
||||
|
||||
29
core/scripts/webpanel/routers/api/v1/config/ip.py
Normal file
29
core/scripts/webpanel/routers/api/v1/config/ip.py
Normal file
@ -0,0 +1,29 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from ..schema.response import DetailResponse
|
||||
|
||||
|
||||
from ..schema.config.ip import EditInputBody
|
||||
import cli_api
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get('/add')
|
||||
async def add():
|
||||
try:
|
||||
cli_api.add_ip_address()
|
||||
return DetailResponse(detail='IP addresses added successfully.')
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=400, detail=f'Error: {str(e)}')
|
||||
|
||||
|
||||
@router.post('/edit', response_model=DetailResponse)
|
||||
async def edit(body: EditInputBody):
|
||||
try:
|
||||
if not body.ipv4 and not body.ipv6:
|
||||
raise HTTPException(status_code=400, detail='Error: You must specify either ipv4 or ipv6')
|
||||
|
||||
cli_api.edit_ip_address(str(body.ipv4), str(body.ipv6))
|
||||
return DetailResponse(detail='IP address edited successfully.')
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=400, detail=f'Error: {str(e)}')
|
||||
7
core/scripts/webpanel/routers/api/v1/schema/config/ip.py
Normal file
7
core/scripts/webpanel/routers/api/v1/schema/config/ip.py
Normal file
@ -0,0 +1,7 @@
|
||||
from pydantic import BaseModel
|
||||
from ipaddress import IPv4Address, IPv6Address
|
||||
|
||||
|
||||
class EditInputBody(BaseModel):
|
||||
ipv4: IPv4Address | None = None
|
||||
ipv6: IPv6Address | None = None
|
||||
Reference in New Issue
Block a user