From d82a4beef7ba85885597622698a9bc81d655169d Mon Sep 17 00:00:00 2001 From: insanity Date: Tue, 5 Jun 2018 22:01:01 +0900 Subject: [PATCH] test --- .../component/search-result.component.html | 2 +- .../component/search-result.component.ts | 77 +++++++------------ .../infra/component/infra-map.component.ts | 14 ++-- @overflow/target/service/target.service.ts | 7 ++ package-lock.json | 6 +- 5 files changed, 47 insertions(+), 59 deletions(-) diff --git a/@overflow/discovery/component/search-result.component.html b/@overflow/discovery/component/search-result.component.html index dc5e054..7caec74 100644 --- a/@overflow/discovery/component/search-result.component.html +++ b/@overflow/discovery/component/search-result.component.html @@ -15,7 +15,7 @@
-
+
diff --git a/@overflow/discovery/component/search-result.component.ts b/@overflow/discovery/component/search-result.component.ts index eb4eed0..e09278e 100644 --- a/@overflow/discovery/component/search-result.component.ts +++ b/@overflow/discovery/component/search-result.component.ts @@ -6,8 +6,8 @@ import { OnInit, OnChanges, } from '@angular/core'; - -import { Subscription } from 'rxjs'; +import { catchError, exhaustMap, map, tap, take } from 'rxjs/operators'; +import { Subscription, Observable, of } from 'rxjs'; import { DiscoverZone, Zone, Host, Port, Service } from '@overflow/commons-typescript/model/discovery'; import { TreeNode, Message, Tree } from 'primeng/primeng'; @@ -17,6 +17,8 @@ import { ProbeHost } from '@overflow/commons-typescript/model/probe'; import { Anim } from './animation'; import { DiscoveryNotify } from '../subscriber/discovery.subscriber'; import { InfraHost, InfraService } from '@overflow/commons-typescript/model/infra'; +import { TargetService } from '../../target/service/target.service'; +import { Target } from '@overflow/commons-typescript/model/target'; @Component({ selector: 'of-discovery-result', @@ -33,13 +35,12 @@ export class SearchResultComponent implements OnInit, OnChanges { discoverySubscription: Subscription; zoneNode: TreeNode[] = []; hostNode: TreeNode[] = []; - selectedItems: TreeNode[] = []; + selectedItems = []; msgs: Message[]; - - discoveredHosts: Host[] = []; - discoveredServices: Service[] = []; + error$: Observable; constructor( + private targetService: TargetService ) { } @@ -56,8 +57,6 @@ export class SearchResultComponent implements OnInit, OnChanges { ngOnChanges(changes: SimpleChanges): void { if (changes['finished'] && changes['finished'].currentValue === true) { - this.saveInfras(); - // TODO: Comes after save infra this.msgs = []; this.msgs.push({ severity: 'success', @@ -68,12 +67,23 @@ export class SearchResultComponent implements OnInit, OnChanges { addHost(host: Host) { - this.discoveredHosts.push(host); + // this.targetService.findExistHostTarget(this.probeHost.probe.id, host.ipv4) + // .pipe( + // map((target: Target) => { + + // }), + // catchError(error => { + // this.error$ = of(error); + // return of(); + // }), + // ).subscribe(); + const idx = this.findHostIndex(host); this.hostNode.splice(idx, 0, { type: 'HOST', label: host.ipv4, data: { + exist: false, ip: this.convertIPtoNumber(host.ipv4), ipv6: host.ipv6, mac: host.mac, @@ -86,7 +96,6 @@ export class SearchResultComponent implements OnInit, OnChanges { } addService(service: Service) { - this.discoveredServices.push(service); const targetHostNode = this.findHostNodeByService(service); const idx = this.findServiceIndex(targetHostNode.children, service); targetHostNode.children.splice(idx, 0, { @@ -162,7 +171,7 @@ export class SearchResultComponent implements OnInit, OnChanges { }); } - checkHighligt(label: string) { + checkHighlight(label: string) { let highlight = true; if (this.filterWord && (label.toUpperCase().indexOf(this.filterWord.toUpperCase()) < 0)) { highlight = false; @@ -173,46 +182,18 @@ export class SearchResultComponent implements OnInit, OnChanges { return highlight; } - saveInfras() { - this.discoveredHosts.forEach(host => { - const infraHost: InfraHost = { - probe: this.probeHost.probe, - infraType: { - id: 2 - }, - os: {}, - ipv4: host.ipv4, - ipv6: host.ipv6, - mac: host.mac, - }; - }); - - this.discoveredServices.forEach(service => { - const infraService: InfraService = { - probe: this.probeHost.probe, - infraType: { - id: 7 - }, - host: { - }, - portType: service.port.portType, - port: service.port.portNumber, - vendor: { - } - }; - }); - } saveTargets() { console.log(this.selectedItems); - let node: TreeNode; - for (node of this.selectedItems) { - if (node.type === 'HOST') { - // InfraHost - } else if (node.type === 'SERVICE') { - // InfraService - // InfraOSPort? + const hosts: Host[] = []; + const services: Service[] = []; + this.selectedItems.forEach(value => { + if (value.ipv4) { + hosts.push(value); + } else { + services.push(value); } - } + }); + this.targetService.registDiscoveredTargets(this.probeHost.probe.id, null, null); } } diff --git a/@overflow/infra/component/infra-map.component.ts b/@overflow/infra/component/infra-map.component.ts index 78f5b08..ab4b1f2 100644 --- a/@overflow/infra/component/infra-map.component.ts +++ b/@overflow/infra/component/infra-map.component.ts @@ -156,7 +156,7 @@ export class InfraMapComponent implements OnInit, AfterContentInit { for (const sensor of sensorList) { const st = { - label: 'Sensors - ' + sensor.crawler.name, + label: 'Sensors - ' + sensor.metaCrawler.name, type: 'sensor', obj: sensor, expanded: true @@ -254,7 +254,7 @@ export class InfraMapComponent implements OnInit, AfterContentInit { for (let i = 0; i < ifsl.length; ++i) { const ts = { - label: 'Service - ' + ifsl[i].vendor.name, + label: 'Service - ' + ifsl[i].metaInfraVendor.name, type: 'service', expandedIcon: 'fa-folder-open', collapsedIcon: 'fa-folder', @@ -285,7 +285,7 @@ export class InfraMapComponent implements OnInit, AfterContentInit { sortInfraToMap(probeMap: Map, hostMap: Map, filterStr: string) { for (const infra of this.totalList) { - const infraType = infra.infraType.name; + const infraType = infra.metaInfraType.name; if (infraType === 'HOST') { const infraHost: InfraHost = infra; if (filterStr && String(infraHost.ipv4).indexOf(filterStr) < 0) { @@ -306,11 +306,11 @@ export class InfraMapComponent implements OnInit, AfterContentInit { continue; } - if (hostMap.has(infraService.host.ipv4) === false) { - hostMap.set(infraService.host.ipv4, []); + if (hostMap.has(infraService.infraHost.ipv4) === false) { + hostMap.set(infraService.infraHost.ipv4, []); } - const isl = hostMap.get(infraService.host.ipv4); + const isl = hostMap.get(infraService.infraHost.ipv4); isl.push(infraService); } @@ -335,7 +335,7 @@ export class InfraMapComponent implements OnInit, AfterContentInit { checkFilterString(infraService: InfraService, filterStr: string) { const upperCased = filterStr.toUpperCase().toUpperCase(); - if (infraService.vendor.name.toUpperCase().indexOf(upperCased) < 0 && + if (infraService.metaInfraVendor.name.toUpperCase().indexOf(upperCased) < 0 && String(infraService.port).toUpperCase().indexOf(upperCased) < 0 && infraService.portType.toUpperCase().indexOf(upperCased)) { return true; diff --git a/@overflow/target/service/target.service.ts b/@overflow/target/service/target.service.ts index 09e9934..8d63b5f 100644 --- a/@overflow/target/service/target.service.ts +++ b/@overflow/target/service/target.service.ts @@ -23,4 +23,11 @@ export class TargetService { return this.rpcService.call('TargetService.modify', target); } + public findExistHostTarget(probeID: number, hostIP: string): Observable { + return this.rpcService.call('TargetService.readExistHostTarget', probeID, hostIP); + } + + public findExistServiceTarget(hostID: number, portNumber: number, portType: string): Observable { + return this.rpcService.call('TargetService.readExistServiceTarget', hostID, portNumber, portType); + } } diff --git a/package-lock.json b/package-lock.json index fc110d2..60c9d05 100644 --- a/package-lock.json +++ b/package-lock.json @@ -453,9 +453,9 @@ } }, "@overflow/commons-typescript": { - "version": "0.0.7", - "resolved": "https://nexus.loafle.net/repository/npm-all/@overflow/commons-typescript/-/commons-typescript-0.0.7.tgz", - "integrity": "sha512-qbrNlHEZjUfmuExcHEQ1Bf+PNQfkAZsbinDSGU4ndD4H8hNg/Cv2i4TWaLSWVqXrbIEZkKmv4AZJC9WQTUcFPA==" + "version": "0.0.8", + "resolved": "https://nexus.loafle.net/repository/npm-all/@overflow/commons-typescript/-/commons-typescript-0.0.8.tgz", + "integrity": "sha512-yaN3kYofzzJjRJsMuRHbryWVQU6AdsmVbGBmvdKvXQrI/xZzss2K5ZRTqDAOAHEXpyk1Ty+yeXMEPihfLv5bqw==" }, "@schematics/angular": { "version": "0.6.5",