Browse Source

packet update

main
gsd 4 months ago
parent
commit
dc7c31945f
  1. 4
      authManager.py
  2. 51
      dbService.py
  3. 1
      service.py
  4. 32
      ui/src/app/utils/PortNums.ts
  5. 27
      webExtensions/packetEndpoint.py

4
authManager.py

@ -21,6 +21,7 @@ class AuthManager:
def __init__(self, args):
self.salt = args.web_salt
self.enable = args.web_auth_enable
self.code_store = {}
async def storeCleaner(self):
@ -45,6 +46,9 @@ class AuthManager:
def decorator(func):
@wraps(func)
async def wrapper(*args, **kwargs):
if not self.enable:
return await func(*args, **kwargs)
request: Request = kwargs.get("request", None)
if request is None:
raise HTTPException(status_code=500, detail="Authed endpoint need request arg, but is missing")

51
dbService.py

@ -1,7 +1,8 @@
from typing import List
from pymongo.asynchronous.database import AsyncDatabase
from typing import List
class DbService:
class NodeDbService:
def __init__(self, dbStore):
self.dbStore:AsyncDatabase = dbStore
@ -84,4 +85,50 @@ class DbService:
]
collection = self.dbStore['node_info']
c = await collection.aggregate(pipeline)
return await c.to_list()
return await c.to_list()
class PacketDbService:
def __init__(self, dbStore):
self.dbStore:AsyncDatabase = dbStore
async def findPacketsAndGroupCount(self,
after: float = -1,
before: float = -1,
nums: List[int] = [],
portnums: List[int] = []):
pipeline = []
match = {}
if after != -1 or before != -1:
match["ts"] = {}
if after != -1:
match["ts"]["$gt"] = after
if before != -1:
match["ts"]["$lt"] = before
if nums:
if type(nums) != list:
nums = [nums]
match["from"] = {"$in":nums}
if portnums:
if type(portnums) != list:
portnums = [portnums]
match["portnums"] = {"$in":portnums}
if match:
pipeline.append({"$match":match})
#групировка по количеству на выхлопе _id номер портнума и count число его юзов
pipeline.append({"$group": {"_id": "$portnum", "count": {"$sum": 1}}})
###print(pipeline)
collection = self.dbStore['packet']
c = await collection.aggregate(pipeline)
return await c.to_list()
class DbService(NodeDbService, PacketDbService):
def __init__(self, dbStore):
NodeDbService.__init__(self, dbStore)
PacketDbService.__init__(self, dbStore)

1
service.py

@ -253,6 +253,7 @@ if __name__ == "__main__":
parser.add_argument("--web-host", default="0.0.0.0")
parser.add_argument("--web-port", default=8680)
parser.add_argument("--web-salt", default=generate_random_string(32))
parser.add_argument("--web-auth-enable", default=False, action="store_true")
#mongodb
parser.add_argument("--mongo-url")
parser.add_argument("--mongo-host", default="192.168.3.2")

32
ui/src/app/utils/PortNums.ts

@ -0,0 +1,32 @@
export class PortNums {
0: "UNKNOWN_APP";
1: "TEXT_MESSAGE_APP";
2: "REMOTE_HARDWARE_APP";
3: "POSITION_APP";
4: "NODEINFO_APP";
5: "ROUTING_APP";
6: "ADMIN_APP";
7: "TEXT_MESSAGE_COMPRESSED_APP";
8: "WAYPOINT_APP";
9: "AUDIO_APP";
10: "DETECTION_SENSOR_APP";
11: "ALERT_APP";
32: "REPLY_APP";
33: "IP_TUNNEL_APP";
34: "PAXCOUNTER_APP";
64: "SERIAL_APP";
65: "STORE_FORWARD_APP";
66: "RANGE_TEST_APP";
67: "TELEMETRY_APP";
68: "ZPS_APP";
69: "SIMULATOR_APP";
70: "TRACEROUTE_APP";
71: "NEIGHBORINFO_APP";
72: "ATAK_PLUGIN";
73: "MAP_REPORT_APP";
74: "POWERSTRESS_APP";
76: "RETICULUM_TUNNEL_APP";
256: "PRIVATE_APP";
257: "ATAK_FORWARDER";
511: "MAX";
}

27
webExtensions/packetEndpoint.py

@ -0,0 +1,27 @@
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from fastapi.requests import Request
from fastapi import Query
from pymongo.asynchronous.database import AsyncDatabase
from extra.MessageDTO import MessageDTO
from typing import List, Annotated
from pymongo import DESCENDING
class WebExtension:
MESSAGE_PORTNUM = 1
app: FastAPI
dbStore: AsyncDatabase
def __init__(self, core):
self.core = core
self.app = core.app
@self.app.get(f"{self.core.context}/packet/stats")
@self.core.authManager.authRequest()
async def findPacketsAndGroupCount(request: Request,
after: float = Query(-1),
before: float = Query(-1),
nums: List[int] = Query([]),
portnums: List[int] = Query([])):
gl = await self.core.dbService.findPacketsAndGroupCount(after, before, nums, portnums)
return gl
Loading…
Cancel
Save