2018-04-11 13:05:09 +00:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
AfterViewInit,
|
|
|
|
AfterContentInit,
|
|
|
|
ViewChild
|
|
|
|
} from '@angular/core';
|
2018-04-10 12:37:09 +00:00
|
|
|
import { Router } from '@angular/router';
|
2018-04-11 12:26:51 +00:00
|
|
|
import { TreeNode } from 'primeng/primeng';
|
2018-04-13 10:32:17 +00:00
|
|
|
import { Store, select } from '@ngrx/store';
|
|
|
|
import * as ListStore from '../../store/list';
|
|
|
|
import { ListSelector } from '../../store';
|
|
|
|
import { Page } from 'app/commons/model';
|
|
|
|
import { RPCClientError } from '@loafer/ng-rpc/protocol';
|
|
|
|
import { Target } from 'packages/target/model';
|
|
|
|
import { Infra, InfraHost, InfraOSApplication, InfraService } from '../../model';
|
|
|
|
|
|
|
|
interface HostData {
|
|
|
|
id: string;
|
|
|
|
target?: Target;
|
|
|
|
host: InfraHost;
|
|
|
|
services: InfraService[];
|
|
|
|
}
|
2018-04-10 12:37:09 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'of-infra-map',
|
2018-04-11 13:05:09 +00:00
|
|
|
templateUrl: './map.component.html'
|
2018-04-10 12:37:09 +00:00
|
|
|
})
|
|
|
|
export class MapComponent implements OnInit, AfterContentInit {
|
2018-04-11 12:26:51 +00:00
|
|
|
infraTree: TreeNode[] = testInfraList;
|
|
|
|
|
2018-04-13 10:32:17 +00:00
|
|
|
infras$ = this.listStore.pipe(select(ListSelector.select('page')));
|
|
|
|
|
2018-04-11 12:26:51 +00:00
|
|
|
display = false;
|
2018-04-13 10:32:17 +00:00
|
|
|
loading = false;
|
|
|
|
|
|
|
|
totalList: Infra[];
|
|
|
|
hostDataList: HostData[] = new Array();
|
2018-04-11 12:26:51 +00:00
|
|
|
|
2018-04-13 10:32:17 +00:00
|
|
|
DEFAULT_EXPANDED: Boolean = true;
|
2018-04-10 12:37:09 +00:00
|
|
|
|
2018-04-13 10:32:17 +00:00
|
|
|
constructor(private router: Router,
|
|
|
|
private listStore: Store<ListStore.State>,
|
|
|
|
) {}
|
|
|
|
|
|
|
|
ngAfterContentInit() {
|
|
|
|
|
|
|
|
this.infras$.subscribe(
|
|
|
|
(page: Page) => {
|
|
|
|
if (page !== null) {
|
|
|
|
this.totalList = page.content;
|
|
|
|
this.generateInfraHostData();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(error: RPCClientError) => {
|
|
|
|
console.log(error.response.message);
|
|
|
|
});
|
|
|
|
}
|
2018-04-10 12:37:09 +00:00
|
|
|
|
2018-04-11 13:05:09 +00:00
|
|
|
ngOnInit() {}
|
2018-04-11 12:26:51 +00:00
|
|
|
|
2018-04-13 10:32:17 +00:00
|
|
|
|
|
|
|
generateInfraHostData(filterStr?: string) {
|
|
|
|
|
|
|
|
const itl: TreeNode[] = [];
|
|
|
|
|
|
|
|
const root: TreeNode = {
|
|
|
|
label: 'Infra',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true,
|
|
|
|
children: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
const probeMap: Map<number, InfraHost[]> = new Map();
|
|
|
|
|
|
|
|
const hostMap: Map<number, InfraService[]> = new Map();
|
|
|
|
|
|
|
|
this.loading = true;
|
|
|
|
|
|
|
|
const infraTree = {
|
|
|
|
label: 'Infra',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true,
|
|
|
|
children: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const infra of this.totalList) {
|
|
|
|
const infraType = infra.infraType.name;
|
|
|
|
if (infraType === 'HOST') {
|
|
|
|
const infraHost: InfraHost = infra;
|
|
|
|
if (filterStr && String(infraHost.ip).indexOf(filterStr) < 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (probeMap.has(infraHost.probe.id) === false) {
|
|
|
|
probeMap.set(infraHost.probe.id, []);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ihl: InfraHost[] = probeMap.get(infraHost.probe.id);
|
|
|
|
ihl.push(infraHost);
|
|
|
|
probeMap.set(infraHost.probe.id, ihl);
|
|
|
|
// const data: HostData = {
|
|
|
|
// id: String(infra.id),
|
|
|
|
// target: infra.target,
|
|
|
|
// host: infra,
|
|
|
|
// services: new Array(),
|
|
|
|
// };
|
|
|
|
// this.hostDataList.push(data);
|
|
|
|
} else if (infraType === 'OS_SERVICE') {
|
|
|
|
const infraService: InfraService = infra;
|
|
|
|
if (filterStr && this.checkFilterString(infraService, filterStr)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hostMap.has(infraService.host.ip) === false) {
|
|
|
|
hostMap.set(infraService.host.ip, []);
|
|
|
|
}
|
|
|
|
|
|
|
|
const isl = hostMap.get(infraService.host.ip);
|
|
|
|
isl.push(infraService);
|
|
|
|
|
|
|
|
// const existHost = this.getExistHost(infraService.host);
|
|
|
|
// if (existHost !== null) {
|
|
|
|
// existHost.services.push(infraService);
|
|
|
|
// } else {
|
|
|
|
// const host: HostData = {
|
|
|
|
// id: String(infra.id),
|
|
|
|
// target: infra.target,
|
|
|
|
// host: infraService.host,
|
|
|
|
// services: new Array()
|
|
|
|
// };
|
|
|
|
// host.services.push(infraService);
|
|
|
|
// this.hostDataList.push(host);
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
const probeTreeNodes: TreeNode[] = [];
|
|
|
|
|
|
|
|
probeMap.forEach((ifhl: InfraHost[], key: number) => {
|
|
|
|
|
|
|
|
const tp: TreeNode = {
|
|
|
|
label: 'Probe - ' + key,
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: this.DEFAULT_EXPANDED.valueOf(),
|
|
|
|
children: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
ifhl.map((ih: InfraHost, idx: number) => {
|
|
|
|
|
|
|
|
const th: TreeNode = {
|
|
|
|
label: 'Host - ' + ih.ip,
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: this.DEFAULT_EXPANDED.valueOf(),
|
|
|
|
children: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
if (hostMap.has(ih.ip)) {
|
|
|
|
|
|
|
|
const ifsl = hostMap.get(ih.ip);
|
|
|
|
|
|
|
|
for (let i = 0 ; i < ifsl.length; ++i) {
|
|
|
|
const ts: TreeNode = {
|
|
|
|
label: 'Service - ' + ifsl[i].vendor.name,
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: this.DEFAULT_EXPANDED.valueOf(),
|
|
|
|
children: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
th.children.push(ts);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tp.children.push(th);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
probeTreeNodes.push(tp);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
infraTree.children.push(probeTreeNodes);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
this.loading = false;
|
|
|
|
|
|
|
|
|
|
|
|
return infraTree;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
checkFilterString(infraService: InfraService, filterStr: string) {
|
|
|
|
const upperCased = filterStr.toUpperCase().toUpperCase();
|
|
|
|
if (infraService.vendor.name.toUpperCase().indexOf(upperCased) < 0 &&
|
|
|
|
String(infraService.port).toUpperCase().indexOf(upperCased) < 0 &&
|
|
|
|
infraService.portType.toUpperCase().indexOf(upperCased)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
getExistHost(infraHost: InfraHost): HostData {
|
|
|
|
let node = null;
|
|
|
|
for (const data of this.hostDataList) {
|
|
|
|
if (data.host.ip === infraHost.ip) {
|
|
|
|
node = data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2018-04-11 12:26:51 +00:00
|
|
|
showDialog() {
|
|
|
|
this.display = true;
|
2018-04-11 13:05:09 +00:00
|
|
|
}
|
2018-04-11 12:26:51 +00:00
|
|
|
|
2018-04-13 10:32:17 +00:00
|
|
|
closeDialog() {
|
|
|
|
this.display = false;
|
|
|
|
}
|
|
|
|
|
2018-04-11 13:05:09 +00:00
|
|
|
expandAll() {
|
|
|
|
this.infraTree.forEach(node => {
|
|
|
|
this.expandRecursive(node, true);
|
|
|
|
});
|
|
|
|
}
|
2018-04-11 12:26:51 +00:00
|
|
|
|
2018-04-11 13:05:09 +00:00
|
|
|
collapseAll() {
|
|
|
|
this.infraTree.forEach(node => {
|
|
|
|
this.expandRecursive(node, false);
|
|
|
|
});
|
|
|
|
}
|
2018-04-11 12:26:51 +00:00
|
|
|
|
2018-04-11 13:05:09 +00:00
|
|
|
private expandRecursive(node: TreeNode, isExpand: boolean) {
|
|
|
|
node.expanded = isExpand;
|
|
|
|
if (node.children) {
|
|
|
|
node.children.forEach(childNode => {
|
|
|
|
this.expandRecursive(childNode, isExpand);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const testInfraList = [
|
2018-04-11 12:26:51 +00:00
|
|
|
{
|
2018-04-11 13:05:09 +00:00
|
|
|
label: 'Infra',
|
2018-04-11 12:26:51 +00:00
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
2018-04-11 13:05:09 +00:00
|
|
|
expanded: true,
|
|
|
|
children: [
|
2018-04-11 12:26:51 +00:00
|
|
|
{
|
2018-04-11 13:05:09 +00:00
|
|
|
label: 'Zone - 192.168.1.0/24',
|
2018-04-11 12:26:51 +00:00
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
2018-04-11 13:05:09 +00:00
|
|
|
expanded: true,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
label: 'Host - 192.168.1.106 - Snoop Host',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
label: 'Sensors - WMI, SSH, SNMP',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Service - FTP(21)',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
label: 'Sensors - FTP, Sensor',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Host - 192.168.1.103 - Geek Host',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
label: 'Sensors - WMI, SSH, SNMP',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Service - MySQL(3306)',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
label: 'Sensors - MySQL, PING',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Service - PostgreSQL(5555)',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
label: 'Sensors - PostgreSQL, PING',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2018-04-11 12:26:51 +00:00
|
|
|
},
|
|
|
|
{
|
2018-04-11 13:05:09 +00:00
|
|
|
label: 'Zone - 192.168.10.0/24',
|
2018-04-11 12:26:51 +00:00
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
2018-04-11 13:05:09 +00:00
|
|
|
expanded: true,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
label: 'Host - 192.168.10.106 - Snoop Host',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
label: 'Sensors - WMI, SSH, SNMP',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Service - FTP(21)',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
label: 'Sensors - FTP, Sensor',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Host - 192.168.10.103 - Geek Host',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
label: 'Sensors - WMI, SSH, SNMP',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Service - MySQL(3306)',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
label: 'Sensors - MySQL, PING',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Service - PostgreSQL(5555)',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
label: 'Sensors - PostgreSQL, PING',
|
|
|
|
expandedIcon: 'fa-folder-open',
|
|
|
|
collapsedIcon: 'fa-folder',
|
|
|
|
expanded: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|