File diff suppressed because it is too large
Load Diff
@ -1,52 +1,297 @@ |
||||
import { Component, Input, OnInit } from '@angular/core'; |
||||
import { Component, Input, OnInit, OnChanges, SimpleChanges, Output } from '@angular/core'; |
||||
import { NzMessageService } from 'ng-zorro-antd'; |
||||
import { NoticeService } from '../../../service/https/notice.service'; |
||||
import { exportAsExcelFile, convertKeys } from '../utils/utils'; |
||||
|
||||
// data mapping
|
||||
// IP
|
||||
const ipKeyMaps = { |
||||
'req_ip': '访问源IP', |
||||
'req_frequency': '访问频次' |
||||
}; |
||||
|
||||
const accountKeyMaps = { |
||||
'req_account': '账号', |
||||
'req_frequency': '访问频次', |
||||
'req_jobnum': '工号' |
||||
}; |
||||
|
||||
const interfaceKeyMaps = { |
||||
'interface_addr': '接口地址', |
||||
'req_ip': '访问IP', |
||||
'req_account': '访问账号', |
||||
'req_frequency': '访问频次' , |
||||
'req_jobnum': '工号' |
||||
}; |
||||
|
||||
const menuKeyMaps = { |
||||
'menu_name': '菜单名称', |
||||
'req_ip': '访问IP', |
||||
'req_account': '访问账号', |
||||
'req_frequency': '访问频次' , |
||||
'req_jobnum': '工号' |
||||
}; |
||||
|
||||
@Component({ |
||||
selector: 'app-path', |
||||
templateUrl: './path.component.html', |
||||
styleUrls: ['./path.component.styl'] |
||||
}) |
||||
export class PathComponent implements OnInit { |
||||
@Input() datas: any; |
||||
|
||||
export class PathComponent implements OnInit, OnChanges { |
||||
@Input() detail_data: any; |
||||
// @Output() detailDataChange = new EventEmitter();
|
||||
data; |
||||
viewType = 0; |
||||
|
||||
whiteListParam = {}; |
||||
greyListParam = {}; |
||||
rules; |
||||
queryLogUrl = "/WebApi/isoc/static/base/#/route/threat-state/log/action?" |
||||
// /WebApi/isoc/static/base/#/route/threat-state/log/action?startTime=1717396269&endTime=1717403469&sip=zhang3
|
||||
startTime; |
||||
endTime; |
||||
constructor( |
||||
private noticeService: NoticeService, |
||||
public message: NzMessageService, |
||||
|
||||
) {} |
||||
|
||||
ngOnInit() { |
||||
// const jsonStr = '{"type":3,"http://190.89.233.2:8909/getpublicconfig":[{"req_ip":"192.156.3.12","interface_addr":"http://190.89.233.2:8909/getpublicconfig","req_jobnum":43327,"req_frequency":43,"req_account":"liuhr"},{"req_ip":"192.156.3.12","interface_addr":"http://190.89.233.2:8909/getpublicconfig","req_jobnum":43328,"req_frequency":44,"req_account":"sunxq01"},{"req_ip":"192.156.3.18","interface_addr":"http://190.89.233.2:8909/getpublicconfig","req_jobnum":65341,"req_frequency":45,"req_account":"shicl"},{"req_ip":"192.106.3.33","interface_addr":"http://190.89.233.2:8909/getpublicconfig","req_jobnum":65342,"req_frequency":46,"req_account":"gongxs"},{"req_ip":"192.106.3.34","interface_addr":"http://190.89.233.2:8909/getpublicconfig","req_jobnum":65343,"req_frequency":47,"req_account":"sunzs"}]}'
|
||||
// if (this.datas == null) {
|
||||
// this.datas = JSON.parse(jsonStr);
|
||||
// if (this.detail_data == null) {
|
||||
// this.detail_data = JSON.parse(jsonStr);
|
||||
// }
|
||||
this.parseData(this.datas); |
||||
|
||||
if (this.rules === undefined) { |
||||
this.noticeService.getDefaultRule().subscribe( |
||||
resp => { |
||||
if (resp.code === 200) { |
||||
this.rules = resp.data; |
||||
} else { |
||||
this.message.error(resp.msg); |
||||
} |
||||
}, |
||||
error => { |
||||
this.message.error('服务器错误'); |
||||
} |
||||
); |
||||
} |
||||
} |
||||
|
||||
parseData(datas: any) { |
||||
for (const dataKey in datas) { |
||||
if (datas.hasOwnProperty(dataKey)) { |
||||
if (dataKey === 'type') { |
||||
this.viewType = datas[dataKey]; |
||||
} else { |
||||
this.data = datas[dataKey]; |
||||
ngOnChanges(changes: SimpleChanges) { |
||||
if ('detail_data' in changes) { |
||||
this.parseData(); |
||||
// 在这里处理接收到的数据
|
||||
} |
||||
} |
||||
|
||||
parseData() { |
||||
for (const dataKey in this.detail_data) { |
||||
if (this.detail_data.hasOwnProperty(dataKey)) { |
||||
|
||||
switch (dataKey) { |
||||
case 'type': |
||||
this.viewType = this.detail_data[dataKey]; |
||||
break; |
||||
case 'startTime': |
||||
this.startTime = this.detail_data[dataKey]; |
||||
break; |
||||
case 'endTime': |
||||
this.endTime = this.detail_data[dataKey]; |
||||
break; |
||||
default: |
||||
this.data = this.detail_data[dataKey]; |
||||
this.data.forEach(item => { |
||||
item['is_in_white_list'] = 0;
|
||||
item['is_in_grey_list'] = 0;
|
||||
}); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
clickWihteList(data) { |
||||
alert("点击白名单"); |
||||
let index = -1; |
||||
// this.message.success('添加白名单成功!');
|
||||
// this.data[index]['is_in_white_list'] = 1;
|
||||
this.whiteListParam['range'] = ["ueba"]; |
||||
this.whiteListParam['des'] = ""; |
||||
this.whiteListParam['is_enable'] = 1; |
||||
switch(this.viewType) { |
||||
case 1: |
||||
this.whiteListParam['fields'] = ["sip"]; |
||||
this.whiteListParam['name'] = data.req_ip + '-' + this.getCurrentTime(); |
||||
this.whiteListParam['content'] = {"sip": data.req_ip}; |
||||
this.whiteListParam['alert_rule_id'] = this.rules["white_list"]["ip"]; |
||||
index = this.data.findIndex(item => item.req_ip === data.req_ip); |
||||
break; |
||||
case 2: |
||||
this.whiteListParam['fields'] = ["url"]; |
||||
this.whiteListParam['name'] = data.interface_addr + '-' + this.getCurrentTime(); |
||||
this.whiteListParam['content'] = {"url": data.interface_addr}; |
||||
this.whiteListParam['alert_rule_id'] = this.rules["white_list"]["interface"]; |
||||
index = this.data.findIndex(item => item.interface_addr === data.interface_addr); |
||||
break; |
||||
case 3: |
||||
break; |
||||
case 4: |
||||
break; |
||||
} |
||||
this.noticeService.addWhitelist(this.whiteListParam).subscribe( |
||||
resp => { |
||||
if (resp.code === 200) { |
||||
this.message.success('添加白名单成功!'); |
||||
this.data[index]['is_in_white_list'] = 1; |
||||
} else { |
||||
this.message.error(resp.msg); |
||||
} |
||||
}, |
||||
error => { |
||||
this.message.error('服务器错误'); |
||||
} |
||||
); |
||||
var log_params = { |
||||
"action":"add wihte list", |
||||
"params":this.whiteListParam |
||||
} |
||||
|
||||
this.noticeService.writeAuditlog(log_params).subscribe(resp => { |
||||
if (resp.code !== 200) { |
||||
this.message.error("审计日志记录失败"); |
||||
} |
||||
}, |
||||
error => { |
||||
this.message.error('服务器错误'); |
||||
}); |
||||
} |
||||
|
||||
clickGreyList(data) { |
||||
alert("点击灰名单"); |
||||
let index = -1; |
||||
// this.message.success('添加灰名单成功!');
|
||||
// this.data[index]['is_in_grey_list'] = 1;
|
||||
this.greyListParam['des'] = ""; |
||||
this.greyListParam['is_enable'] = 1; |
||||
switch(this.viewType) { |
||||
case 1: |
||||
this.greyListParam['fields'] = ["sip"]; |
||||
this.greyListParam['name'] = data.req_ip + '-' + this.getCurrentTime(); |
||||
this.greyListParam['content'] = {"sip": data.req_ip}; |
||||
this.greyListParam['alert_rule_id'] = this.rules["grey_list"]["ip"]; |
||||
index = this.data.findIndex(item => item.req_ip === data.req_ip); |
||||
break; |
||||
case 2: |
||||
this.greyListParam['fields'] = ["url"]; |
||||
this.greyListParam['name'] = data.interface_addr + '-' + this.getCurrentTime(); |
||||
this.greyListParam['content'] = {"url": data.interface_addr}; |
||||
this.greyListParam['alert_rule_id'] = this.rules["grey_list"]["interface"]; |
||||
index = this.data.findIndex(item => item.interface_addr === data.interface_addr); |
||||
break; |
||||
case 3: |
||||
break; |
||||
case 4: |
||||
break; |
||||
} |
||||
this.greyListParam["type"]=0; |
||||
this.noticeService.addGreyList(this.greyListParam).subscribe( |
||||
resp => { |
||||
if (resp.code === 200) { |
||||
this.message.success('添加灰名单成功!'); |
||||
this.data[index]['is_in_grey_list'] = 1; |
||||
} else { |
||||
this.message.error(resp.msg); |
||||
} |
||||
}, |
||||
error => { |
||||
this.message.error('服务器错误'); |
||||
} |
||||
); |
||||
|
||||
var log_params = { |
||||
"action":"add greyList", |
||||
"params":this.greyListParam |
||||
} |
||||
|
||||
this.noticeService.writeAuditlog(log_params).subscribe(resp => { |
||||
if (resp.code!== 200) { |
||||
this.message.error("审计日志记录失败"); |
||||
} |
||||
}, |
||||
error => { |
||||
this.message.error('服务器错误'); |
||||
}); |
||||
} |
||||
|
||||
clickFrequency(data) { |
||||
alert("点击超链接"); |
||||
if(this.detail_data!=undefined){ |
||||
var params = "startTime="+this.detail_data.startTime+"&endTime="+this.detail_data.endTime; |
||||
switch(this.detail_data.type) { |
||||
case 1: |
||||
params += "&sip="+data.req_ip; |
||||
break; |
||||
case 2: |
||||
params += "&sip="+data.req_account; |
||||
break; |
||||
case 3: |
||||
params += "&sip="+data.interface_addr; |
||||
break; |
||||
case 4: |
||||
params += "&sip="+data.menu_name; |
||||
break; |
||||
} |
||||
|
||||
window.open(this.queryLogUrl+params, '_blank'); |
||||
} |
||||
} |
||||
|
||||
// 在组件类中
|
||||
getCurrentTime(): string { |
||||
const now = new Date(); |
||||
const year = now.getFullYear(); |
||||
const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份是从0开始的
|
||||
const day = String(now.getDate()).padStart(2, '0'); |
||||
const hours = String(now.getHours()).padStart(2, '0'); |
||||
const minutes = String(now.getMinutes()).padStart(2, '0'); |
||||
const seconds = String(now.getSeconds()).padStart(2, '0'); |
||||
|
||||
return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`; |
||||
} |
||||
exportExcel(){ |
||||
var keysMap :any; |
||||
var fileName = ""; |
||||
switch(this.viewType){ |
||||
case 1: |
||||
keysMap= ipKeyMaps; |
||||
fileName="ip维度" |
||||
break; |
||||
case 2: |
||||
keysMap= accountKeyMaps; |
||||
fileName="账号维度" |
||||
break; |
||||
case 3: |
||||
keysMap= interfaceKeyMaps; |
||||
fileName="接口维度" |
||||
break; |
||||
case 4: |
||||
keysMap= menuKeyMaps; |
||||
fileName="菜单维度" |
||||
break; |
||||
} |
||||
console.log(JSON.stringify(keysMap)); |
||||
var data =convertKeys(this.data,keysMap) |
||||
exportAsExcelFile(data,fileName); |
||||
} |
||||
|
||||
|
||||
// async getval(){
|
||||
// const [ewAssetDetailsRes, assetTypeRes] = await Promise.all([
|
||||
// this.noticeService.getUebaResult(this.di),
|
||||
// this.noticeService.getQueryRange(this.di)
|
||||
// ]);
|
||||
|
||||
// if(ewAssetDetailsRes && assetTypeRes){
|
||||
// this.ewAssetDetails = ewAssetDetailsRes.data;
|
||||
// this.assetType = assetTypeRes.data;
|
||||
// }
|
||||
// }
|
||||
|
||||
} |
||||
|
@ -0,0 +1,18 @@ |
||||
<nz-modal [(nzVisible)]="open" |
||||
[nzMaskClosable]="false" |
||||
[nzKeyboard]="false" |
||||
(nzOnCancel)="justClose()" |
||||
[nzFooter]="footer" |
||||
nzTitle="搜索进度"> |
||||
<nz-row> |
||||
<nz-col nzSpan="4">查询进度</nz-col> |
||||
<nz-col nzSpan="20"> |
||||
<nz-progress [nzPercent]="process"> |
||||
</nz-progress> |
||||
</nz-col> |
||||
</nz-row> |
||||
</nz-modal> |
||||
|
||||
<ng-template #footer> |
||||
<button nz-button (click)="cancel()">取消查询</button> |
||||
</ng-template> |
@ -0,0 +1,28 @@ |
||||
/* tslint:disable:no-unused-variable */ |
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; |
||||
import { By } from '@angular/platform-browser'; |
||||
import { DebugElement } from '@angular/core'; |
||||
|
||||
import { PathComponent } from './process.component'; |
||||
|
||||
describe('PathComponent', () => { |
||||
let component: PathComponent; |
||||
let fixture: ComponentFixture<PathComponent>; |
||||
|
||||
beforeEach(async(() => { |
||||
TestBed.configureTestingModule({ |
||||
declarations: [ PathComponent ] |
||||
}) |
||||
.compileComponents(); |
||||
})); |
||||
|
||||
beforeEach(() => { |
||||
fixture = TestBed.createComponent(PathComponent); |
||||
component = fixture.componentInstance; |
||||
fixture.detectChanges(); |
||||
}); |
||||
|
||||
it('should create', () => { |
||||
expect(component).toBeTruthy(); |
||||
}); |
||||
}); |
@ -0,0 +1,88 @@ |
||||
import { |
||||
ChangeDetectionStrategy, |
||||
ChangeDetectorRef, |
||||
Component, |
||||
EventEmitter, |
||||
Input, |
||||
OnChanges, |
||||
Output, |
||||
SimpleChanges |
||||
} from '@angular/core'; |
||||
|
||||
@Component({ |
||||
selector: 'app-process', |
||||
templateUrl: './process.component.html', |
||||
styleUrls: ['./process.component.styl'], |
||||
changeDetection: ChangeDetectionStrategy.OnPush |
||||
}) |
||||
// @ts-ignore
|
||||
export class ProcessComponent implements OnChanges { |
||||
// @ts-ignore
|
||||
@Input() visible = false; |
||||
// @ts-ignore
|
||||
// tslint:disable-next-line:no-output-on-prefix
|
||||
@Output() onCancel = new EventEmitter(); |
||||
|
||||
open = false; |
||||
process = 0; |
||||
intervalId = -1; |
||||
|
||||
constructor( |
||||
private cdr: ChangeDetectorRef |
||||
) {} |
||||
|
||||
ngOnChanges(changes: SimpleChanges): void { |
||||
const visible = changes['visible']; |
||||
|
||||
if (visible.currentValue !== null) { |
||||
if (visible.currentValue) { |
||||
this.start(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
random() { |
||||
const acc = Math.ceil(Math.random() * 10); |
||||
const added = this.process + acc; |
||||
this.process = added >= 99 ? 99 : added; |
||||
} |
||||
|
||||
start() { |
||||
this.open = true; |
||||
this.process = 0; |
||||
clearTimeout(this.intervalId); |
||||
this.ticker(); |
||||
} |
||||
|
||||
ticker() { |
||||
this.intervalId = setTimeout(() => { |
||||
if (this.visible) { |
||||
this.random(); |
||||
this.ticker(); |
||||
} else { |
||||
this.process = 100; |
||||
this.autoClose(); |
||||
} |
||||
this.cdr.markForCheck(); |
||||
}, 1000); |
||||
} |
||||
|
||||
cancel() { |
||||
this.open = false; |
||||
clearTimeout(this.intervalId); |
||||
this.onCancel.emit(); |
||||
} |
||||
|
||||
autoClose() { |
||||
clearTimeout(this.intervalId); |
||||
setTimeout(() => { |
||||
this.open = false; |
||||
this.cdr.markForCheck(); |
||||
}, 300); |
||||
} |
||||
|
||||
justClose() { |
||||
this.open = false; |
||||
clearTimeout(this.intervalId); |
||||
} |
||||
} |
@ -0,0 +1,33 @@ |
||||
import * as XLSX from 'xlsx';
|
||||
import { saveAs } from 'file-saver';
|
||||
|
||||
const EXCEL_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8';
|
||||
const EXCEL_EXTENSION = '.xlsx'; |
||||
export function exportAsExcelFile(json: any[], excelFileName: string): void {
|
||||
const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json);
|
||||
const workbook: XLSX.WorkBook = { Sheets: { 'data': worksheet }, SheetNames: ['data'] };
|
||||
const excelBuffer: any = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
|
||||
saveAsExcelFile(excelBuffer, excelFileName);
|
||||
} |
||||
|
||||
export function saveAsExcelFile(buffer: any, fileName: string): void {
|
||||
const data: Blob = new Blob([buffer], {
|
||||
type: EXCEL_TYPE
|
||||
});
|
||||
saveAs(data, fileName + '_export_' + new Date().getTime() + EXCEL_EXTENSION);
|
||||
} |
||||
|
||||
export function convertKeys<Raw = any, Target = any>(excelData: Raw[], keysMap: Record<string, string>): Target[] { |
||||
return excelData.map(excelItem => { |
||||
const reorderedItem: any = {}; |
||||
|
||||
// 按照keysMap中定义的顺序重建对象
|
||||
Object.entries(keysMap).forEach(([originalKey, newKey]) => { |
||||
if (excelItem.hasOwnProperty(originalKey)) { |
||||
reorderedItem[newKey] = excelItem[originalKey]; |
||||
} |
||||
}); |
||||
|
||||
return reorderedItem; |
||||
}); |
||||
} |
@ -1,5 +1,5 @@ |
||||
export const environment = { |
||||
production: true, |
||||
productionUrls: '/WebApi/notice/static/dist/', |
||||
productionUrls: '/WebApi/uebaMetricsAnalysis/static/dist/', |
||||
hashPrefx: '' |
||||
}; |
||||
|
Loading…
Reference in new issue