项目-子域名BUG
This commit is contained in:
parent
c6b59b76f3
commit
9ac4e1d332
|
@ -5,6 +5,7 @@
|
||||||
# @time : 2024/7/8 21:02
|
# @time : 2024/7/8 21:02
|
||||||
# -------------------------------------------
|
# -------------------------------------------
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import copy
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
@ -89,6 +90,39 @@ async def get_projects_vul_data(request_data: dict, db=Depends(get_mongo_db), _:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def process_domains(root_domains, query, db):
|
||||||
|
cursor: AsyncIOMotorCursor = db['subdomain'].find(query, {
|
||||||
|
"_id": 0, "id": {"$toString": "$_id"}, "host": 1, "type": 1, "value": 1, "ip": 1, "time": 1
|
||||||
|
}).sort([("time", -1)])
|
||||||
|
result = await cursor.to_list(length=None)
|
||||||
|
|
||||||
|
domain_results = {root_domain: [] for root_domain in root_domains}
|
||||||
|
for r in result:
|
||||||
|
host = r.get('host', '')
|
||||||
|
for root_domain in root_domains:
|
||||||
|
if host.endswith(root_domain):
|
||||||
|
domain_results[root_domain].append(r)
|
||||||
|
break
|
||||||
|
|
||||||
|
processed_results = []
|
||||||
|
for root_domain, result_list in domain_results.items():
|
||||||
|
for r in result_list:
|
||||||
|
if r['value'] is None:
|
||||||
|
r['value'] = []
|
||||||
|
if r['ip'] is None:
|
||||||
|
r['ip'] = []
|
||||||
|
processed_results.append({
|
||||||
|
"host": root_domain,
|
||||||
|
"type": "",
|
||||||
|
"value": [],
|
||||||
|
"ip": [],
|
||||||
|
"id": generate_random_string(5),
|
||||||
|
"children": result_list,
|
||||||
|
"count": len(result_list)
|
||||||
|
})
|
||||||
|
|
||||||
|
return processed_results
|
||||||
|
|
||||||
@router.post("/project/subdomain/data")
|
@router.post("/project/subdomain/data")
|
||||||
async def get_projects_subdomain_data(request_data: dict, db=Depends(get_mongo_db), _: dict = Depends(verify_token)):
|
async def get_projects_subdomain_data(request_data: dict, db=Depends(get_mongo_db), _: dict = Depends(verify_token)):
|
||||||
filter = request_data.get("filter", {})
|
filter = request_data.get("filter", {})
|
||||||
|
@ -101,21 +135,8 @@ async def get_projects_subdomain_data(request_data: dict, db=Depends(get_mongo_d
|
||||||
query = await get_search_query("subdomain", request_data)
|
query = await get_search_query("subdomain", request_data)
|
||||||
if query == "":
|
if query == "":
|
||||||
return {"message": "Search condition parsing error", "code": 500}
|
return {"message": "Search condition parsing error", "code": 500}
|
||||||
results = []
|
root_domains = doc["root_domains"]
|
||||||
for root_domain in doc["root_domains"]:
|
results = await process_domains(root_domains, query, db)
|
||||||
query["$and"].append({"host": {"$regex": f"{root_domain}$"}})
|
|
||||||
cursor: AsyncIOMotorCursor = db['subdomain'].find(query, {
|
|
||||||
"_id": 0, "id": {"$toString": "$_id"}, "host": 1, "type": 1, "value": 1, "ip": 1, "time": 1
|
|
||||||
}).sort([("time", -1)])
|
|
||||||
result = await cursor.to_list(length=None)
|
|
||||||
result_list = []
|
|
||||||
for r in result:
|
|
||||||
if r['value'] is None:
|
|
||||||
r['value'] = []
|
|
||||||
if r['ip'] is None:
|
|
||||||
r['ip'] = []
|
|
||||||
result_list.append(r)
|
|
||||||
results.append({"host": root_domain, "type": "", "value": [], "ip": [], "id": generate_random_string(5), "children": result_list, "count": len(result_list)})
|
|
||||||
return {
|
return {
|
||||||
"code": 200,
|
"code": 200,
|
||||||
"data": {
|
"data": {
|
||||||
|
|
Loading…
Reference in New Issue