Skip to content

Commit

Permalink
fix: 任务模块字段修改
Browse files Browse the repository at this point in the history
feat: 新增cve 功能模块
  • Loading branch information
EmbraceAn committed Dec 20, 2024
1 parent 3fbcdb1 commit daed59d
Show file tree
Hide file tree
Showing 27 changed files with 948 additions and 201 deletions.
4 changes: 2 additions & 2 deletions .env.production
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# 高鹏 本地
# VITE_BASE_URL = "http://192.168.3.3:8082/"
VITE_BASE_URL = "http://192.168.3.3:8082/"

# 秦晨凯 本地
VITE_BASE_URL = "http://192.168.3.179:8082/"
# VITE_BASE_URL = "http://192.168.3.179:8082/"

# 线上 地址
# VITE_BASE_URL = "http://legion-4g.yaklang.com:8080/pre/"
7 changes: 7 additions & 0 deletions src/App/routers/routers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import SystemManagement from '@/pages/SystemManagement';
import { PortAssets } from '@/pages/DataService/PortAssets';
import { AssetsVulns } from '@/pages/DataService/AssetsVulns';
import { SensitiveMessage } from '@/pages/DataService/SensitiveMessage';
import { CveLoophole } from '@/pages/DataService/CveLoophole';

// 继承路由接口,增加name字段
type RouteObjectRootMy = RouteObject & {
Expand Down Expand Up @@ -106,6 +107,12 @@ const routers: RouteObjectRootMy[] = [
key: 'sensitive-message',
element: <SensitiveMessage />,
},
{
path: 'cve-loophole',
name: 'CVE漏洞库',
key: 'cve-loophole',
element: <CveLoophole />,
},
],
},
{
Expand Down
14 changes: 14 additions & 0 deletions src/apis/CveLoopholeApi/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import axios from '@/utils/axios';
import { ResponseData, TableResponseData } from '@/utils/commonTypes';
import { TCveQueryRequest, TCveQueryResponse } from './type';

// 节点是否安装成功
const postCveQuery = (
data: TCveQueryRequest,
): Promise<ResponseData<TableResponseData<TCveQueryResponse>>> =>
axios.post<never, ResponseData<TableResponseData<TCveQueryResponse>>>(
`/cve/query`,
data,
);

export { postCveQuery };
115 changes: 115 additions & 0 deletions src/apis/CveLoopholeApi/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
interface TCveQueryRequest {
cpe?: string[];
CPEVersion?: { [key: string]: any };
cve?: string;
CVEExploitabilityScore?: { [key: string]: any };
CVEImpactScore?: { [key: string]: any };
CVELastModifiedTime?: { [key: string]: any };
CVEPublishedTime?: { [key: string]: any };
CVESeverity?: { [key: string]: any };
cvssV2Scope?: { [key: string]: any };
cwe?: string;
keyword?: string[];
Order?: { [key: string]: any };
limit: number;
page: number;
total: number;
total_page: number;
order?: string;
order_by?: string;
}

/**
* CVEList,CVE 列表
*
* CVE,CVE 的具体内容
*/
interface TCveQueryResponse {
/**
* 攻击复杂度
*/
access_complexity: string;
/**
* 攻击路径
*/
access_vector: string;
/**
* 需要的认证情况
*/
authentication: string;
/**
* 可用性影响
*/
availability_impact: string;
/**
* CVSS 评分
*/
base_cvss_v2_score: number;
/**
* 泄密影响
*/
confidentiality_impact: string;
/**
* CVE 编号
*/
cve: string;
/**
* 漏洞类型/CWE类型
*/
cwe: string;
/**
* 漏洞详细描述信息
*/
description: string;
/**
* 精确搜索,如果为 True,表明搜索结果应该是准确的,如果为 False 说明可能不准确
*/
exact_search: boolean;
/**
* 利用评分
*/
exploitability_score: number;
/**
* CVE 的搜索来源
*/
from: string;
/**
* 影响评分
*/
impact_score: number;
/**
* 完整性影响
*/
integrity_impact: string;
/**
* 最近修改日期
*/
last_modified_date: string;
/**
* 是否可以获取所有权限
*/
obtain_all_privilege: boolean;
/**
* 是否可以获取其他权限
*/
obtain_other_privilege: boolean;
/**
* 是否可以获取用户权限
*/
obtain_user_privilege: boolean;
/**
* 发布日期
*/
published_date: string;
/**
* 严重程度
*/
severity: string;
/**
* 是否需要用户交互利用
*/
user_interaction_required: boolean;
vulnerable_product: string;
}

export type { TCveQueryRequest, TCveQueryResponse };
14 changes: 13 additions & 1 deletion src/apis/SystemManagementApi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,16 @@ const postAddUser = (
): Promise<ResponseData<TAddUserResponse>> =>
axios.post<never, ResponseData<TAddUserResponse>>('/user', data);

export { getUserList, postAddUser };
// 重置密码
const postUserReset = (data: {
username: string;
}): Promise<ResponseData<{ password: string; username: string }>> =>
axios.post<never, ResponseData<{ password: string; username: string }>>(
`/user/reset?username=${data.username}`,
);

// 添加用户
const deleteUser = (username: string): Promise<ResponseData<boolean>> =>
axios.delete<never, ResponseData<boolean>>(`/user?username=${username}`);

export { getUserList, postAddUser, postUserReset, deleteUser };
87 changes: 53 additions & 34 deletions src/compoments/WizardTable/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useMemo, useReducer, useRef } from 'react';
import { message, Spin, Table } from 'antd';
import { Button, message, Spin, Table } from 'antd';

