2018-05-30 09:39:26 +00:00
|
|
|
import {
|
|
|
|
AfterContentInit, Component, Input,
|
|
|
|
EventEmitter,
|
2018-05-30 14:05:58 +00:00
|
|
|
Output,
|
2018-06-01 11:25:51 +00:00
|
|
|
SimpleChanges,
|
|
|
|
OnInit,
|
2018-06-05 02:56:45 +00:00
|
|
|
OnChanges,
|
2018-05-30 09:39:26 +00:00
|
|
|
} from '@angular/core';
|
2018-06-04 08:55:47 +00:00
|
|
|
|
2018-06-01 11:25:51 +00:00
|
|
|
import { Subscription } from 'rxjs';
|
2018-06-04 08:55:47 +00:00
|
|
|
|
|
|
|
import { DiscoverZone, Zone, Host, Port, Service } from '@overflow/commons-typescript/model/discovery';
|
2018-06-05 06:07:12 +00:00
|
|
|
import { TreeNode, Message, Tree } from 'primeng/primeng';
|
2018-06-04 08:55:47 +00:00
|
|
|
|
2018-06-01 11:25:51 +00:00
|
|
|
import { ProbeHost } from '@overflow/commons-typescript/model/probe';
|
2018-05-30 09:39:26 +00:00
|
|
|
|
2018-06-04 08:55:47 +00:00
|
|
|
import { Anim } from './animation';
|
|
|
|
import { DiscoveryNotify } from '../subscriber/discovery.subscriber';
|
2018-06-05 06:07:12 +00:00
|
|
|
import { InfraHost, InfraService } from '@overflow/commons-typescript/model/infra';
|
2018-06-04 08:55:47 +00:00
|
|
|
|
2018-05-30 09:39:26 +00:00
|
|
|
@Component({
|
|
|
|
selector: 'of-discovery-result',
|
|
|
|
templateUrl: './search-result.component.html',
|
2018-05-30 14:05:58 +00:00
|
|
|
animations: Anim
|
2018-05-30 09:39:26 +00:00
|
|
|
})
|
2018-06-05 02:56:45 +00:00
|
|
|
export class SearchResultComponent implements OnInit, OnChanges {
|
2018-05-30 09:39:26 +00:00
|
|
|
|
2018-06-01 11:25:51 +00:00
|
|
|
@Input() probeHost: ProbeHost;
|
2018-06-04 08:31:00 +00:00
|
|
|
@Input() filterWord: string;
|
2018-06-05 02:56:45 +00:00
|
|
|
@Input() filterServices: Map<string, boolean>;
|
|
|
|
@Input() finished: boolean;
|
2018-05-30 14:05:58 +00:00
|
|
|
|
2018-06-01 11:25:51 +00:00
|
|
|
discoverySubscription: Subscription;
|
2018-06-01 07:32:16 +00:00
|
|
|
zoneNode: TreeNode[] = [];
|
|
|
|
hostNode: TreeNode[] = [];
|
2018-06-05 06:07:12 +00:00
|
|
|
selectedItems: TreeNode[] = [];
|
2018-06-05 02:56:45 +00:00
|
|
|
msgs: Message[];
|
2018-05-30 09:39:26 +00:00
|
|
|
|
2018-06-05 06:07:12 +00:00
|
|
|
infraHosts = [];
|
|
|
|
infraServices = [];
|
|
|
|
|
2018-05-30 09:39:26 +00:00
|
|
|
constructor(
|
|
|
|
) {
|
2018-06-01 11:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2018-06-01 07:32:16 +00:00
|
|
|
this.zoneNode.push({
|
2018-06-01 11:25:51 +00:00
|
|
|
label: this.probeHost.probe.cidr,
|
|
|
|
type: 'ZONE',
|
|
|
|
data: {
|
|
|
|
},
|
2018-06-01 07:32:16 +00:00
|
|
|
children: this.hostNode,
|
|
|
|
expanded: true
|
|
|
|
});
|
2018-05-30 09:39:26 +00:00
|
|
|
}
|
2018-05-30 14:05:58 +00:00
|
|
|
|
2018-06-05 02:56:45 +00:00
|
|
|
ngOnChanges(changes: SimpleChanges): void {
|
|
|
|
if (changes['finished'] && changes['finished'].currentValue === true) {
|
2018-06-05 06:07:12 +00:00
|
|
|
// this.saveInfras();
|
|
|
|
// TODO: Comes after save infra
|
2018-06-05 02:56:45 +00:00
|
|
|
this.msgs = [];
|
|
|
|
this.msgs.push({
|
|
|
|
severity: 'success',
|
|
|
|
summary: 'Discovery가 완료되었습니다. 모니터링 대상(들)을 선택 후 저장하세요.',
|
|
|
|
});
|
|
|
|
}
|
2018-05-30 14:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-04 08:31:00 +00:00
|
|
|
addHost(host: Host) {
|
2018-06-01 11:25:51 +00:00
|
|
|
const idx = this.findHostIndex(host);
|
2018-06-01 07:32:16 +00:00
|
|
|
this.hostNode.splice(idx, 0, {
|
2018-06-01 11:25:51 +00:00
|
|
|
type: 'HOST',
|
|
|
|
label: host.ipv4,
|
|
|
|
data: {
|
|
|
|
ip: this.convertIPtoNumber(host.ipv4),
|
2018-06-05 06:07:12 +00:00
|
|
|
ipv6: host.ipv6,
|
|
|
|
mac: host.mac,
|
|
|
|
openPorts: [],
|
|
|
|
zone: host.zone,
|
2018-06-01 11:25:51 +00:00
|
|
|
},
|
2018-06-01 07:32:16 +00:00
|
|
|
expanded: true,
|
|
|
|
children: []
|
|
|
|
});
|
|
|
|
}
|
2018-06-04 12:50:46 +00:00
|
|
|
|
2018-06-04 08:31:00 +00:00
|
|
|
addService(service: Service) {
|
2018-06-01 11:25:51 +00:00
|
|
|
const targetHostNode = this.findHostNodeByService(service);
|
|
|
|
const idx = this.findServiceIndex(targetHostNode.children, service);
|
2018-06-04 12:50:46 +00:00
|
|
|
targetHostNode.children.splice(idx, 0, {
|
2018-06-01 11:25:51 +00:00
|
|
|
type: 'SERVICE',
|
2018-06-04 09:25:48 +00:00
|
|
|
label: service.serviceName + ' (' + service.port.portNumber + ')',
|
2018-06-01 11:25:51 +00:00
|
|
|
data: {
|
2018-06-04 09:25:48 +00:00
|
|
|
name: service.serviceName,
|
2018-06-01 11:25:51 +00:00
|
|
|
portType: service.port.portType,
|
|
|
|
portNumber: service.port.portNumber,
|
2018-06-05 06:07:12 +00:00
|
|
|
host: service.port.host
|
2018-06-01 11:25:51 +00:00
|
|
|
},
|
2018-06-04 12:50:46 +00:00
|
|
|
});
|
2018-06-01 11:25:51 +00:00
|
|
|
}
|
2018-06-04 08:31:00 +00:00
|
|
|
addPort(port: Port) {
|
|
|
|
this.hostNode.forEach(node => {
|
2018-06-04 12:50:46 +00:00
|
|
|
if (node.data.id === port.host.id) {
|
2018-06-04 08:31:00 +00:00
|
|
|
node.data.openPorts.push(port);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-06-01 11:25:51 +00:00
|
|
|
|
|
|
|
onTargetSelect(e, data) {
|
|
|
|
if (e.checked) {
|
|
|
|
this.selectedItems.push(data);
|
|
|
|
} else {
|
|
|
|
const index = this.selectedItems.indexOf(data);
|
|
|
|
this.selectedItems.splice(index, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
findHostIndex(host: Host): number {
|
|
|
|
let index = 0;
|
|
|
|
this.hostNode.forEach(node => {
|
|
|
|
if (node.data.ip < this.convertIPtoNumber(host.ipv4)) {
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
findServiceIndex(serviceNodes: TreeNode[], service: Service) {
|
|
|
|
let index = 0;
|
|
|
|
serviceNodes.forEach(node => {
|
2018-06-04 12:50:46 +00:00
|
|
|
// if (node.data.portNumber < service.port.portNumber) {
|
2018-06-04 09:25:48 +00:00
|
|
|
// index++;
|
|
|
|
// }
|
2018-06-04 12:50:46 +00:00
|
|
|
if (node.data.name.toUpperCase().localeCompare(service.serviceName.toUpperCase()) === -1) {
|
|
|
|
index++;
|
|
|
|
}
|
2018-06-01 11:25:51 +00:00
|
|
|
});
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
findHostNodeByService(service: Service) {
|
|
|
|
let targetHost = null;
|
|
|
|
this.hostNode.forEach((value, i) => {
|
2018-06-04 12:50:46 +00:00
|
|
|
if (value.data.ip === this.convertIPtoNumber(service.port.host.ipv4)) {
|
|
|
|
targetHost = value;
|
2018-06-04 04:13:06 +00:00
|
|
|
return;
|
2018-06-01 11:25:51 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return targetHost;
|
|
|
|
}
|
|
|
|
|
|
|
|
convertIPtoNumber(ip: string) {
|
|
|
|
return ip.split('.').map((octet, index, array) => {
|
|
|
|
// tslint:disable-next-line:radix
|
|
|
|
return parseInt(octet) * Math.pow(256, (array.length - index - 1));
|
|
|
|
}).reduce((prev, curr) => {
|
|
|
|
return prev + curr;
|
2018-06-01 07:32:16 +00:00
|
|
|
});
|
|
|
|
}
|
2018-06-04 08:31:00 +00:00
|
|
|
|
2018-06-05 02:56:45 +00:00
|
|
|
checkHighligtHost(label: string) {
|
|
|
|
if (!this.filterWord) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-06-04 12:50:46 +00:00
|
|
|
if (this.filterWord &&
|
2018-06-05 02:56:45 +00:00
|
|
|
label.toUpperCase().indexOf(this.filterWord.toUpperCase()) > 0) {
|
2018-06-04 09:25:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2018-06-04 08:31:00 +00:00
|
|
|
}
|
2018-06-04 12:50:46 +00:00
|
|
|
|
|
|
|
checkHighligtService(name: string) {
|
2018-06-05 02:56:45 +00:00
|
|
|
if (this.filterServices && (this.filterServices[name])) {
|
|
|
|
return true;
|
2018-06-04 12:50:46 +00:00
|
|
|
}
|
2018-06-05 02:56:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-05 06:07:12 +00:00
|
|
|
saveInfras(host: Host, service: Service) {
|
|
|
|
// Host
|
|
|
|
const infraHost: InfraHost = {
|
|
|
|
probe: this.probeHost.probe,
|
|
|
|
infraType: {
|
|
|
|
id: 2
|
|
|
|
},
|
|
|
|
os: {},
|
|
|
|
ipv4: host.ipv4,
|
|
|
|
ipv6: host.ipv6,
|
|
|
|
mac: host.mac,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Service
|
|
|
|
const infraService: InfraService = {
|
|
|
|
probe: this.probeHost.probe,
|
|
|
|
infraType: {
|
|
|
|
id: 7
|
|
|
|
},
|
|
|
|
host: {
|
|
|
|
},
|
|
|
|
portType: service.port.portType,
|
|
|
|
port: service.port.portNumber,
|
|
|
|
vendor: {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-06-05 02:56:45 +00:00
|
|
|
saveTargets() {
|
|
|
|
console.log(this.selectedItems);
|
2018-06-05 06:07:12 +00:00
|
|
|
let node: TreeNode;
|
|
|
|
for (node of this.selectedItems) {
|
|
|
|
if (node.type === 'HOST') {
|
|
|
|
// InfraHost
|
|
|
|
} else if (node.type === 'SERVICE') {
|
|
|
|
// InfraService
|
|
|
|
// InfraOSPort?
|
|
|
|
}
|
|
|
|
}
|
2018-06-04 12:50:46 +00:00
|
|
|
}
|
2018-05-30 09:39:26 +00:00
|
|
|
}
|