reformatted file structure and reformatted for phones, as well as fixed web sockets for remote devices

This commit is contained in:
UpstreamData
2022-03-08 11:39:10 -07:00
parent 7ba8044564
commit 43834203a8
20 changed files with 430 additions and 324 deletions

View File

@@ -0,0 +1,36 @@
import asyncio
import websockets.exceptions
from fastapi import WebSocket, WebSocketDisconnect, APIRouter
from tools.web_monitor.scan.func import do_websocket_scan
router = APIRouter()
@router.websocket("/ws")
async def websocket_scan(websocket: WebSocket):
await websocket.accept()
cur_task = None
try:
while True:
ws_data = await websocket.receive_text()
if "-Cancel-" in ws_data:
if cur_task:
cur_task.cancel()
print("Cancelling scan...")
try:
await cur_task
except asyncio.CancelledError:
cur_task = None
await websocket.send_text("Cancelled")
else:
cur_task = asyncio.create_task(
do_websocket_scan(websocket, ws_data))
if cur_task and cur_task.done():
cur_task = None
except WebSocketDisconnect:
print("Websocket disconnected.")
except websockets.exceptions.ConnectionClosedOK:
pass