Check failure on line 2 in src/compoments/WizardTable/index.tsx

View workflow job for this annotation

GitHub Actions / build_and_pack_frontend

'Button' is declared but its value is never read.
import { AnyObject } from 'antd/es/_util/type';
import { useRequest, useSafeState } from 'ahooks';

Expand Down Expand Up @@ -37,7 +37,7 @@ const WizardTable = <T extends AnyObject = AnyObject>(
const preFilter = useRef(undefined); // 跟踪上次的 filter, 触发请求
const manualReq = useRef(false);
// 表格容器的 ref,用来控制滚动
const tableRef = useRef<HTMLDivElement>(null);
const tableContainerRef = useRef<HTMLDivElement>(null);

const [state, dispatch] = useReducer(reducer, initialValue);
const { dataSource, params, filter } = state;
Expand Down Expand Up @@ -78,6 +78,7 @@ const WizardTable = <T extends AnyObject = AnyObject>(
}

dispatch({ loading: false, noResetFields: true });
setIsBottom(false);
}
},
{
Expand Down Expand Up @@ -106,7 +107,8 @@ const WizardTable = <T extends AnyObject = AnyObject>(
[params, filter],
);

const [wizardScrollHeight, wizardScrollWidth] = useListenWidth(tableRef);
const [wizardScrollHeight, wizardScrollWidth] =
useListenWidth(tableContainerRef);
const [isBottom, setIsBottom] = useSafeState(false);

// 表格容器的 state, 用来保存计算得到的可滚动高度和表格高度
Expand All @@ -115,10 +117,11 @@ const WizardTable = <T extends AnyObject = AnyObject>(
// 动态计算表格高度
useEffect(() => {
const tableFilterDomHeight =
tableRef.current?.children[0].getBoundingClientRect().height ?? 0;
tableContainerRef.current?.children[0].getBoundingClientRect()
.height ?? 0;
const antTableHeader =
tableRef?.current &&
tableRef.current.querySelector('.ant-table-header');
tableContainerRef?.current &&
tableContainerRef.current.querySelector('.ant-table-header');
const antTableHeaderHeight =
antTableHeader?.getBoundingClientRect().height ?? 0;

Expand All @@ -136,14 +139,15 @@ const WizardTable = <T extends AnyObject = AnyObject>(
const pagemetaStatus =
(pagemeta?.page ?? 0) * (pagemeta?.limit ?? 0) >=
(pagemeta?.total ?? 1);

if (
dataSource &&
dataSource.length > 0 &&
tableRef.current &&
tableContainerRef.current &&
!pagemetaStatus
) {
// 获取表格 DOM 节点
const tableElement = tableRef.current.querySelector(
const tableElement = tableContainerRef.current.querySelector(
'#table-container > .ant-table-wrapper',
);
if (tableElement && !state.loading) {
Expand Down Expand Up @@ -198,29 +202,17 @@ const WizardTable = <T extends AnyObject = AnyObject>(
requestTable(request);
}, [requestTable]);

// 回到顶部,并清空数据方法
const handClearFilter = () => {
if (tableRef.current) {
// 滚动条回到顶部
tableRef.current.scrollTop = 0;

dispatch({
dataSource: [], // 清空数据源
});
}
};

// 对外提供方法
// 刷新
page.refresh = async () => {
handClearFilter();
handleScrollToFirstRow();
runAsync(request, true);
};

// 手动触发
page.onLoad = (arg) => {
handClearFilter();
runAsync(request, true, arg);
page.onLoad = async (arg) => {
handleScrollToFirstRow();
await runAsync(request, false, arg);
};

// 获取表格参数
Expand All @@ -230,7 +222,7 @@ const WizardTable = <T extends AnyObject = AnyObject>(

// 清除页面选中项
page.clear = () => {
handClearFilter();
handleScrollToFirstRow();
dispatch({
params: {
page: 1,
Expand All @@ -247,6 +239,7 @@ const WizardTable = <T extends AnyObject = AnyObject>(

// 更改高级筛选项
page.editFilter = (args) => {
handleScrollToFirstRow();
dispatch({
filter: {
...state.filter,
Expand Down Expand Up @@ -312,6 +305,27 @@ const WizardTable = <T extends AnyObject = AnyObject>(
.exhaustive();
};

const tableRef = useRef<any>(null);

// 回到顶部,并清空数据方法
const handleScrollToFirstRow = () => {
if (tableRef.current) {
// 调用 scrollTo 方法,传递 (0, 0) 来滚动到顶部
tableRef.current.scrollTo(0, 0);
dispatch({
params: {
page: 1,
limit: state.params!.limit,
total: state.pagemeta!.total,
total_page: state.pagemeta!.total_page,
},
dataSource: [], // 清空数据源
});

runAsync(request, true);
}
};

// 底部loading状态
const bottomLoading = useMemo(() => {
const pagemeta = state.pagemeta;
Expand All @@ -321,16 +335,15 @@ const WizardTable = <T extends AnyObject = AnyObject>(
(pagemeta?.total ?? 1);

const width =
(tableRef.current?.getBoundingClientRect().width ?? 0) - 108;
(tableContainerRef.current?.getBoundingClientRect().width ?? 0) -
108;

return (
<div
className={`flex items-center justify-center border border-solid border-[#EAECF3] border-t-none relative bottom-14`}
className={`flex items-center justify-center border border-solid border-[#EAECF3] border-t-none relative bottom-14 pt-2`}
style={{
width: dataSource?.length
? wizardScrollWidth - 40
: wizardScrollWidth - 33,
height: dataSource?.length ? '48px' : '56px',
width: wizardScrollWidth - 32,
height: '48px',
}}
>
{pagemetaStatus &&
Expand Down Expand Up @@ -367,7 +380,7 @@ const WizardTable = <T extends AnyObject = AnyObject>(

<div
id="table-container"
ref={tableRef}
ref={tableContainerRef}
className={`transition-all duration-500 w-full p-4 bg-[#fff] relative`}
style={{
width: `${
Expand All @@ -384,7 +397,9 @@ const WizardTable = <T extends AnyObject = AnyObject>(
/>

<Table
id="table"
{...props}
ref={tableRef}
dataSource={dataSource}
columns={extendTableProps(
dispatch,
Expand All @@ -396,12 +411,16 @@ const WizardTable = <T extends AnyObject = AnyObject>(
pagination={false}
scroll={{
x: wizardScrollHeight,
y: height - 1,
y: isBottom || state.loading ? height - 48 : height,
scrollToFirstRowOnChange: true,
}}
onScroll={throttledTableOnScrollFn}
loading={state.loading && dataSource!.length === 0}
virtual
/>
{bottomLoading}
{(isBottom || state.loading) && dataSource?.length
? bottomLoading
: null}
</div>

{/* 右侧抽屉 */}
Expand Down
3 changes: 2 additions & 1 deletion src/compoments/WizardTableFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ const WizardTableFilter: FC<{
{props?.options?.trigger}

{proFilterSwitch?.trigger && !filterState?.proSwitchStatus && (
<div>
<div className="flex gap-2 justify-center items-center ml-2">
<div className="color-[#85899E]">高级筛选</div>
<Switch onChange={headSwitchChange} />
</div>
)}
Expand Down
Loading

0 comments on commit daed59d

Please sign in to comment.