This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
cyber-narrator-cn-ui/src/utils/api.js

199 lines
8.1 KiB
JavaScript
Raw Normal View History

2021-06-11 23:00:33 +08:00
/**
* @author 陈劲松
* @date 2021/6/11
* @description 1.定义api2.定义通用查询方法函数名应为 获取详情getItem获取列表getItemList例如getUsergetUserList
2021-06-11 23:00:33 +08:00
*/
import { get, post } from '@/utils/http'
2021-10-16 15:50:12 +08:00
import axios from 'axios'
import { sortByOrderNum } from '@/permission'
2021-08-11 22:14:23 +08:00
import { storageKey } from '@/utils/constants'
2021-06-11 23:00:33 +08:00
2021-06-15 09:25:10 +08:00
export const api = {
// 系统相关
permission: '/sys/user/permissions',
i18n: '/sys/i18n/lang',
dict: '/sys/dict',
2021-09-02 17:12:27 +08:00
user: '/sys/user',
role: '/sys/role',
galaxyProxy: '/galaxy/setting',
operationLog: '/sys/log',
chartList: '/visual/chart/list',
// 业务
2021-06-15 09:25:10 +08:00
panel: '/visual/panel',
2021-07-07 22:58:52 +08:00
chart: '/visual/chart',
entityList: '/interface/entity/list/basic',
2022-01-05 20:24:02 +08:00
entityListTotal: '/interface/entity/list/total',
2021-08-11 22:14:23 +08:00
entityCount: '/interface/entity/total',
entityFilter: '/interface/entity/filter/count',
entityFilterTop: '/interface/entity/filter/top',
2021-09-30 00:50:11 +08:00
ipThroughput: '/interface/entity/ip/detail/throughput',
domainThroughput: '/interface/entity/domain/detail/throughput',
appThroughput: '/interface/entity/app/detail/throughput',
2021-12-31 10:40:37 +08:00
filterTop: '/interface/entity/filter/top',
entityTotal: '/interface/entity/index/total',
entityNew: '/interface/entity/index/new',
entityActive: '/interface/entity/index/active',
entityTraffic: '/interface/entity/list/traffic',
entityAlertNum: '/interface/entity/list/alertNum',
entitySecurityNum: '/interface/entity/list/detectionNum',
ipBytes: '/interface/entity/detail/ip/bytes',
domainBytes: '/interface/entity/detail/domain/bytes',
2022-01-04 14:54:26 +08:00
appBytes: '/interface/entity/detail/app/bytes',
// app detail
entityAppDetailTraffic: '/interface/entity/detail/overview/app/traffic',
entityAppDetailRelation: '/interface/entity/detail/overview/app/relation',
entityAppDetailNetworkQuantity: '/interface/entity/detail/overview/app/networkQuantity',
entityAppDetailLinkIn: '/interface/entity/detail/overview/app/linkIn',
entityAppDetailLinkOut: '/interface/entity/detail/overview/app/linkOut',
2022-01-04 14:54:26 +08:00
entityAppDetailAlert: '/interface/entity/detail/overview/app/alert',
entityAppDetailSecurity: '/interface/entity/detail/overview/app/security',
entityAppRelatedServerDomain: '/interface/entity/detail/overview/app/relatedDomain',
entityAppRelatedServerIp: '/interface/entity/detail/overview/app/relatedServerIp',
2022-01-04 14:54:26 +08:00
// domain detail
entityDomainDetailBasic: '/interface/entity/detail/overview/domain/basic',
entityDomainDetailTraffic: '/interface/entity/detail/overview/domain/traffic',
entityDomainDetailRelation: '/interface/entity/detail/overview/domain/relation',
entityDomainDetailNetworkQuantity: '/interface/entity/detail/overview/domain/networkQuantity',
entityDomainDetailLinkIn: '/interface/entity/detail/overview/domain/linkIn',
entityDomainDetailLinkOut: '/interface/entity/detail/overview/domain/linkOut',
entityDomainDetailAlert: '/interface/entity/detail/overview/domain/alert',
entityDomainDetailSecurity: '/interface/entity/detail/overview/domain/security',
entityDomainRelatedServerIp: '/interface/entity/detail/overview/domain/relatedServerIp',
entityDomainRelatedServerApp: '/interface/entity/detail/overview/domain/relatedApp',
2022-01-04 14:54:26 +08:00
// ip detail
entityIpDetailTraffic: '/interface/entity/detail/overview/ip/traffic',
entityIpDetailTrafficMap: '/interface/entity/detail/ip/trafficMap',
entityDomainDetailTrafficMap: '/interface/entity/detail/domain/trafficMap',
entityAppDetailTrafficMap: '/interface/entity/detail/app/trafficMap',
2022-01-04 14:54:26 +08:00
entityIpDetailRelation: '/interface/entity/detail/overview/ip/relation',
entityIpDetailNetworkQuantity: '/interface/entity/detail/overview/ip/networkQuantity',
entityIpDetailLinkIn: '/interface/entity/detail/overview/ip/linkIn',
entityIpDetailLinkOut: '/interface/entity/detail/overview/ip/linkOut',
2022-01-04 14:54:26 +08:00
entityIpDetailAlert: '/interface/entity/detail/overview/ip/alert',
entityIpDetailSecurity: '/interface/entity/detail/overview/ip/security',
entityIpRelatedServerDomain: '/interface/entity/detail/overview/ip/relatedDomain',
entityIpRelatedServerApp: '/interface/entity/detail/overview/ip/relatedApp',
// detection
detection: {
securityEvent: {
2022-02-28 11:53:37 +08:00
eventSeverityTrend: '/interface/detection/security/filter/severityTrend',
securityType: '/interface/detection/security/filter/securityType',
offenderIp: '/interface/detection/security/filter/offenderIp',
offenderLocation: '/interface/detection/security/filter/offenderLocation',
victimIp: '/interface/detection/security/filter/victimIp',
victimLocation: '/interface/detection/security/filter/victimLocation',
eventSeverity: '/interface/detection/security/filter/severity',
listBasic: '/interface/detection/security/list/basic',
listCount: '/interface/detection/security/list/count',
2022-02-28 11:53:37 +08:00
overviewBasic: '/interface/detection/security/detail/overview/basic',
overviewEvent: '/interface/detection/security/detail/overview/event'
},
performanceEvent: {
2022-02-28 11:53:37 +08:00
eventSeverityTrend: '/interface/detection/performance/filter/severityTrend',
2022-03-04 15:46:30 +08:00
eventType: '/interface/detection/performance/filter/eventType',
2022-02-28 11:53:37 +08:00
eventSeverity: '/interface/detection/performance/filter/severity',
activeEntity: '/interface/detection/performance/filter/activeEntity',
listBasic: '/interface/detection/performance/list/basic',
listCount: '/interface/detection/performance/list/count',
2022-02-28 11:53:37 +08:00
overviewBasic: '/interface/detection/performance/detail/overview/basic'
}
},
2021-06-15 09:25:10 +08:00
}
/* panel */
2021-06-11 23:00:33 +08:00
export async function getPanelList (params) {
2021-06-15 09:25:10 +08:00
return await getData(api.panel, params, true)
2021-06-11 23:00:33 +08:00
}
export async function getPanel (id) {
return await getData(`${api.chart}/${id}`)
}
/* chart */
export async function getChartList (params) {
return await getData(api.chart, params, true)
}
export async function getChart (id) {
return await getData(`${api.chart}/${id}`)
2021-06-11 23:00:33 +08:00
}
2021-08-11 22:14:23 +08:00
/* entity列表 */
export async function getEntityList (params) {
return await getData(api.entityList, params, true)
2021-07-07 22:58:52 +08:00
}
2021-08-11 22:14:23 +08:00
/* entity总数 */
export async function getEntityCount (params) {
return await getData(api.entityCount, params)
}
2021-08-11 22:14:23 +08:00
/* ip类型entity过滤器数据 */
export async function getEntityFilter (params) {
return await getData(api.entityFilter, params, true)
}
/* 字典 */
export async function getDictList (params) {
return await getData(api.dict, params, true)
}
2021-06-11 23:00:33 +08:00
export async function getData (url, params = {}, isQueryList) {
2021-08-11 22:14:23 +08:00
const request = new Promise((resolve, reject) => {
try {
get(url, params).then(response => {
if (response.code === 200) {
resolve(isQueryList ? response.data.list || response.data.result : response.data.result || response.data)
} else {
reject(response)
}
})
} catch (e) {
reject(e)
}
}).catch(response => {
console.error(response)
2021-06-11 23:00:33 +08:00
})
return await request
}
export async function getConfigJson () {
const request = new Promise(resolve => {
get(`${process.env.BASE_URL}config.json?Timestamp=${new Date().getTime()}`).then(config => {
resolve(config)
})
})
return await request
}
export async function getPermission () {
const request = new Promise(resolve => {
2022-01-03 22:46:22 +08:00
post(api.permission, { token: localStorage.getItem('cn-token') }).then(response => {
resolve({
menuList: sortByOrderNum(response.data.menus),
buttonList: response.data.buttons,
roleList: response.data.roles
})
})
})
return await request
}
export async function getI18n () {
2022-02-21 10:52:14 +08:00
const dictData = await getDictList({ type: 'lang' })
const langs = dictData.map(d => d.value).join(',')
2022-01-03 22:46:22 +08:00
localStorage.setItem(storageKey.languages, langs)
const request = new Promise(resolve => {
get(api.i18n, { l: langs }).then(response => {
response.data.cn = response.data.zh
resolve(response.data)
})
})
return await request
}
2021-07-01 15:39:48 +08:00
2021-07-05 17:40:43 +08:00
/* 获得原始的3611-2 json字符串数据 */
export async function getIso36112JsonData (suffix) {
const request = new Promise(resolve => {
2021-10-16 15:50:12 +08:00
axios({
2021-11-11 23:28:52 +08:00
url: `${window.location.protocol}//${window.location.host}:${window.location.port}/geojson/${suffix}.json`
2021-10-16 15:50:12 +08:00
}).then(response => {
resolve(response.data || response || null)
2021-07-05 17:40:43 +08:00
})
2021-07-01 15:39:48 +08:00
})
2021-07-05 17:40:43 +08:00
return await request
2021-07-01 15:39:48 +08:00
}